test fee behavior

This commit is contained in:
Ivan Socolsky 2015-06-10 17:57:48 -03:00
parent 06b521853d
commit 9f4ef16bba
2 changed files with 18 additions and 4 deletions

View File

@ -693,6 +693,8 @@ WalletService.prototype.getBalance = function(opts, cb) {
WalletService.prototype._selectTxInputs = function(txp, cb) {
var self = this;
Bitcore.Transaction.FEE_SECURITY_MARGIN = 1;
self._getUtxos(function(err, utxos) {
if (err) return cb(err);

View File

@ -1407,9 +1407,9 @@ describe('Wallet service', function() {
});
});
it.only('should fail to create tx when insufficient funds for fee', function(done) {
helpers.stubUtxos(server, wallet, 0.04822200, function() {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.04820000, null, TestData.copayers[0].privKey_1H_0);
it('should fail to create tx when insufficient funds for fee', function(done) {
helpers.stubUtxos(server, wallet, 0.048222, function() {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.048200, null, TestData.copayers[0].privKey_1H_0);
server.createTx(txOpts, function(err, tx) {
should.exist(err);
err.code.should.equal('INSUFFICIENTFUNDS');
@ -1419,6 +1419,18 @@ describe('Wallet service', function() {
});
});
it('should scale fees according to tx size', function(done) {
helpers.stubUtxos(server, wallet, [1, 1, 1, 1], function() {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 3.5, null, TestData.copayers[0].privKey_1H_0);
server.createTx(txOpts, function(err, tx) {
should.not.exist(err);
tx.getBitcoreTx()._estimateSize().should.be.within(1001, 1999);
tx.fee.should.equal(20000);
done();
});
});
});
it('should fail to create tx for dust amount', function(done) {
helpers.stubUtxos(server, wallet, [1], function() {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.00000001, null, TestData.copayers[0].privKey_1H_0);
@ -2445,7 +2457,7 @@ describe('Wallet service', function() {
helpers.createAndJoinWallet(1, 1, function(s, w) {
server = s;
wallet = w;
helpers.stubUtxos(server, wallet, helpers.toSatoshi(_.range(4)), function() {
helpers.stubUtxos(server, wallet, _.range(4), function() {
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.01, null, TestData.copayers[0].privKey_1H_0);
async.eachSeries(_.range(3), function(i, next) {
server.createTx(txOpts, function(err, tx) {