|
|
@ -299,6 +299,43 @@ describe('Wallet service', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should create wallet with given id', function(done) { |
|
|
|
var opts = { |
|
|
|
name: 'my wallet', |
|
|
|
m: 2, |
|
|
|
n: 3, |
|
|
|
pubKey: TestData.keyPair.pub, |
|
|
|
id: '1234', |
|
|
|
}; |
|
|
|
server.createWallet(opts, function(err, walletId) { |
|
|
|
should.not.exist(err); |
|
|
|
server.storage.fetchWallet('1234', function(err, wallet) { |
|
|
|
should.not.exist(err); |
|
|
|
wallet.id.should.equal(walletId); |
|
|
|
wallet.name.should.equal('my wallet'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail to create wallets with same id', function(done) { |
|
|
|
var opts = { |
|
|
|
name: 'my wallet', |
|
|
|
m: 2, |
|
|
|
n: 3, |
|
|
|
pubKey: TestData.keyPair.pub, |
|
|
|
id: '1234', |
|
|
|
}; |
|
|
|
server.createWallet(opts, function(err, walletId) { |
|
|
|
server.createWallet(opts, function(err, walletId) { |
|
|
|
err.message.should.contain('Wallet already exists'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should fail to create wallet with no name', function(done) { |
|
|
|
var opts = { |
|
|
|
name: '', |
|
|
@ -2595,6 +2632,207 @@ describe('Wallet service', function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
it.skip('should abort scan if there is an error checking address activity', function(done) {}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('#replaceTemporaryRequestKey', function() { |
|
|
|
var server, walletId; |
|
|
|
beforeEach(function(done) { |
|
|
|
server = new WalletService(); |
|
|
|
var walletOpts = { |
|
|
|
name: 'my wallet', |
|
|
|
m: 2, |
|
|
|
n: 2, |
|
|
|
pubKey: TestData.keyPair.pub, |
|
|
|
}; |
|
|
|
server.createWallet(walletOpts, function(err, wId) { |
|
|
|
should.not.exist(err); |
|
|
|
should.exist.walletId; |
|
|
|
walletId = wId; |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should join existing wallet with temporaryRequestKey', function(done) { |
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[0].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[0].pubKey_1H_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = true; |
|
|
|
|
|
|
|
server.joinWallet(copayerOpts, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerId = result.copayerId; |
|
|
|
helpers.getAuthServer(copayerId, function(server) { |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
wallet.id.should.equal(walletId); |
|
|
|
var copayer = wallet.copayers[0]; |
|
|
|
copayer.isTemporaryRequestKey.should.equal(true); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail to replace a temporaryRequestKey on a not-complete wallet', function(done) { |
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[0].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[0].pubKey_1_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = true; |
|
|
|
|
|
|
|
server.joinWallet(copayerOpts, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerId = result.copayerId; |
|
|
|
helpers.getAuthServer(copayerId, function(server) { |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
|
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[0].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[0].pubKey_1H_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = false; |
|
|
|
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) { |
|
|
|
err.code.should.equal('WNOTFULL'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should fail to replace a temporaryRequestKey is Copayer is not in wallet', function(done) { |
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[0].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[0].pubKey_1_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = true; |
|
|
|
|
|
|
|
server.joinWallet(copayerOpts, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerId = result.copayerId; |
|
|
|
helpers.getAuthServer(copayerId, function(server) { |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
|
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[1].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[1].pubKey_1H_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = false; |
|
|
|
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) { |
|
|
|
err.code.should.equal('CDATAMISMATCH'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should fail replace a temporaryRequestKey with invalid copayer', function(done) { |
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[0].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[0].pubKey_1_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = true; |
|
|
|
|
|
|
|
server.joinWallet(copayerOpts, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
|
|
|
|
var copayerOpts2 = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[1].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[1].pubKey_1H_0, |
|
|
|
}); |
|
|
|
copayerOpts2.isTemporaryRequestKey = false; |
|
|
|
|
|
|
|
server.joinWallet(copayerOpts2, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
|
|
|
|
var copayerId = result.copayerId; |
|
|
|
helpers.getAuthServer(copayerId, function(server) { |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
|
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[1].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[1].pubKey_1H_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = false; |
|
|
|
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) { |
|
|
|
err.code.should.equal('CDATAMISMATCH'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should replace a temporaryRequestKey', function(done) { |
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[0].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[0].pubKey_1_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = true; |
|
|
|
|
|
|
|
server.joinWallet(copayerOpts, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerId = result.copayerId; |
|
|
|
|
|
|
|
var copayerOpts2 = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[1].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[1].pubKey_1H_0, |
|
|
|
}); |
|
|
|
copayerOpts2.isTemporaryRequestKey = false; |
|
|
|
|
|
|
|
server.joinWallet(copayerOpts2, function(err, result) { |
|
|
|
should.not.exist(err); |
|
|
|
var copayerId2 = result.copayerId; |
|
|
|
|
|
|
|
|
|
|
|
helpers.getAuthServer(copayerId, function(server) { |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
|
|
|
|
var copayerOpts = helpers.getSignedCopayerOpts({ |
|
|
|
walletId: walletId, |
|
|
|
name: 'me', |
|
|
|
xPubKey: TestData.copayers[0].xPubKey_45H, |
|
|
|
requestPubKey: TestData.copayers[0].pubKey_1H_0, |
|
|
|
}); |
|
|
|
copayerOpts.isTemporaryRequestKey = false; |
|
|
|
server.replaceTemporaryRequestKey(copayerOpts, function(err, wallet) { |
|
|
|
should.not.exist(err); |
|
|
|
server.getWallet({}, function(err, wallet) { |
|
|
|
wallet.copayers[0].isTemporaryRequestKey.should.equal(false); |
|
|
|
wallet.copayers[1].isTemporaryRequestKey.should.equal(false); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|