add extra test

This commit is contained in:
Manuel Araoz 2015-03-18 17:22:32 -03:00
parent 62ea45a524
commit a9328d76ff
2 changed files with 6 additions and 4 deletions

View File

@ -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);
}

View File

@ -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