Skip to content

Commit

Permalink
wallet: check auction TXs for dust and null address before sending
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Jul 21, 2020
1 parent a3049d5 commit b5378f9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/wallet/wallet.js
Expand Up @@ -3400,6 +3400,19 @@ class Wallet extends EventEmitter {
if (ancestors.size + 1 > this.maxAncestors)
throw new Error('TX exceeds maximum unconfirmed ancestors.');

for (const output of tx.outputs) {
if (output.isDust())
throw new Error('Output is dust.');

if (output.value > 0) {
if (!output.address)
throw new Error('Cannot send to unknown address.');

if (output.address.isNull())
throw new Error('Cannot send to null address.');
}
}

await this.wdb.addTX(tx);

this.logger.debug('Sending wallet tx (%s): %x', this.id, tx.hash());
Expand Down
12 changes: 12 additions & 0 deletions test/wallet-auction-test.js
Expand Up @@ -12,6 +12,7 @@ const Miner = require('../lib/mining/miner');
const WalletDB = require('../lib/wallet/walletdb');
const Network = require('../lib/protocol/network');
const rules = require('../lib/covenants/rules');
const Address = require('../lib/primitives/address');

const network = Network.get('regtest');
const NAME1 = rules.grindName(5, 2, network);
Expand Down Expand Up @@ -123,6 +124,17 @@ describe('Wallet Auction', function() {
}
});

it('should fail to send bid to null address', async () => {
const mtx = await winner.makeBid(NAME1, 1000, 2000, 0);
mtx.outputs[0].address = new Address();
await winner.fill(mtx);
await winner.finalize(mtx);

const fn = async () => await winner.sendMTX(mtx);

assert.rejects(fn, {message: 'Cannot send to null address.'});
});

it('should fail to re-open auction during BIDDING phase', async () => {
let err;
try {
Expand Down
18 changes: 17 additions & 1 deletion test/wallet-http-test.js
Expand Up @@ -483,18 +483,34 @@ describe('Wallet HTTP', function() {
await assert.rejects(fn, {message: 'Lockup is required.'});
});

it('should send bid with 0 value and 0 lockup', async () => {
it('should send bid with 0 value and non-dust lockup', async () => {
await wallet.client.post(`/wallet/${wallet.id}/open`, {
name: name
});

await mineBlocks(treeInterval + 1, cbAddress);

await wallet.client.post(`/wallet/${wallet.id}/bid`, {
name: name,
bid: 0,
lockup: 1000
});
});

it('should fail to send bid with 0 value and 0 lockup', async () => {
await wallet.client.post(`/wallet/${wallet.id}/open`, {
name: name
});

await mineBlocks(treeInterval + 1, cbAddress);

const fn = async () => await wallet.client.post(`/wallet/${wallet.id}/bid`, {
name: name,
bid: 0,
lockup: 0
});

await assert.rejects(fn, {message: 'Output is dust.'});
});

it('should get all bids (single player)', async () => {
Expand Down

0 comments on commit b5378f9

Please sign in to comment.