Merge pull request #1111 from eordano/serialize/checks

Minor: Less repetition on tests for skipping serialization checks
This commit is contained in:
Manuel Aráoz 2015-02-24 15:32:58 -03:00
commit 5e08fcdfff
1 changed files with 40 additions and 43 deletions

View File

@ -340,56 +340,53 @@ describe('Transaction', function() {
}).to.not.throw(errors.Transaction.DustOutputs); }).to.not.throw(errors.Transaction.DustOutputs);
}); });
describe('skipping checks', function() { 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() { it('can skip the check for too much fee', function() {
var transaction = new Transaction() buildSkipTest(function(transaction) {
.from(simpleUtxoWith1BTC) return transaction
.fee(50000000) .fee(50000000)
.change(changeAddress) .change(changeAddress)
.sign(privateKey); .sign(privateKey);
expect(function() { }, 'disableLargeFees');
return transaction.serialize({disableLargeFees: true});
}).to.not.throw();
expect(function() {
return transaction.serialize();
}).to.throw();
}); });
it('can skip the check for a fee that is too small', function() { it('can skip the check for a fee that is too small', function() {
var transaction = new Transaction() buildSkipTest(function(transaction) {
.from(simpleUtxoWith1BTC) return transaction
.fee(1) .fee(1)
.change(changeAddress) .change(changeAddress)
.sign(privateKey); .sign(privateKey);
expect(function() { }, 'disableSmallFees');
return transaction.serialize({disableSmallFees: true});
}).to.not.throw();
expect(function() {
return transaction.serialize();
}).to.throw();
}); });
it('can skip the check that prevents dust outputs', function() { it('can skip the check that prevents dust outputs', function() {
var transaction = new Transaction() buildSkipTest(function(transaction) {
.from(simpleUtxoWith1BTC) return transaction
.to(toAddress, 1000) .to(toAddress, 1000)
.change(changeAddress) .change(changeAddress)
.sign(privateKey); .sign(privateKey);
expect(function() { }, 'disableDustOutputs');
return transaction.serialize({disableDustOutputs: true});
}).to.not.throw();
expect(function() {
return transaction.serialize();
}).to.throw();
}); });
it('can skip the check that prevents unsigned outputs', function() { it('can skip the check that prevents unsigned outputs', function() {
var transaction = new Transaction() buildSkipTest(function(transaction) {
.from(simpleUtxoWith1BTC) return transaction
.to(toAddress, 10000) .to(toAddress, 10000)
.change(changeAddress); .change(changeAddress);
expect(function() { }, 'disableIsFullySigned');
return transaction.serialize({disableIsFullySigned: true});
}).to.not.throw();
expect(function() {
return transaction.serialize();
}).to.throw();
}); });
}); });
}); });