|
|
@ -94,7 +94,7 @@ helpers.toSatoshi = function(btc) { |
|
|
|
helpers.stubUtxos = function(server, wallet, amounts, cb) { |
|
|
|
var amounts = [].concat(amounts); |
|
|
|
|
|
|
|
async.map(_.range(Math.ceil(amounts.length / 2)), function(i, next) { |
|
|
|
async.map(_.range(1, Math.ceil(amounts.length / 2) + 1), function(i, next) { |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
next(err, address); |
|
|
|
}); |
|
|
@ -669,18 +669,16 @@ describe('Copay server', function() { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should create a tx', function(done) { |
|
|
|
helpers.stubUtxos(server, wallet, [100, 200], function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
should.exist(tx); |
|
|
|
tx.message.should.equal('some message'); |
|
|
|
tx.isAccepted().should.equal.false; |
|
|
|
tx.isRejected().should.equal.false; |
|
|
@ -810,11 +808,11 @@ describe('Copay server', function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 12, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
should.exist(tx); |
|
|
|
var txOpts2 = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 8, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts2, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
should.exist(tx); |
|
|
|
server.getPendingTxs({}, function(err, txs) { |
|
|
|
should.not.exist(err); |
|
|
|
txs.length.should.equal(2); |
|
|
@ -835,7 +833,7 @@ describe('Copay server', function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 12, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
should.exist(tx); |
|
|
|
var txOpts2 = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 24, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts2, function(err, tx) { |
|
|
|
err.code.should.equal('INSUFFICIENTFUNDS'); |
|
|
@ -858,9 +856,7 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
it('should create tx using different UTXOs for simultaneous requests', function(done) { |
|
|
|
var N = 5; |
|
|
|
helpers.stubUtxos(server, wallet, _.times(N, function() { |
|
|
|
return 100; |
|
|
|
}), function(utxos) { |
|
|
|
helpers.stubUtxos(server, wallet, _.range(100, 100 + N, 0), function(utxos) { |
|
|
|
server.getBalance({}, function(err, balance) { |
|
|
|
should.not.exist(err); |
|
|
|
balance.totalAmount.should.equal(helpers.toSatoshi(N * 100)); |
|
|
@ -896,19 +892,17 @@ describe('Copay server', function() { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.stubUtxos(server, wallet, _.range(1, 9), function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
should.exist(tx); |
|
|
|
txid = tx.id; |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should reject a TX', function(done) { |
|
|
|
server.getPendingTxs({}, function(err, txs) { |
|
|
@ -1178,14 +1172,12 @@ describe('Copay server', function() { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.stubUtxos(server, wallet, _.range(1, 9), function() { |
|
|
|
helpers.stubBroadcast('999'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('other copayers should see pending proposal created by one copayer', function(done) { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey); |
|
|
@ -1378,7 +1370,6 @@ describe('Copay server', function() { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.stubUtxos(server, wallet, _.range(10), function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.1, null, TestData.copayers[0].privKey); |
|
|
|
async.eachSeries(_.range(10), function(i, next) { |
|
|
@ -1392,7 +1383,6 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
afterEach(function() { |
|
|
|
clock.restore(); |
|
|
|
}); |
|
|
@ -1464,7 +1454,6 @@ describe('Copay server', function() { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.stubUtxos(server, wallet, helpers.toSatoshi(_.range(4)), function() { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.01, null, TestData.copayers[0].privKey); |
|
|
|
async.eachSeries(_.range(3), function(i, next) { |
|
|
@ -1478,7 +1467,6 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should pull the last 4 notifications after 3 TXs', function(done) { |
|
|
|
server.getNotifications({ |
|
|
@ -1598,7 +1586,6 @@ describe('Copay server', function() { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
|
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.stubUtxos(server, wallet, _.range(2), function() { |
|
|
|
var txOpts = { |
|
|
|
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', |
|
|
@ -1612,7 +1599,6 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should delete a wallet', function(done) { |
|
|
|
var i = 0; |
|
|
|
var count = function() { |
|
|
@ -1647,7 +1633,6 @@ describe('Copay server', function() { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
|
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.stubUtxos(server, wallet, _.range(2), function() { |
|
|
|
var txOpts = { |
|
|
|
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', |
|
|
@ -1669,7 +1654,6 @@ describe('Copay server', function() { |
|
|
|
}, cat); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, cat); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1763,7 +1747,7 @@ describe('Copay server', function() { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
helpers.createAddresses(server, wallet, 3, 3, function(main, change) { |
|
|
|
helpers.createAddresses(server, wallet, 1, 1, function(main, change) { |
|
|
|
mainAddresses = main; |
|
|
|
changeAddresses = change; |
|
|
|
done(); |
|
|
@ -1867,14 +1851,14 @@ describe('Copay server', function() { |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should get tx history for outgoing txs with proposal', function(done) { |
|
|
|
it('should get tx history with accepted proposal', function(done) { |
|
|
|
server._normalizeTxHistory = sinon.stub().returnsArg(0); |
|
|
|
|
|
|
|
helpers.stubUtxos(server, wallet, [100, 200], function(utxos) { |
|
|
|
var txOpts = helpers.createProposalOpts(mainAddresses[0].address, 80, 'some message', TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
should.exist(tx); |
|
|
|
|
|
|
|
helpers.stubBroadcast('1122334455'); |
|
|
|
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey); |
|
|
@ -1909,7 +1893,7 @@ describe('Copay server', function() { |
|
|
|
var tx = txs[0]; |
|
|
|
tx.action.should.equal('sent'); |
|
|
|
tx.amount.should.equal(helpers.toSatoshi(80)); |
|
|
|
tx.message.should.equal(tx.message); |
|
|
|
tx.message.should.equal('some message'); |
|
|
|
tx.actions.length.should.equal(1); |
|
|
|
tx.actions[0].type.should.equal('accept'); |
|
|
|
tx.actions[0].copayerName.should.equal('copayer 1'); |
|
|
|