fix regressions

This commit is contained in:
Manuel Araoz 2015-04-29 18:55:42 -03:00
parent dfc075e5d1
commit d556a0c33d
7 changed files with 13 additions and 27 deletions

View File

@ -9,6 +9,9 @@ var BufferReader = function BufferReader(buf) {
if (!(this instanceof BufferReader)) {
return new BufferReader(buf);
}
if (_.isUndefined(buf)) {
return;
}
if (Buffer.isBuffer(buf)) {
this.set({
buf: buf

View File

@ -93,10 +93,6 @@ Script.fromBuffer = function(buffer) {
opcodenum: opcodenum
});
} else {
var op = Opcode.reverseMap[opcodenum];
if (!op) {
throw new errors.Script.InvalidBuffer(buffer.toString('hex'));
}
script.chunks.push({
opcodenum: opcodenum
});

View File

@ -123,7 +123,8 @@ Input.prototype.setScript = function(script) {
this._scriptBuffer = new Buffer(script, 'hex');
} else if (_.isString(script)) {
// human readable string script
this._scriptBuffer = script.toBuffer();
this._script = new Script(script);
this._scriptBuffer = this._script.toBuffer();
} else if (BufferUtil.isBuffer(script)) {
// buffer script
this._scriptBuffer = new buffer.Buffer(script);

View File

@ -1017,7 +1017,7 @@ Transaction.prototype.verify = function() {
var isCoinbase = this.isCoinbase();
if (isCoinbase) {
var buf = this.inputs[0]._script.toBuffer();
var buf = this.inputs[0]._scriptBuffer;
if (buf.length < 2 || buf.length > 100) {
return 'coinbase transaction script size invalid';
}

View File

@ -36,6 +36,7 @@ Script.fromBitcoindString = function(str) {
var tstr = token.slice(1, token.length - 1);
var cbuf = new Buffer(tstr);
tbuf = Script().add(cbuf).toBuffer();
//bw.writeUInt8(tstr.length);
bw.write(tbuf);
} else if (typeof Opcode['OP_' + token] !== 'undefined') {
opstr = 'OP_' + token;
@ -196,9 +197,6 @@ describe('Interpreter', function() {
var scriptPubkey = Script.fromBitcoindString(vector[1]);
var flags = getFlags(vector[2]);
//testToFromString(scriptSig);
//testToFromString(scriptPubkey);
var hashbuf = new Buffer(32);
hashbuf.fill(0);
var credtx = new Transaction();
@ -242,7 +240,8 @@ describe('Interpreter', function() {
var fullScriptString = vector[0] + ' ' + vector[1];
var comment = descstr ? (' (' + descstr + ')') : '';
it('should pass script_' + (expected ? '' : 'in') + 'valid ' +
'vector #' + c + ': ' + fullScriptString + comment, function() {
'vector #' + c + ': ' + fullScriptString + comment,
function() {
testFixture(vector, expected);
});
});
@ -279,12 +278,15 @@ describe('Interpreter', function() {
var tx = new Transaction(txhex);
var allInputsVerified = true;
tx.inputs.forEach(function(txin, j) {
if (txin.isNull()) {
return;
}
var scriptSig = txin.script;
var txidhex = txin.prevTxId.toString('hex');
var txoutnum = txin.outputIndex;
var scriptPubkey = map[txidhex + ':' + txoutnum];
should.exist(scriptPubkey);
should.exist(scriptSig);
(scriptSig !== undefined).should.equal(true);
var interp = new Interpreter();
var verified = interp.verify(scriptSig, scriptPubkey, tx, j, flags);
if (!verified) {

View File

@ -11,8 +11,6 @@ var Opcode = bitcore.Opcode;
var PublicKey = bitcore.PublicKey;
var Address = bitcore.Address;
var script_valid = require('../data/bitcoind/script_valid');
describe('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);
});
});
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');
});
});
});

View File

@ -73,7 +73,6 @@ describe('Transaction.Input', function() {
it('fromObject should work', function() {
var input = Input.fromJSON(coinbaseJSON);
var obj = input.toObject();
obj.script = new Buffer(obj.script, 'hex');
Input.fromObject(obj).should.deep.equal(input);
obj.script = 42;
Input.fromObject.bind(null, obj).should.throw('Invalid argument type: script');