From a9328d76ff6438c66f8bda54eae2c4aa29314651 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 18 Mar 2015 17:22:32 -0300 Subject: [PATCH] add extra test --- lib/address.js | 8 ++++---- test/script/script.js | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/address.js b/lib/address.js index 31ca3fcd7..14d89f323 100644 --- a/lib/address.js +++ b/lib/address.js @@ -254,14 +254,14 @@ Address._transformScript = function(script, network) { } else if (script.isPublicKeyHashOut()) { info.hashBuffer = script.getData(); info.type = Address.PayToPublicKeyHash; - } else if (script.isScriptHashIn()) { - // hash the redeemscript found at the end of the scriptSig - info.hashBuffer = Hash.sha256ripemd160(script.chunks[script.chunks.length - 1].buf); - info.type = Address.PayToScriptHash; } else if (script.isPublicKeyHashIn()) { // hash the publickey found in the scriptSig info.hashBuffer = Hash.sha256ripemd160(script.chunks[1].buf); info.type = Address.PayToPublicKeyHash; + } else if (script.isScriptHashIn()) { + // hash the redeemscript found at the end of the scriptSig + info.hashBuffer = Hash.sha256ripemd160(script.chunks[script.chunks.length - 1].buf); + info.type = Address.PayToScriptHash; } else { throw new errors.Script.CantDeriveAddress(script); } diff --git a/test/script/script.js b/test/script/script.js index 477c82078..64416dde2 100644 --- a/test/script/script.js +++ b/test/script/script.js @@ -679,6 +679,8 @@ describe('Script', function() { it('works for p2pkh input', function() { var script = new Script('72 0x3045022100eff96230ca0f55b1e8c7a63e014f48611ff1af40875ecd33dee9062d7a6f5e2002206320405b5f6992c756e03e66b21a05a812b60996464ac6af815c2638b930dd7a01 65 0x04150defa035a2c7d826d7d5fc8ab2154bd1bb832f1a5c8ecb338f436362ad232e428b57db44677c5a8bd42c5ed9e2d7e04e742c59bee1b40080cfd57dec64b23a'); script.toAddress().toString().should.equal('1KK9oz4bFH8c1t6LmighHaoSEGx3P3FEmc'); + var s2 = new Script('71 0x3044022017053dad84aa06213749df50a03330cfd24d6b8e7ddbb6de66c03697b78a752a022053bc0faca8b4049fb3944a05fcf7c93b2861734d39a89b73108f605f70f5ed3401 33 0x0225386e988b84248dc9c30f784b06e02fdec57bbdbd443768eb5744a75ce44a4c'); + s2.toAddress().toString().should.equal('17VArX6GRE6i6MVscBUZoXwi6NhnHa68B7'); }); // taken from txid fe1f764299dc7f3b5a8fae912050df2b633bf99554c68bf1c456edb9c2b63585