fixing tests for new script internals 2

This commit is contained in:
Manuel Araoz 2014-12-11 11:46:25 -03:00
parent 016bc6e3ed
commit f5b7f73d09
2 changed files with 32 additions and 29 deletions

View File

@ -202,14 +202,14 @@ Script.prototype.toString = function() {
* @returns true if this is a pay to pubkey hash output script
*/
Script.prototype.isPublicKeyHashOut = function() {
return this.chunks[0] && this.chunks[0].opcodenum === Opcode.OP_DUP &&
return !!(this.chunks[0] && this.chunks[0].opcodenum === Opcode.OP_DUP &&
this.chunks[1] &&
this.chunks[1].opcodenum === Opcode.OP_HASH160 &&
this.chunks[2].buf &&
this.chunks[3] &&
this.chunks[3].opcodenum === Opcode.OP_EQUALVERIFY &&
this.chunks[4] &&
this.chunks[4].opcodenum === Opcode.OP_CHECKSIG;
this.chunks[4].opcodenum === Opcode.OP_CHECKSIG);
};
/**
@ -272,7 +272,9 @@ Script.prototype.isScriptHashIn = function() {
return false;
}
var redeemScript = new Script(scriptBuf);
console.log(redeemScript.toString());
var type = redeemScript.classify();
console.log('type='+type);
return type !== Script.types.UNKNOWN;
};
@ -281,11 +283,11 @@ Script.prototype.isScriptHashIn = function() {
*/
Script.prototype.isMultisigOut = function() {
return (this.chunks.length > 3 &&
Opcode.isSmallIntOp(this.chunks[0]) &&
Opcode.isSmallIntOp(this.chunks[0].opcodenum) &&
this.chunks.slice(1, this.chunks.length - 2).every(function(obj) {
return obj.buf && bufferUtil.isBuffer(obj.buf);
}) &&
Opcode.isSmallIntOp(this.chunks[this.chunks.length - 2]) &&
Opcode.isSmallIntOp(this.chunks[this.chunks.length - 2].opcodenum) &&
this.chunks[this.chunks.length - 1] === Opcode.map.OP_CHECKMULTISIG);
};

View File

@ -242,31 +242,6 @@ describe('Script', function() {
});
describe('#isScripthashIn', function() {
it('should identify this known scripthashin', function() {
Script('OP_0 73 0x30460221008ca148504190c10eea7f5f9c283c719a37be58c3ad617928011a1bb9570901d2022100ced371a23e86af6f55ff4ce705c57d2721a09c4d192ca39d82c4239825f75a9801 72 0x30450220357011fd3b3ad2b8f2f2d01e05dc6108b51d2a245b4ef40c112d6004596f0475022100a8208c93a39e0c366b983f9a80bfaf89237fcd64ca543568badd2d18ee2e1d7501 OP_PUSHDATA1 105 0x5221024c02dff2f0b8263a562a69ec875b2c95ffad860f428acf2f9e8c6492bd067d362103546324a1351a6b601c623b463e33b6103ca444707d5b278ece1692f1aa7724a42103b1ad3b328429450069cc3f9fa80d537ee66ba1120e93f3f185a5bf686fb51e0a53ae').isScriptHashIn().should.equal(true);
});
it('should identify this known non-scripthashin', function() {
Script('20 0000000000000000000000000000000000000000 OP_CHECKSIG').isScriptHashIn().should.equal(false);
});
});
describe('#isScripthashOut', function() {
it('should identify this known pubkeyhashout as pubkeyhashout', function() {
Script('OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL').isScriptHashOut().should.equal(true);
});
it('should identify these known non-pubkeyhashout as not pubkeyhashout', function() {
Script('OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL OP_EQUAL').isScriptHashOut().should.equal(false);
Script('OP_HASH160 21 0x000000000000000000000000000000000000000000 OP_EQUAL').isScriptHashOut().should.equal(false);
});
});
describe('#isMultisigOut', function() {
it('should identify known multisig out 1', function() {
Script('OP_2 21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 OP_2 OP_CHECKMULTISIG').isMultisigOut().should.equal(true);
@ -301,6 +276,32 @@ describe('Script', function() {
});
});
describe('#isScriptHashIn', function() {
it('should identify this known scripthashin', function() {
var sstr = 'OP_0 73 0x30460221008ca148504190c10eea7f5f9c283c719a37be58c3ad617928011a1bb9570901d2022100ced371a23e86af6f55ff4ce705c57d2721a09c4d192ca39d82c4239825f75a9801 72 0x30450220357011fd3b3ad2b8f2f2d01e05dc6108b51d2a245b4ef40c112d6004596f0475022100a8208c93a39e0c366b983f9a80bfaf89237fcd64ca543568badd2d18ee2e1d7501 OP_PUSHDATA1 105 0x5221024c02dff2f0b8263a562a69ec875b2c95ffad860f428acf2f9e8c6492bd067d362103546324a1351a6b601c623b463e33b6103ca444707d5b278ece1692f1aa7724a42103b1ad3b328429450069cc3f9fa80d537ee66ba1120e93f3f185a5bf686fb51e0a53ae';
var s = Script(sstr);
s.toString().should.equal(sstr);
s.isScriptHashIn().should.equal(true);
});
it('should identify this known non-scripthashin', function() {
Script('20 0000000000000000000000000000000000000000 OP_CHECKSIG').isScriptHashIn().should.equal(false);
});
});
describe('#isScripthashOut', function() {
it('should identify this known pubkeyhashout as pubkeyhashout', function() {
Script('OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL').isScriptHashOut().should.equal(true);
});
it('should identify these known non-pubkeyhashout as not pubkeyhashout', function() {
Script('OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL OP_EQUAL').isScriptHashOut().should.equal(false);
Script('OP_HASH160 21 0x000000000000000000000000000000000000000000 OP_EQUAL').isScriptHashOut().should.equal(false);
});
});
describe('#isPushOnly', function() {
it('should know these scripts are or aren\'t push only', function() {
Script('OP_NOP 1 0x01').isPushOnly().should.equal(false);