From fa54ba4f82a7280bcd924a33de0e6952fff42b7d Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 10 Aug 2016 11:43:48 +1000 Subject: [PATCH] tests/transaction: add test for target Buffer --- test/transaction.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/transaction.js b/test/transaction.js index d11ab29..b17dbf8 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -67,6 +67,24 @@ describe('Transaction', function () { assert.strictEqual(actual.toHex(), f.hex, actual.toHex()) }) }) + + it('accepts target Buffer and offset parameters', function () { + var f = fixtures.valid[0] + var actual = fromRaw(f.raw) + var byteLength = actual.byteLength() + + var target = new Buffer(byteLength * 2) + var a = actual.toBuffer(target, 0) + var b = actual.toBuffer(target, byteLength) + + assert.strictEqual(a.length, byteLength) + assert.strictEqual(b.length, byteLength) + assert.strictEqual(a.toString('hex'), f.hex) + assert.strictEqual(b.toString('hex'), f.hex) + assert.deepEqual(a, b) + assert.deepEqual(a, target.slice(0, byteLength)) + assert.deepEqual(b, target.slice(byteLength)) + }) }) describe('addInput', function () {