Skip to content

Commit 968698b

Browse files
committed
test: add helper for update_service{,_evo} calls
1 parent 1493d67 commit 968698b

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

test/functional/feature_dip3_deterministicmns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def update_mn_payee(self, mn: MasternodeInfo, payee):
270270

271271
def test_protx_update_service(self, mn: MasternodeInfo):
272272
self.nodes[0].sendtoaddress(mn.fundsAddr, 0.001)
273-
self.nodes[0].protx('update_service', mn.proTxHash, '127.0.0.2:%d' % mn.nodePort, mn.keyOperator, "", mn.fundsAddr)
273+
mn.update_service(self.nodes[0], ipAndPort=f'127.0.0.2:{mn.nodePort}')
274274
self.generate(self.nodes[0], 1)
275275
for node in self.nodes:
276276
protx_info = node.protx('info', mn.proTxHash)
@@ -279,7 +279,7 @@ def test_protx_update_service(self, mn: MasternodeInfo):
279279
assert_equal(mn_list['%s-%d' % (mn.collateral_txid, mn.collateral_vout)]['address'], '127.0.0.2:%d' % mn.nodePort)
280280

281281
# undo
282-
self.nodes[0].protx('update_service', mn.proTxHash, '127.0.0.1:%d' % mn.nodePort, mn.keyOperator, "", mn.fundsAddr)
282+
mn.update_service(self.nodes[0])
283283
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
284284

285285
def assert_mnlists(self, mns):

test/functional/feature_llmq_simplepose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def repair_masternodes(self, restart):
208208
if check_banned(self.nodes[0], mn) or check_punished(self.nodes[0], mn):
209209
addr = self.nodes[0].getnewaddress()
210210
self.nodes[0].sendtoaddress(addr, 0.1)
211-
self.nodes[0].protx('update_service', mn.proTxHash, f'127.0.0.1:{mn.nodePort}', mn.keyOperator, "", addr)
211+
mn.update_service(self.nodes[0], fundsAddr=addr)
212212
if restart:
213213
self.stop_node(mn.nodeIdx)
214214
self.start_masternode(mn)

test/functional/test_framework/test_framework.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,42 @@ def update_registrar(self, node: TestNode, pubKeyOperator: Optional[str] = None,
13261326

13271327
return node.protx(command, *args)
13281328

1329+
def update_service(self, node: TestNode, ipAndPort: Optional[str] = None, platform_node_id: Optional[str] = None, platform_p2p_port: Optional[int] = None,
1330+
platform_http_port: Optional[int] = None, address_operator: Optional[str] = None, fundsAddr: Optional[str] = None) -> str:
1331+
# Update commands should be run from the appropriate MasternodeInfo instance, we do not allow overriding some values for this reason
1332+
if self.proTxHash is None:
1333+
raise AssertionError("proTxHash not set, did you call set_params()")
1334+
if self.keyOperator is None:
1335+
raise AssertionError("keyOperator not set, did you call generate_addresses()")
1336+
1337+
# EvoNode-specific fields are ignored for regular masternodes
1338+
if self.evo:
1339+
if platform_node_id is None:
1340+
raise AssertionError("EvoNode but platform_node_id is missing, must be specified!")
1341+
if platform_p2p_port is None:
1342+
raise AssertionError("EvoNode but platform_p2p_port is missing, must be specified!")
1343+
if platform_http_port is None:
1344+
raise AssertionError("EvoNode but platform_http_port is missing, must be specified!")
1345+
1346+
# Common arguments shared between regular masternodes and EvoNodes
1347+
args = [
1348+
self.proTxHash,
1349+
ipAndPort or f'127.0.0.1:{self.nodePort}',
1350+
self.keyOperator,
1351+
]
1352+
address_funds = fundsAddr or self.fundsAddr
1353+
address_operator = address_operator or ""
1354+
1355+
# Construct final command and arguments
1356+
if self.evo:
1357+
command = "update_service_evo"
1358+
args = args + [platform_node_id, platform_p2p_port, platform_http_port, address_operator, address_funds] # type: ignore
1359+
else:
1360+
command = "update_service"
1361+
args = args + [address_operator, address_funds] # type: ignore
1362+
1363+
return node.protx(command, *args)
1364+
13291365
class DashTestFramework(BitcoinTestFramework):
13301366
def set_test_params(self):
13311367
"""Tests must this method to change default values for number of nodes, topology, etc"""
@@ -1527,16 +1563,16 @@ def dynamically_evo_update_service(self, evo_info: MasternodeInfo, rnd=None, sho
15271563
# For the sake of the test, generate random nodeid, p2p and http platform values
15281564
r = rnd if rnd is not None else random.randint(21000, 65000)
15291565
platform_node_id = hash160(b'%d' % r).hex()
1530-
platform_p2p_port = '%d' % (r + 1)
1531-
platform_http_port = '%d' % (r + 2)
1566+
platform_p2p_port = r + 1
1567+
platform_http_port = r + 2
15321568

15331569
fund_txid = self.nodes[0].sendtoaddress(funds_address, 1)
15341570
self.bump_mocktime(10 * 60 + 1) # to make tx safe to include in block
15351571
evo_info.bury_tx(self, genIdx=0, txid=fund_txid, depth=1)
15361572

15371573
protx_success = False
15381574
try:
1539-
protx_result = self.nodes[0].protx('update_service_evo', evo_info.proTxHash, f'127.0.0.1:{evo_info.nodePort}', evo_info.keyOperator, platform_node_id, platform_p2p_port, platform_http_port, operator_reward_address, funds_address)
1575+
protx_result = evo_info.update_service(self.nodes[0], f'127.0.0.1:{evo_info.nodePort}', platform_node_id, platform_p2p_port, platform_http_port, operator_reward_address, funds_address)
15401576
self.bump_mocktime(10 * 60 + 1) # to make tx safe to include in block
15411577
evo_info.bury_tx(self, genIdx=0, txid=protx_result, depth=1)
15421578
self.log.info("Updated EvoNode %s: platformNodeID=%s, platformP2PPort=%s, platformHTTPPort=%s" % (evo_info.proTxHash, platform_node_id, platform_p2p_port, platform_http_port))
@@ -1583,12 +1619,13 @@ def prepare_masternode(self, idx):
15831619
else:
15841620
proTxHash = self.nodes[0].sendrawtransaction(protx_result)
15851621

1622+
mn.set_params(proTxHash=proTxHash, operator_reward=operatorReward, collateral_txid=txid, collateral_vout=collateral_vout, nodePort=port)
1623+
15861624
if operatorReward > 0:
15871625
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
15881626
operatorPayoutAddress = self.nodes[0].getnewaddress()
1589-
self.nodes[0].protx('update_service', proTxHash, ipAndPort, mn.keyOperator, operatorPayoutAddress, mn.fundsAddr)
1627+
mn.update_service(self.nodes[0], ipAndPort=ipAndPort, address_operator=operatorPayoutAddress)
15901628

1591-
mn.set_params(proTxHash=proTxHash, operator_reward=operatorReward, collateral_txid=txid, collateral_vout=collateral_vout, nodePort=port)
15921629
self.mninfo.append(mn)
15931630
self.log.info("Prepared MN %d: collateral_txid=%s, collateral_vout=%d, protxHash=%s" % (idx, txid, collateral_vout, proTxHash))
15941631

0 commit comments

Comments
 (0)