tests: Add BCH to test_xmr_persistent

This commit is contained in:
tecnovert 2024-10-31 14:31:44 +02:00
parent 8e00753f97
commit 51d9685af0
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
2 changed files with 54 additions and 0 deletions

View file

@ -34,6 +34,9 @@ from tests.basicswap.common import (
from tests.basicswap.extended.test_dcr import ( from tests.basicswap.extended.test_dcr import (
DCR_BASE_PORT, DCR_BASE_RPC_PORT, DCR_BASE_PORT, DCR_BASE_RPC_PORT,
) )
from tests.basicswap.test_bch_xmr import (
BCH_BASE_PORT, BCH_BASE_RPC_PORT,
)
from basicswap.contrib.rpcauth import generate_salt, password_to_hmac from basicswap.contrib.rpcauth import generate_salt, password_to_hmac
@ -51,6 +54,8 @@ BITCOIN_TOR_PORT_BASE = int(os.getenv('BITCOIN_TOR_PORT_BASE', BTC_BASE_TOR_PORT
LITECOIN_RPC_PORT_BASE = int(os.getenv('LITECOIN_RPC_PORT_BASE', LTC_BASE_RPC_PORT)) LITECOIN_RPC_PORT_BASE = int(os.getenv('LITECOIN_RPC_PORT_BASE', LTC_BASE_RPC_PORT))
DECRED_RPC_PORT_BASE = int(os.getenv('DECRED_RPC_PORT_BASE', DCR_BASE_RPC_PORT)) DECRED_RPC_PORT_BASE = int(os.getenv('DECRED_RPC_PORT_BASE', DCR_BASE_RPC_PORT))
BITCOINCASH_RPC_PORT_BASE = int(os.getenv('BITCOINCASH_RPC_PORT_BASE', BCH_BASE_RPC_PORT))
FIRO_BASE_PORT = 34832 FIRO_BASE_PORT = 34832
FIRO_BASE_RPC_PORT = 35832 FIRO_BASE_RPC_PORT = 35832
@ -100,6 +105,7 @@ def run_prepare(node_id, datadir_path, bins_path, with_coins, mnemonic_in=None,
os.environ['BTC_RPC_PORT'] = str(BITCOIN_RPC_PORT_BASE) os.environ['BTC_RPC_PORT'] = str(BITCOIN_RPC_PORT_BASE)
os.environ['LTC_RPC_PORT'] = str(LITECOIN_RPC_PORT_BASE) os.environ['LTC_RPC_PORT'] = str(LITECOIN_RPC_PORT_BASE)
os.environ['DCR_RPC_PORT'] = str(DECRED_RPC_PORT_BASE) os.environ['DCR_RPC_PORT'] = str(DECRED_RPC_PORT_BASE)
os.environ['BCH_RPC_PORT'] = str(BITCOINCASH_RPC_PORT_BASE)
os.environ['FIRO_RPC_PORT'] = str(FIRO_RPC_PORT_BASE) os.environ['FIRO_RPC_PORT'] = str(FIRO_RPC_PORT_BASE)
os.environ['XMR_RPC_USER'] = 'xmr_user' os.environ['XMR_RPC_USER'] = 'xmr_user'
@ -120,6 +126,7 @@ def run_prepare(node_id, datadir_path, bins_path, with_coins, mnemonic_in=None,
'-regtest', '-regtest',
f'-withcoins={with_coins}', f'-withcoins={with_coins}',
'-noextractover', '-noextractover',
'-noreleasesizecheck',
'-xmrrestoreheight=0'] '-xmrrestoreheight=0']
if mnemonic_in: if mnemonic_in:
testargs.append(f'-particl_mnemonic="{mnemonic_in}"') testargs.append(f'-particl_mnemonic="{mnemonic_in}"')
@ -314,6 +321,33 @@ def run_prepare(node_id, datadir_path, bins_path, with_coins, mnemonic_in=None,
if ip != node_id: if ip != node_id:
fp.write('add-exclusive-node=127.0.0.1:{}\n'.format(XMR_BASE_P2P_PORT + ip + port_ofs)) fp.write('add-exclusive-node=127.0.0.1:{}\n'.format(XMR_BASE_P2P_PORT + ip + port_ofs))
if 'bitcoincash' in coins_array:
config_filename = os.path.join(datadir_path, 'bitcoincash', 'bitcoin.conf')
with open(config_filename, 'r') as fp:
lines = fp.readlines()
with open(config_filename, 'w') as fp:
for line in lines:
if not line.startswith('prune'):
fp.write(line)
fp.write('port={}\n'.format(BCH_BASE_PORT + node_id + port_ofs))
fp.write('bind=127.0.0.1\n')
fp.write('dnsseed=0\n')
fp.write('discover=0\n')
fp.write('listenonion=0\n')
fp.write('upnp=0\n')
if use_rpcauth:
salt = generate_salt(16)
rpc_user = 'test_bch_' + str(node_id)
rpc_pass = 'test_bch_pwd_' + str(node_id)
fp.write('rpcauth={}:{}${}\n'.format(rpc_user, salt, password_to_hmac(salt, rpc_pass)))
settings['chainclients']['bitcoincash']['rpcuser'] = rpc_user
settings['chainclients']['bitcoincash']['rpcpassword'] = rpc_pass
for ip in range(num_nodes):
if ip != node_id:
fp.write('connect=127.0.0.1:{}\n'.format(BCH_BASE_PORT + ip + port_ofs))
for opt in EXTRA_CONFIG_JSON.get('bch{}'.format(node_id), []):
fp.write(opt + '\n')
with open(config_path) as fs: with open(config_path) as fs:
settings = json.load(fs) settings = json.load(fs)

View file

@ -44,6 +44,9 @@ from tests.basicswap.common import (
BTC_BASE_RPC_PORT, BTC_BASE_RPC_PORT,
LTC_BASE_RPC_PORT, LTC_BASE_RPC_PORT,
) )
from tests.basicswap.test_bch_xmr import (
BCH_BASE_RPC_PORT,
)
from tests.basicswap.util import ( from tests.basicswap.util import (
make_boolean, make_boolean,
read_json_api, read_json_api,
@ -66,6 +69,7 @@ UI_PORT = 12700 + PORT_OFS
PARTICL_RPC_PORT_BASE = int(os.getenv('PARTICL_RPC_PORT_BASE', BASE_RPC_PORT)) PARTICL_RPC_PORT_BASE = int(os.getenv('PARTICL_RPC_PORT_BASE', BASE_RPC_PORT))
BITCOIN_RPC_PORT_BASE = int(os.getenv('BITCOIN_RPC_PORT_BASE', BTC_BASE_RPC_PORT)) BITCOIN_RPC_PORT_BASE = int(os.getenv('BITCOIN_RPC_PORT_BASE', BTC_BASE_RPC_PORT))
LITECOIN_RPC_PORT_BASE = int(os.getenv('LITECOIN_RPC_PORT_BASE', LTC_BASE_RPC_PORT)) LITECOIN_RPC_PORT_BASE = int(os.getenv('LITECOIN_RPC_PORT_BASE', LTC_BASE_RPC_PORT))
BITCOINCASH_RPC_PORT_BASE = int(os.getenv('BITCOINCASH_RPC_PORT_BASE', BCH_BASE_RPC_PORT))
DECRED_WALLET_RPC_PORT_BASE = int(os.getenv('DECRED_WALLET_RPC_PORT_BASE', 9210)) DECRED_WALLET_RPC_PORT_BASE = int(os.getenv('DECRED_WALLET_RPC_PORT_BASE', 9210))
XMR_BASE_RPC_PORT = int(os.getenv('XMR_BASE_RPC_PORT', XMR_BASE_RPC_PORT)) XMR_BASE_RPC_PORT = int(os.getenv('XMR_BASE_RPC_PORT', XMR_BASE_RPC_PORT))
TEST_COINS_LIST = os.getenv('TEST_COINS_LIST', 'bitcoin,monero') TEST_COINS_LIST = os.getenv('TEST_COINS_LIST', 'bitcoin,monero')
@ -99,6 +103,11 @@ def calldcrrpc(node_id, method, params=[], wallet=None, base_rpc_port=DECRED_WAL
return callrpc_dcr(base_rpc_port + node_id, auth, method, params) return callrpc_dcr(base_rpc_port + node_id, auth, method, params)
def callbchrpc(node_id, method, params=[], wallet=None, base_rpc_port=BITCOINCASH_RPC_PORT_BASE + PORT_OFS):
auth = 'test_bch_{0}:test_bch_pwd_{0}'.format(node_id)
return callrpc(base_rpc_port + node_id, auth, method, params, wallet)
def updateThread(cls): def updateThread(cls):
while not cls.delay_event.is_set(): while not cls.delay_event.is_set():
try: try:
@ -106,6 +115,8 @@ def updateThread(cls):
callbtcrpc(0, 'generatetoaddress', [1, cls.btc_addr]) callbtcrpc(0, 'generatetoaddress', [1, cls.btc_addr])
if cls.ltc_addr is not None: if cls.ltc_addr is not None:
callltcrpc(0, 'generatetoaddress', [1, cls.ltc_addr]) callltcrpc(0, 'generatetoaddress', [1, cls.ltc_addr])
if cls.bch_addr is not None:
callbchrpc(0, 'generatetoaddress', [1, cls.bch_addr])
except Exception as e: except Exception as e:
print('updateThread error', str(e)) print('updateThread error', str(e))
cls.delay_event.wait(random.randrange(cls.update_min, cls.update_max)) cls.delay_event.wait(random.randrange(cls.update_min, cls.update_max))
@ -174,6 +185,7 @@ class Test(unittest.TestCase):
cls.processes = [] cls.processes = []
cls.btc_addr = None cls.btc_addr = None
cls.ltc_addr = None cls.ltc_addr = None
cls.bch_addr = None
cls.xmr_addr = None cls.xmr_addr = None
cls.dcr_addr = 'SsYbXyjkKAEXXcGdFgr4u4bo4L8RkCxwQpH' cls.dcr_addr = 'SsYbXyjkKAEXXcGdFgr4u4bo4L8RkCxwQpH'
cls.dcr_acc = None cls.dcr_acc = None
@ -257,6 +269,14 @@ class Test(unittest.TestCase):
self.update_thread_dcr = threading.Thread(target=updateThreadDCR, args=(self,)) self.update_thread_dcr = threading.Thread(target=updateThreadDCR, args=(self,))
self.update_thread_dcr.start() self.update_thread_dcr.start()
if 'bitcoincash' in TEST_COINS_LIST:
self.bch_addr = callbchrpc(0, 'getnewaddress', ['mining_addr'], wallet='wallet.dat')
num_blocks: int = 200
have_blocks: int = callbchrpc(0, 'getblockcount')
if have_blocks < num_blocks:
logging.info('Mining %d Bitcoincash blocks to %s', num_blocks - have_blocks, self.bch_addr)
callbchrpc(0, 'generatetoaddress', [num_blocks - have_blocks, self.bch_addr], wallet='wallet.dat')
if RESET_TEST: if RESET_TEST:
# Lower output split threshold for more stakeable outputs # Lower output split threshold for more stakeable outputs
for i in range(NUM_NODES): for i in range(NUM_NODES):