Skip to content

Commit 17b5a94

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): add test for explainPsbt utility
Add unit test for the explainPsbt utility function using AcidTest framework from utxo-lib. Tests ensure that transaction explanations correctly include output amounts, change outputs, and signature counts across different signing stages. Issue: BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent aad58a2 commit 17b5a94

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import assert from 'node:assert/strict';
2+
3+
import { testutil } from '@bitgo/utxo-lib';
4+
5+
import { explainPsbt } from '../../../../src/transaction/fixedScript';
6+
7+
function describeTransactionWith(acidTest: testutil.AcidTest) {
8+
describe(`explainPsbt ${acidTest.name}`, function () {
9+
it('should explain the transaction', function () {
10+
const psbt = acidTest.createPsbt();
11+
const explanation = explainPsbt(
12+
psbt,
13+
{ pubs: acidTest.rootWalletKeys.triple.map((k) => k.toBase58()) },
14+
acidTest.network,
15+
{ strict: true }
16+
);
17+
assert.strictEqual(explanation.outputs.length, 3);
18+
assert.strictEqual(explanation.outputAmount, '2700');
19+
assert.strictEqual(explanation.changeOutputs.length, acidTest.outputs.length - 3);
20+
explanation.changeOutputs.forEach((change) => {
21+
assert.strictEqual(change.amount, '900');
22+
assert.strictEqual(typeof change.address, 'string');
23+
});
24+
assert.strictEqual(explanation.inputSignatures.length, acidTest.inputs.length);
25+
explanation.inputSignatures.forEach((signature, i) => {
26+
if (acidTest.inputs[i].scriptType === 'p2shP2pk') {
27+
return;
28+
}
29+
if (acidTest.signStage === 'unsigned') {
30+
assert.strictEqual(signature, 0);
31+
} else if (acidTest.signStage === 'halfsigned') {
32+
assert.strictEqual(signature, 1);
33+
} else if (acidTest.signStage === 'fullsigned') {
34+
assert.strictEqual(signature, 2);
35+
}
36+
});
37+
});
38+
});
39+
}
40+
41+
testutil.AcidTest.suite().forEach((test) => describeTransactionWith(test));

0 commit comments

Comments
 (0)