Skip to content

Commit db26eeb

Browse files
committed
Merge bitcoin#19877: [test] clarify rpc_net & p2p_disconnect_ban functional tests
47ff509 [test] Clarify setup of node topology. (Amiti Uttarwar) 0672522 [move-only, test]: Match test order with run order (Amiti Uttarwar) Pull request description: small improvements to clarify logic in the functional tests 1. have test logic in `rpc_net.py` match run order of the test 2. remove `connect_nodes` calls that are redundant with the automatic test setup executed by the test framework Noticed when I was trying to debug a test for bitcoin#19725. Small changes but imo very helpful, because they initially confused me. ACKs for top commit: laanwj: ACK 47ff509 Tree-SHA512: 2843da2c0b4f06b2600b3adb97900a62be7bb2228770abd67d86f2a65c58079af22c7c20957474a98c17da85f40a958a6f05cb8198aa0c56a58adc1c31100492
2 parents 488b77f + 47ff509 commit db26eeb

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

test/functional/p2p_disconnect_ban.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ def set_test_params(self):
1818

1919
def run_test(self):
2020
self.log.info("Connect nodes both way")
21+
# By default, the test framework sets up an addnode connection from
22+
# node 1 --> node0. By connecting node0 --> node 1, we're left with
23+
# the two nodes being connected both ways.
24+
# Topology will look like: node0 <--> node1
2125
self.connect_nodes(0, 1)
22-
self.connect_nodes(1, 0)
2326

2427
self.log.info("Test setban and listbanned RPCs")
2528

test/functional/rpc_net.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ def set_test_params(self):
5151
def run_test(self):
5252
# Get out of IBD for the minfeefilter and getpeerinfo tests.
5353
self.nodes[0].generate(101)
54-
# Connect nodes both ways.
54+
55+
# By default, the test framework sets up an addnode connection from
56+
# node 1 --> node0. By connecting node0 --> node 1, we're left with
57+
# the two nodes being connected both ways.
58+
# Topology will look like: node0 <--> node1
5559
self.connect_nodes(0, 1)
56-
self.connect_nodes(1, 0)
5760
self.sync_all()
5861

5962
self.test_connection_count()
@@ -69,6 +72,36 @@ def test_connection_count(self):
6972
# After using `connect_nodes` to connect nodes 0 and 1 to each other.
7073
assert_equal(self.nodes[0].getconnectioncount(), 2)
7174

75+
def test_getpeerinfo(self):
76+
self.log.info("Test getpeerinfo")
77+
# Create a few getpeerinfo last_block/last_transaction values.
78+
if self.is_wallet_compiled():
79+
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
80+
self.nodes[1].generate(1)
81+
self.sync_all()
82+
time_now = int(time.time())
83+
peer_info = [x.getpeerinfo() for x in self.nodes]
84+
# Verify last_block and last_transaction keys/values.
85+
for node, peer, field in product(range(self.num_nodes), range(2), ['last_block', 'last_transaction']):
86+
assert field in peer_info[node][peer].keys()
87+
if peer_info[node][peer][field] != 0:
88+
assert_approx(peer_info[node][peer][field], time_now, vspan=60)
89+
# check both sides of bidirectional connection between nodes
90+
# the address bound to on one side will be the source address for the other node
91+
assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr'])
92+
assert_equal(peer_info[1][0]['addrbind'], peer_info[0][0]['addr'])
93+
assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500"))
94+
assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000"))
95+
# check the `servicesnames` field
96+
for info in peer_info:
97+
assert_net_servicesnames(int(info[0]["services"], 0x10), info[0]["servicesnames"])
98+
99+
assert_equal(peer_info[0][0]['connection_type'], 'inbound')
100+
assert_equal(peer_info[0][1]['connection_type'], 'manual')
101+
102+
assert_equal(peer_info[1][0]['connection_type'], 'manual')
103+
assert_equal(peer_info[1][1]['connection_type'], 'inbound')
104+
72105
def test_getnettotals(self):
73106
self.log.info("Test getnettotals")
74107
# getnettotals totalbytesrecv and totalbytessent should be
@@ -151,36 +184,6 @@ def test_getaddednodeinfo(self):
151184
# check that a non-existent node returns an error
152185
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')
153186

154-
def test_getpeerinfo(self):
155-
self.log.info("Test getpeerinfo")
156-
# Create a few getpeerinfo last_block/last_transaction values.
157-
if self.is_wallet_compiled():
158-
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
159-
self.nodes[1].generate(1)
160-
self.sync_all()
161-
time_now = int(time.time())
162-
peer_info = [x.getpeerinfo() for x in self.nodes]
163-
# Verify last_block and last_transaction keys/values.
164-
for node, peer, field in product(range(self.num_nodes), range(2), ['last_block', 'last_transaction']):
165-
assert field in peer_info[node][peer].keys()
166-
if peer_info[node][peer][field] != 0:
167-
assert_approx(peer_info[node][peer][field], time_now, vspan=60)
168-
# check both sides of bidirectional connection between nodes
169-
# the address bound to on one side will be the source address for the other node
170-
assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr'])
171-
assert_equal(peer_info[1][0]['addrbind'], peer_info[0][0]['addr'])
172-
assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500"))
173-
assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000"))
174-
# check the `servicesnames` field
175-
for info in peer_info:
176-
assert_net_servicesnames(int(info[0]["services"], 0x10), info[0]["servicesnames"])
177-
178-
assert_equal(peer_info[0][0]['connection_type'], 'inbound')
179-
assert_equal(peer_info[0][1]['connection_type'], 'manual')
180-
181-
assert_equal(peer_info[1][0]['connection_type'], 'manual')
182-
assert_equal(peer_info[1][1]['connection_type'], 'inbound')
183-
184187
def test_service_flags(self):
185188
self.log.info("Test service flags")
186189
self.nodes[0].add_p2p_connection(P2PInterface(), services=(1 << 4) | (1 << 63))

0 commit comments

Comments
 (0)