Skip to content

Commit e7d24df

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): add test for custom change outputs in PSBT
Add a test case to verify that the reference implementation correctly identifies and handles custom change outputs in PSBTs. Issue: BTC-2732 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 4d80186 commit e7d24df

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

modules/abstract-utxo/test/unit/transaction/fixedScript/explainPsbt.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ function hasWasmUtxoSupport(network: utxolib.Network): boolean {
1818

1919
function describeTransactionWith(acidTest: testutil.AcidTest) {
2020
describe(`${acidTest.name}`, function () {
21+
let psbt: utxolib.bitgo.UtxoPsbt;
2122
let psbtBytes: Buffer;
2223
let refExplanation: TransactionExplanation;
2324
before('prepare', function () {
24-
const psbt = acidTest.createPsbt();
25+
psbt = acidTest.createPsbt();
2526
refExplanation = explainPsbt(psbt, { pubs: acidTest.rootWalletKeys }, acidTest.network, {
2627
strict: true,
2728
});
@@ -40,6 +41,20 @@ function describeTransactionWith(acidTest: testutil.AcidTest) {
4041
});
4142
});
4243

44+
it('reference implementation should support custom change outputs', function () {
45+
const customChangeExplanation = explainPsbt(
46+
psbt,
47+
{ pubs: acidTest.rootWalletKeys, customChangePubs: acidTest.otherWalletKeys },
48+
acidTest.network,
49+
{ strict: true }
50+
);
51+
assert.ok(customChangeExplanation.customChangeOutputs);
52+
assert.strictEqual(customChangeExplanation.changeOutputs.length, refExplanation.changeOutputs.length);
53+
assert.strictEqual(customChangeExplanation.outputs.length, refExplanation.outputs.length - 1);
54+
assert.strictEqual(customChangeExplanation.customChangeOutputs.length, 1);
55+
assert.strictEqual(customChangeExplanation.customChangeOutputs[0].amount, '900');
56+
});
57+
4358
it('should match explainPsbtWasm', function () {
4459
if (!hasWasmUtxoSupport(acidTest.network)) {
4560
return this.skip();

0 commit comments

Comments
 (0)