Skip to content

Commit fafc9d5

Browse files
author
MarcoFalke
committed
test: Fix intermittent issue in wallet_bumpfee
1 parent fa347b2 commit fafc9d5

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

test/functional/wallet_bumpfee.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def set_test_params(self):
5050
def skip_test_if_missing_module(self):
5151
self.skip_if_no_wallet()
5252

53+
def clear_mempool(self):
54+
# Clear mempool between subtests. The subtests may only depend on chainstate (utxos)
55+
self.nodes[1].generate(1)
56+
self.sync_all()
57+
5358
def run_test(self):
5459
# Encrypt wallet for test_locked_wallet_fails test
5560
self.nodes[1].encryptwallet(WALLET_PASSPHRASE)
@@ -71,7 +76,7 @@ def run_test(self):
7176

7277
self.log.info("Running tests")
7378
dest_address = peer_node.getnewaddress()
74-
test_invalid_parameters(rbf_node, dest_address)
79+
self.test_invalid_parameters(rbf_node, dest_address)
7580
test_simple_bumpfee_succeeds(self, "default", rbf_node, peer_node, dest_address)
7681
test_simple_bumpfee_succeeds(self, "fee_rate", rbf_node, peer_node, dest_address)
7782
test_feerate_args(self, rbf_node, peer_node, dest_address)
@@ -93,28 +98,30 @@ def run_test(self):
9398
test_small_output_with_feerate_succeeds(self, rbf_node, dest_address)
9499
test_no_more_inputs_fails(self, rbf_node, dest_address)
95100

96-
def test_invalid_parameters(node, dest_address):
97-
txid = spend_one_input(node, dest_address)
98-
# invalid estimate mode
99-
assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", node.bumpfee, txid, {
100-
"estimate_mode": "moo",
101-
})
102-
assert_raises_rpc_error(-3, "Expected type string", node.bumpfee, txid, {
103-
"estimate_mode": 38,
104-
})
105-
assert_raises_rpc_error(-3, "Expected type string", node.bumpfee, txid, {
106-
"estimate_mode": {
107-
"foo": "bar",
108-
},
109-
})
110-
assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", node.bumpfee, txid, {
111-
"estimate_mode": Decimal("3.141592"),
112-
})
113-
# confTarget and conf_target
114-
assert_raises_rpc_error(-8, "confTarget and conf_target options should not both be set", node.bumpfee, txid, {
115-
"confTarget": 123,
116-
"conf_target": 456,
117-
})
101+
def test_invalid_parameters(self, node, dest_address):
102+
txid = spend_one_input(node, dest_address)
103+
# invalid estimate mode
104+
assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", node.bumpfee, txid, {
105+
"estimate_mode": "moo",
106+
})
107+
assert_raises_rpc_error(-3, "Expected type string", node.bumpfee, txid, {
108+
"estimate_mode": 38,
109+
})
110+
assert_raises_rpc_error(-3, "Expected type string", node.bumpfee, txid, {
111+
"estimate_mode": {
112+
"foo": "bar",
113+
},
114+
})
115+
assert_raises_rpc_error(-8, "Invalid estimate_mode parameter", node.bumpfee, txid, {
116+
"estimate_mode": Decimal("3.141592"),
117+
})
118+
# confTarget and conf_target
119+
assert_raises_rpc_error(-8, "confTarget and conf_target options should not both be set", node.bumpfee, txid, {
120+
"confTarget": 123,
121+
"conf_target": 456,
122+
})
123+
self.clear_mempool()
124+
118125

119126
def test_simple_bumpfee_succeeds(self, mode, rbf_node, peer_node, dest_address):
120127
self.log.info('Test simple bumpfee: {}'.format(mode))
@@ -148,6 +155,7 @@ def test_simple_bumpfee_succeeds(self, mode, rbf_node, peer_node, dest_address):
148155
bumpedwtx = rbf_node.gettransaction(bumped_tx["txid"])
149156
assert_equal(oldwtx["replaced_by_txid"], bumped_tx["txid"])
150157
assert_equal(bumpedwtx["replaces_txid"], rbfid)
158+
self.clear_mempool()
151159

