Skip to content

Commit d4ef534

Browse files
committed
add testcases to BCH/testnet support
1 parent 267cfdb commit d4ef534

File tree

5 files changed

+129
-5
lines changed

5 files changed

+129
-5
lines changed

config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ var config = {
4646
testnet: {
4747
provider: 'insight',
4848
url: 'https://test-insight.bitpay.com:443',
49-
// url: 'http://localhost:3001',
5049
// Multiple servers (in priority order)
5150
// url: ['http://a.b.c', 'https://test-insight.bitpay.com:443'],
5251
},
5352
},
5453
bch: {
5554
livenet: {
5655
provider: 'insight',
57-
url: 'https://cashexplorer.bitcoin.com',
56+
//url: 'https://cashexplorer.bitcoin.com',
57+
url: 'http://localhost:2001',
58+
translateAddresses: false,
5859
},
5960
},
6061
},

scripts/deleteWallet.mongo

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
a='bd0e9eed-4712-42e5-bb21-193cde4c9e21';
2+
// json support
3+
a='f42c8c47-0f7e-4cb0-9056-6c50bb821d7d';
34
b= {'walletId':a};
45

56
db.addresses.remove(b);

test/integration/helpers.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) {
185185
pubKey: TestData.keyPair.pub,
186186
singleAddress: !!opts.singleAddress,
187187
coin: opts.coin || 'btc',
188+
network: opts.network || 'livenet',
188189
};
189190
if (_.isBoolean(opts.supportBIP44AndP2PKH))
190191
walletOpts.supportBIP44AndP2PKH = opts.supportBIP44AndP2PKH;
@@ -194,18 +195,26 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) {
194195

195196
async.each(_.range(n), function(i, cb) {
196197
var copayerData = TestData.copayers[i + offset];
198+
199+
200+
var pub = (_.isBoolean(opts.supportBIP44AndP2PKH) && !opts.supportBIP44AndP2PKH) ? copayerData.xPubKey_45H : copayerData.xPubKey_44H_0H_0H;
201+
202+
if (opts.network == 'testnet')
203+
pub = copayerData.xPubKey_44H_0H_0Ht;
204+
197205
var copayerOpts = helpers.getSignedCopayerOpts({
198206
walletId: walletId,
199207
coin: opts.coin,
200208
name: 'copayer ' + (i + 1),
201-
xPubKey: (_.isBoolean(opts.supportBIP44AndP2PKH) && !opts.supportBIP44AndP2PKH) ? copayerData.xPubKey_45H : copayerData.xPubKey_44H_0H_0H,
209+
xPubKey: pub,
202210
requestPubKey: copayerData.pubKey_1H_0,
203211
customData: 'custom data ' + (i + 1),
204212
});
205213
if (_.isBoolean(opts.supportBIP44AndP2PKH))
206214
copayerOpts.supportBIP44AndP2PKH = opts.supportBIP44AndP2PKH;
207215

208216
server.joinWallet(copayerOpts, function(err, result) {
217+
if (err) console.log(err);
209218
should.not.exist(err);
210219
copayerIds.push(result.copayerId);
211220
return cb(err);

test/integration/server.js

+109-1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ describe('Wallet service', function() {
458458
});
459459
});
460460

461+
461462
describe('Address derivation strategy', function() {
462463
var server;
463464
beforeEach(function() {
@@ -1249,7 +1250,7 @@ describe('Wallet service', function() {
12491250
});
12501251
});
12511252

1252-
it('should create address', function(done) {
1253+
it('should create address ', function(done) {
12531254
server.createAddress({}, function(err, address) {
12541255
should.not.exist(err);
12551256
should.exist(address);
@@ -1377,6 +1378,113 @@ describe('Wallet service', function() {
13771378
});
13781379
});
13791380

1381+
describe('shared wallets (BIP44/BCH)', function() {
1382+
beforeEach(function(done) {
1383+
helpers.createAndJoinWallet(2, 2, {
1384+
coin: 'bch'
1385+
}, function(s, w) {
1386+
server = s;
1387+
wallet = w;
1388+
done();
1389+
});
1390+
});
1391+
1392+
it('should create address', function(done) {
1393+
server.createAddress({}, function(err, address) {
1394+
should.not.exist(err);
1395+
should.exist(address);
1396+
address.walletId.should.equal(wallet.id);
1397+
address.network.should.equal('livenet');
1398+
address.address.should.equal('HBf8isgS8EXG1r3X6GP89FmooUmiJ42wHS');
1399+
address.isChange.should.be.false;
1400+
address.path.should.equal('m/0/0');
1401+
address.type.should.equal('P2SH');
1402+
address.coin.should.equal('bch');
1403+
server.getNotifications({}, function(err, notifications) {
1404+
should.not.exist(err);
1405+
var notif = _.find(notifications, {
1406+
type: 'NewAddress'
1407+
});
1408+
should.exist(notif);
1409+
notif.data.address.should.equal(address.address);
1410+
done();
1411+
});
1412+
});
1413+
});
1414+
1415+
it('should create many addresses on simultaneous requests', function(done) {
1416+
var N = 5;
1417+
async.mapSeries(_.range(N), function(i, cb) {
1418+
server.createAddress({}, cb);
1419+
}, function(err, addresses) {
1420+
addresses.length.should.equal(N);
1421+
_.each(_.range(N), function(i) {
1422+
addresses[i].path.should.equal('m/0/' + i);
1423+
});
1424+
// No two identical addresses
1425+
_.uniq(_.pluck(addresses, 'address')).length.should.equal(N);
1426+
done();
1427+
});
1428+
});
1429+
1430+
it('should not create address if unable to store it', function(done) {
1431+
sinon.stub(server.storage, 'storeAddressAndWallet').yields('dummy error');
1432+
server.createAddress({}, function(err, address) {
1433+
should.exist(err);
1434+
should.not.exist(address);
1435+
1436+
server.getMainAddresses({}, function(err, addresses) {
1437+
addresses.length.should.equal(0);
1438+
1439+
server.storage.storeAddressAndWallet.restore();
1440+
server.createAddress({}, function(err, address) {
1441+
should.not.exist(err);
1442+
should.exist(address);
1443+
done();
1444+
});
1445+
});
1446+
});
1447+
});
1448+
});
1449+
1450+
1451+
describe('1-1 wallet (BIP44/BCH/Testnet)', function() {
1452+
beforeEach(function(done) {
1453+
helpers.createAndJoinWallet(1, 1, {
1454+
coin: 'bch',
1455+
network: 'testnet',
1456+
}, function(s, w) {
1457+
server = s;
1458+
wallet = w;
1459+
done();
1460+
});
1461+
});
1462+
1463+
it('should create address', function(done) {
1464+
server.createAddress({}, function(err, address) {
1465+
should.not.exist(err);
1466+
should.exist(address);
1467+
address.walletId.should.equal(wallet.id);
1468+
address.network.should.equal('testnet');
1469+
address.address.should.equal('mrM5kMkqZccK5MxZYSsM3SjqdMaNKLJgrJ');
1470+
address.isChange.should.be.false;
1471+
address.path.should.equal('m/0/0');
1472+
address.type.should.equal('P2PKH');
1473+
address.coin.should.equal('bch');
1474+
server.getNotifications({}, function(err, notifications) {
1475+
should.not.exist(err);
1476+
var notif = _.find(notifications, {
1477+
type: 'NewAddress'
1478+
});
1479+
should.exist(notif);
1480+
notif.data.address.should.equal(address.address);
1481+
done();
1482+
});
1483+
});
1484+
});
1485+
});
1486+
1487+
13801488
describe('1-of-1 (BIP44 & P2PKH)', function() {
13811489
beforeEach(function(done) {
13821490
helpers.createAndJoinWallet(1, 1, function(s, w) {

test/testdata.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ var copayers = [{
1313
xPubKey_45H: 'xpub68pKcb8jHWqWuTgPz2czjFSJJBJTsTNdd87Mgh5bVz4sNFBJBus5KyptGBWgA4V6LGCi12s4Mw4S1JC2GkqX4NJ4kfQ47XqRZLbyM2DY9Jd',
1414
xPrivKey_44H_0H_0H: 'xprv9zWRZ7CXrC4z9xA9RRBFXohmPKbyCajWaCNTHPtwNeJwTnysHG5QK7WMqpNLVtvqGxts7WNcNtqBLfdaFdCGknDPXjLKt2E2BUrPaFDqrLh',
1515
xPubKey_44H_0H_0H: 'xpub6DVmxcjRgZdHNSEcXSiFtweVwMSTc3TMwRJ45nJYvyqvLbK1poPerupqh87rSoz27wvckb1CKnGZoLmLXSZyNGZtVd7neqSvdwJL6fceQpe',
16+
17+
18+
xPrivKey_44H_0H_0Ht: 'tprv8ZgxMBicQKsPcxUEtgtQ2wKpkmuNKS6R2w3UmFTUHHURv4PKGE2aGkkbQEcQs9gGsoW4zPr7VM98xdbjQuWc3cZ6bkEyKy1sywhV9gLUcUi',
19+
xPubKey_44H_0H_0Ht: 'tpubD6NzVbkrYhZ4WRW2nLYzSLywKoRJUmHKcEeG3mVmhZGpkYe5tcrATFNTaQRAWM3dzL2QyXoctpjkaAXruDXyc6xkF4EDGu3eQdwZXFzoFSW',
20+
1621
xPrivKey_1H: 'xprv9upyD5bqT9HBkWym7TvTH3njEzTnjrtkLB2sg3DD2CxxA5hZKGee1sYJUtD8C4QaeATLXQ33TirRzRhuTGDBA6XRoYDMwfXAj1KSmGyNBio',
1722
xPubKey_1H: 'xpub68pKcb8jHWqUy14EDVTTeBjTo2JH9KcbhPxUURcpaYVw2t2hroxtZfrnLBw1bWzBrHbEJA48QmZ8DB9gTvhphKSitC15SiYx9k2ncGh55Hq',
1823
privKey_1H_0: 'a710be25950738a7d13637e2e09affd7f579a3479fd7cc024bd9459f8fba6659',

0 commit comments

Comments
 (0)