Skip to content

Commit 601d550

Browse files
author
Kevin Daniel
committed
refactor(bitgo): replace bluebird with native promises
Ticket: DX-1129 TICKET: DX-1129
1 parent 7aded40 commit 601d550

File tree

18 files changed

+1420
-1539
lines changed

18 files changed

+1420
-1539
lines changed

modules/bitgo/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@
116116
"@bitgo/statics": "^51.3.0",
117117
"@bitgo/unspents": "^0.47.20",
118118
"@bitgo/utxo-lib": "^11.2.4",
119-
"@types/bluebird": "^3.5.25",
120119
"@types/superagent": "^4.1.3",
121120
"bignumber.js": "^9.1.1",
122-
"bluebird": "^3.5.3",
123121
"fs-extra": "^9.1.0",
124122
"lodash": "^4.17.14",
125123
"openpgp": "5.10.1",

modules/bitgo/test/integration/enterprise.ts

Lines changed: 74 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,115 +6,96 @@
66

77
import 'should';
88

9-
import * as Promise from 'bluebird';
10-
const co = Promise.coroutine;
119
const BigNumber = require('bignumber.js');
1210

1311
const TestBitGo = require('../lib/test_bitgo');
1412

1513
describe('Enterprise', function () {
1614
let bitgo;
1715

18-
before(
19-
co(function* () {
20-
bitgo = new TestBitGo({ env: 'test' });
21-
bitgo.initializeTestVars();
22-
yield bitgo.authenticateEnterpriseCreatorTestUser(bitgo.testUserOTP());
23-
})
24-
);
16+
before(async function () {
17+
bitgo = new TestBitGo({ env: 'test' });
18+
bitgo.initializeTestVars();
19+
await bitgo.authenticateEnterpriseCreatorTestUser(bitgo.testUserOTP());
20+
});
2521

2622
describe('Fetch Enterprise', function () {
27-
it(
28-
'should fetch an enterprise',
29-
co(function* () {
30-
const enterprises = bitgo.coin('tltc').enterprises();
31-
const entList = yield enterprises.list();
32-
entList.length.should.be.greaterThan(6);
33-
const enterprise1 = entList[0];
34-
enterprise1.id.should.equal('5a84db9be4b3cab007c08ab59fb93ec3');
35-
enterprise1.name.should.equal('Test Enterprise');
36-
})
37-
);
23+
it('should fetch an enterprise', async function () {
24+
const enterprises = bitgo.coin('tltc').enterprises();
25+
const entList = await enterprises.list();
26+
entList.length.should.be.greaterThan(6);
27+
const enterprise1 = entList[0];
28+
enterprise1.id.should.equal('5a84db9be4b3cab007c08ab59fb93ec3');
29+
enterprise1.name.should.equal('Test Enterprise');
30+
});
3831

39-
it(
40-
'should fetch the users of an enterprise',
41-
co(function* () {
42-
const enterprises = bitgo.coin('tltc').enterprises();
43-
const enterprise = (yield enterprises.list())[0];
44-
const users = yield enterprise.users();
45-
users.should.have.property('adminUsers');
46-
users.should.have.property('walletUsers');
47-
const { adminUsers, walletUsers } = users;
48-
adminUsers.length.should.equal(2);
49-
walletUsers.length.should.equal(1);
50-
const walletUser = walletUsers[0];
51-
walletUser.should.have.property('id');
52-
walletUser.should.have.property('username');
53-
walletUser.id.should.equal('5a84db312cd303af07897eebb5a0fba2');
54-
walletUser.username.should.equal('[email protected]');
55-
const adminUser = adminUsers[0];
56-
adminUser.should.have.property('id');
57-
adminUser.should.have.property('username');
58-
adminUser.should.have.property('verified');
59-
adminUser.id.should.equal('5a849b8cb6f7cb5007b77741e632675a');
60-
adminUser.username.should.equal('[email protected]');
61-
adminUser.verified.should.equal(true);
62-
})
63-
);
32+
it('should fetch the users of an enterprise', async function () {
33+
const enterprises = bitgo.coin('tltc').enterprises();
34+
const enterprise = (await enterprises.list())[0];
35+
const users = await enterprise.users();
36+
users.should.have.property('adminUsers');
37+
users.should.have.property('walletUsers');
38+
const { adminUsers, walletUsers } = users;
39+
adminUsers.length.should.equal(2);
40+
walletUsers.length.should.equal(1);
41+
const walletUser = walletUsers[0];
42+
walletUser.should.have.property('id');
43+
walletUser.should.have.property('username');
44+
walletUser.id.should.equal('5a84db312cd303af07897eebb5a0fba2');
45+
walletUser.username.should.equal('[email protected]');
46+
const adminUser = adminUsers[0];
47+
adminUser.should.have.property('id');
48+
adminUser.should.have.property('username');
49+
adminUser.should.have.property('verified');
50+
adminUser.id.should.equal('5a849b8cb6f7cb5007b77741e632675a');
51+
adminUser.username.should.equal('[email protected]');
52+
adminUser.verified.should.equal(true);
53+
});
6454

65-
it(
66-
'should fetch an enterprise eth fee balance',
67-
co(function* () {
68-
const enterprises = bitgo.coin('teth').enterprises();
69-
const enterprise = (yield enterprises.list())[0];
70-
const feeBalance = yield enterprise.getFeeAddressBalance();
71-
feeBalance.should.have.property('balance');
72-
const balance = new BigNumber(feeBalance.balance);
73-
balance.greaterThan(1000).should.equal(true);
74-
})
75-
);
55+
it('should fetch an enterprise eth fee balance', async function () {
56+
const enterprises = bitgo.coin('teth').enterprises();
57+
const enterprise = (await enterprises.list())[0];
58+
const feeBalance = await enterprise.getFeeAddressBalance();
59+
feeBalance.should.have.property('balance');
60+
const balance = new BigNumber(feeBalance.balance);
61+
balance.greaterThan(1000).should.equal(true);
62+
});
7663
});
7764

7865
// TODO: remove enterprises after creating them once the functionality is available
7966
describe('Modify Enterprise', function () {
8067
// TODO: figure out how to approve the removal request from another user
81-
it(
82-
'should add and remove user from enterprise',
83-
co(function* () {
84-
const enterprise = yield bitgo.coin('tltc').enterprises().create({ name: 'Test Enterprise' });
85-
const refetchedEnterprise = yield bitgo.coin('tltc').enterprises().get({ id: enterprise.id });
86-
const users0 = yield refetchedEnterprise.users();
87-
yield enterprise.addUser({ username: '[email protected]' });
88-
const users1 = yield refetchedEnterprise.users();
89-
const removalPendingApproval = yield enterprise.removeUser({ username: '[email protected]' });
90-
enterprise.id.should.equal(refetchedEnterprise.id);
91-
refetchedEnterprise.name.should.equal('Test Enterprise');
92-
users0.adminUsers.length.should.equal(1);
93-
users1.adminUsers.length.should.equal(2);
94-
users0.walletUsers.length.should.equal(0);
95-
users1.walletUsers.length.should.equal(0);
96-
removalPendingApproval.state.should.equal('pending');
97-
})
98-
);
68+
it('should add and remove user from enterprise', async function () {
69+
const enterprise = await bitgo.coin('tltc').enterprises().create({ name: 'Test Enterprise' });
70+
const refetchedEnterprise = await bitgo.coin('tltc').enterprises().get({ id: enterprise.id });
71+
const users0 = await refetchedEnterprise.users();
72+
await enterprise.addUser({ username: '[email protected]' });
73+
const users1 = await refetchedEnterprise.users();
74+
const removalPendingApproval = await enterprise.removeUser({ username: '[email protected]' });
75+
enterprise.id.should.equal(refetchedEnterprise.id);
76+
refetchedEnterprise.name.should.equal('Test Enterprise');
77+
users0.adminUsers.length.should.equal(1);
78+
users1.adminUsers.length.should.equal(2);
79+
users0.walletUsers.length.should.equal(0);
80+
users1.walletUsers.length.should.equal(0);
81+
removalPendingApproval.state.should.equal('pending');
82+
});
9983

100-
it(
101-
'should add wallets and then list them on an enterprise',
102-
co(function* coEnterpriseWalletAdditionTest() {
103-
const enterprise = yield bitgo.coin('tltc').enterprises().create({ name: 'Test Enterprise' });
104-
const wallet = yield bitgo.coin('tltc').wallets().generateWallet({
105-
label: 'Enterprise Test Wallet',
106-
enterprise: enterprise.id,
107-
passphrase: TestBitGo.TEST_WALLET1_PASSCODE,
108-
});
109-
const enterpriseWallets = yield enterprise.coinWallets();
110-
enterpriseWallets.should.have.property('wallets');
111-
enterpriseWallets.wallets.length.should.equal(1);
112-
enterpriseWallets.wallets[0].id().should.equal(wallet.wallet.id());
113-
yield wallet.wallet.remove();
114-
const updatedEnterpriseWallets = yield enterprise.coinWallets();
115-
updatedEnterpriseWallets.should.have.property('wallets');
116-
updatedEnterpriseWallets.wallets.length.should.equal(0);
117-
})
118-
);
84+
it('should add wallets and then list them on an enterprise', async function coEnterpriseWalletAdditionTest() {
85+
const enterprise = await bitgo.coin('tltc').enterprises().create({ name: 'Test Enterprise' });
86+
const wallet = await bitgo.coin('tltc').wallets().generateWallet({
87+
label: 'Enterprise Test Wallet',
88+
enterprise: enterprise.id,
89+
passphrase: TestBitGo.TEST_WALLET1_PASSCODE,
90+
});
91+
const enterpriseWallets = await enterprise.coinWallets();
92+
enterpriseWallets.should.have.property('wallets');
93+
enterpriseWallets.wallets.length.should.equal(1);
94+
enterpriseWallets.wallets[0].id().should.equal(wallet.wallet.id());
95+
await wallet.wallet.remove();
96+
const updatedEnterpriseWallets = await enterprise.coinWallets();
97+
updatedEnterpriseWallets.should.have.property('wallets');
98+
updatedEnterpriseWallets.wallets.length.should.equal(0);
99+
});
119100
});
120101
});

