@@ -180,13 +180,15 @@ def run_test(self):
180180 self .log .info ("Test input validation for masternode address fields (pre-fork)" )
181181 self .test_validation_common ()
182182 self .test_validation_legacy ()
183- self .log .info ("Test output masternode address fields for consistency" )
183+ self .log .info ("Test output masternode address fields for consistency (pre-fork) " )
184184 self .test_deprecation ()
185185 self .log .info ("Mine blocks to activate DEPLOYMENT_V23" )
186186 self .activate_v23 ()
187187 self .log .info ("Test input validation for masternode address fields (post-fork)" )
188188 self .test_validation_common ()
189189 self .test_validation_extended ()
190+ self .log .info ("Test output masternode address fields for consistency (post-fork)" )
191+ self .test_shims ()
190192
191193 def test_validation_common (self ):
192194 # Arrays of addresses with invalid inputs get refused
@@ -455,5 +457,57 @@ def test_deprecation(self):
455457 assert "service" in protx_diff_rpc ['mnList' ][0 ].keys ()
456458 assert "service" in protx_listdiff_rpc .keys ()
457459
460+ def test_shims (self ):
461+ # There are two shims there to help with migrating between legacy and extended addresses, one reads from legacy platform
462+ # fields to ensure 'addresses' is adequately populated. The other, reads from netInfo to populate platform{HTTP,P2P}Port.
463+ # As the fork is now active, we can now evaluate the test cases that couldn't be evaluated in test_deprecation().
464+ self .log .info ("Collect JSON RPC responses from node" )
465+
466+ # Create an masternode that clearly uses extended addresses (hello IPv6!)
467+ proregtx_hash = self .node_evo .register_mn (self , True ,
468+ [f"127.0.0.1:{ self .node_evo .mn .nodePort } " , f"[::1]:{ self .node_evo .mn .nodePort } " ],
469+ [f"127.0.0.2:{ DEFAULT_PORT_PLATFORM_P2P } " , f"[::2]:{ DEFAULT_PORT_PLATFORM_P2P } " ],
470+ [f"127.0.0.3:{ DEFAULT_PORT_PLATFORM_HTTP } " , f"[::3]:{ DEFAULT_PORT_PLATFORM_HTTP } " ])
471+ proregtx_rpc = self .node_evo .node .getrawtransaction (proregtx_hash , True )
472+
473+ # Update only a platform field (platformP2PAddrs) but with an odd twist, we only specify the port number and expect the shim
474+ # to auto-fill the addr portion from coreP2PAddrs[0]
475+ proupservtx_hash = self .node_evo .update_mn (self , True ,
476+ [f"127.0.0.1:{ self .node_evo .mn .nodePort } " , f"[::1]:{ self .node_evo .mn .nodePort } " ],
477+ DEFAULT_PORT_PLATFORM_P2P + 12 ,
478+ [f"127.0.0.3:{ DEFAULT_PORT_PLATFORM_HTTP } " , f"[::3]:{ DEFAULT_PORT_PLATFORM_HTTP } " ])
479+ proupservtx_rpc = self .node_evo .node .getrawtransaction (proupservtx_hash , True )
480+ assert_equal (proupservtx_rpc ['proUpServTx' ]['addresses' ]['platform_p2p' ][0 ], f"127.0.0.1:{ DEFAULT_PORT_PLATFORM_P2P + 12 } " )
481+
482+ # Since all fields are stored in the netInfo, even though we updated only platformP2PAddrs, the dummy address should never be visible
483+ # and *all* the addresses fields will be visible as they're now in one data structure
484+ proupservtx_height = proupservtx_rpc ['height' ]
485+ protx_listdiff_rpc = self .node_evo .node .protx ('listdiff' , proupservtx_height - 1 , proupservtx_height )
486+ protx_listdiff_rpc = self .extract_from_listdiff (protx_listdiff_rpc , proregtx_hash )
487+ assert_equal (protx_listdiff_rpc ['addresses' ], {
488+ 'core_p2p' : [f"127.0.0.1:{ self .node_evo .mn .nodePort } " , f"[::1]:{ self .node_evo .mn .nodePort } " ],
489+ 'platform_p2p' : [f"127.0.0.1:{ DEFAULT_PORT_PLATFORM_P2P + 12 } " ],
490+ 'platform_https' : [f"127.0.0.3:{ DEFAULT_PORT_PLATFORM_HTTP } " , f"[::3]:{ DEFAULT_PORT_PLATFORM_HTTP } " ]
491+ })
492+
493+ # Check platform{HTTP,P2P}Port shims work as expected
494+ assert_equal (proregtx_rpc ['proRegTx' ]['platformP2PPort' ], DEFAULT_PORT_PLATFORM_P2P )
495+ assert_equal (proregtx_rpc ['proRegTx' ]['platformHTTPPort' ], DEFAULT_PORT_PLATFORM_HTTP )
496+ assert_equal (proupservtx_rpc ['proUpServTx' ]['platformP2PPort' ], DEFAULT_PORT_PLATFORM_P2P + 12 )
497+ assert_equal (proupservtx_rpc ['proUpServTx' ]['platformHTTPPort' ], DEFAULT_PORT_PLATFORM_HTTP )
498+ # platform{HTTP,P2P}Port *won't* be populated by listdiff as that *field* is now unused and it's dangerous to report "updates" to disused fields
499+ assert "platformP2PPort" not in protx_listdiff_rpc .keys ()
500+ assert "platformHTTPPort" not in protx_listdiff_rpc .keys ()
501+
502+ # Restart the client to see if (de)ser works as intended (CDeterministicMNStateDiff is a special case and we just made an update)
503+ self .node_evo .set_active_state (self , False )
504+ self .reconnect_nodes ()
505+
506+ # Check that 'service' correctly reports as coreP2PAddrs[0]
507+ proregtx_rpc = self .node_simple .getrawtransaction (proregtx_hash , True )
508+ proupservtx_rpc = self .node_simple .getrawtransaction (proupservtx_hash , True )
509+ assert_equal (proregtx_rpc ['proRegTx' ]['service' ], f"127.0.0.1:{ self .node_evo .mn .nodePort } " )
510+ assert_equal (proupservtx_rpc ['proUpServTx' ]['service' ], f"127.0.0.1:{ self .node_evo .mn .nodePort } " )
511+
458512if __name__ == "__main__" :
459513 NetInfoTest ().main ()
0 commit comments