|
|
@ -73,24 +73,23 @@ helpers.getAuthServer = function(copayerId, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
helpers.createAndJoinWallet = function(id, m, n, cb) { |
|
|
|
helpers.createAndJoinWallet = function(m, n, cb) { |
|
|
|
var server = new CopayServer(); |
|
|
|
var copayerIds = []; |
|
|
|
|
|
|
|
var walletOpts = { |
|
|
|
id: id, |
|
|
|
name: id + ' wallet', |
|
|
|
name: 'a wallet', |
|
|
|
m: m, |
|
|
|
n: n, |
|
|
|
pubKey: keyPair.pub, |
|
|
|
}; |
|
|
|
server.createWallet(walletOpts, function(err) { |
|
|
|
server.createWallet(walletOpts, function(err, walletId) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
async.each(_.range(1, n + 1), function(i, cb) { |
|
|
|
|
|
|
|
var copayerOpts = { |
|
|
|
walletId: id, |
|
|
|
walletId: walletId, |
|
|
|
name: 'copayer ' + i, |
|
|
|
xPubKey: someXPubKeys[i - 1], |
|
|
|
xPubKeySignature: someXPubKeysSignatures[i - 1], |
|
|
@ -237,24 +236,24 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
it('should create and store wallet', function(done) { |
|
|
|
var opts = { |
|
|
|
id: '123', |
|
|
|
name: 'my wallet', |
|
|
|
m: 2, |
|
|
|
n: 3, |
|
|
|
pubKey: aPubKey, |
|
|
|
}; |
|
|
|
server.createWallet(opts, function(err) { |
|
|
|
server.createWallet(opts, function(err, walletId) { |
|
|
|
should.not.exist(err); |
|
|
|
server.storage.fetchWallet('123', function(err, wallet) { |
|
|
|
server.storage.fetchWallet(walletId, function(err, wallet) { |
|
|
|
should.not.exist(err); |
|
|
|
wallet.id.should.equal('123'); |
|
|
|
wallet.id.should.equal(walletId); |
|
|
|
wallet.name.should.equal('my wallet'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail to recreate existing wallet', function(done) { |
|
|
|
// non sense with server generated UUIDs
|
|
|
|
it.skip('should fail to recreate existing wallet', function(done) { |
|
|
|
var opts = { |
|
|
|
id: '123', |
|
|
|
name: 'my wallet', |
|
|
@ -323,17 +322,16 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
it('should join existing wallet', function(done) { |
|
|
|
var walletOpts = { |
|
|
|
id: '123', |
|
|
|
name: 'my wallet', |
|
|
|
m: 2, |
|
|
|
n: 3, |
|
|
|
pubKey: keyPair.pub, |
|
|
|
}; |
|
|
|
|
|
|
|
server.createWallet(walletOpts, function(err) { |
|
|
|
server.createWallet(walletOpts, function(err, walletId) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerOpts = { |
|
|
|
walletId: '123', |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: aXPubKey, |
|
|
|
xPubKeySignature: aXPubKeySignature, |
|
|
@ -342,7 +340,7 @@ describe('Copay server', function() { |
|
|
|
should.not.exist(err); |
|
|
|
helpers.getAuthServer(copayerId, function(server) { |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
wallet.id.should.equal('123'); |
|
|
|
wallet.id.should.equal(walletId); |
|
|
|
wallet.copayers.length.should.equal(1); |
|
|
|
var copayer = wallet.copayers[0]; |
|
|
|
copayer.name.should.equal('me'); |
|
|
@ -355,47 +353,36 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail to join non-existent wallet', function(done) { |
|
|
|
var walletOpts = { |
|
|
|
id: '123', |
|
|
|
name: 'my wallet', |
|
|
|
m: 2, |
|
|
|
n: 3, |
|
|
|
pubKey: aPubKey, |
|
|
|
var copayerOpts = { |
|
|
|
walletId: '234', |
|
|
|
name: 'me', |
|
|
|
xPubKey: 'dummy', |
|
|
|
xPubKeySignature: 'dummy', |
|
|
|
}; |
|
|
|
server.createWallet(walletOpts, function(err) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerOpts = { |
|
|
|
walletId: '234', |
|
|
|
name: 'me', |
|
|
|
xPubKey: 'dummy', |
|
|
|
xPubKeySignature: 'dummy', |
|
|
|
}; |
|
|
|
server.joinWallet(copayerOpts, function(err) { |
|
|
|
should.exist(err); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
server.joinWallet(copayerOpts, function(err) { |
|
|
|
should.exist(err); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail to join full wallet', function(done) { |
|
|
|
var walletOpts = { |
|
|
|
id: '123', |
|
|
|
name: 'my wallet', |
|
|
|
m: 1, |
|
|
|
n: 1, |
|
|
|
pubKey: keyPair.pub, |
|
|
|
}; |
|
|
|
server.createWallet(walletOpts, function(err) { |
|
|
|
server.createWallet(walletOpts, function(err,walletId) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayer1Opts = { |
|
|
|
walletId: '123', |
|
|
|
walletId: walletId, |
|
|
|
id: '111', |
|
|
|
name: 'me', |
|
|
|
xPubKey: someXPubKeys[0], |
|
|
|
xPubKeySignature: someXPubKeysSignatures[0], |
|
|
|
}; |
|
|
|
var copayer2Opts = { |
|
|
|
walletId: '123', |
|
|
|
walletId: walletId, |
|
|
|
id: '222', |
|
|
|
name: 'me 2', |
|
|
|
xPubKey: someXPubKeys[1], |
|
|
@ -420,16 +407,15 @@ describe('Copay server', function() { |
|
|
|
|
|
|
|
it('should fail to re-join wallet', function(done) { |
|
|
|
var walletOpts = { |
|
|
|
id: '123', |
|
|
|
name: 'my wallet', |
|
|
|
m: 1, |
|
|
|
n: 1, |
|
|
|
pubKey: keyPair.pub, |
|
|
|
}; |
|
|
|
server.createWallet(walletOpts, function(err) { |
|
|
|
server.createWallet(walletOpts, function(err, walletId) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerOpts = { |
|
|
|
walletId: '123', |
|
|
|
walletId: walletId, |
|
|
|
id: '111', |
|
|
|
name: 'me', |
|
|
|
xPubKey: someXPubKeys[0], |
|
|
@ -456,11 +442,10 @@ describe('Copay server', function() { |
|
|
|
n: 1, |
|
|
|
pubKey: aPubKey, |
|
|
|
}; |
|
|
|
server.createWallet(walletOpts, function(err) { |
|
|
|
server.createWallet(walletOpts, function(err, walletId) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerOpts = { |
|
|
|
walletId: '123', |
|
|
|
id: '111', |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: someXPubKeys[0], |
|
|
|
xPubKeySignature: 'bad sign', |
|
|
@ -506,11 +491,10 @@ describe('Copay server', function() { |
|
|
|
n: 1, |
|
|
|
pubKey: aPubKey, |
|
|
|
}; |
|
|
|
server.createWallet(walletOpts, function(err) { |
|
|
|
server.createWallet(walletOpts, function(err, walletId) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerOpts = { |
|
|
|
walletId: '123', |
|
|
|
id: '111', |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: someXPubKeys[0], |
|
|
|
xPubKeySignature: someXPubKeysSignatures[0], |
|
|
@ -523,7 +507,7 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should set pkr and status = complete on last copayer joining (2-3)', function(done) { |
|
|
|
helpers.createAndJoinWallet('123', 2, 3, function(server) { |
|
|
|
helpers.createAndJoinWallet(2, 3, function(server) { |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
should.not.exist(err); |
|
|
|
wallet.status.should.equal('complete'); |
|
|
@ -538,7 +522,7 @@ describe('Copay server', function() { |
|
|
|
describe('#verifyMessageSignature', function() { |
|
|
|
var server, wallet; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet('123', 2, 2, function(s, w) { |
|
|
|
helpers.createAndJoinWallet(2, 2, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
done(); |
|
|
@ -562,7 +546,7 @@ describe('Copay server', function() { |
|
|
|
message: aText, |
|
|
|
signature: aTextSignature, |
|
|
|
}; |
|
|
|
helpers.getAuthServer(wallet.copayers[1].id, function (server) { |
|
|
|
helpers.getAuthServer(wallet.copayers[1].id, function(server) { |
|
|
|
server.verifyMessageSignature(opts, function(err, isValid) { |
|
|
|
should.not.exist(err); |
|
|
|
isValid.should.be.false; |
|
|
@ -575,7 +559,7 @@ describe('Copay server', function() { |
|
|
|
describe('#createAddress', function() { |
|
|
|
var server, wallet; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet('123', 2, 2, function(s, w) { |
|
|
|
helpers.createAndJoinWallet(2, 2, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
done(); |
|
|
@ -607,8 +591,7 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it.skip('should fail to create address when wallet is not complete', function(done) { |
|
|
|
}); |
|
|
|
it.skip('should fail to create address when wallet is not complete', function(done) {}); |
|
|
|
|
|
|
|
it('should create many addresses on simultaneous requests', function(done) { |
|
|
|
async.map(_.range(10), function(i, cb) { |
|
|
@ -683,7 +666,7 @@ describe('Copay server', function() { |
|
|
|
describe('#createTx', function() { |
|
|
|
var server, wallet; |
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet('123', 2, 2, function(s, w) { |
|
|
|
helpers.createAndJoinWallet(2, 2, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({ |
|
|
@ -725,11 +708,9 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it.skip('should fail to create tx when wallet is not complete', function(done) { |
|
|
|
}); |
|
|
|
it.skip('should fail to create tx when wallet is not complete', function(done) {}); |
|
|
|
|
|
|
|
it.skip('should fail to create tx when wallet is not complete', function(done) { |
|
|
|
}); |
|
|
|
it.skip('should fail to create tx when wallet is not complete', function(done) {}); |
|
|
|
|
|
|
|
it('should fail to create tx when insufficient funds', function(done) { |
|
|
|
helpers.createUtxos(server, wallet, helpers.toSatoshi([100]), function(utxos) { |
|
|
@ -844,7 +825,7 @@ describe('Copay server', function() { |
|
|
|
var server, wallet, txid; |
|
|
|
|
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet('123', 2, 2, function(s, w) { |
|
|
|
helpers.createAndJoinWallet(2, 2, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({ |
|
|
@ -903,7 +884,7 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('should fail on invalid signature', function(done) { |
|
|
|
it('should fail on invalid signature', function(done) { |
|
|
|
server.getPendingTxs({}, function(err, txs) { |
|
|
|
var tx = txs[0]; |
|
|
|
tx.id.should.equal(txid); |
|
|
@ -926,7 +907,7 @@ describe('Copay server', function() { |
|
|
|
var server, wallet, utxos; |
|
|
|
|
|
|
|
beforeEach(function(done) { |
|
|
|
helpers.createAndJoinWallet('123', 1, 1, function(s, w) { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({ |
|
|
@ -1015,17 +996,13 @@ describe('Copay server', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Multisignature wallet', function() { |
|
|
|
it.skip('all copayers should see pending proposal created by one copayer', function (done) { |
|
|
|
}); |
|
|
|
it.skip('all copayers should see pending proposal created by one copayer', function(done) {}); |
|
|
|
|
|
|
|
it.skip('tx proposals should not be broadcast until quorum is reached', function (done) { |
|
|
|
}); |
|
|
|
it.skip('tx proposals should not be broadcast until quorum is reached', function(done) {}); |
|
|
|
|
|
|
|
it.skip('tx proposals should accept as many rejections as possible without finally rejecting', function (done) { |
|
|
|
}); |
|
|
|
it.skip('tx proposals should accept as many rejections as possible without finally rejecting', function(done) {}); |
|
|
|
|
|
|
|
it.skip('proposal creator should be able to delete proposal if there are no other signatures', function (done) { |
|
|
|
}); |
|
|
|
it.skip('proposal creator should be able to delete proposal if there are no other signatures', function(done) {}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#getTxs', function() { |
|
|
@ -1034,7 +1011,7 @@ describe('Copay server', function() { |
|
|
|
beforeEach(function(done) { |
|
|
|
console.log('\tCreating TXS...'); |
|
|
|
clock = sinon.useFakeTimers(); |
|
|
|
helpers.createAndJoinWallet('123', 1, 1, function(s, w) { |
|
|
|
helpers.createAndJoinWallet(1, 1, function(s, w) { |
|
|
|
server = s; |
|
|
|
wallet = w; |
|
|
|
server.createAddress({ |
|
|
@ -1068,8 +1045,8 @@ describe('Copay server', function() { |
|
|
|
limit: 8 |
|
|
|
}, function(err, txps) { |
|
|
|
should.not.exist(err); |
|
|
|
var times = _.pluck(txps,'createdOn'); |
|
|
|
times.should.deep.equal([90,80,70,60]); |
|
|
|
var times = _.pluck(txps, 'createdOn'); |
|
|
|
times.should.deep.equal([90, 80, 70, 60]); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1080,8 +1057,8 @@ describe('Copay server', function() { |
|
|
|
limit: 5 |
|
|
|
}, function(err, txps) { |
|
|
|
should.not.exist(err); |
|
|
|
var times = _.pluck(txps,'createdOn'); |
|
|
|
times.should.deep.equal([50,40,30,20,10]); |
|
|
|
var times = _.pluck(txps, 'createdOn'); |
|
|
|
times.should.deep.equal([50, 40, 30, 20, 10]); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1091,18 +1068,17 @@ describe('Copay server', function() { |
|
|
|
limit: 4 |
|
|
|
}, function(err, txps) { |
|
|
|
should.not.exist(err); |
|
|
|
var times = _.pluck(txps,'createdOn'); |
|
|
|
times.should.deep.equal([90,80,70,60]); |
|
|
|
var times = _.pluck(txps, 'createdOn'); |
|
|
|
times.should.deep.equal([90, 80, 70, 60]); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should pull all txs', function(done) { |
|
|
|
server.getTxs({ |
|
|
|
}, function(err, txps) { |
|
|
|
server.getTxs({}, function(err, txps) { |
|
|
|
should.not.exist(err); |
|
|
|
var times = _.pluck(txps,'createdOn'); |
|
|
|
times.should.deep.equal([90,80,70,60,50,40,30,20,10]); |
|
|
|
var times = _.pluck(txps, 'createdOn'); |
|
|
|
times.should.deep.equal([90, 80, 70, 60, 50, 40, 30, 20, 10]); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1114,8 +1090,8 @@ describe('Copay server', function() { |
|
|
|
maxTs: 70, |
|
|
|
}, function(err, txps) { |
|
|
|
should.not.exist(err); |
|
|
|
var times = _.pluck(txps,'createdOn'); |
|
|
|
times.should.deep.equal([70,60,50]); |
|
|
|
var times = _.pluck(txps, 'createdOn'); |
|
|
|
times.should.deep.equal([70, 60, 50]); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|