From f12f8eac488a1b0a95646088869fc572a1d1ed5e Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 26 Mar 2014 19:11:10 +1100 Subject: [PATCH] Adds failing test for larger transaction --- test/transaction.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/transaction.js b/test/transaction.js index ab0226f..8a185e6 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -69,6 +69,22 @@ describe('Transaction', function() { var hashHex = "a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c" assert.deepEqual(tx.hash, convert.hexToBytes(hashHex)) }) + + it('decodes large inputs correctly', function() { + // transaction has only 1 input + var tx = new Transaction() + tx.addInput("0cb859105100ebc3344f749c835c7af7d7103ec0d8cbc3d8ccbd5d28c3c36b57", 0) + tx.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3", 100) + + // but we're going to replace the tx.ins.length VarInt with a 32-bit equivalent + // however the same resultant number of inputs (1) + var bytes = tx.serialize() + var mutated = bytes.slice(0, 4).concat([254, 1, 0, 0, 0], bytes.slice(5)) + + // the deserialized-serialized transaction should return to its original state (== tx) + var bytes2 = Transaction.deserialize(mutated).serialize() + assert.deepEqual(bytes, bytes2) + }); }) describe('creating a transaction', function() {