From 116024a7cb224e386266f80f3a35e562ced9329a Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sun, 29 Mar 2015 20:12:39 +0300 Subject: [PATCH] fix Script.isPublicKeyHashOut --- lib/script/script.js | 1 + test/script/script.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/script/script.js b/lib/script/script.js index 523e88c1a..641a72483 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -231,6 +231,7 @@ Script.prototype.isPublicKeyHashOut = function() { this.chunks[0].opcodenum === Opcode.OP_DUP && this.chunks[1].opcodenum === Opcode.OP_HASH160 && this.chunks[2].buf && + this.chunks[2].buf.length === 20 && this.chunks[3].opcodenum === Opcode.OP_EQUALVERIFY && this.chunks[4].opcodenum === Opcode.OP_CHECKSIG); }; diff --git a/test/script/script.js b/test/script/script.js index 61cf787d8..71cd7dffd 100644 --- a/test/script/script.js +++ b/test/script/script.js @@ -256,11 +256,15 @@ describe('Script', function() { describe('#isPublicKeyHashOut', function() { it('should identify this known pubkeyhashout as pubkeyhashout', function() { - Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').isPublicKeyHashOut().should.equal(true); + Script('OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').isPublicKeyHashOut().should.equal(true); }); - it('should identify this known non-pubkeyhashout as not pubkeyhashout', function() { - Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000').isPublicKeyHashOut().should.equal(false); + it('should identify this known non-pubkeyhashout as not pubkeyhashout 1', function() { + Script('OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000').isPublicKeyHashOut().should.equal(false); + }); + + it('should identify this known non-pubkeyhashout as not pubkeyhashout 2', function() { + Script('OP_DUP OP_HASH160 2 0x0000 OP_EQUALVERIFY OP_CHECKSIG').isPublicKeyHashOut().should.equal(false); }); }); @@ -348,7 +352,7 @@ describe('Script', function() { describe('#classify', function() { it('should classify public key hash out', function() { - Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classify().should.equal(Script.types.PUBKEYHASH_OUT); + Script('OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classify().should.equal(Script.types.PUBKEYHASH_OUT); }); it('should classify public key hash in', function() { Script('47 0x3044022077a8d81e656c4a1c1721e68ce35fa0b27f13c342998e75854858c12396a15ffa02206378a8c6959283c008c87a14a9c0ada5cf3934ac5ee29f1fef9cac6969783e9801 21 0x03993c230da7dabb956292851ae755f971c50532efc095a16bee07f83ab9d262df').classify().should.equal(Script.types.PUBKEYHASH_IN);