ui: Render 404 for unknown pages.

Wait for wallet update to complete, to handle corner case where user opens wallet page before refreshing.
Withdraw txn in selenium test.
This commit is contained in:
tecnovert 2022-09-23 22:07:41 +02:00
parent 6b4666d632
commit 46d1856f71
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
5 changed files with 75 additions and 17 deletions

View file

@ -5398,7 +5398,7 @@ class BasicSwap(BaseApp):
finally:
self._updating_wallets_info[int(coin)] = False
def updateWalletsInfo(self, force_update=False, only_coin=None):
def updateWalletsInfo(self, force_update=False, only_coin=None, wait_for_complete=False):
now = int(time.time())
if not force_update and now - self._last_updated_wallets_info < 30:
return
@ -5407,11 +5407,18 @@ class BasicSwap(BaseApp):
continue
if c not in chainparams:
continue
if self.coin_clients[c]['connection_type'] == 'rpc':
cc = self.coin_clients[c]
if cc['connection_type'] == 'rpc':
if not force_update and now - cc.get('last_updated_wallet_info', 0) < 30:
return
cc['last_updated_wallet_info'] = int(time.time())
self._updating_wallets_info[int(c)] = True
self.thread_pool.submit(self.updateWalletInfo, c)
if only_coin is None:
self._last_updated_wallets_info = int(time.time())
handle = self.thread_pool.submit(self.updateWalletInfo, c)
if wait_for_complete:
try:
handle.result(timeout=10)
except Exception as e:
self.log.error(f'updateWalletInfo {e}')
def getWalletsInfo(self, opts=None):
rv = {}

View file

@ -146,7 +146,7 @@ class HttpHandler(BaseHTTPRequestHandler):
template = env.get_template('info.html')
return self.render_simple_template(template, {
'title_str': 'BasicSwap Info',
'message_str': error_str,
'message_str': info_str,
})
def page_error(self, error_str):
@ -780,6 +780,8 @@ class HttpHandler(BaseHTTPRequestHandler):
return page_automation_strategy_new(self, url_split, post_string)
if page == 'shutdown':
return self.page_shutdown(url_split, post_string)
if page != '':
return self.page_404(url_split)
return self.page_index(url_split)
except Exception as ex:
if self.server.swap_client.debug is True:

View file

@ -1,6 +1,5 @@
{% include 'header.html' %}
<p><a id="refresh" href="/wallet/{{ w.ticker }}">refresh</a></p>
<p><a id="back" href="/wallets">back</a></p>
@ -10,7 +9,7 @@
{% endif %}
{% for m in messages %}
<p>{{ m }}</p>
<p class="infomsg">{{ m }}</p>
{% endfor %}
<form method="post">
@ -47,7 +46,7 @@
<tr><td>Main Address</td><td colspan=2>{{ w.main_address }}</td></tr>
<tr><td><input type="submit" name="newaddr_{{ w.cid }}" value="New Subaddress"></td><td colspan=2>{{ w.deposit_address }}</td></tr>
{% else %}
<tr><td><input type="submit" name="newaddr_{{ w.cid }}" value="New Deposit Address"></td><td colspan=2>{{ w.deposit_address }}</td></tr>
<tr><td><input type="submit" name="newaddr_{{ w.cid }}" value="New Deposit Address"></td><td colspan=2 id="deposit_address">{{ w.deposit_address }}</td></tr>
{% endif %}
<tr><td><input type="submit" name="withdraw_{{ w.cid }}" value="Withdraw" onclick="return confirmWithdrawal();"></td><td>Amount: <input type="text" name="amt_{{ w.cid }}" value="{{ w.wd_value }}"></td><td>Address: <input type="text" name="to_{{ w.cid }}" value="{{ w.wd_address }}"></td><td>Subtract fee: <input type="checkbox" name="subfee_{{ w.cid }}" {% if w.wd_subfee==true %} checked=checked{% endif %}></td></tr>
{% if w.cid == '1' %}

View file

@ -239,7 +239,8 @@ def page_wallet(self, url_split, post_string):
if swap_client.debug is True:
swap_client.log.error(traceback.format_exc())
swap_client.updateWalletsInfo()
swap_client.updateWalletsInfo(only_coin=coin_id, wait_for_complete=True)
wallets = swap_client.getCachedWalletsInfo({'coin_id': coin_id})
for k in wallets.keys():
w = wallets[k]

View file

@ -7,7 +7,7 @@
"""
cd /tmp
wget -4 https://chromedriver.storage.googleapis.com/96.0.4664.45/chromedriver_linux64.zip
wget -4 https://chromedriver.storage.googleapis.com/105.0.5195.52/chromedriver_linux64.zip
7z x chromedriver_linux64.zip
sudo mv chromedriver /opt/chromedriver96
@ -16,12 +16,12 @@ python tests/basicswap/extended/test_xmr_persistent.py
python tests/basicswap/selenium/test_wallets.py
html = driver.page_source
print('html', html)
"""
import json
import time
from urllib.request import urlopen
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
@ -29,20 +29,69 @@ from selenium.webdriver.chrome.service import Service
def test_html():
base_url = 'http://localhost:12701'
node2_url = 'http://localhost:12702'
driver = webdriver.Chrome(service=Service('/opt/chromedriver96'))
url = base_url + '/wallets'
# Check json coins data
coins = json.loads(urlopen(base_url + '/json/coins').read())
part_coin = [f for f in coins if f['ticker'] == 'PART'][0]
part_id = part_coin['id']
assert (part_id == 1)
# Check 404 pages
url = base_url + '/unknown'
driver.get(url)
p1 = driver.find_element(By.TAG_NAME, 'p')
assert ('404' in p1.text)
url = base_url + '/static/nothing.png'
driver.get(url)
p1 = driver.find_element(By.TAG_NAME, 'p')
assert ('404' in p1.text)
url = base_url + '/wallet'
driver.get(url)
h2 = driver.find_element(By.TAG_NAME, 'h2')
assert ('Error' in h2.text)
p1 = driver.find_element(By.TAG_NAME, 'p')
assert ('Wallet not specified' in p1.text)
url = base_url + '/wallet/NOCOIN'
driver.get(url)
h2 = driver.find_element(By.TAG_NAME, 'h2')
assert ('Error' in h2.text)
p1 = driver.find_element(By.TAG_NAME, 'p')
assert ('Unknown coin' in p1.text)
driver.get(base_url + '/wallets')
time.sleep(1)
driver.refresh()
driver.find_element(By.ID, 'refresh').click()
time.sleep(1)
driver.refresh()
driver.find_element(By.ID, "refresh").click()
print('Finding deposit address of node 2')
driver.get(node2_url + '/wallet/PART')
e = driver.find_element(By.ID, 'deposit_address')
node2_deposit_address = e.text
print('Withdrawing from node 1')
driver.get(base_url + '/wallet/PART')
driver.find_element(By.NAME, f'to_{part_id}').send_keys(node2_deposit_address)
driver.find_element(By.NAME, f'amt_{part_id}').send_keys('10')
driver.find_element(By.NAME, f'withdraw_{part_id}').click()
driver.switch_to.alert.accept()
time.sleep(1)
driver.refresh()
elements = driver.find_elements(By.CLASS_NAME, "infomsg")
assert (len(elements) == 1)
e = elements[0]
assert ('Withdrew 10 rtPART (plain to plain) to address' in e.text)
driver.close()
print('Done.')
if __name__ == '__main__':
test_html()