fix regressions
This commit is contained in:
parent
dfc075e5d1
commit
d556a0c33d
@ -9,6 +9,9 @@ var BufferReader = function BufferReader(buf) {
|
|||||||
if (!(this instanceof BufferReader)) {
|
if (!(this instanceof BufferReader)) {
|
||||||
return new BufferReader(buf);
|
return new BufferReader(buf);
|
||||||
}
|
}
|
||||||
|
if (_.isUndefined(buf)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Buffer.isBuffer(buf)) {
|
if (Buffer.isBuffer(buf)) {
|
||||||
this.set({
|
this.set({
|
||||||
buf: buf
|
buf: buf
|
||||||
|
|||||||
@ -93,10 +93,6 @@ Script.fromBuffer = function(buffer) {
|
|||||||
opcodenum: opcodenum
|
opcodenum: opcodenum
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var op = Opcode.reverseMap[opcodenum];
|
|
||||||
if (!op) {
|
|
||||||
throw new errors.Script.InvalidBuffer(buffer.toString('hex'));
|
|
||||||
}
|
|
||||||
script.chunks.push({
|
script.chunks.push({
|
||||||
opcodenum: opcodenum
|
opcodenum: opcodenum
|
||||||
});
|
});
|
||||||
|
|||||||
@ -123,7 +123,8 @@ Input.prototype.setScript = function(script) {
|
|||||||
this._scriptBuffer = new Buffer(script, 'hex');
|
this._scriptBuffer = new Buffer(script, 'hex');
|
||||||
} else if (_.isString(script)) {
|
} else if (_.isString(script)) {
|
||||||
// human readable string script
|
// human readable string script
|
||||||
this._scriptBuffer = script.toBuffer();
|
this._script = new Script(script);
|
||||||
|
this._scriptBuffer = this._script.toBuffer();
|
||||||
} else if (BufferUtil.isBuffer(script)) {
|
} else if (BufferUtil.isBuffer(script)) {
|
||||||
// buffer script
|
// buffer script
|
||||||
this._scriptBuffer = new buffer.Buffer(script);
|
this._scriptBuffer = new buffer.Buffer(script);
|
||||||
|
|||||||
@ -1017,7 +1017,7 @@ Transaction.prototype.verify = function() {
|
|||||||
|
|
||||||
var isCoinbase = this.isCoinbase();
|
var isCoinbase = this.isCoinbase();
|
||||||
if (isCoinbase) {
|
if (isCoinbase) {
|
||||||
var buf = this.inputs[0]._script.toBuffer();
|
var buf = this.inputs[0]._scriptBuffer;
|
||||||
if (buf.length < 2 || buf.length > 100) {
|
if (buf.length < 2 || buf.length > 100) {
|
||||||
return 'coinbase transaction script size invalid';
|
return 'coinbase transaction script size invalid';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ Script.fromBitcoindString = function(str) {
|
|||||||
var tstr = token.slice(1, token.length - 1);
|
var tstr = token.slice(1, token.length - 1);
|
||||||
var cbuf = new Buffer(tstr);
|
var cbuf = new Buffer(tstr);
|
||||||
tbuf = Script().add(cbuf).toBuffer();
|
tbuf = Script().add(cbuf).toBuffer();
|
||||||
|
//bw.writeUInt8(tstr.length);
|
||||||
bw.write(tbuf);
|
bw.write(tbuf);
|
||||||
} else if (typeof Opcode['OP_' + token] !== 'undefined') {
|
} else if (typeof Opcode['OP_' + token] !== 'undefined') {
|
||||||
opstr = 'OP_' + token;
|
opstr = 'OP_' + token;
|
||||||
@ -196,9 +197,6 @@ describe('Interpreter', function() {
|
|||||||
var scriptPubkey = Script.fromBitcoindString(vector[1]);
|
var scriptPubkey = Script.fromBitcoindString(vector[1]);
|
||||||
var flags = getFlags(vector[2]);
|
var flags = getFlags(vector[2]);
|
||||||
|
|
||||||
//testToFromString(scriptSig);
|
|
||||||
//testToFromString(scriptPubkey);
|
|
||||||
|
|
||||||
var hashbuf = new Buffer(32);
|
var hashbuf = new Buffer(32);
|
||||||
hashbuf.fill(0);
|
hashbuf.fill(0);
|
||||||
var credtx = new Transaction();
|
var credtx = new Transaction();
|
||||||
@ -242,7 +240,8 @@ describe('Interpreter', function() {
|
|||||||
var fullScriptString = vector[0] + ' ' + vector[1];
|
var fullScriptString = vector[0] + ' ' + vector[1];
|
||||||
var comment = descstr ? (' (' + descstr + ')') : '';
|
var comment = descstr ? (' (' + descstr + ')') : '';
|
||||||
it('should pass script_' + (expected ? '' : 'in') + 'valid ' +
|
it('should pass script_' + (expected ? '' : 'in') + 'valid ' +
|
||||||
'vector #' + c + ': ' + fullScriptString + comment, function() {
|
'vector #' + c + ': ' + fullScriptString + comment,
|
||||||
|
function() {
|
||||||
testFixture(vector, expected);
|
testFixture(vector, expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -279,12 +278,15 @@ describe('Interpreter', function() {
|
|||||||
var tx = new Transaction(txhex);
|
var tx = new Transaction(txhex);
|
||||||
var allInputsVerified = true;
|
var allInputsVerified = true;
|
||||||
tx.inputs.forEach(function(txin, j) {
|
tx.inputs.forEach(function(txin, j) {
|
||||||
|
if (txin.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var scriptSig = txin.script;
|
var scriptSig = txin.script;
|
||||||
var txidhex = txin.prevTxId.toString('hex');
|
var txidhex = txin.prevTxId.toString('hex');
|
||||||
var txoutnum = txin.outputIndex;
|
var txoutnum = txin.outputIndex;
|
||||||
var scriptPubkey = map[txidhex + ':' + txoutnum];
|
var scriptPubkey = map[txidhex + ':' + txoutnum];
|
||||||
should.exist(scriptPubkey);
|
should.exist(scriptPubkey);
|
||||||
should.exist(scriptSig);
|
(scriptSig !== undefined).should.equal(true);
|
||||||
var interp = new Interpreter();
|
var interp = new Interpreter();
|
||||||
var verified = interp.verify(scriptSig, scriptPubkey, tx, j, flags);
|
var verified = interp.verify(scriptSig, scriptPubkey, tx, j, flags);
|
||||||
if (!verified) {
|
if (!verified) {
|
||||||
|
|||||||
@ -11,8 +11,6 @@ var Opcode = bitcore.Opcode;
|
|||||||
var PublicKey = bitcore.PublicKey;
|
var PublicKey = bitcore.PublicKey;
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
|
|
||||||
var script_valid = require('../data/bitcoind/script_valid');
|
|
||||||
|
|
||||||
describe('Script', function() {
|
describe('Script', function() {
|
||||||
|
|
||||||
it('should make a new script', function() {
|
it('should make a new script', function() {
|
||||||
@ -754,19 +752,6 @@ describe('Script', function() {
|
|||||||
Script().add(new Buffer('a')).equals(Script().add(new Buffer('b'))).should.equal(false);
|
Script().add(new Buffer('a')).equals(Script().add(new Buffer('b'))).should.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('coinbase transaction input script for tx ', function() {
|
|
||||||
it('fails for that specific malformed script', function() {
|
|
||||||
var hex = '03984b05' + // push 0x03 bytes with block height
|
|
||||||
'e4' + // attempt to push 0xe4 bytes, but should use OP_PUSHDATA 0xe4
|
|
||||||
'b883e5bda9e7a59ee4bb99e9b1bcfabe6d6d5cb348c1c7d58062783520' +
|
|
||||||
'2f5ad93c2f3db10bb850a1a513979f8328d9f35aff1000000000000000' +
|
|
||||||
'006189dd01cf00004d696e6564206279207975313333353131373131';
|
|
||||||
var fails = function() {
|
|
||||||
return new Script(hex);
|
|
||||||
};
|
|
||||||
fails.should.throw('Invalid script buffer: can\'t parse valid script from given buffer');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -73,7 +73,6 @@ describe('Transaction.Input', function() {
|
|||||||
it('fromObject should work', function() {
|
it('fromObject should work', function() {
|
||||||
var input = Input.fromJSON(coinbaseJSON);
|
var input = Input.fromJSON(coinbaseJSON);
|
||||||
var obj = input.toObject();
|
var obj = input.toObject();
|
||||||
obj.script = new Buffer(obj.script, 'hex');
|
|
||||||
Input.fromObject(obj).should.deep.equal(input);
|
Input.fromObject(obj).should.deep.equal(input);
|
||||||
obj.script = 42;
|
obj.script = 42;
|
||||||
Input.fromObject.bind(null, obj).should.throw('Invalid argument type: script');
|
Input.fromObject.bind(null, obj).should.throw('Invalid argument type: script');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user