Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_limit.py
Show All 13 Lines | from test_framework.util import ( | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
) | ) | ||||
class MempoolLimitTest(BitcoinTestFramework): | class MempoolLimitTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [[ | self.extra_args = [ | ||||
[ | |||||
"-acceptnonstdtxn=1", | "-acceptnonstdtxn=1", | ||||
"-maxmempool=5", | "-maxmempool=5", | ||||
"-spendzeroconfchange=0", | "-spendzeroconfchange=0", | ||||
]] | ] | ||||
] | |||||
self.supports_cli = False | self.supports_cli = False | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
relayfee = self.nodes[0].getnetworkinfo()['relayfee'] | relayfee = self.nodes[0].getnetworkinfo()["relayfee"] | ||||
self.log.info('Check that mempoolminfee is minrelytxfee') | self.log.info("Check that mempoolminfee is minrelytxfee") | ||||
assert_equal(self.nodes[0].getmempoolinfo()[ | assert_equal(self.nodes[0].getmempoolinfo()["minrelaytxfee"], Decimal("10.00")) | ||||
'minrelaytxfee'], Decimal('10.00')) | assert_equal(self.nodes[0].getmempoolinfo()["mempoolminfee"], Decimal("10.00")) | ||||
assert_equal(self.nodes[0].getmempoolinfo()[ | |||||
'mempoolminfee'], Decimal('10.00')) | |||||
txids = [] | txids = [] | ||||
utxo_groups = 4 | utxo_groups = 4 | ||||
utxos = create_confirmed_utxos( | utxos = create_confirmed_utxos(self, self.nodes[0], 1 + 30 * utxo_groups) | ||||
self, self.nodes[0], 1 + 30 * utxo_groups) | |||||
self.log.info('Create a mempool tx that will be evicted') | self.log.info("Create a mempool tx that will be evicted") | ||||
us0 = utxos.pop() | us0 = utxos.pop() | ||||
inputs = [{"txid": us0["txid"], "vout": us0["vout"]}] | inputs = [{"txid": us0["txid"], "vout": us0["vout"]}] | ||||
outputs = {self.nodes[0].getnewaddress(): 100} | outputs = {self.nodes[0].getnewaddress(): 100} | ||||
tx = self.nodes[0].createrawtransaction(inputs, outputs) | tx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
# specifically fund this tx with low fee | # specifically fund this tx with low fee | ||||
self.nodes[0].settxfee(relayfee) | self.nodes[0].settxfee(relayfee) | ||||
txF = self.nodes[0].fundrawtransaction(tx) | txF = self.nodes[0].fundrawtransaction(tx) | ||||
# return to automatic fee selection | # return to automatic fee selection | ||||
self.nodes[0].settxfee(0) | self.nodes[0].settxfee(0) | ||||
txFS = self.nodes[0].signrawtransactionwithwallet(txF['hex']) | txFS = self.nodes[0].signrawtransactionwithwallet(txF["hex"]) | ||||
txid = self.nodes[0].sendrawtransaction(txFS['hex']) | txid = self.nodes[0].sendrawtransaction(txFS["hex"]) | ||||
for i in range(utxo_groups): | for i in range(utxo_groups): | ||||
txids.append([]) | txids.append([]) | ||||
txids[i] = send_big_transactions( | txids[i] = send_big_transactions( | ||||
self.nodes[0], utxos[30 * i:30 * i + 30], 30, 10 * (i + 1)) | self.nodes[0], utxos[30 * i : 30 * i + 30], 30, 10 * (i + 1) | ||||
) | |||||
self.log.info('The tx should be evicted by now') | self.log.info("The tx should be evicted by now") | ||||
assert txid not in self.nodes[0].getrawmempool() | assert txid not in self.nodes[0].getrawmempool() | ||||
txdata = self.nodes[0].gettransaction(txid) | txdata = self.nodes[0].gettransaction(txid) | ||||
# confirmation should still be 0 | # confirmation should still be 0 | ||||
assert txdata['confirmations'] == 0 | assert txdata["confirmations"] == 0 | ||||
self.log.info('Check that mempoolminfee is larger than minrelytxfee') | self.log.info("Check that mempoolminfee is larger than minrelytxfee") | ||||
assert_equal(self.nodes[0].getmempoolinfo()[ | assert_equal(self.nodes[0].getmempoolinfo()["minrelaytxfee"], Decimal("10.00")) | ||||
'minrelaytxfee'], Decimal('10.00')) | assert_greater_than( | ||||
assert_greater_than(self.nodes[0].getmempoolinfo()[ | self.nodes[0].getmempoolinfo()["mempoolminfee"], Decimal("10.00") | ||||
'mempoolminfee'], Decimal('10.00')) | ) | ||||
self.log.info('Create a mempool tx that will not pass mempoolminfee') | self.log.info("Create a mempool tx that will not pass mempoolminfee") | ||||
us0 = utxos.pop() | us0 = utxos.pop() | ||||
inputs = [{"txid": us0["txid"], "vout": us0["vout"]}] | inputs = [{"txid": us0["txid"], "vout": us0["vout"]}] | ||||
outputs = {self.nodes[0].getnewaddress(): 100} | outputs = {self.nodes[0].getnewaddress(): 100} | ||||
tx = self.nodes[0].createrawtransaction(inputs, outputs) | tx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
# specifically fund this tx with a fee < mempoolminfee, >= than | # specifically fund this tx with a fee < mempoolminfee, >= than | ||||
# minrelaytxfee | # minrelaytxfee | ||||
txF = self.nodes[0].fundrawtransaction(tx, {'feeRate': relayfee}) | txF = self.nodes[0].fundrawtransaction(tx, {"feeRate": relayfee}) | ||||
txFS = self.nodes[0].signrawtransactionwithwallet(txF['hex']) | txFS = self.nodes[0].signrawtransactionwithwallet(txF["hex"]) | ||||
assert_raises_rpc_error(-26, "mempool min fee not met", | assert_raises_rpc_error( | ||||
self.nodes[0].sendrawtransaction, txFS['hex']) | -26, | ||||
"mempool min fee not met", | |||||
self.nodes[0].sendrawtransaction, | |||||
txFS["hex"], | |||||
) | |||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
MempoolLimitTest().main() | MempoolLimitTest().main() |