Skip to content

Commit adc9fb2

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): replace should.js with node's assert module
Update test assertions to use Node's built-in assert module instead of should.js. This improves code consistency and reduces dependencies. Issue: BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent 4962069 commit adc9fb2

File tree

3 files changed

+116
-102
lines changed

3 files changed

+116
-102
lines changed

modules/abstract-utxo/test/unit/explainTransaction.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import should from 'should';
1+
import assert from 'assert';
2+
23
import { Triple } from '@bitgo/sdk-core';
34

45
import { bip322Fixtures } from './fixtures/bip322/fixtures';
@@ -22,51 +23,51 @@ describe('Explain Transaction', function () {
2223
it('should successfully run with a user nonce', async function () {
2324
const psbtHex = bip322Fixtures.valid.userNonce;
2425
const result = await coin.explainTransaction({ txHex: psbtHex, pubs });
25-
should.equal(result.outputAmount, '0');
26-
should.equal(result.changeAmount, '0');
27-
should.equal(result.outputs.length, 1);
28-
should.equal(result.outputs[0].address, 'scriptPubKey:6a');
29-
should.equal(result.fee, '0');
30-
should.equal(result.signatures, 0);
31-
should.exist(result.messages);
26+
assert.strictEqual(result.outputAmount, '0');
27+
assert.strictEqual(result.changeAmount, '0');
28+
assert.strictEqual(result.outputs.length, 1);
29+
assert.strictEqual(result.outputs[0].address, 'scriptPubKey:6a');
30+
assert.strictEqual(result.fee, '0');
31+
assert.strictEqual(result.signatures, 0);
32+
assert.ok(result.messages);
3233
result.messages?.forEach((obj) => {
33-
should.exist(obj.address);
34-
should.exist(obj.message);
35-
should.equal(obj.message, bip322Fixtures.valid.message);
34+
assert.ok(obj.address);
35+
assert.ok(obj.message);
36+
assert.strictEqual(obj.message, bip322Fixtures.valid.message);
3637
});
3738
});
3839

3940
it('should successfully run with a user signature', async function () {
4041
const psbtHex = bip322Fixtures.valid.userSignature;
4142
const result = await coin.explainTransaction({ txHex: psbtHex, pubs });
42-
should.equal(result.outputAmount, '0');
43-
should.equal(result.changeAmount, '0');
44-
should.equal(result.outputs.length, 1);
45-
should.equal(result.outputs[0].address, 'scriptPubKey:6a');
46-
should.equal(result.fee, '0');
47-
should.equal(result.signatures, 1);
48-
should.exist(result.messages);
43+
assert.strictEqual(result.outputAmount, '0');
44+
assert.strictEqual(result.changeAmount, '0');
45+
assert.strictEqual(result.outputs.length, 1);
46+
assert.strictEqual(result.outputs[0].address, 'scriptPubKey:6a');
47+
assert.strictEqual(result.fee, '0');
48+
assert.strictEqual(result.signatures, 1);
49+
assert.ok(result.messages);
4950
result.messages?.forEach((obj) => {
50-
should.exist(obj.address);
51-
should.exist(obj.message);
52-
should.equal(obj.message, bip322Fixtures.valid.message);
51+
assert.ok(obj.address);
52+
assert.ok(obj.message);
53+
assert.strictEqual(obj.message, bip322Fixtures.valid.message);
5354
});
5455
});
5556

5657
it('should successfully run with a hsm signature', async function () {
5758
const psbtHex = bip322Fixtures.valid.hsmSignature;
5859
const result = await coin.explainTransaction({ txHex: psbtHex, pubs });
59-
should.equal(result.outputAmount, '0');
60-
should.equal(result.changeAmount, '0');
61-
should.equal(result.outputs.length, 1);
62-
should.equal(result.outputs[0].address, 'scriptPubKey:6a');
63-
should.equal(result.fee, '0');
64-
should.equal(result.signatures, 2);
65-
should.exist(result.messages);
60+
assert.strictEqual(result.outputAmount, '0');
61+
assert.strictEqual(result.changeAmount, '0');
62+
assert.strictEqual(result.outputs.length, 1);
63+
assert.strictEqual(result.outputs[0].address, 'scriptPubKey:6a');
64+
assert.strictEqual(result.fee, '0');
65+
assert.strictEqual(result.signatures, 2);
66+
assert.ok(result.messages);
6667
result.messages?.forEach((obj) => {
67-
should.exist(obj.address);
68-
should.exist(obj.message);
69-
should.equal(obj.message, bip322Fixtures.valid.message);
68+
assert.ok(obj.address);
69+
assert.ok(obj.message);
70+
assert.strictEqual(obj.message, bip322Fixtures.valid.message);
7071
});
7172
});
7273
});

modules/abstract-utxo/test/unit/parseTransaction.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import should = require('should');
1+
import assert from 'assert';
2+
23
import * as sinon from 'sinon';
34
import { Wallet, UnexpectedAddressError, VerificationOptions } from '@bitgo/sdk-core';
45

