Skip to content

Commit c52568f

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): improve parseTransaction tests
Refactor tests to use afterEach cleanup pattern instead of manual restore calls. Add proper TypeScript typing to test function parameters. Issue: BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent adc9fb2 commit c52568f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,25 @@ describe('Parse Transaction', function () {
3030

3131
const outputAmount = (0.01 * 1e8).toString();
3232

33-
async function runClassifyOutputsTest(outputAddress, verification, expectExternal, txParams: TransactionParams = {}) {
34-
sinon.stub(coin, 'explainTransaction').resolves({
33+
let stubExplainTransaction: sinon.SinonStub;
34+
let stubVerifyAddress: sinon.SinonStub | undefined;
35+
36+
afterEach(() => {
37+
if (stubExplainTransaction) {
38+
stubExplainTransaction.restore();
39+
}
40+
if (stubVerifyAddress) {
41+
stubVerifyAddress.restore();
42+
}
43+
});
44+
45+
async function runClassifyOutputsTest(
46+
outputAddress: string | undefined,
47+
verification: VerificationOptions,
48+
expectExternal: boolean,
49+
txParams: TransactionParams = {}
50+
) {
51+
stubExplainTransaction = sinon.stub(coin, 'explainTransaction').resolves({
3552
outputs: [] as Output[],
3653
changeOutputs: [
3754
{
@@ -42,7 +59,7 @@ describe('Parse Transaction', function () {
4259
} as TransactionExplanation);
4360

4461
if (!txParams.changeAddress) {
45-
sinon.stub(coin, 'verifyAddress').throws(new UnexpectedAddressError('test error'));
62+
stubVerifyAddress = sinon.stub(coin, 'verifyAddress').throws(new UnexpectedAddressError('test error'));
4663
}
4764

4865
const parsedTransaction = await coin.parseTransaction({
@@ -69,12 +86,6 @@ describe('Parse Transaction', function () {
6986
parsedTransaction.implicitExternalSpendAmount,
7087
Number(!isExplicit && expectExternal ? outputAmount : 0)
7188
);
72-
73-
(coin.explainTransaction as any).restore();
74-
75-
if (!txParams.changeAddress) {
76-
(coin.verifyAddress as any).restore();
77-
}
7889
}
7990

8091
it('should classify outputs which spend change back to a v1 wallet base address as internal', async function () {

0 commit comments

Comments
 (0)