|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2026 The Dash Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +""" |
| 7 | +Test MNAUTH emission on the registered masternode service only. |
| 8 | +""" |
| 9 | + |
| 10 | +from test_framework.test_framework import ( |
| 11 | + DashTestFramework, |
| 12 | + MasternodeInfo, |
| 13 | +) |
| 14 | +from test_framework.util import ( |
| 15 | + assert_equal, |
| 16 | + p2p_port, |
| 17 | +) |
| 18 | + |
| 19 | + |
| 20 | +class P2PMNAUTHTest(DashTestFramework): |
| 21 | + def add_options(self, parser): |
| 22 | + self.add_wallet_options(parser) |
| 23 | + |
| 24 | + def set_test_params(self): |
| 25 | + self.alt_port = p2p_port(10) |
| 26 | + self.mn_port = p2p_port(2) |
| 27 | + self.set_dash_test_params(3, 1, extra_args=[ |
| 28 | + [], |
| 29 | + [], |
| 30 | + [f"-bind=127.0.0.1:{self.alt_port}", f"-externalip=127.0.0.1:{self.mn_port}"], |
| 31 | + ]) |
| 32 | + |
| 33 | + def run_test(self): |
| 34 | + masternode: MasternodeInfo = self.mninfo[0] |
| 35 | + masternode_node = masternode.get_node(self) |
| 36 | + connector = self.nodes[1] |
| 37 | + use_v2transport = self.options.v2transport |
| 38 | + |
| 39 | + expected_addr = f"127.0.0.1:{masternode.nodePort}" |
| 40 | + alternate_addr = f"127.0.0.1:{self.alt_port}" |
| 41 | + |
| 42 | + self.wait_until(lambda: masternode_node.masternode("status")["state"] == "READY") |
| 43 | + assert_equal(masternode_node.masternode("status")["service"], expected_addr) |
| 44 | + |
| 45 | + self.log.info(f"Connect to the registered masternode service over {'v2' if use_v2transport else 'v1'} and expect MNAUTH") |
| 46 | + with connector.assert_debug_log([f"Masternode probe successful for {masternode.proTxHash}"]): |
| 47 | + assert_equal(connector.masternode("connect", expected_addr, use_v2transport), "successfully connected") |
| 48 | + |
| 49 | + self.log.info(f"Connect to the alternate bind over {'v2' if use_v2transport else 'v1'} and expect no MNAUTH") |
| 50 | + with masternode_node.assert_debug_log(["Not sending MNAUTH on unexpected local service"]): |
| 51 | + with connector.assert_debug_log(["connection is a masternode probe but first received message is not MNAUTH"]): |
| 52 | + assert_equal(connector.masternode("connect", alternate_addr, use_v2transport), "successfully connected") |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == '__main__': |
| 56 | + P2PMNAUTHTest().main() |
0 commit comments