Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@ export abstract class AbstractUtxoCoin
return (chainhead as any).height;
}

checkRecipient(recipient: { address: string; amount: number | string }): void {
checkRecipient(recipient: { address?: string; amount: number | string }): void {
assertValidTransactionRecipient(recipient);
if (!isScriptRecipient(recipient.address)) {
super.checkRecipient(recipient);
if (recipient.address && !isScriptRecipient(recipient.address)) {
super.checkRecipient({ address: recipient.address, amount: recipient.amount });
}
}

Expand Down
39 changes: 39 additions & 0 deletions modules/abstract-utxo/test/unit/transaction/recipient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import assert from 'assert';

import { getUtxoCoin } from '../util/utxoCoins';

describe('AbstractUtxoCoin.checkRecipient', function () {
const coin = getUtxoCoin('btc');

it('does not throw for OP_RETURN output with no address field', function () {
// Simulates { amount: '0', script: '6a0c...' } coming from buildParams.recipients
assert.doesNotThrow(() => {
coin.checkRecipient({ amount: '0' });
});
});

it('does not throw for script-prefixed address with zero amount', function () {
assert.doesNotThrow(() => {
coin.checkRecipient({ address: 'scriptPubKey:6a0c68656c6c6f20776f726c64', amount: '0' });
});
});

it('does not throw for a regular address', function () {
// A valid mainnet P2PKH address
assert.doesNotThrow(() => {
coin.checkRecipient({ address: '1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf', amount: '1000' });
});
});

it('throws when OP_RETURN output (no address) has non-zero amount', function () {
assert.throws(() => {
coin.checkRecipient({ amount: '1000' });
}, /Only zero amounts allowed for non-encodeable scriptPubkeys/);
});

it('throws when script-prefixed address has non-zero amount', function () {
assert.throws(() => {
coin.checkRecipient({ address: 'scriptPubKey:6a0c68656c6c6f20776f726c64', amount: '500' });
}, /Only zero amounts allowed for non-encodeable scriptPubkeys/);
});
});
Loading