Skip to content

Commit

Permalink
fix classify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maraoz committed Dec 2, 2014
1 parent 9d6ff4d commit 7d9151a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions lib/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,17 @@ Script.prototype.isScriptHashOut = function() {
* Note that these are frequently indistinguishable from pubkeyhashin
*/
Script.prototype.isScriptHashIn = function() {
return this.chunks.every(function(chunk) {
return Buffer.isBuffer(chunk.buf);
});
var chunk = this.chunks[this.chunks.length - 1];
if (!chunk) {
return false;
}
var scriptBuf = chunk.buf;
if (!scriptBuf) {
return false;
}
var redeemScript = new Script(scriptBuf);
var type = redeemScript.classify();
return type !== Script.types.UNKNOWN;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions test/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,11 @@ describe('Script', function() {
Script('47 0x3044022077a8d81e656c4a1c1721e68ce35fa0b27f13c342998e75854858c12396a15ffa02206378a8c6959283c008c87a14a9c0ada5cf3934ac5ee29f1fef9cac6969783e9801 21 0x03993c230da7dabb956292851ae755f971c50532efc095a16bee07f83ab9d262df').classify().should.equal(Script.types.PUBKEYHASH_IN);
});
it('should classify script hash out', function() {
Script('').classify().should.equal(Script.types.SCRIPTHASH_OUT);
Script('OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL').classify().should.equal(Script.types.SCRIPTHASH_OUT);
});
it('should classify script hash in', function() {
Script('').classify().should.equal(Script.types.SCRIPTHASH_IN);
var x = Script('OP_0 73 0x30460221008ca148504190c10eea7f5f9c283c719a37be58c3ad617928011a1bb9570901d2022100ced371a23e86af6f55ff4ce705c57d2721a09c4d192ca39d82c4239825f75a9801 72 0x30450220357011fd3b3ad2b8f2f2d01e05dc6108b51d2a245b4ef40c112d6004596f0475022100a8208c93a39e0c366b983f9a80bfaf89237fcd64ca543568badd2d18ee2e1d7501 OP_PUSHDATA1 105 0x5221024c02dff2f0b8263a562a69ec875b2c95ffad860f428acf2f9e8c6492bd067d362103546324a1351a6b601c623b463e33b6103ca444707d5b278ece1692f1aa7724a42103b1ad3b328429450069cc3f9fa80d537ee66ba1120e93f3f185a5bf686fb51e0a53ae');
x.classify().should.equal(Script.types.SCRIPTHASH_IN);
});
it('should classify MULTISIG out', function() {
Script('').classify().should.equal(Script.types.MULTISIG_OUT);
Expand Down

0 comments on commit 7d9151a

Please sign in to comment.