Skip to content

Commit 2ee406c

Browse files
committed
test: add functional test for deprecatedrpc=fees
Test for old fields when `-deprecatedrpc=fees` flag is passed and verify values in the deprecated fields match values in the fees sub-object.
1 parent 35d928c commit 2ee406c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2021 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test deprecation of fee fields from top level mempool entry object"""
6+
7+
from test_framework.blocktools import COIN
8+
from test_framework.test_framework import BitcoinTestFramework
9+
from test_framework.util import assert_equal
10+
from test_framework.wallet import MiniWallet
11+
12+
13+
def assertions_helper(new_object, deprecated_object, deprecated_fields):
14+
for field in deprecated_fields:
15+
assert field in deprecated_object
16+
assert field not in new_object
17+
18+
19+
class MempoolFeeFieldsDeprecationTest(BitcoinTestFramework):
20+
def set_test_params(self):
21+
self.num_nodes = 2
22+
self.extra_args = [[], ["-deprecatedrpc=fees"]]
23+
24+
def run_test(self):
25+
# we get spendable outputs from the premined chain starting
26+
# at block 76. see BitcoinTestFramework._initialize_chain() for details
27+
self.wallet = MiniWallet(self.nodes[0])
28+
self.wallet.rescan_utxos()
29+
30+
# we create the tx on the first node and wait until it syncs to node_deprecated
31+
# thus, any differences must be coming from getmempoolentry or getrawmempool
32+
tx = self.wallet.send_self_transfer(from_node=self.nodes[0])
33+
self.nodes[1].sendrawtransaction(tx["hex"])
34+
35+
deprecated_fields = ["ancestorfees", "descendantfees", "modifiedfee", "fee"]
36+
self.test_getmempoolentry(tx["txid"], deprecated_fields)
37+
self.test_getrawmempool(tx["txid"], deprecated_fields)
38+
self.test_deprecated_fields_match(tx["txid"])
39+
40+
def test_getmempoolentry(self, txid, deprecated_fields):
41+
42+
self.log.info("Test getmempoolentry rpc")
43+
entry = self.nodes[0].getmempoolentry(txid)
44+
deprecated_entry = self.nodes[1].getmempoolentry(txid)
45+
assertions_helper(entry, deprecated_entry, deprecated_fields)
46+
47+
def test_getrawmempool(self, txid, deprecated_fields):
48+
49+
self.log.info("Test getrawmempool rpc")
50+
entry = self.nodes[0].getrawmempool(verbose=True)[txid]
51+
deprecated_entry = self.nodes[1].getrawmempool(verbose=True)[txid]
52+
assertions_helper(entry, deprecated_entry, deprecated_fields)
53+
54+
def test_deprecated_fields_match(self, txid):
55+
56+
self.log.info("Test deprecated fee fields match new fees object")
57+
entry = self.nodes[0].getmempoolentry(txid)
58+
deprecated_entry = self.nodes[1].getmempoolentry(txid)
59+
60+
assert_equal(deprecated_entry["fee"], entry["fees"]["base"])
61+
assert_equal(deprecated_entry["modifiedfee"], entry["fees"]["modified"])
62+
assert_equal(deprecated_entry["descendantfees"], entry["fees"]["descendant"] * COIN)
63+
assert_equal(deprecated_entry["ancestorfees"], entry["fees"]["ancestor"] * COIN)
64+
65+
66+
if __name__ == "__main__":
67+
MempoolFeeFieldsDeprecationTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
'feature_presegwit_node_upgrade.py',
310310
'feature_settings.py',
311311
'rpc_getdescriptorinfo.py',
312+
'rpc_mempool_entry_fee_fields_deprecation.py',
312313
'rpc_help.py',
313314
'feature_help.py',
314315
'feature_shutdown.py',

0 commit comments

Comments
 (0)