modules/bitgo/test/integration/keychains.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import { strict as assert } from 'assert';
99
import 'should';
10-
import { coroutine as co } from 'bluebird';
1110
import * as _ from 'lodash';
1211

1312
const TestBitGo = require('../lib/test_bitgo');
@@ -138,36 +137,31 @@ describe('Keychains', function () {
138137
let keychains;
139138
let correctPassword;
140139

141-
before(
142-
co(function* beforeUpdatePassword() {
143-
bitgo = new TestBitGo({ env: 'test' });
144-
bitgo.initializeTestVars();
145-
keychains = bitgo.keychains();
146-
const loginPasswords = yield bitgo.authenticateChangePWTestUser(bitgo.testUserOTP());
147-
correctPassword = loginPasswords.password;
148-
yield bitgo.unlock({ otp: bitgo.testUserOTP() });
149-
})
150-
);
151-
152-
it(
153-
'successful update the password for all v1 keychains that are encrypted with the old password',
154-
co(function* itUpdatePassword() {
155-
const newPassword = 'newPassword';
156-
const result = yield keychains.updatePassword({ oldPassword: correctPassword, newPassword });
157-
_.forOwn(result.keychains, function (encryptedXprv, xpub) {
158-
xpub.should.startWith('xpub');
159-
try {
160-
const decryptedPrv = bitgo.decrypt({ input: encryptedXprv, password: newPassword });
161-
decryptedPrv.should.startWith('xprv');
162-
} catch (e) {
163-
// the decryption didn't work because of the wrong password, this is one of the keychains that wasn't
164-
// encrypted with the old password
165-
e.message.should.startWith('password error');
166-
}
167-
});
168-
result.should.hasOwnProperty('version');
169-
})
170-
);
140+
before(async function beforeUpdatePassword() {
141+
bitgo = new TestBitGo({ env: 'test' });
142+
bitgo.initializeTestVars();
143+
keychains = bitgo.keychains();
144+
const loginPasswords = await bitgo.authenticateChangePWTestUser(bitgo.testUserOTP());
145+
correctPassword = loginPasswords.password;
146+
await bitgo.unlock({ otp: bitgo.testUserOTP() });
147+
});
148+
149+
it('successful update the password for all v1 keychains that are encrypted with the old password', async function itUpdatePassword() {
150+
const newPassword = 'newPassword';
151+
const result = await keychains.updatePassword({ oldPassword: correctPassword, newPassword });
152+
_.forOwn(result.keychains, function (encryptedXprv, xpub) {
153+
xpub.should.startWith('xpub');
154+
try {
155+
const decryptedPrv = bitgo.decrypt({ input: encryptedXprv, password: newPassword });
156+
decryptedPrv.should.startWith('xprv');
157+
} catch (e) {
158+
// the decryption didn't work because of the wrong password, this is one of the keychains that wasn't
159+
// encrypted with the old password
160+
e.message.should.startWith('password error');
161+
}
162+
});
163+
result.should.hasOwnProperty('version');
164+
});
171165
});
172166

173167
describe('Get', function () {

0 commit comments

Comments
 (0)