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); + }); }); });