From a137dd72f7881d2a7d0ee01abaed099b49c008ef Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Fri, 25 Oct 2024 09:36:43 -0400 Subject: [PATCH] test(utxo-lib): add check in utxo-lib for op-return TICKET: BTC-1582 --- modules/utxo-lib/src/testutil/psbt.ts | 8 ++++-- .../utxo-lib/test/bitgo/psbt/PsbtOutputs.ts | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/modules/utxo-lib/src/testutil/psbt.ts b/modules/utxo-lib/src/testutil/psbt.ts index 0fa1121c9b..7e849763f9 100644 --- a/modules/utxo-lib/src/testutil/psbt.ts +++ b/modules/utxo-lib/src/testutil/psbt.ts @@ -49,10 +49,11 @@ export type Input = { /** * Set isInternalAddress=true for internal output address */ +// Make script: string as instead of scriptType or address export type Output = { value: bigint; isInternalAddress?: boolean; -} & ({ scriptType: OutputScriptType } | { address: string }); +} & ({ scriptType: OutputScriptType } | { address: string } | { script: string }); /** * array of supported input script types. @@ -207,9 +208,12 @@ export function constructPsbt( i, output.value ); - } else if (output.address) { + } else if ('address' in output) { const { address, value } = output; psbt.addOutput({ script: toOutputScript(address, network), value }); + } else if ('script' in output) { + const { script, value } = output; + psbt.addOutput({ script: Buffer.from(script, 'hex'), value }); } }); diff --git a/modules/utxo-lib/test/bitgo/psbt/PsbtOutputs.ts b/modules/utxo-lib/test/bitgo/psbt/PsbtOutputs.ts index c9ce96b275..e878e59a23 100644 --- a/modules/utxo-lib/test/bitgo/psbt/PsbtOutputs.ts +++ b/modules/utxo-lib/test/bitgo/psbt/PsbtOutputs.ts @@ -239,5 +239,31 @@ describe('psbt internal and wallet outputs', function () { (e: any) => e.message === 'Input Bip32Derivation can not be found' ); }); + + it('PSBT woth an OP_RETURN output', function () { + const opReturnScript = + '6a4c505341542b01045bde60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1a9e209f5ea0036c8c2f41078a3cebee57d8a47d501041f5e0e66b17576a914c4b8ae927ff2b9ce218e20bf06d425d6b68424fd88ac'; + const psbt = testutil.constructPsbt( + [{ scriptType: 'p2wsh', value: BigInt(value) }], + [ + { + address: externalAddress, + value: BigInt(value - fee), + }, + { + script: opReturnScript, + value: BigInt(0), + }, + ], + network, + rootWalletKeys, + 'unsigned' + ); + const tx = psbt.getUnsignedTx(); + assert.strictEqual(tx.outs.length, 2); + const out = tx.outs[1]; + assert.strictEqual(out.value, BigInt(0)); + assert.strictEqual(out.script.toString('hex'), opReturnScript); + }); }); });