152160

153161
def test_feerate_args(self, rbf_node, peer_node, dest_address):
@@ -167,6 +175,7 @@ def test_feerate_args(self, rbf_node, peer_node, dest_address):
167175
assert_raises_rpc_error(-3, "Amount out of range", rbf_node.bumpfee, rbfid, {"fee_rate": -1})
168176

169177
assert_raises_rpc_error(-4, "is too high (cannot be higher than", rbf_node.bumpfee, rbfid, {"fee_rate": TOO_HIGH})
178+
self.clear_mempool()
170179

171180

172181
def test_segwit_bumpfee_succeeds(self, rbf_node, dest_address):
@@ -198,12 +207,14 @@ def test_segwit_bumpfee_succeeds(self, rbf_node, dest_address):
198207
bumped_tx = rbf_node.bumpfee(rbfid)
199208
assert bumped_tx["txid"] in rbf_node.getrawmempool()
200209
assert rbfid not in rbf_node.getrawmempool()
210+
self.clear_mempool()
201211

202212

203213
def test_nonrbf_bumpfee_fails(self, peer_node, dest_address):
204214
self.log.info('Test that we cannot replace a non RBF transaction')
205215
not_rbfid = peer_node.sendtoaddress(dest_address, Decimal("0.00090000"))
206216
assert_raises_rpc_error(-4, "not BIP 125 replaceable", peer_node.bumpfee, not_rbfid)
217+
self.clear_mempool()
207218

208219

209220
def test_notmine_bumpfee_fails(self, rbf_node, peer_node, dest_address):
@@ -226,6 +237,7 @@ def test_notmine_bumpfee_fails(self, rbf_node, peer_node, dest_address):
226237
rbfid = rbf_node.sendrawtransaction(signedtx["hex"])
227238
assert_raises_rpc_error(-4, "Transaction contains inputs that don't belong to this wallet",
228239
rbf_node.bumpfee, rbfid)
240+
self.clear_mempool()
229241

230242

