|
|
@ -184,13 +184,15 @@ helpers.stubAddressActivity = function(activeAddresses) { |
|
|
|
|
|
|
|
helpers.clientSign = WalletUtils.signTxp; |
|
|
|
|
|
|
|
helpers.createProposalOpts = function(toAddress, amount, message, signingKey) { |
|
|
|
helpers.createProposalOpts = function(toAddress, amount, message, signingKey, feePerKb) { |
|
|
|
var opts = { |
|
|
|
toAddress: toAddress, |
|
|
|
amount: helpers.toSatoshi(amount), |
|
|
|
message: message, |
|
|
|
proposalSignature: null, |
|
|
|
}; |
|
|
|
if (feePerKb) opts.feePerKb = feePerKb; |
|
|
|
|
|
|
|
var hash = WalletUtils.getProposalHash(opts.toAddress, opts.amount, opts.message); |
|
|
|
try { |
|
|
|
opts.proposalSignature = WalletUtils.signMessage(hash, signingKey); |
|
|
@ -1322,7 +1324,6 @@ describe('Wallet service', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should fail to create tx with invalid proposal signature', function(done) { |
|
|
|
helpers.stubUtxos(server, wallet, [100, 200], function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, null, 'dummy'); |
|
|
@ -1409,8 +1410,8 @@ describe('Wallet service', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail to create tx when insufficient funds for fee', function(done) { |
|
|
|
helpers.stubUtxos(server, wallet, [100], function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 100, null, TestData.copayers[0].privKey_1H_0); |
|
|
|
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'); |
|
|
@ -1420,6 +1421,42 @@ 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 be possible to use a smaller fee', function(done) { |
|
|
|
helpers.stubUtxos(server, wallet, 1, function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.99995, null, TestData.copayers[0].privKey_1H_0); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.exist(err); |
|
|
|
err.code.should.equal('INSUFFICIENTFUNDS'); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.99995, null, TestData.copayers[0].privKey_1H_0, 5000); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.fee.should.equal(5000); |
|
|
|
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey); |
|
|
|
// Sign it to make sure Bitcore doesn't complain about the fees
|
|
|
|
server.signTx({ |
|
|
|
txProposalId: tx.id, |
|
|
|
signatures: signatures, |
|
|
|
}, function(err) { |
|
|
|
should.not.exist(err); |
|
|
|
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); |
|
|
@ -1434,7 +1471,7 @@ describe('Wallet service', function() { |
|
|
|
|
|
|
|
it('should fail to create tx that would return change for dust amount', function(done) { |
|
|
|
helpers.stubUtxos(server, wallet, [1], function() { |
|
|
|
var fee = Bitcore.Transaction.FEE_PER_KB / 1e8; |
|
|
|
var fee = 10000 / 1e8; |
|
|
|
var change = 0.00000001; |
|
|
|
var amount = 1 - fee - change; |
|
|
|
|
|
|
@ -2446,7 +2483,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) { |
|
|
|