Skip to content

Commit 5c564c2

Browse files
committed
test: check pre-fork conditions for ProRegTx and ProUpServTx preparation
1 parent 859ce5c commit 5c564c2

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

test/functional/rpc_netinfo.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from _decimal import Decimal
2121
from random import randint
2222

23+
# See CMainParams in src/chainparams.cpp
24+
DEFAULT_PORT_MAINNET_CORE_P2P = 9999
2325
# See CRegTestParams in src/chainparams.cpp
2426
DEFAULT_PORT_PLATFORM_P2P = 22200
2527
DEFAULT_PORT_PLATFORM_HTTP = 22201
@@ -59,7 +61,7 @@ def is_mn_visible(self, _protx_hash = None) -> bool:
5961
mn_visible = True
6062
return mn_visible
6163

62-
def register_mn(self, test: BitcoinTestFramework, submit: bool, addrs_core_p2p, addrs_platform_p2p = None, addrs_platform_http = None) -> str:
64+
def register_mn(self, test: BitcoinTestFramework, submit: bool, addrs_core_p2p, addrs_platform_p2p = None, addrs_platform_http = None, code = None, msg = None) -> str:
6365
assert self.mn.nodeIdx is not None
6466

6567
if self.mn.evo and (not addrs_platform_http or not addrs_platform_p2p):
@@ -69,11 +71,16 @@ def register_mn(self, test: BitcoinTestFramework, submit: bool, addrs_core_p2p,
6971
self.platform_nodeid = hash160(b'%d' % randint(1, 65535)).hex()
7072
protx_output = self.mn.register(self.node, submit=submit, coreP2PAddrs=addrs_core_p2p, operator_reward=0,
7173
platform_node_id=self.platform_nodeid, platform_p2p_port=addrs_platform_p2p,
72-
platform_http_port=addrs_platform_http)
73-
assert protx_output is not None
74+
platform_http_port=addrs_platform_http, expected_assert_code=code, expected_assert_msg=msg)
7475

75-
if not submit:
76+
# If we expected error, make sure the transaction didn't succeed
77+
if code and msg:
78+
assert protx_output is None
7679
return ""
80+
else:
81+
assert protx_output is not None
82+
if not submit:
83+
return ""
7784

7885
# Bury ProTx transaction and check if masternode is online
7986
self.mn.set_params(proTxHash=protx_output, operator_reward=0)
@@ -157,6 +164,7 @@ def run_test(self):
157164

158165
self.log.info("Test input validation for masternode address fields")
159166
self.test_validation_common()
167+
self.test_validation_legacy()
160168

161169
self.log.info("Test output masternode address fields for consistency")
162170
self.test_deprecation()
@@ -183,6 +191,27 @@ def test_validation_common(self):
183191
self.node_evo.register_mn(self, False, f"127.0.0.1:{self.node_evo.mn.nodePort}", DEFAULT_PORT_PLATFORM_P2P, "65536",
184192
-8, "platformHTTPPort must be a valid port [1-65535]")
185193

194+
def test_validation_legacy(self):
195+
# Using mainnet P2P port gets refused
196+
self.node_evo.register_mn(self, False, f"127.0.0.1:{DEFAULT_PORT_MAINNET_CORE_P2P}",
197+
DEFAULT_PORT_PLATFORM_P2P, DEFAULT_PORT_PLATFORM_HTTP,
198+
-8, f"Error setting coreP2PAddrs[0] to '127.0.0.1:{DEFAULT_PORT_MAINNET_CORE_P2P}' (invalid port)")
199+
200+
# Arrays of addresses are recognized by coreP2PAddrs (but get refused for too many entries)
201+
self.node_evo.register_mn(self, False, [f"127.0.0.1:{self.node_evo.mn.nodePort}", f"127.0.0.2:{self.node_evo.mn.nodePort}"],
202+
DEFAULT_PORT_PLATFORM_P2P, DEFAULT_PORT_PLATFORM_HTTP,
203+
-8, f"Error setting coreP2PAddrs[1] to '127.0.0.2:{self.node_evo.mn.nodePort}' (too many entries)")
204+
205+
# platformP2PPort and platformHTTPPort doesn't accept non-numeric inputs
206+
self.node_evo.register_mn(self, False, f"127.0.0.1:{self.node_evo.mn.nodePort}", f"127.0.0.1:{DEFAULT_PORT_PLATFORM_P2P}", DEFAULT_PORT_PLATFORM_HTTP,
207+
-8, f"platformP2PPort must be a 32bit integer (not '127.0.0.1:{DEFAULT_PORT_PLATFORM_P2P}')")
208+
self.node_evo.register_mn(self, False, f"127.0.0.1:{self.node_evo.mn.nodePort}", [f"127.0.0.1:{DEFAULT_PORT_PLATFORM_P2P}"], DEFAULT_PORT_PLATFORM_HTTP,
209+
-8, "Invalid param for platformP2PPort, must be number")
210+
self.node_evo.register_mn(self, False, f"127.0.0.1:{self.node_evo.mn.nodePort}", DEFAULT_PORT_PLATFORM_P2P, f"127.0.0.1:{DEFAULT_PORT_PLATFORM_HTTP}",
211+
-8, f"platformHTTPPort must be a 32bit integer (not '127.0.0.1:{DEFAULT_PORT_PLATFORM_HTTP}')")
212+
self.node_evo.register_mn(self, False, f"127.0.0.1:{self.node_evo.mn.nodePort}", DEFAULT_PORT_PLATFORM_P2P, [f"127.0.0.1:{DEFAULT_PORT_PLATFORM_HTTP}"],
213+
-8, "Invalid param for platformHTTPPort, must be number")
214+
186215
def test_deprecation(self):
187216
# netInfo is represented with JSON in CProRegTx, CProUpServTx, CDeterministicMNState and CSimplifiedMNListEntry,
188217
# so we need to test calls that rely on these underlying implementations. Start by collecting RPC responses.

0 commit comments

Comments
 (0)