231243
def test_bumpfee_with_descendant_fails(self, rbf_node, rbf_node_address, dest_address):
@@ -236,6 +248,7 @@ def test_bumpfee_with_descendant_fails(self, rbf_node, rbf_node_address, dest_ad
236248
tx = rbf_node.signrawtransactionwithwallet(tx)
237249
rbf_node.sendrawtransaction(tx["hex"])
238250
assert_raises_rpc_error(-8, "Transaction has descendants in the wallet", rbf_node.bumpfee, parent_id)
251+
self.clear_mempool()
239252

240253

241254
def test_small_output_with_feerate_succeeds(self, rbf_node, dest_address):
@@ -277,6 +290,7 @@ def test_small_output_with_feerate_succeeds(self, rbf_node, dest_address):
277290

278291
rbf_node.generatetoaddress(1, rbf_node.getnewaddress())
279292
assert_equal(rbf_node.gettransaction(rbfid)["confirmations"], 1)
293+
self.clear_mempool()
280294

281295

282296
def test_dust_to_fee(self, rbf_node, dest_address):
@@ -299,6 +313,7 @@ def test_dust_to_fee(self, rbf_node, dest_address):
299313
assert_equal(len(fulltx["vout"]), 2)
300314
assert_equal(len(full_bumped_tx["vout"]), 1) # change output is eliminated
301315
assert_equal(full_bumped_tx["vout"][0]['value'], Decimal("0.00050000"))
316+
self.clear_mempool()
302317

303318

304319
def test_settxfee(self, rbf_node, dest_address):
@@ -321,6 +336,8 @@ def test_settxfee(self, rbf_node, dest_address):
321336
assert_raises_rpc_error(-8, "txfee cannot be more than wallet max tx fee", rbf_node.settxfee, Decimal('0.00003'))
322337
self.restart_node(1, self.extra_args[1])
323338
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
339+
self.connect_nodes(1, 0)
340+
self.clear_mempool()
324341

325342

326343
def test_maxtxfee_fails(self, rbf_node, dest_address):
@@ -334,6 +351,8 @@ def test_maxtxfee_fails(self, rbf_node, dest_address):
334351
assert_raises_rpc_error(-4, "Unable to create transaction. Fee exceeds maximum configured by -maxtxfee", rbf_node.bumpfee, rbfid)
335352
self.restart_node(1, self.extra_args[1])
336353
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
354+
self.connect_nodes(1, 0)
355+
self.clear_mempool()
337356

338357

339358
def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
@@ -416,6 +435,7 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
416435

417436
rbf_node.unloadwallet("watcher")
418437
rbf_node.unloadwallet("signer")
438+
self.clear_mempool()
419439

420440

421441
def test_rebumping(self, rbf_node, dest_address):
@@ -424,6 +444,7 @@ def test_rebumping(self, rbf_node, dest_address):
424444
bumped = rbf_node.bumpfee(rbfid, {"fee_rate": ECONOMICAL})
425445
assert_raises_rpc_error(-4, "already bumped", rbf_node.bumpfee, rbfid, {"fee_rate": NORMAL})
426446
rbf_node.bumpfee(bumped["txid"], {"fee_rate": NORMAL})
447+
self.clear_mempool()
427448

428449

429450
def test_rebumping_not_replaceable(self, rbf_node, dest_address):
@@ -432,6 +453,7 @@ def test_rebumping_not_replaceable(self, rbf_node, dest_address):
432453
bumped = rbf_node.bumpfee(rbfid, {"fee_rate": ECONOMICAL, "replaceable": False})
433454
assert_raises_rpc_error(-4, "Transaction is not BIP 125 replaceable", rbf_node.bumpfee, bumped["txid"],
434455
{"fee_rate": NORMAL})
456+
self.clear_mempool()
435457

436458

437459
def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
@@ -471,6 +493,7 @@ def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
471493
assert_equal(
472494
sum(1 for t in rbf_node.listunspent(minconf=0, include_unsafe=False)
473495
if t["txid"] == rbfid and t["address"] == rbf_node_address and t["spendable"]), 1)
496+
self.clear_mempool()
474497

475498

476499
def test_bumpfee_metadata(self, rbf_node, dest_address):
@@ -482,6 +505,7 @@ def test_bumpfee_metadata(self, rbf_node, dest_address):
482505
bumped_wtx = rbf_node.gettransaction(bumped_tx["txid"])
483506
assert_equal(bumped_wtx["comment"], "comment value")
484507
assert_equal(bumped_wtx["to"], "to value")
508+
self.clear_mempool()
485509

486510

487511
def test_locked_wallet_fails(self, rbf_node, dest_address):
@@ -491,6 +515,7 @@ def test_locked_wallet_fails(self, rbf_node, dest_address):
491515
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first.",
492516
rbf_node.bumpfee, rbfid)
493517
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
518+
self.clear_mempool()
494519

495520

496521
def test_change_script_match(self, rbf_node, dest_address):
@@ -511,6 +536,7 @@ def get_change_address(tx):
511536
assert_equal(change_addresses, get_change_address(bumped_total_tx['txid']))
512537
bumped_rate_tx = rbf_node.bumpfee(bumped_total_tx["txid"])
513538
assert_equal(change_addresses, get_change_address(bumped_rate_tx['txid']))
539+
self.clear_mempool()
514540

515541

516542
def spend_one_input(node, dest_address, change_size=Decimal("0.00049000")):
@@ -549,6 +575,7 @@ def test_no_more_inputs_fails(self, rbf_node, dest_address):
549575
# spend all funds, no change output
550576
rbfid = rbf_node.sendtoaddress(rbf_node.getnewaddress(), rbf_node.getbalance(), "", "", True)
551577
assert_raises_rpc_error(-4, "Unable to create transaction. Insufficient funds", rbf_node.bumpfee, rbfid)
578+
self.clear_mempool()
552579

553580

554581
if __name__ == "__main__":

0 commit comments

Comments
 (0)