|
|
@ -66,7 +66,7 @@ helpers.createAndJoinWallet = function(m, n, cb) { |
|
|
|
|
|
|
|
helpers.getAuthServer(copayerIds[0], function(s) { |
|
|
|
s.getWallet({}, function(err, w) { |
|
|
|
cb(s, w, _.take(TestData.copayers, w.n), copayerIds); |
|
|
|
cb(s, w); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -193,8 +193,8 @@ describe('Copay server', function() { |
|
|
|
beforeEach(function() {}); |
|
|
|
|
|
|
|
it('should get server instance for existing copayer', function(done) { |
|
|
|
helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) { |
|
|
|
var xpriv = copayers[0].xPrivKey; |
|
|
|
helpers.createAndJoinWallet(1, 2, function(s, wallet) { |
|
|
|
var xpriv = TestData.copayers[0].xPrivKey; |
|
|
|
var priv = Bitcore.HDPrivateKey |
|
|
|
.fromString(xpriv) |
|
|
|
.derive('m/1/0') |
|
|
@ -205,7 +205,7 @@ describe('Copay server', function() { |
|
|
|
var sig = SignUtils.sign(message, priv); |
|
|
|
|
|
|
|
CopayServer.getInstanceWithAuth({ |
|
|
|
copayerId: copayerIds[0], |
|
|
|
copayerId: wallet.copayers[0].id, |
|
|
|
message: message, |
|
|
|
signature: sig, |
|
|
|
}, function(err, server) { |
|
|
@ -228,9 +228,9 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail when message signature cannot be verified', function(done) { |
|
|
|
helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) { |
|
|
|
helpers.createAndJoinWallet(1, 2, function(s, wallet) { |
|
|
|
CopayServer.getInstanceWithAuth({ |
|
|
|
copayerId: copayerIds[0], |
|
|
|
copayerId: wallet.copayers[0].id, |
|
|
|
message: 'dummy', |
|
|
|
signature: 'dummy', |
|
|
|
}, function(err, server) { |
|
|
@ -601,12 +601,11 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#createTx', function() { |
|
|
|
var server, wallet, copayerPriv; |
|
|
|
var server, wallet; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w, c) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
done(); |
|
|
|
}); |
|
|
@ -616,7 +615,7 @@ describe('Copay server', function() { |
|
|
|
it('should create a tx', function(done) { |
|
|
|
helpers.createUtxos(server, wallet, [100, 200], function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', copayerPriv[0].privKey); |
|
|
|
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; |
|
|
@ -656,7 +655,7 @@ describe('Copay server', function() { |
|
|
|
server.joinWallet(copayerOpts, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
helpers.getAuthServer(result.copayerId, function(server, wallet) { |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(tx); |
|
|
|
err.should.exist; |
|
|
@ -671,7 +670,7 @@ describe('Copay server', function() { |
|
|
|
it('should fail to create tx for address invalid address', function(done) { |
|
|
|
helpers.createUtxos(server, wallet, [100, 200], function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('invalid address', 80, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('invalid address', 80, null, TestData.copayers[0].privKey); |
|
|
|
|
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(tx); |
|
|
@ -686,7 +685,7 @@ describe('Copay server', function() { |
|
|
|
it('should fail to create tx for address of different network', function(done) { |
|
|
|
helpers.createUtxos(server, wallet, [100, 200], function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('myE38JHdxmQcTJGP1ZiX4BiGhDxMJDvLJD', 80, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('myE38JHdxmQcTJGP1ZiX4BiGhDxMJDvLJD', 80, null, TestData.copayers[0].privKey); |
|
|
|
|
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(tx); |
|
|
@ -701,7 +700,7 @@ describe('Copay server', function() { |
|
|
|
it('should fail to create tx when insufficient funds', function(done) { |
|
|
|
helpers.createUtxos(server, wallet, [100], function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 120, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 120, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
err.code.should.equal('INSUFFICIENTFUNDS'); |
|
|
|
err.message.should.equal('Insufficient funds'); |
|
|
@ -726,11 +725,11 @@ describe('Copay server', function() { |
|
|
|
it('should create tx when there is a pending tx and enough UTXOs', function(done) { |
|
|
|
helpers.createUtxos(server, wallet, [10.1, 10.2, 10.3], function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 12, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 12, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
var txOpts2 = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 8, null, copayerPriv[0].privKey); |
|
|
|
var txOpts2 = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 8, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts2, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
@ -752,11 +751,11 @@ describe('Copay server', function() { |
|
|
|
it('should fail to create tx when there is a pending tx and not enough UTXOs', function(done) { |
|
|
|
helpers.createUtxos(server, wallet, [10.1, 10.2, 10.3], function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 12, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 12, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
|
var txOpts2 = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 24, null, copayerPriv[0].privKey); |
|
|
|
var txOpts2 = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 24, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts2, function(err, tx) { |
|
|
|
err.code.should.equal('INSUFFICIENTFUNDS'); |
|
|
|
err.message.should.equal('Insufficient funds'); |
|
|
@ -786,7 +785,7 @@ describe('Copay server', function() { |
|
|
|
should.not.exist(err); |
|
|
|
balance.totalAmount.should.equal(helpers.toSatoshi(N * 100)); |
|
|
|
balance.lockedAmount.should.equal(helpers.toSatoshi(0)); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, null, TestData.copayers[0].privKey); |
|
|
|
async.map(_.range(N), function(i, cb) { |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
cb(err, tx); |
|
|
@ -811,18 +810,16 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
|
|
|
|
describe('#rejectTx', function() { |
|
|
|
var server, wallet, copayerPriv, txid, copayerIds; |
|
|
|
var server, wallet, txid; |
|
|
|
|
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w, c, ids) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
copayerIds = ids; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.createUtxos(server, wallet, _.range(1, 9), function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
@ -850,8 +847,8 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
var actors = tx.getActors(); |
|
|
|
actors.length.should.equal(1); |
|
|
|
actors[0].should.equal(copayerIds[0]); |
|
|
|
tx.getActionBy(copayerIds[0]).type.should.equal('reject'); |
|
|
|
actors[0].should.equal(wallet.copayers[0].id); |
|
|
|
tx.getActionBy(wallet.copayers[0].id).type.should.equal('reject'); |
|
|
|
|
|
|
|
done(); |
|
|
|
}); |
|
|
@ -861,18 +858,16 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#signTx', function() { |
|
|
|
var server, wallet, copayerPriv, txid, copayerIds; |
|
|
|
var server, wallet, txid; |
|
|
|
|
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w, c, ids) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
copayerIds = ids; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.createUtxos(server, wallet, _.range(1, 9), function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
|
tx.should.exist; |
|
|
@ -902,8 +897,8 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
var actors = tx.getActors(); |
|
|
|
actors.length.should.equal(1); |
|
|
|
actors[0].should.equal(copayerIds[0]); |
|
|
|
tx.getActionBy(copayerIds[0]).type.should.equal('accept'); |
|
|
|
actors[0].should.equal(wallet.copayers[0].id); |
|
|
|
tx.getActionBy(wallet.copayers[0].id).type.should.equal('accept'); |
|
|
|
|
|
|
|
done(); |
|
|
|
}); |
|
|
@ -1005,12 +1000,11 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
|
|
|
|
describe('#signTx and broadcast', function() { |
|
|
|
var server, wallet, copayerPriv, utxos; |
|
|
|
var server, wallet, utxos; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w, c) { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.createUtxos(server, wallet, _.range(1, 9), function(inutxos) { |
|
|
|
utxos = inutxos; |
|
|
@ -1022,7 +1016,7 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
it('should sign and broadcast a tx', function(done) { |
|
|
|
helpers.stubBlockExplorer(server, utxos, '1122334455'); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, txp) { |
|
|
|
should.not.exist(err); |
|
|
|
txp.should.exist; |
|
|
@ -1048,7 +1042,7 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
it('should keep tx as *accepted* if unable to broadcast it', function(done) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, txp) { |
|
|
|
should.not.exist(err); |
|
|
|
txp.should.exist; |
|
|
@ -1079,12 +1073,11 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Tx proposal workflow', function() { |
|
|
|
var server, wallet, copayerPriv, utxos; |
|
|
|
var server, wallet, utxos; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w, c) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.createUtxos(server, wallet, _.range(1, 9), function(inutxos) { |
|
|
|
utxos = inutxos; |
|
|
@ -1096,7 +1089,7 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
it('other copayers should see pending proposal created by one copayer', function(done) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, 'some message', TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, txp) { |
|
|
|
should.not.exist(err); |
|
|
|
should.exist.txp; |
|
|
@ -1122,21 +1115,20 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#getTxs', function() { |
|
|
|
var server, wallet, copayerPriv, clock; |
|
|
|
var server, wallet, clock; |
|
|
|
|
|
|
|
beforeEach(function(done) { |
|
|
|
if (server) return done(); |
|
|
|
this.timeout(5000); |
|
|
|
console.log('\tCreating TXS...'); |
|
|
|
clock = sinon.useFakeTimers(); |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w, c) { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.createUtxos(server, wallet, _.range(10), function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.1, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.1, null, TestData.copayers[0].privKey); |
|
|
|
async.eachSeries(_.range(10), function(i, next) { |
|
|
|
clock.tick(10000); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
@ -1214,19 +1206,18 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
|
|
|
|
describe('Notifications', function() { |
|
|
|
var server, wallet, copayerPriv; |
|
|
|
var server, wallet; |
|
|
|
|
|
|
|
beforeEach(function(done) { |
|
|
|
if (server) return done(); |
|
|
|
console.log('\tCreating TXS...'); |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w, c) { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.createUtxos(server, wallet, helpers.toSatoshi(_.range(4)), function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.01, null, copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.01, null, TestData.copayers[0].privKey); |
|
|
|
async.eachSeries(_.range(3), function(i, next) { |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
should.not.exist(err); |
|
|
@ -1439,16 +1430,15 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
|
|
|
|
describe('#removePendingTx', function() { |
|
|
|
var server, wallet, copayerPriv, txp; |
|
|
|
var server, wallet, txp; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w, c) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
copayerPriv = c; |
|
|
|
server.createAddress({}, function(err, address) { |
|
|
|
helpers.createUtxos(server, wallet, [100, 200], function(utxos) { |
|
|
|
helpers.stubBlockExplorer(server, utxos); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', copayerPriv[0].privKey); |
|
|
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey); |
|
|
|
server.createTx(txOpts, function(err, tx) { |
|
|
|
server.getPendingTxs({}, function(err, txs) { |
|
|
|
txp = txs[0]; |
|
|
|