|
| 1 | +import assert from 'assert'; |
| 2 | + |
| 3 | +import { getUtxoCoin } from '../util/utxoCoins'; |
| 4 | + |
| 5 | +describe('AbstractUtxoCoin.checkRecipient', function () { |
| 6 | + const coin = getUtxoCoin('btc'); |
| 7 | + |
| 8 | + it('does not throw for OP_RETURN output with no address field', function () { |
| 9 | + // Simulates { amount: '0', script: '6a0c...' } coming from buildParams.recipients |
| 10 | + assert.doesNotThrow(() => { |
| 11 | + coin.checkRecipient({ amount: '0' }); |
| 12 | + }); |
| 13 | + }); |
| 14 | + |
| 15 | + it('does not throw for script-prefixed address with zero amount', function () { |
| 16 | + assert.doesNotThrow(() => { |
| 17 | + coin.checkRecipient({ address: 'scriptPubKey:6a0c68656c6c6f20776f726c64', amount: '0' }); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + it('does not throw for a regular address', function () { |
| 22 | + // A valid mainnet P2PKH address |
| 23 | + assert.doesNotThrow(() => { |
| 24 | + coin.checkRecipient({ address: '1A1zP1eP5QGefi2DMPTfTL5SLmv7Divf', amount: '1000' }); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it('throws when OP_RETURN output (no address) has non-zero amount', function () { |
| 29 | + assert.throws(() => { |
| 30 | + coin.checkRecipient({ amount: '1000' }); |
| 31 | + }, /Only zero amounts allowed for non-encodeable scriptPubkeys/); |
| 32 | + }); |
| 33 | + |
| 34 | + it('throws when script-prefixed address has non-zero amount', function () { |
| 35 | + assert.throws(() => { |
| 36 | + coin.checkRecipient({ address: 'scriptPubKey:6a0c68656c6c6f20776f726c64', amount: '500' }); |
| 37 | + }, /Only zero amounts allowed for non-encodeable scriptPubkeys/); |
| 38 | + }); |
| 39 | +}); |
0 commit comments