tests: Wait for height before starting

2024-05-20_merge
tecnovert 2 years ago
parent 8ec6d55963
commit d08e85e73e
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 1
      tests/basicswap/common_xmr.py
  2. 3
      tests/basicswap/extended/test_xmr_persistent.py
  3. 3
      tests/basicswap/test_run.py
  4. 26
      tests/basicswap/test_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('listenonion=0\n')
fp.write('upnp=0\n') fp.write('upnp=0\n')
fp.write('minstakeinterval=5\n') fp.write('minstakeinterval=5\n')
fp.write('stakethreadconddelayms=2000\n')
fp.write('smsgsregtestadjust=0\n') fp.write('smsgsregtestadjust=0\n')
if use_rpcauth: if use_rpcauth:
salt = generate_salt(16) salt = generate_salt(16)

@ -181,8 +181,7 @@ class Test(unittest.TestCase):
if particl_blocks >= num_blocks: if particl_blocks >= num_blocks:
break break
self.delay_event.wait(1) self.delay_event.wait(1)
logging.info('PART blocks: %d', callpartrpc(0, 'getblockcount'))
logging.info('PART blocks: %d', callpartrpc(0, 'getblockchaininfo')['blocks'])
assert particl_blocks >= num_blocks assert particl_blocks >= num_blocks
@classmethod @classmethod

@ -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_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') 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 @classmethod
def tearDownClass(cls): def tearDownClass(cls):
logging.info('Finalising test') logging.info('Finalising test')

@ -367,7 +367,11 @@ class BaseTest(unittest.TestCase):
if not cls.restore_instance: if not cls.restore_instance:
data_dir = prepareDataDir(TEST_DIR, i, 'particl.conf', 'part_') data_dir = prepareDataDir(TEST_DIR, i, 'particl.conf', 'part_')
if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')): if os.path.exists(os.path.join(cfg.PARTICL_BINDIR, 'particl-wallet')):
try:
callrpc_cli(cfg.PARTICL_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'particl-wallet') 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)) 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) 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: 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) 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')): if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, 'bitcoin-wallet')):
try:
callrpc_cli(cfg.BITCOIN_BINDIR, data_dir, 'regtest', '-wallet=wallet.dat -legacy create', 'bitcoin-wallet') 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)) 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) 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) 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) callnoderpc(0, 'generatetoaddress', [num_blocks, cls.btc_addr], 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)) 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: if cls.start_ltc_nodes:
num_blocks = 400 num_blocks = 400
@ -619,6 +631,20 @@ class BaseTest(unittest.TestCase):
if cls.xmr_addr is not None: 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}) 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): 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) return callrpc_xmr(XMR_BASE_WALLET_RPC_PORT + node_id, self.xmr_wallet_auth[node_id], method, params)

Loading…
Cancel
Save