Skip to content

Commit e97a650

Browse files
committed
test: validate address reporting behavior for empty address ProRegTxes
1 parent 5317eef commit e97a650

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/functional/rpc_netinfo.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
DEFAULT_PORT_PLATFORM_HTTP = 22201
3232
# See CDeterministicMNStateDiff::ToJson() in src/evo/dmnstate.h
3333
DMNSTATE_DIFF_DUMMY_ADDR = "255.255.255.255"
34+
# See ProTxVersion in src/evo/providertx.h
35+
PROTXVER_BASIC = 2
36+
PROTXVER_EXTADDR = 3
3437

3538
class EvoNode:
3639
mn: MasternodeInfo
@@ -187,6 +190,8 @@ def run_test(self):
187190
self.log.info("Test input validation for masternode address fields (post-fork)")
188191
self.test_validation_common()
189192
self.test_validation_extended()
193+
self.log.info("Test masternode address fields for ProRegTx without addresses")
194+
self.test_empty_fields()
190195
self.log.info("Test output masternode address fields for consistency (post-fork)")
191196
self.test_shims()
192197

@@ -457,6 +462,48 @@ def test_deprecation(self):
457462
assert "service" in protx_diff_rpc['mnList'][0].keys()
458463
assert "service" in protx_listdiff_rpc.keys()
459464

465+
def test_empty_fields(self):
466+
def empty_common(grt_dict):
467+
# Even if '[::]:0' is reported by 'service', 'addresses' should always be blank if we have nothing to report
468+
assert_equal(len(grt_dict['addresses']), 0)
469+
# 'service' will never be empty. Legacy addresses stored an empty CService, which evaluates to
470+
# '[::]:0' when printed in string form. This behavior has been preserved for continuity.
471+
assert_equal(grt_dict['service'], "[::]:0")
472+
473+
# Validate that our masternode was registered before the fork
474+
grt_proregtx = self.node_simple.getrawtransaction(self.node_two.mn.proTxHash, True)['proRegTx']
475+
assert_equal(grt_proregtx['version'], PROTXVER_BASIC)
476+
477+
# Test reporting on legacy address (i.e. basic BLS and earlier) nodes
478+
empty_common(grt_proregtx)
479+
480+
# platform{P2P,HTTP}Port are non-optional fields for legacy addresses and will be populated
481+
assert_equal(grt_proregtx['platformP2PPort'], DEFAULT_PORT_PLATFORM_P2P)
482+
assert_equal(grt_proregtx['platformHTTPPort'], DEFAULT_PORT_PLATFORM_HTTP)
483+
484+
# Destroy and re-register node as blank
485+
self.node_two.destroy_mn(self)
486+
self.reconnect_nodes()
487+
self.node_two.register_mn(self, True, "", "", "")
488+
489+
# Validate that masternode uses extended addresses
490+
grt_proregtx = self.node_simple.getrawtransaction(self.node_two.mn.proTxHash, True)['proRegTx']
491+
assert_equal(grt_proregtx['version'], PROTXVER_EXTADDR)
492+
493+
# Test reporting for extended addresses
494+
empty_common(grt_proregtx)
495+
496+
# Extended addresses store addr:port pairs for platform{P2P,HTTPS}Addrs but ProRegTx allows blank
497+
# address declarations (for later update with a ProUpServTx), this means that *unlike* legacy
498+
# addresses, ProRegTxes that opt to omit addresses cannot report platform{P2P,HTTP}Port, which
499+
# is signified with -1.
500+
assert_equal(grt_proregtx['platformP2PPort'], -1)
501+
assert_equal(grt_proregtx['platformHTTPPort'], -1)
502+
503+
# Destroy masternode
504+
self.node_evo.destroy_mn(self)
505+
self.reconnect_nodes()
506+
460507
def test_shims(self):
461508
# There are two shims there to help with migrating between legacy and extended addresses, one reads from legacy platform
462509
# fields to ensure 'addresses' is adequately populated. The other, reads from netInfo to populate platform{HTTP,P2P}Port.

0 commit comments

Comments
 (0)