@@ -51,17 +52,23 @@ describe('Parse Transaction', function () {
5152
verification,
5253
});
5354

54-
should.exist(parsedTransaction.outputs[0]);
55-
parsedTransaction.outputs[0].should.deepEqual({
55+
assert.ok(parsedTransaction.outputs[0]);
56+
assert.deepStrictEqual(parsedTransaction.outputs[0], {
5657
address: outputAddress,
5758
amount: outputAmount,
5859
external: expectExternal,
5960
});
6061

6162
const isExplicit =
6263
txParams.recipients !== undefined && txParams.recipients.some((recipient) => recipient.address === outputAddress);
63-
should.equal(parsedTransaction.explicitExternalSpendAmount, isExplicit && expectExternal ? outputAmount : '0');
64-
should.equal(parsedTransaction.implicitExternalSpendAmount, !isExplicit && expectExternal ? outputAmount : '0');
64+
assert.strictEqual(
65+
parsedTransaction.explicitExternalSpendAmount,
66+
Number(isExplicit && expectExternal ? outputAmount : 0)
67+
);
68+
assert.strictEqual(
69+
parsedTransaction.implicitExternalSpendAmount,
70+
Number(!isExplicit && expectExternal ? outputAmount : 0)
71+
);
6572

6673
(coin.explainTransaction as any).restore();
6774

modules/abstract-utxo/test/unit/verifyTransaction.ts

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import assert from 'assert';
2+
13
import * as utxolib from '@bitgo/utxo-lib';
2-
import 'should';
34
import * as sinon from 'sinon';
45
import { Wallet } from '@bitgo/sdk-core';
56

@@ -85,69 +86,71 @@ describe('Verify Transaction', function () {
8586
sinon.stub(coin, 'parseTransaction').resolves(stubData.parseTransactionData.badKey as any);
8687
const verifyWallet = sinon.createStubInstance(Wallet, {});
8788

88-
await coin
89-
.verifyTransaction({
89+
await assert.rejects(
90+
coin.verifyTransaction({
9091
txParams: {
9192
walletPassphrase: passphrase,
9293
},
9394
txPrebuild: {},
9495
wallet: verifyWallet as any,
9596
verification: {},
96-
})
97-
.should.be.rejectedWith(/transaction requires verification of user public key, but it was unable to be verified/);
97+
}),
98+
/transaction requires verification of user public key, but it was unable to be verified/
99+
);
98100

99101
(coin.parseTransaction as any).restore();
100102
});
101103

102104
it('should fail if the custom change verification data is required but missing', async () => {
103105
sinon.stub(coin, 'parseTransaction').resolves(stubData.parseTransactionData.noCustomChange as any);
104106

105-
await coin
106-
.verifyTransaction({
107+
await assert.rejects(
108+
coin.verifyTransaction({
107109
txParams: {
108110
walletPassphrase: passphrase,
109111
},
110112
txPrebuild: {},
111113
wallet: unsignedSendingWallet as any,
112114
verification: {},
113-
})
114-
.should.be.rejectedWith(/parsed transaction is missing required custom change verification data/);
115+
}),
116+
/parsed transaction is missing required custom change verification data/
117+
);
115118

116119
(coin.parseTransaction as any).restore();
117120
});
118121

119122
it('should fail if the custom change keys or key signatures are missing', async () => {
120123
sinon.stub(coin, 'parseTransaction').resolves(stubData.parseTransactionData.emptyCustomChange as any);
121124

122-
await coin
123-
.verifyTransaction({
125+
await assert.rejects(
126+
coin.verifyTransaction({
124127
txParams: {
125128
walletPassphrase: passphrase,
126129
},
127130
txPrebuild: {},
128131
wallet: unsignedSendingWallet as any,
129132
verification: {},
130-
})
131-
.should.be.rejectedWith(/customChange property is missing keys or signatures/);
133+
}),
134+
/customChange property is missing keys or signatures/
135+
);
132136

133137
(coin.parseTransaction as any).restore();
134138
});
135139

136140
it('should fail if the custom change key signatures cannot be verified', async () => {
137141
sinon.stub(coin, 'parseTransaction').resolves((await stubData.parseTransactionData.badSigs()) as any);
138142

139-
await coin
140-
.verifyTransaction({
143+
await assert.rejects(
144+
coin.verifyTransaction({
141145
txParams: {
142146
walletPassphrase: passphrase,
143147
},
144148
txPrebuild: {},
145149
wallet: unsignedSendingWallet as any,
146150
verification: {},
147-
})
148-
.should.be.rejectedWith(
149-
/transaction requires verification of custom change key signatures, but they were unable to be verified/
150-
);
151+
}),
152+
/transaction requires verification of custom change key signatures, but they were unable to be verified/
153+
);
151154

152155
(coin.parseTransaction as any).restore();
153156
});
@@ -157,16 +160,17 @@ describe('Verify Transaction', function () {
157160

158161
// if verify transaction gets rejected with the outputs missing error message,
159162
// then we know that the verification of the custom change key signatures was successful
160-
await coin
161-
.verifyTransaction({
163+
await assert.rejects(
164+
coin.verifyTransaction({
162165
txParams: {
163166
walletPassphrase: passphrase,
164167
},
165168
txPrebuild: {},
166169
wallet: unsignedSendingWallet as any,
167170
verification: {},
168-
})
169-
.should.be.rejectedWith(/expected outputs missing in transaction prebuild/);
171+
}),
172+
/expected outputs missing in transaction prebuild/
173+
);
170174

171175
(coin.parseTransaction as any).restore();
172176
});
@@ -185,15 +189,16 @@ describe('Verify Transaction', function () {
185189
needsCustomChangeKeySignatureVerification: false,
186190
});
187191

188-
await coin
189-
.verifyTransaction({
192+
await assert.rejects(
193+
coin.verifyTransaction({
190194
txParams: {
191195
walletPassphrase: passphrase,
192196
},
193197
txPrebuild: {},
194198
wallet: unsignedSendingWallet as any,
195-
})
196-
.should.be.rejectedWith('prebuild attempts to spend to unintended external recipients');
199+
}),
200+
/prebuild attempts to spend to unintended external recipients/
201+
);
197202

198203
coinMock.restore();
199204
});
@@ -216,17 +221,17 @@ describe('Verify Transaction', function () {
216221
.stub(coin, 'createTransactionFromHex')
217222
.returns({ ins: [] } as unknown as utxolib.bitgo.UtxoTransaction);
218223

219-
await coin
220-
.verifyTransaction({
221-
txParams: {
222-
walletPassphrase: passphrase,
223-
},
224-
txPrebuild: {
225-
txHex: '00',
226-
},
227-
wallet: unsignedSendingWallet as any,
228-
})
229-
.should.eventually.be.true();
224+
const result = await coin.verifyTransaction({
225+
txParams: {
226+
walletPassphrase: passphrase,
227+
},
228+
txPrebuild: {
229+
txHex: '00',
230+
},
231+
wallet: unsignedSendingWallet as any,
232+
});
233+
234+
assert.strictEqual(result, true);
230235

231236
coinMock.restore();
232237
bitcoinMock.restore();
@@ -246,8 +251,8 @@ describe('Verify Transaction', function () {
246251
needsCustomChangeKeySignatureVerification: false,
247252
});
248253

249-
await coin
250-
.verifyTransaction({
254+
await assert.rejects(
255+
coin.verifyTransaction({
251256
txParams: {
252257
walletPassphrase: passphrase,
253258
},
@@ -258,8 +263,9 @@ describe('Verify Transaction', function () {
258263
verification: {
259264
allowPaygoOutput: false,
260265
},
261-
})
262-
.should.be.rejectedWith('prebuild attempts to spend to unintended external recipients');
266+
}),
267+
/prebuild attempts to spend to unintended external recipients/
268+
);
263269

264270
coinMock.restore();
265271
});
@@ -282,18 +288,18 @@ describe('Verify Transaction', function () {
282288
.stub(coin, 'createTransactionFromHex')
283289
.returns({ ins: [] } as unknown as utxolib.bitgo.UtxoTransaction);
284290

285-
await coin
286-
.verifyTransaction({
287-
txParams: {
288-
walletPassphrase: passphrase,
289-
},
290-
txPrebuild: {
291-
txHex: '00',
292-
},
293-
wallet: unsignedSendingWallet as any,
294-
verification: {},
295-
})
296-
.should.eventually.be.true();
291+
const result = await coin.verifyTransaction({
292+
txParams: {
293+
walletPassphrase: passphrase,
294+
},
295+
txPrebuild: {
296+
txHex: '00',
297+
},
298+
wallet: unsignedSendingWallet as any,
299+
verification: {},
300+
});
301+
302+
assert.strictEqual(result, true);
297303

298304
coinMock.restore();
299305
bitcoinMock.restore();
@@ -330,18 +336,18 @@ describe('Verify Transaction', function () {
330336
.stub(bigintCoin, 'createTransactionFromHex')
331337
.returns({ ins: [] } as unknown as utxolib.bitgo.UtxoTransaction);
332338

333-
await bigintCoin
334-
.verifyTransaction({
335-
txParams: {
336-
walletPassphrase: passphrase,
337-
},
338-
txPrebuild: {
339-
txHex: '00',
340-
},
341-
wallet: unsignedSendingWallet as any,
342-
verification: {},
343-
})
344-
.should.eventually.be.true();
339+
const result = await bigintCoin.verifyTransaction({
340+
txParams: {
341+
walletPassphrase: passphrase,
342+
},
343+
txPrebuild: {
344+
txHex: '00',
345+
},
346+
wallet: unsignedSendingWallet as any,
347+
verification: {},
348+
});
349+
350+
assert.strictEqual(result, true);
345351

346352
coinMock.restore();
347353
bitcoinMock.restore();

0 commit comments

Comments
 (0)