From d08e85e73e2e0d2159014ce2d9301fb8063c4c20 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Mon, 14 Nov 2022 15:01:48 +0200 Subject: [PATCH] tests: Wait for height before starting --- tests/basicswap/common_xmr.py | 1 + .../basicswap/extended/test_xmr_persistent.py | 3 +- tests/basicswap/test_run.py | 3 ++ tests/basicswap/test_xmr.py | 32 +++++++++++++++++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tests/basicswap/common_xmr.py b/tests/basicswap/common_xmr.py index 8493276..52b7624 100644 --- a/tests/basicswap/common_xmr.py +++ b/tests/basicswap/common_xmr.py @@ -124,6 +124,7 @@ def run_prepare(node_id, datadir_path, bins_path, with_coins, mnemonic_in=None, fp.write('listenonion=0\n') fp.write('upnp=0\n') fp.write('minstakeinterval=5\n') + fp.write('stakethreadconddelayms=2000\n') fp.write('smsgsregtestadjust=0\n') if use_rpcauth: salt = generate_salt(16) diff --git a/tests/basicswap/extended/test_xmr_persistent.py b/tests/basicswap/extended/test_xmr_persistent.py index 10d1f6d..bc2d761 100644 --- a/tests/basicswap/extended/test_xmr_persistent.py +++ b/tests/basicswap/extended/test_xmr_persistent.py @@ -181,8 +181,7 @@ class Test(unittest.TestCase): if particl_blocks >= num_blocks: break self.delay_event.wait(1) - - logging.info('PART blocks: %d', callpartrpc(0, 'getblockchaininfo')['blocks']) + logging.info('PART blocks: %d', callpartrpc(0, 'getblockcount')) assert particl_blocks >= num_blocks @classmethod diff --git a/tests/basicswap/test_run.py b/tests/basicswap/test_run.py index f0e71b3..43dbff9 100644 --- a/tests/basicswap/test_run.py +++ b/tests/basicswap/test_run.py @@ -78,6 +78,9 @@ class Test(BaseTest): cls.states_bidder = extract_states_from_xu_file(os.path.join(diagrams_dir, 'bidder.alt.xu'), 'B') cls.states_offerer = extract_states_from_xu_file(os.path.join(diagrams_dir, 'offerer.alt.xu'), 'O') + # Wait for height, or sequencelock is thrown off by genesis blocktime + cls.waitForParticlHeight(3) + @classmethod def tearDownClass(cls): logging.info('Finalising test') diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index 1da0f7b..8a346b8 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -367,7 +367,11 @@ class BaseTest(unittest.TestCase): if not cls.restore_instance: data_dir = prepareDataDir(TEST_DIR, i, 'particl.conf', 'part_') if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')): - callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') + try: + callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') + except Exception as e: + logging.warning('particl-wallet create failed, retrying without -legacy') + callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat create', 'particl-wallet') cls.part_daemons.append(startDaemon(os.path.join(TEST_DIR, 'part_' + str(i)), cfg.PARTICL_BINDIR, cfg.PARTICLD)) logging.info('Started %s %d', cfg.PARTICLD, cls.part_daemons[-1].pid) @@ -392,7 +396,11 @@ class BaseTest(unittest.TestCase): if not cls.restore_instance: data_dir = prepareDataDir(TEST_DIR, i, 'bitcoin.conf', 'btc_', base_p2p_port=BTC_BASE_PORT, base_rpc_port=BTC_BASE_RPC_PORT) if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')): - callrpc_cli(cfg.BITCOIN_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') + try: + callrpc_cli(cfg.BITCOIN_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') + except Exception as e: + logging.warning('bitcoin-wallet create failed, retrying without -legacy') + callrpc_cli(cfg.BITCOIN_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat create', 'bitcoin-wallet') cls.btc_daemons.append(startDaemon(os.path.join(TEST_DIR, 'btc_' + str(i)), cfg.BITCOIN_BINDIR, cfg.BITCOIND)) logging.info('Started %s %d', cfg.BITCOIND, cls.part_daemons[-1].pid) @@ -501,7 +509,11 @@ class BaseTest(unittest.TestCase): logging.info('Mining %d Bitcoin blocks to %s', num_blocks, cls.btc_addr) callnoderpc(0, 'generatetoaddress', [num_blocks, cls.btc_addr], base_rpc_port=BTC_BASE_RPC_PORT) - checkForks(callnoderpc(0, 'getdeploymentinfo', base_rpc_port=BTC_BASE_RPC_PORT)) + major_version = int(str(callnoderpc(0, 'getnetworkinfo', base_rpc_port=BTC_BASE_RPC_PORT)['version'])[:2]) + if major_version >= 23: + checkForks(callnoderpc(0, 'getdeploymentinfo', base_rpc_port=BTC_BASE_RPC_PORT)) + else: + checkForks(callnoderpc(0, 'getblockchaininfo', base_rpc_port=BTC_BASE_RPC_PORT)) if cls.start_ltc_nodes: num_blocks = 400 @@ -619,6 +631,20 @@ class BaseTest(unittest.TestCase): if cls.xmr_addr is not None: callrpc_xmr_na(XMR_BASE_RPC_PORT + 1, 'generateblocks', {'wallet_address': cls.xmr_addr, 'amount_of_blocks': 1}) + @classmethod + def waitForParticlHeight(cls, num_blocks, node_id=0): + logging.info(f'Waiting for Particl chain height {num_blocks}', ) + for i in range(60): + if test_delay_event.is_set(): + raise ValueError('Test stopped.') + particl_blocks = callnoderpc(0, 'getblockcount') + print('particl_blocks', particl_blocks) + if particl_blocks >= num_blocks: + break + test_delay_event.wait(1) + logging.info('PART blocks: %d', callnoderpc(0, 'getblockcount')) + assert particl_blocks >= num_blocks + def callxmrnodewallet(self, node_id, method, params=None): return callrpc_xmr(XMR_BASE_WALLET_RPC_PORT + node_id, self.xmr_wallet_auth[node_id], method, params)