diff --git a/src/script.js b/src/script.js index a0c0997..2c6fbea 100644 --- a/src/script.js +++ b/src/script.js @@ -184,19 +184,7 @@ function isSmallIntOp(opcode) { ((opcode >= Opcode.map.OP_1) && (opcode <= Opcode.map.OP_16))) } -/** - * Returns the address corresponding to this output in hash160 form. - * Assumes strange scripts are P2SH - */ -Script.prototype.toScriptHash = function() { - if(isPubkeyhash.call(this)) { - return this.chunks[2] - } - - if(isScripthash.call(this)) { - return crypto.hash160(this.buffer) - } - +Script.prototype.getHash = function() { return crypto.hash160(this.buffer) } diff --git a/test/script.js b/test/script.js index 1da5fc1..faf4bb8 100644 --- a/test/script.js +++ b/test/script.js @@ -26,9 +26,19 @@ describe('Script', function() { }) describe('fromHex/toHex', function() { + fixtures.valid.forEach(function(f) { + it('decodes/encodes ' + f.description, function() { + assert.equal(Script.fromHex(f.hex).toHex(), f.hex) + }) + }) + }) + + describe('getHash', function() { it('matches the test vectors', function() { fixtures.valid.forEach(function(f) { - assert.equal(Script.fromHex(f.hex).toHex(), f.hex) + var script = Script.fromHex(f.hex) + + assert.equal(script.getHash().toString('hex'), f.hash) }) }) }) diff --git a/test/transaction.js b/test/transaction.js index e1ca2f4..62e0525 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -72,9 +72,7 @@ describe('Transaction', function() { var output = tx.outs[0] assert.equal(output.value, 5000000000) - assert.equal(b2h(output.script.toScriptHash()), "dd40dedd8f7e37466624c4dacc6362d8e7be23dd") - // assert.equal(output.address.toString(), "n1gqLjZbRH1biT5o4qiVMiNig8wcCPQeB9") - // TODO: address is wrong because it's a testnet transaction. Transaction needs to support testnet + assert.deepEqual(output.script, Address.fromBase58Check('n1gqLjZbRH1biT5o4qiVMiNig8wcCPQeB9').toScriptPubKey()) }) it('assigns hash to deserialized object', function(){