From bbd3d701c0b6977747197b06314f003ae1882e15 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Tue, 16 Feb 2021 23:41:07 +0200 Subject: [PATCH] preparescript: Fix UI_HTML_PORT bug. Warn on os.chmod failure, workaround for mounted ntfs volumes. client: Set delay_event in stopRunning() Raise version --- basicswap/__init__.py | 2 +- basicswap/base.py | 8 ++++--- basicswap/basicswap.py | 1 - bin/basicswap_prepare.py | 25 ++++++++++++--------- tests/basicswap/extended/test_http_ui.py | 28 +++++++++++++++++++----- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/basicswap/__init__.py b/basicswap/__init__.py index c0779bd..1eeffa1 100644 --- a/basicswap/__init__.py +++ b/basicswap/__init__.py @@ -1,3 +1,3 @@ name = "basicswap" -__version__ = "0.0.17" +__version__ = "0.0.18" diff --git a/basicswap/base.py b/basicswap/base.py index b2fb699..15acdb7 100644 --- a/basicswap/base.py +++ b/basicswap/base.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2019 tecnovert +# Copyright (c) 2019-2021 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -38,14 +38,16 @@ class BaseApp: self.coin_interfaces = {} self.mxDB = threading.RLock() self.debug = self.settings.get('debug', False) + self.delay_event = threading.Event() self._network = None - self.prepareLogging() self.log.info('Network: {}'.format(self.chain)) def stopRunning(self, with_code=0): self.fail_code = with_code - self.is_running = False + with self.mxDB: + self.is_running = False + self.delay_event.set() def prepareLogging(self): self.log = logging.getLogger(self.log_name) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index a32cd75..c363cd7 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -470,7 +470,6 @@ class BasicSwap(BaseApp): self.SMSG_SECONDS_IN_HOUR = 60 * 60 # Note: Set smsgsregtestadjust=0 for regtest - self.delay_event = threading.Event() self.threads = [] # Encode key to match network diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index 717b20f..aa3ae4c 100755 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -64,7 +64,7 @@ XMR_SITE_COMMIT = 'd27c1eee9fe0e8daa011d07baae8b67dd2b62a04' # Lock hashes.txt DEFAULT_XMR_RESTORE_HEIGHT = 2245107 -UI_HTML_PORT = int(os.getenv('BASE_XMR_RPC_PORT', 12700)) +UI_HTML_PORT = int(os.getenv('UI_HTML_PORT', 12700)) PART_ZMQ_PORT = int(os.getenv('PART_ZMQ_PORT', 20792)) PART_RPC_HOST = os.getenv('PART_RPC_HOST', '127.0.0.1') @@ -131,11 +131,12 @@ def extractCore(coin, version, settings, bin_dir, release_path): continue out_path = os.path.join(bin_dir, bin_name) if (not os.path.exists(out_path)) or extract_core_overwrite: - fi = ft.extractfile(member) - with open(out_path, 'wb') as fout: + with open(out_path, 'wb') as fout, ft.extractfile(member) as fi: fout.write(fi.read()) - fi.close() - os.chmod(out_path, stat.S_IRWXU | stat.S_IXGRP | stat.S_IXOTH) + try: + os.chmod(out_path, stat.S_IRWXU | stat.S_IXGRP | stat.S_IXOTH) + except Exception as e: + logging.warning('Unable to set file permissions: %s, for %s', str(e), out_path) return bins = [coin + 'd', coin + '-cli', coin + '-tx'] @@ -150,17 +151,21 @@ def extractCore(coin, version, settings, bin_dir, release_path): if (not os.path.exists(out_path)) or extract_core_overwrite: with open(out_path, 'wb') as fout: fout.write(fz.read('{}-{}/bin/{}'.format(coin, version, b))) - os.chmod(out_path, stat.S_IRWXU | stat.S_IXGRP | stat.S_IXOTH) + try: + os.chmod(out_path, stat.S_IRWXU | stat.S_IXGRP | stat.S_IXOTH) + except Exception as e: + logging.warning('Unable to set file permissions: %s, for %s', str(e), out_path) else: with tarfile.open(release_path) as ft: for b in bins: out_path = os.path.join(bin_dir, b) if not os.path.exists(out_path) or extract_core_overwrite: - fi = ft.extractfile('{}-{}/bin/{}'.format(coin, version, b)) - with open(out_path, 'wb') as fout: + with open(out_path, 'wb') as fout, ft.extractfile('{}-{}/bin/{}'.format(coin, version, b)) as fi: fout.write(fi.read()) - fi.close() - os.chmod(out_path, stat.S_IRWXU | stat.S_IXGRP | stat.S_IXOTH) + try: + os.chmod(out_path, stat.S_IRWXU | stat.S_IXGRP | stat.S_IXOTH) + except Exception as e: + logging.warning('Unable to set file permissions: %s, for %s', str(e), out_path) def prepareCore(coin, version, settings, data_dir): diff --git a/tests/basicswap/extended/test_http_ui.py b/tests/basicswap/extended/test_http_ui.py index f37c2c2..7afa278 100644 --- a/tests/basicswap/extended/test_http_ui.py +++ b/tests/basicswap/extended/test_http_ui.py @@ -6,22 +6,29 @@ # sudo mv chromedriver /opt/chromedriver88 # Run test_xmr_persistent.py +# python tests/basicswap/extended/test_http_ui.py import time +import logging from urllib.parse import urljoin from selenium import webdriver -from selenium.webdriver.support.ui import Select +from selenium.webdriver.support.ui import Select, WebDriverWait + +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') def run_test(): base_url = 'http://localhost:12701' driver = webdriver.Chrome('/opt/chromedriver88') - driver.get(urljoin(base_url, 'newoffer')) - html = driver.page_source - print('html', html) + driver.get(base_url) + link = driver.find_element_by_xpath('//a[@href="/offers"]') + num_offers_start = int(link.text.split(':')[1].strip()) + logging.info('Offers: %d', num_offers_start) + logging.info('Creating offer') + driver.get(urljoin(base_url, 'newoffer')) select_coin_from = Select(driver.find_element_by_name('coin_from')) select_coin_from.select_by_visible_text('Particl') @@ -35,15 +42,24 @@ def run_test(): submit_button = driver.find_element_by_name('continue') submit_button.click() + time.sleep(0.1) submit_button = driver.find_element_by_name('check_offer') submit_button.click() + time.sleep(0.1) submit_button = driver.find_element_by_name('submit_offer') submit_button.click() + time.sleep(0.1) - driver.get(urljoin(base_url)) - time.sleep(3) + link = WebDriverWait(driver, 5).until(lambda d: d.find_element_by_xpath("//a[contains(@href, '/offer')]")) + offer_id = link.text.rsplit(' ', 1)[1] + logging.info('Offer ID: %s', offer_id) + + driver.get(base_url) + link = driver.find_element_by_xpath('//a[@href="/offers"]') + num_offers_end = int(link.text.split(':')[1].strip()) + assert(num_offers_end == num_offers_start + 1) driver.quit()