Skip to content

Commit d2a8ecc

Browse files
MarcoFalkecodablock
authored andcommitted
Merge bitcoin#9395: Add test for -walletrejectlongchains
ffeb195 add test for -walletrejectlongchains (Alex Morcos)
1 parent e5873a5 commit d2a8ecc

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

qa/rpc-tests/wallet.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,42 @@ def run_test (self):
364364
self.nodes[0].generate(1)
365365

366366
# Make a long chain of unconfirmed payments without hitting mempool limit
367+
# Each tx we make leaves only one output of change on a chain 1 longer
368+
# Since the amount to send is always much less than the outputs, we only ever need one output
369+
# So we should be able to generate exactly chainlimit txs for each original output
370+
sending_addr = self.nodes[1].getnewaddress()
367371
txid_list = []
368372
for i in range(chainlimit*2):
369-
txid_list.append(self.nodes[0].sendtoaddress(chain_addrs[0], Decimal('0.0001')))
373+
txid_list.append(self.nodes[0].sendtoaddress(sending_addr, Decimal('0.0001')))
370374
assert_equal(self.nodes[0].getmempoolinfo()['size'], chainlimit*2)
371375
assert_equal(len(txid_list), chainlimit*2)
372376

377+
# Without walletrejectlongchains, we will still generate a txid
378+
# The tx will be stored in the wallet but not accepted to the mempool
379+
extra_txid = self.nodes[0].sendtoaddress(sending_addr, Decimal('0.0001'))
380+
assert(extra_txid not in self.nodes[0].getrawmempool())
381+
assert(extra_txid in [tx["txid"] for tx in self.nodes[0].listtransactions()])
382+
self.nodes[0].abandontransaction(extra_txid)
383+
total_txs = len(self.nodes[0].listtransactions("*",99999))
384+
385+
# Try with walletrejectlongchains
386+
# Double chain limit but require combining inputs, so we pass SelectCoinsMinConf
387+
stop_node(self.nodes[0],0)
388+
self.nodes[0] = start_node(0, self.options.tmpdir, ["-walletrejectlongchains", "-limitancestorcount="+str(2*chainlimit)])
389+
390+
# wait for loadmempool
391+
timeout = 10
392+
while (timeout > 0 and len(self.nodes[0].getrawmempool()) < chainlimit*2):
393+
time.sleep(0.5)
394+
timeout -= 0.5
395+
assert_equal(len(self.nodes[0].getrawmempool()), chainlimit*2)
396+
397+
node0_balance = self.nodes[0].getbalance()
398+
# With walletrejectlongchains we will not create the tx and store it in our wallet.
399+
assert_raises_message(JSONRPCException, "mempool chain", self.nodes[0].sendtoaddress, sending_addr, node0_balance - Decimal('0.01'))
400+
401+
# Verify nothing new in wallet
402+
assert_equal(total_txs, len(self.nodes[0].listtransactions("*",99999)))
403+
373404
if __name__ == '__main__':
374405
WalletTest().main()

0 commit comments

Comments
 (0)