From ef51719e6262910ff0c66645fe1af71835d138ab Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 8 Dec 2022 14:38:40 +0200 Subject: [PATCH] tests: Fix test_xmr_persistent --- .../basicswap/extended/test_xmr_persistent.py | 16 +++-- tests/basicswap/selenium/__init__.py | 0 .../basicswap/selenium/test_swap_direction.py | 69 +++++++++++++++++++ 3 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 tests/basicswap/selenium/__init__.py create mode 100644 tests/basicswap/selenium/test_swap_direction.py diff --git a/tests/basicswap/extended/test_xmr_persistent.py b/tests/basicswap/extended/test_xmr_persistent.py index dc4e385..df70415 100644 --- a/tests/basicswap/extended/test_xmr_persistent.py +++ b/tests/basicswap/extended/test_xmr_persistent.py @@ -90,10 +90,14 @@ def updateThread(cls): def updateThreadXmr(cls): + xmr_auth = None + if os.getenv('XMR_RPC_USER', '') != '': + xmr_auth = (os.getenv('XMR_RPC_USER', ''), os.getenv('XMR_RPC_PWD', '')) + while not cls.delay_event.is_set(): try: if cls.xmr_addr is not None: - callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'generateblocks', {'wallet_address': cls.xmr_addr, 'amount_of_blocks': 1}) + callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'generateblocks', {'wallet_address': cls.xmr_addr, 'amount_of_blocks': 1}, auth=xmr_auth) except Exception as e: print('updateThreadXmr error', str(e)) cls.delay_event.wait(random.randrange(cls.xmr_update_min, cls.xmr_update_max)) @@ -149,12 +153,16 @@ class Test(unittest.TestCase): wallets = read_json_api(UI_PORT + 1, 'wallets') + xmr_auth = None + if os.getenv('XMR_RPC_USER', '') != '': + xmr_auth = (os.getenv('XMR_RPC_USER', ''), os.getenv('XMR_RPC_PWD', '')) + self.xmr_addr = wallets['XMR']['main_address'] num_blocks = 100 - if callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'get_block_count')['count'] < num_blocks: + if callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'get_block_count', auth=xmr_auth)['count'] < num_blocks: logging.info('Mining {} Monero blocks to {}.'.format(num_blocks, self.xmr_addr)) - callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'generateblocks', {'wallet_address': self.xmr_addr, 'amount_of_blocks': num_blocks}) - logging.info('XMR blocks: %d', callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'get_block_count')['count']) + callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'generateblocks', {'wallet_address': self.xmr_addr, 'amount_of_blocks': num_blocks}, auth=xmr_auth) + logging.info('XMR blocks: %d', callrpc_xmr(XMR_BASE_RPC_PORT + 1, 'get_block_count', auth=xmr_auth)['count']) self.btc_addr = callbtcrpc(0, 'getnewaddress', ['mining_addr', 'bech32']) num_blocks = 500 # Mine enough to activate segwit diff --git a/tests/basicswap/selenium/__init__.py b/tests/basicswap/selenium/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/basicswap/selenium/test_swap_direction.py b/tests/basicswap/selenium/test_swap_direction.py new file mode 100644 index 0000000..aa422e0 --- /dev/null +++ b/tests/basicswap/selenium/test_swap_direction.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright (c) 2022 tecnovert +# Distributed under the MIT software license, see the accompanying +# file LICENSE or http://www.opensource.org/licenses/mit-license.php. + +import time + +from tests.basicswap.util import ( + read_json_api, +) + +from selenium import webdriver +from selenium.webdriver.chrome.service import Service + + +def test_html(driver): + node_1_port = 12701 + node_2_port = 12702 + node1_url = f'http://localhost:{node_1_port}' + node2_url = f'http://localhost:{node_2_port}' + + offer_data = { + 'addr_from': -1, + 'coin_from': 'PART', + 'coin_to': 'XMR', + 'amt_from': 1, + 'amt_to': 2, + 'lockhrs': 24} + rv = read_json_api(node_1_port, 'offers/new', offer_data) + offer0_id = rv['offer_id'] + + offer_data = { + 'addr_from': -1, + 'coin_from': 'PART', + 'coin_to': 'BTC', + 'amt_from': 3, + 'amt_to': 4, + 'lockhrs': 24} + rv = read_json_api(node_1_port, 'offers/new', offer_data) + offer0_id = rv['offer_id'] + + # Wait for offer to propagate + offers_api_1 = read_json_api(node_1_port, 'offers') + print('offers_api_1', offers_api_1) + + offers_api_2 = read_json_api(node_2_port, 'offers') + while len(offers_api_2) < 1: + rv = read_json_api(node_2_port, 'offers') + print('offers_api_2', offers_api_2) + + driver.get(f'{node1_url}/offers') + time.sleep(1) + + driver.get(f'{node2_url}/offers') + time.sleep(300) + + raise ValueError('TODO') + + print('Done.') + + +if __name__ == '__main__': + driver = webdriver.Chrome(service=Service('/opt/chromedriver96')) + try: + test_html(driver) + finally: + driver.close()