From 427c9b3234da461ab9417369bd08b30843a9def4 Mon Sep 17 00:00:00 2001 From: eordano Date: Tue, 24 Feb 2015 14:47:12 -0300 Subject: [PATCH] Less repetition on tests for skipping serialization checks --- test/transaction/transaction.js | 83 ++++++++++++++++----------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index 1f70b70..bd97e4b 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -340,56 +340,53 @@ describe('Transaction', function() { }).to.not.throw(errors.Transaction.DustOutputs); }); describe('skipping checks', function() { + var buildSkipTest = function(builder, check) { + return function() { + var transaction = new Transaction(); + transaction.from(simpleUtxoWith1BTC) + builder(transaction); + + var options = {}; + options[check] = true; + + expect(function() { + return transaction.serialize(options); + }).not.to.throw(); + expect(function() { + return transaction.serialize(); + }).to.throw(); + }; + }; it('can skip the check for too much fee', function() { - var transaction = new Transaction() - .from(simpleUtxoWith1BTC) - .fee(50000000) - .change(changeAddress) - .sign(privateKey); - expect(function() { - return transaction.serialize({disableLargeFees: true}); - }).to.not.throw(); - expect(function() { - return transaction.serialize(); - }).to.throw(); + buildSkipTest(function(transaction) { + return transaction + .fee(50000000) + .change(changeAddress) + .sign(privateKey); + }, 'disableLargeFees'); }); it('can skip the check for a fee that is too small', function() { - var transaction = new Transaction() - .from(simpleUtxoWith1BTC) - .fee(1) - .change(changeAddress) - .sign(privateKey); - expect(function() { - return transaction.serialize({disableSmallFees: true}); - }).to.not.throw(); - expect(function() { - return transaction.serialize(); - }).to.throw(); + buildSkipTest(function(transaction) { + return transaction + .fee(1) + .change(changeAddress) + .sign(privateKey); + }, 'disableSmallFees'); }); it('can skip the check that prevents dust outputs', function() { - var transaction = new Transaction() - .from(simpleUtxoWith1BTC) - .to(toAddress, 1000) - .change(changeAddress) - .sign(privateKey); - expect(function() { - return transaction.serialize({disableDustOutputs: true}); - }).to.not.throw(); - expect(function() { - return transaction.serialize(); - }).to.throw(); + buildSkipTest(function(transaction) { + return transaction + .to(toAddress, 1000) + .change(changeAddress) + .sign(privateKey); + }, 'disableDustOutputs'); }); it('can skip the check that prevents unsigned outputs', function() { - var transaction = new Transaction() - .from(simpleUtxoWith1BTC) - .to(toAddress, 10000) - .change(changeAddress); - expect(function() { - return transaction.serialize({disableIsFullySigned: true}); - }).to.not.throw(); - expect(function() { - return transaction.serialize(); - }).to.throw(); + buildSkipTest(function(transaction) { + return transaction + .to(toAddress, 10000) + .change(changeAddress); + }, 'disableIsFullySigned'); }); }); });