mirror of
https://github.com/basicswap/basicswap.git
synced 2026-06-11 13:31:41 +02:00
Reformat tests with black.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2023-2024 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -18,106 +19,125 @@ from util import get_driver
|
||||
|
||||
|
||||
def test_offer(driver):
|
||||
node1_url = 'http://localhost:12701'
|
||||
node2_url = 'http://localhost:12702'
|
||||
node1_url = "http://localhost:12701"
|
||||
|
||||
driver.get(node1_url + '/newoffer')
|
||||
driver.get(node1_url + "/newoffer")
|
||||
time.sleep(1)
|
||||
|
||||
select = Select(driver.find_element(By.ID, 'coin_from'))
|
||||
select.select_by_visible_text('Bitcoin')
|
||||
select = Select(driver.find_element(By.ID, 'coin_to'))
|
||||
select.select_by_visible_text('Monero')
|
||||
select = Select(driver.find_element(By.ID, "coin_from"))
|
||||
select.select_by_visible_text("Bitcoin")
|
||||
select = Select(driver.find_element(By.ID, "coin_to"))
|
||||
select.select_by_visible_text("Monero")
|
||||
|
||||
amt_from = driver.find_element(By.NAME, 'amt_from')
|
||||
amt_to = driver.find_element(By.NAME, 'amt_to')
|
||||
rate = driver.find_element(By.ID, 'rate')
|
||||
amt_from.send_keys('1')
|
||||
amt_to.send_keys('2')
|
||||
amt_from = driver.find_element(By.NAME, "amt_from")
|
||||
amt_to = driver.find_element(By.NAME, "amt_to")
|
||||
rate = driver.find_element(By.ID, "rate")
|
||||
amt_from.send_keys("1")
|
||||
amt_to.send_keys("2")
|
||||
amt_from.click()
|
||||
time.sleep(0.5)
|
||||
rate_value = rate.get_attribute('value')
|
||||
assert (float(rate_value) == 2.0)
|
||||
rate_value = rate.get_attribute("value")
|
||||
assert float(rate_value) == 2.0
|
||||
|
||||
rate.clear()
|
||||
rate.send_keys('3')
|
||||
rate.send_keys("3")
|
||||
amt_from.click()
|
||||
time.sleep(0.5)
|
||||
amt_to_value = amt_to.get_attribute('value')
|
||||
assert (float(amt_to_value) == 3.0)
|
||||
amt_to_value = amt_to.get_attribute("value")
|
||||
assert float(amt_to_value) == 3.0
|
||||
|
||||
amt_from.clear()
|
||||
amt_from.send_keys('2')
|
||||
amt_from.send_keys("2")
|
||||
amt_to.click()
|
||||
time.sleep(0.5)
|
||||
amt_to_value = amt_to.get_attribute('value')
|
||||
assert (float(amt_to_value) == 6.0)
|
||||
amt_to_value = amt_to.get_attribute("value")
|
||||
assert float(amt_to_value) == 6.0
|
||||
|
||||
amt_from.clear()
|
||||
amt_to.clear()
|
||||
rate.clear()
|
||||
amt_to.send_keys('2')
|
||||
rate.send_keys('2')
|
||||
amt_to.send_keys("2")
|
||||
rate.send_keys("2")
|
||||
amt_to.click()
|
||||
time.sleep(0.2)
|
||||
amt_from_value = amt_from.get_attribute('value')
|
||||
assert (float(amt_from_value) == 1.0)
|
||||
amt_from_value = amt_from.get_attribute("value")
|
||||
assert float(amt_from_value) == 1.0
|
||||
|
||||
driver.find_element(By.NAME, 'continue').click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
|
||||
driver.find_element(By.NAME, "continue").click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "check_offer"))
|
||||
).click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "submit_offer"))
|
||||
).click()
|
||||
time.sleep(1)
|
||||
|
||||
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
|
||||
offer1_id = offer_link.text.split(' ')[2]
|
||||
offer1_id = offer_link.text.split(" ")[2]
|
||||
|
||||
driver.get(node1_url + '/newoffer')
|
||||
driver.get(node1_url + "/newoffer")
|
||||
time.sleep(1)
|
||||
|
||||
select = Select(driver.find_element(By.ID, 'coin_from'))
|
||||
select.select_by_visible_text('Particl')
|
||||
select = Select(driver.find_element(By.ID, 'coin_to'))
|
||||
select.select_by_visible_text('Monero')
|
||||
select = Select(driver.find_element(By.ID, "coin_from"))
|
||||
select.select_by_visible_text("Particl")
|
||||
select = Select(driver.find_element(By.ID, "coin_to"))
|
||||
select.select_by_visible_text("Monero")
|
||||
|
||||
driver.find_element(By.NAME, 'amt_from').send_keys('3')
|
||||
driver.find_element(By.NAME, 'amt_to').send_keys('4')
|
||||
driver.find_element(By.NAME, "amt_from").send_keys("3")
|
||||
driver.find_element(By.NAME, "amt_to").send_keys("4")
|
||||
|
||||
driver.find_element(By.NAME, 'continue').click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
|
||||
driver.find_element(By.NAME, "continue").click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "check_offer"))
|
||||
).click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "submit_offer"))
|
||||
).click()
|
||||
time.sleep(1)
|
||||
|
||||
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
|
||||
offer2_id = offer_link.text.split(' ')[2]
|
||||
offer2_id = offer_link.text.split(" ")[2]
|
||||
|
||||
driver.get(node1_url + '/offer/' + offer1_id)
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'repeat_offer'))).click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
|
||||
driver.get(node1_url + "/offer/" + offer1_id)
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "repeat_offer"))
|
||||
).click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "check_offer"))
|
||||
).click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "submit_offer"))
|
||||
).click()
|
||||
time.sleep(1)
|
||||
|
||||
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
|
||||
offer3_id = offer_link.text.split(' ')[2]
|
||||
offer3_id = offer_link.text.split(" ")[2]
|
||||
|
||||
offer3_json = json.loads(urlopen(node1_url + '/json/offers/' + offer3_id).read())[0]
|
||||
assert (offer3_json['coin_from'] == 'Bitcoin')
|
||||
assert (offer3_json['coin_to'] == 'Monero')
|
||||
offer3_json = json.loads(urlopen(node1_url + "/json/offers/" + offer3_id).read())[0]
|
||||
assert offer3_json["coin_from"] == "Bitcoin"
|
||||
assert offer3_json["coin_to"] == "Monero"
|
||||
|
||||
driver.get(node1_url + '/offer/' + offer2_id)
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'repeat_offer'))).click()
|
||||
driver.get(node1_url + "/offer/" + offer2_id)
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "repeat_offer"))
|
||||
).click()
|
||||
time.sleep(1) # Add time for setupCustomSelect to fire
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "check_offer"))
|
||||
).click()
|
||||
WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "submit_offer"))
|
||||
).click()
|
||||
time.sleep(1)
|
||||
|
||||
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
|
||||
offer4_id = offer_link.text.split(' ')[2]
|
||||
offer4_id = offer_link.text.split(" ")[2]
|
||||
|
||||
offer4_json = json.loads(urlopen(node1_url + '/json/offers/' + offer4_id).read())[0]
|
||||
assert (offer4_json['coin_from'] == 'Particl')
|
||||
assert (offer4_json['coin_to'] == 'Monero')
|
||||
offer4_json = json.loads(urlopen(node1_url + "/json/offers/" + offer4_id).read())[0]
|
||||
assert offer4_json["coin_from"] == "Particl"
|
||||
assert offer4_json["coin_to"] == "Monero"
|
||||
|
||||
print('Test Passed!')
|
||||
print("Test Passed!")
|
||||
|
||||
|
||||
def run_tests():
|
||||
@@ -128,5 +148,5 @@ def run_tests():
|
||||
driver.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
||||
@@ -13,196 +13,229 @@ from selenium.webdriver.support.select import Select
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
from util import (
|
||||
BSX_0_PORT, BSX_1_PORT,
|
||||
BSX_0_PORT,
|
||||
BSX_1_PORT,
|
||||
click_option,
|
||||
get_driver,
|
||||
)
|
||||
from tests.basicswap.util import read_json_api
|
||||
|
||||
|
||||
base_url = 'http://localhost'
|
||||
base_url = "http://localhost"
|
||||
|
||||
|
||||
def recover_chain_b_lock_tx(driver, offer_data, offerer_port, bidder_port):
|
||||
print('Test case: {} -> {}'.format(offer_data['coin_from'], offer_data['coin_to']))
|
||||
offerer_url = f'{base_url}:{offerer_port}'
|
||||
bidder_url = f'{base_url}:{bidder_port}'
|
||||
print("Test case: {} -> {}".format(offer_data["coin_from"], offer_data["coin_to"]))
|
||||
offerer_url = f"{base_url}:{offerer_port}"
|
||||
bidder_url = f"{base_url}:{bidder_port}"
|
||||
|
||||
rv = read_json_api(offerer_port, 'offers/new', offer_data)
|
||||
offer0_id = rv['offer_id']
|
||||
rv = read_json_api(offerer_port, "offers/new", offer_data)
|
||||
offer0_id = rv["offer_id"]
|
||||
|
||||
for i in range(10):
|
||||
rv = read_json_api(bidder_port, f'offers/{offer0_id}')
|
||||
rv = read_json_api(bidder_port, f"offers/{offer0_id}")
|
||||
if len(rv) > 0:
|
||||
break
|
||||
print('Bidder: Waiting for offer')
|
||||
print("Bidder: Waiting for offer")
|
||||
time.sleep(1)
|
||||
|
||||
bid_data = {
|
||||
'offer_id': offer0_id,
|
||||
'amount_from': 1.0}
|
||||
rv = read_json_api(bidder_port, 'bids/new', bid_data)
|
||||
bid0_id = rv['bid_id']
|
||||
bid_data = {"offer_id": offer0_id, "amount_from": 1.0}
|
||||
rv = read_json_api(bidder_port, "bids/new", bid_data)
|
||||
bid0_id = rv["bid_id"]
|
||||
|
||||
bid_state = None
|
||||
for i in range(10):
|
||||
rv = read_json_api(offerer_port, f'bids/{bid0_id}')
|
||||
if 'error' not in rv:
|
||||
bid_state = rv['bid_state']
|
||||
if bid_state == 'Received':
|
||||
rv = read_json_api(offerer_port, f"bids/{bid0_id}")
|
||||
if "error" not in rv:
|
||||
bid_state = rv["bid_state"]
|
||||
if bid_state == "Received":
|
||||
break
|
||||
print('Offerer: Waiting for bid')
|
||||
print("Offerer: Waiting for bid")
|
||||
time.sleep(2)
|
||||
assert (bid_state == 'Received')
|
||||
assert bid_state == "Received"
|
||||
|
||||
# Set BID_STOP_AFTER_COIN_B_LOCK (13) debugind
|
||||
rv = read_json_api(offerer_port, f'bids/{bid0_id}', {'debugind': 13})
|
||||
assert ('error' not in rv)
|
||||
rv = read_json_api(offerer_port, f"bids/{bid0_id}", {"debugind": 13})
|
||||
assert "error" not in rv
|
||||
|
||||
# Accept bid
|
||||
rv = read_json_api(offerer_port, f'bids/{bid0_id}', {'accept': 1})
|
||||
assert ('error' not in rv)
|
||||
rv = read_json_api(offerer_port, f"bids/{bid0_id}", {"accept": 1})
|
||||
assert "error" not in rv
|
||||
|
||||
for i in range(100):
|
||||
rv = read_json_api(bidder_port, f'bids/{bid0_id}')
|
||||
bid_state = rv['bid_state']
|
||||
if bid_state == 'Scriptless coin locked':
|
||||
rv = read_json_api(bidder_port, f"bids/{bid0_id}")
|
||||
bid_state = rv["bid_state"]
|
||||
if bid_state == "Scriptless coin locked":
|
||||
break
|
||||
print('Bidder: Waiting for state')
|
||||
print("Bidder: Waiting for state")
|
||||
time.sleep(5)
|
||||
assert (bid_state == 'Scriptless coin locked')
|
||||
assert bid_state == "Scriptless coin locked"
|
||||
|
||||
for i in range(100):
|
||||
rv = read_json_api(offerer_port, f'bids/{bid0_id}')
|
||||
bid_state = rv['bid_state']
|
||||
if bid_state == 'Stalled (debug)':
|
||||
rv = read_json_api(offerer_port, f"bids/{bid0_id}")
|
||||
bid_state = rv["bid_state"]
|
||||
if bid_state == "Stalled (debug)":
|
||||
break
|
||||
print('Offerer: Waiting for state')
|
||||
print("Offerer: Waiting for state")
|
||||
time.sleep(5)
|
||||
assert (bid_state == 'Stalled (debug)')
|
||||
assert bid_state == "Stalled (debug)"
|
||||
|
||||
# Show bid state history
|
||||
rv = read_json_api(offerer_port, f'bids/{bid0_id}/states')
|
||||
assert (len(rv) > 1)
|
||||
rv = read_json_api(offerer_port, f"bids/{bid0_id}/states")
|
||||
assert len(rv) > 1
|
||||
|
||||
url = f'{bidder_url}/bid/{bid0_id}'
|
||||
url = f"{bidder_url}/bid/{bid0_id}"
|
||||
driver.get(url)
|
||||
btn_more_info = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'show_txns')))
|
||||
btn_more_info = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "show_txns"))
|
||||
)
|
||||
btn_more_info.click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'hide_txns')))
|
||||
bidder_localkeyhalf = driver.find_element(By.ID, 'localkeyhalf').text
|
||||
print('Bidder keyhalf', bidder_localkeyhalf)
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "hide_txns")))
|
||||
bidder_localkeyhalf = driver.find_element(By.ID, "localkeyhalf").text
|
||||
print("Bidder keyhalf", bidder_localkeyhalf)
|
||||
try:
|
||||
driver.find_element(By.ID, 'remotekeyhalf')
|
||||
driver.find_element(By.ID, "remotekeyhalf")
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
raise ValueError('Nodes should not have remotekeyhalves yet.')
|
||||
raise ValueError("Nodes should not have remotekeyhalves yet.")
|
||||
|
||||
url = f'{offerer_url}/bid/{bid0_id}'
|
||||
url = f"{offerer_url}/bid/{bid0_id}"
|
||||
driver.get(url)
|
||||
btn_more_info = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'show_txns')))
|
||||
btn_more_info = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "show_txns"))
|
||||
)
|
||||
btn_more_info.click()
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'hide_txns')))
|
||||
offerer_localkeyhalf = driver.find_element(By.ID, 'localkeyhalf').text
|
||||
print('Offerer keyhalf', offerer_localkeyhalf)
|
||||
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "hide_txns")))
|
||||
offerer_localkeyhalf = driver.find_element(By.ID, "localkeyhalf").text
|
||||
print("Offerer keyhalf", offerer_localkeyhalf)
|
||||
|
||||
print('Trying with the local key in place of remote')
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
print("Trying with the local key in place of remote")
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
btn_edit.click()
|
||||
btn_submit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'edit_bid_submit')))
|
||||
kbs_other = driver.find_element(By.ID, 'kbs_other')
|
||||
btn_submit = WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid_submit"))
|
||||
)
|
||||
kbs_other = driver.find_element(By.ID, "kbs_other")
|
||||
kbs_other.send_keys(offerer_localkeyhalf)
|
||||
btn_submit.click()
|
||||
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
elements = driver.find_elements(By.CLASS_NAME, 'error_msg')
|
||||
expect_err_msg: str = 'Provided key matches local key'
|
||||
assert (any(expect_err_msg in el.text for el in elements))
|
||||
print('Found expected error: ' + expect_err_msg)
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
elements = driver.find_elements(By.CLASS_NAME, "error_msg")
|
||||
expect_err_msg: str = "Provided key matches local key"
|
||||
assert any(expect_err_msg in el.text for el in elements)
|
||||
print("Found expected error: " + expect_err_msg)
|
||||
|
||||
print('Trying with incorrect key')
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
print("Trying with incorrect key")
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
btn_edit.click()
|
||||
btn_submit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'edit_bid_submit')))
|
||||
kbs_other = driver.find_element(By.ID, 'kbs_other')
|
||||
btn_submit = WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid_submit"))
|
||||
)
|
||||
kbs_other = driver.find_element(By.ID, "kbs_other")
|
||||
last_byte = bidder_localkeyhalf[-2:]
|
||||
invalid_byte = '01' if last_byte == '00' else '00'
|
||||
invalid_byte = "01" if last_byte == "00" else "00"
|
||||
kbs_other.send_keys(bidder_localkeyhalf[:-2] + invalid_byte)
|
||||
btn_submit.click()
|
||||
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
elements = driver.find_elements(By.CLASS_NAME, 'error_msg')
|
||||
expect_err_msg: str = 'Summed key does not match expected wallet'
|
||||
assert (any(expect_err_msg in el.text for el in elements))
|
||||
print('Found expected error: ' + expect_err_msg)
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
elements = driver.find_elements(By.CLASS_NAME, "error_msg")
|
||||
expect_err_msg: str = "Summed key does not match expected wallet"
|
||||
assert any(expect_err_msg in el.text for el in elements)
|
||||
print("Found expected error: " + expect_err_msg)
|
||||
|
||||
print('Trying with correct key')
|
||||
print("Trying with correct key")
|
||||
btn_edit.click()
|
||||
btn_submit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'edit_bid_submit')))
|
||||
btn_submit = WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid_submit"))
|
||||
)
|
||||
|
||||
lock_tx_b_depth = -1
|
||||
for i in range(100):
|
||||
# Check the non-stalled node
|
||||
rv = read_json_api(bidder_port, f'bids/{bid0_id}', {'show_extra': True})
|
||||
for tx in rv['txns']:
|
||||
if tx['type'] == 'Chain B Lock' and tx['confirms'] is not None:
|
||||
lock_tx_b_depth = tx['confirms']
|
||||
rv = read_json_api(bidder_port, f"bids/{bid0_id}", {"show_extra": True})
|
||||
for tx in rv["txns"]:
|
||||
if tx["type"] == "Chain B Lock" and tx["confirms"] is not None:
|
||||
lock_tx_b_depth = tx["confirms"]
|
||||
break
|
||||
if lock_tx_b_depth >= 10:
|
||||
break
|
||||
print(f'Waiting for lock tx B depth, have {lock_tx_b_depth}')
|
||||
print(f"Waiting for lock tx B depth, have {lock_tx_b_depth}")
|
||||
time.sleep(2)
|
||||
|
||||
kbs_other = driver.find_element(By.ID, 'kbs_other')
|
||||
kbs_other = driver.find_element(By.ID, "kbs_other")
|
||||
kbs_other.send_keys(bidder_localkeyhalf)
|
||||
btn_submit.click()
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
elements = driver.find_elements(By.CLASS_NAME, 'infomsg')
|
||||
expect_msg: str = 'Bid edited'
|
||||
assert (any(expect_msg in el.text for el in elements))
|
||||
print('Found expected message: ' + expect_msg)
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
elements = driver.find_elements(By.CLASS_NAME, "infomsg")
|
||||
expect_msg: str = "Bid edited"
|
||||
assert any(expect_msg in el.text for el in elements)
|
||||
print("Found expected message: " + expect_msg)
|
||||
|
||||
print('Trying with nodes reversed (should fail as already spent)') # But should sum to the expected wallet key
|
||||
url = f'{bidder_url}/bid/{bid0_id}'
|
||||
print(
|
||||
"Trying with nodes reversed (should fail as already spent)"
|
||||
) # But should sum to the expected wallet key
|
||||
url = f"{bidder_url}/bid/{bid0_id}"
|
||||
driver.get(url)
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
btn_edit.click()
|
||||
btn_submit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'edit_bid_submit')))
|
||||
btn_submit = WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid_submit"))
|
||||
)
|
||||
|
||||
driver.get(url)
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
btn_edit.click()
|
||||
btn_submit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'edit_bid_submit')))
|
||||
btn_submit = WebDriverWait(driver, 20).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid_submit"))
|
||||
)
|
||||
|
||||
kbs_other = driver.find_element(By.ID, 'kbs_other')
|
||||
kbs_other = driver.find_element(By.ID, "kbs_other")
|
||||
kbs_other.send_keys(offerer_localkeyhalf)
|
||||
btn_submit.click()
|
||||
btn_edit = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'edit_bid')))
|
||||
btn_edit = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "edit_bid"))
|
||||
)
|
||||
# In log: "Balance is too low, checking for existing spend"
|
||||
# Should error here, but the code can't tell where the tx was sent, and treats any existing send as correct.
|
||||
elements = driver.find_elements(By.CLASS_NAME, 'infomsg')
|
||||
expect_msg: str = 'Bid edited'
|
||||
assert (any(expect_msg in el.text for el in elements))
|
||||
elements = driver.find_elements(By.CLASS_NAME, "infomsg")
|
||||
expect_msg: str = "Bid edited"
|
||||
assert any(expect_msg in el.text for el in elements)
|
||||
|
||||
|
||||
def enable_debug_ui(driver):
|
||||
for port in (BSX_0_PORT, BSX_1_PORT):
|
||||
url = f'{base_url}:{port}/settings'
|
||||
url = f"{base_url}:{port}/settings"
|
||||
driver.get(url)
|
||||
driver.find_element(By.ID, 'general-tab').click()
|
||||
driver.find_element(By.ID, "general-tab").click()
|
||||
|
||||
btn_apply_general = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, 'apply_general')))
|
||||
btn_apply_general = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.NAME, "apply_general"))
|
||||
)
|
||||
|
||||
el = driver.find_element(By.NAME, 'debugmode')
|
||||
el = driver.find_element(By.NAME, "debugmode")
|
||||
selected_option = Select(el).first_selected_option
|
||||
if selected_option.text != 'True':
|
||||
click_option(el, 'True')
|
||||
if selected_option.text != "True":
|
||||
click_option(el, "True")
|
||||
|
||||
el = driver.find_element(By.NAME, 'debugui')
|
||||
el = driver.find_element(By.NAME, "debugui")
|
||||
selected_option = Select(el).first_selected_option
|
||||
if selected_option.text != 'True':
|
||||
click_option(el, 'True')
|
||||
if selected_option.text != "True":
|
||||
click_option(el, "True")
|
||||
|
||||
btn_apply_general.click()
|
||||
|
||||
@@ -213,25 +246,27 @@ def run_tests():
|
||||
enable_debug_ui(driver)
|
||||
|
||||
offer_data = {
|
||||
'coin_from': 'BTC',
|
||||
'coin_to': 'XMR',
|
||||
'amt_from': 1.0,
|
||||
'amt_to': 2.0,
|
||||
'lockhrs': 24}
|
||||
"coin_from": "BTC",
|
||||
"coin_to": "XMR",
|
||||
"amt_from": 1.0,
|
||||
"amt_to": 2.0,
|
||||
"lockhrs": 24,
|
||||
}
|
||||
recover_chain_b_lock_tx(driver, offer_data, BSX_0_PORT, BSX_1_PORT)
|
||||
|
||||
offer_data = {
|
||||
'coin_from': 'XMR',
|
||||
'coin_to': 'BTC',
|
||||
'amt_from': 1.0,
|
||||
'amt_to': 2.0,
|
||||
'lockhrs': 24}
|
||||
"coin_from": "XMR",
|
||||
"coin_to": "BTC",
|
||||
"amt_from": 1.0,
|
||||
"amt_to": 2.0,
|
||||
"lockhrs": 24,
|
||||
}
|
||||
recover_chain_b_lock_tx(driver, offer_data, BSX_1_PORT, BSX_0_PORT)
|
||||
|
||||
print('Test Passed!')
|
||||
print("Test Passed!")
|
||||
finally:
|
||||
driver.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2022-2024 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -14,7 +15,7 @@ from selenium.webdriver.support.select import Select
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
from util import (
|
||||
BSX_0_PORT, BSX_1_PORT,
|
||||
BSX_0_PORT,
|
||||
click_option,
|
||||
get_driver,
|
||||
)
|
||||
@@ -22,118 +23,121 @@ from basicswap.ui.page_offers import default_chart_api_key
|
||||
|
||||
|
||||
def test_settings(driver):
|
||||
base_url = f'http://localhost:{BSX_0_PORT}'
|
||||
node2_url = f'http://localhost:{BSX_1_PORT}'
|
||||
base_url = f"http://localhost:{BSX_0_PORT}"
|
||||
|
||||
url = base_url + '/settings'
|
||||
url = base_url + "/settings"
|
||||
driver.get(url)
|
||||
driver.find_element(By.ID, 'general-tab').click()
|
||||
driver.find_element(By.ID, "general-tab").click()
|
||||
|
||||
wait = WebDriverWait(driver, 10)
|
||||
btn_apply_general = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_general')))
|
||||
btn_apply_general = wait.until(
|
||||
EC.element_to_be_clickable((By.NAME, "apply_general"))
|
||||
)
|
||||
|
||||
el = driver.find_element(By.NAME, 'debugmode')
|
||||
el = driver.find_element(By.NAME, "debugmode")
|
||||
selected_option = Select(el).first_selected_option
|
||||
assert (selected_option.text == 'True')
|
||||
click_option(el, 'False')
|
||||
assert selected_option.text == "True"
|
||||
click_option(el, "False")
|
||||
|
||||
el = driver.find_element(By.NAME, 'debugui')
|
||||
el = driver.find_element(By.NAME, "debugui")
|
||||
selected_option = Select(el).first_selected_option
|
||||
assert (selected_option.text == 'False')
|
||||
click_option(el, 'True')
|
||||
assert selected_option.text == "False"
|
||||
click_option(el, "True")
|
||||
|
||||
btn_apply_general.click()
|
||||
time.sleep(1)
|
||||
|
||||
settings_path_0 = '/tmp/test_persistent/client0/basicswap.json'
|
||||
settings_path_0 = "/tmp/test_persistent/client0/basicswap.json"
|
||||
with open(settings_path_0) as fs:
|
||||
settings = json.load(fs)
|
||||
|
||||
assert (settings['debug'] is False)
|
||||
assert (settings['debug_ui'] is True)
|
||||
assert settings["debug"] is False
|
||||
assert settings["debug_ui"] is True
|
||||
|
||||
el = driver.find_element(By.NAME, 'showchart')
|
||||
el = driver.find_element(By.NAME, "showchart")
|
||||
selected_option = Select(el).first_selected_option
|
||||
assert (selected_option.text == 'True')
|
||||
click_option(el, 'False')
|
||||
assert selected_option.text == "True"
|
||||
click_option(el, "False")
|
||||
|
||||
difficult_text = '`~!@#$%^&*()-_=+[{}]\\|;:\'",<>./? '
|
||||
el = driver.find_element(By.NAME, 'chartapikey')
|
||||
difficult_text = "`~!@#$%^&*()-_=+[{}]\\|;:'\",<>./? "
|
||||
el = driver.find_element(By.NAME, "chartapikey")
|
||||
el.clear()
|
||||
el.send_keys(difficult_text)
|
||||
|
||||
btn_apply_chart = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_chart')))
|
||||
btn_apply_chart = wait.until(EC.element_to_be_clickable((By.NAME, "apply_chart")))
|
||||
btn_apply_chart.click()
|
||||
time.sleep(1)
|
||||
|
||||
with open(settings_path_0) as fs:
|
||||
settings = json.load(fs)
|
||||
|
||||
assert (settings['show_chart'] is False)
|
||||
chart_api_key = bytes.fromhex(settings.get('chart_api_key_enc', '')).decode('utf-8')
|
||||
assert (chart_api_key == difficult_text)
|
||||
assert settings["show_chart"] is False
|
||||
chart_api_key = bytes.fromhex(settings.get("chart_api_key_enc", "")).decode("utf-8")
|
||||
assert chart_api_key == difficult_text
|
||||
|
||||
hex_text = default_chart_api_key
|
||||
el = driver.find_element(By.NAME, 'chartapikey')
|
||||
el = driver.find_element(By.NAME, "chartapikey")
|
||||
el.clear()
|
||||
el.send_keys(hex_text)
|
||||
btn_apply_chart = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_chart')))
|
||||
btn_apply_chart = wait.until(EC.element_to_be_clickable((By.NAME, "apply_chart")))
|
||||
btn_apply_chart.click()
|
||||
time.sleep(1)
|
||||
|
||||
el = driver.find_element(By.NAME, 'chartapikey')
|
||||
assert el.get_property('value') == hex_text
|
||||
el = driver.find_element(By.NAME, "chartapikey")
|
||||
assert el.get_property("value") == hex_text
|
||||
|
||||
with open(settings_path_0) as fs:
|
||||
settings = json.load(fs)
|
||||
|
||||
assert (settings.get('chart_api_key') == hex_text)
|
||||
assert settings.get("chart_api_key") == hex_text
|
||||
|
||||
# Reset
|
||||
btn_apply_general = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_general')))
|
||||
click_option(driver.find_element(By.NAME, 'debugmode'), 'True')
|
||||
click_option(driver.find_element(By.NAME, 'debugui'), 'False')
|
||||
btn_apply_general = wait.until(
|
||||
EC.element_to_be_clickable((By.NAME, "apply_general"))
|
||||
)
|
||||
click_option(driver.find_element(By.NAME, "debugmode"), "True")
|
||||
click_option(driver.find_element(By.NAME, "debugui"), "False")
|
||||
btn_apply_general.click()
|
||||
btn_apply_chart = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_chart')))
|
||||
click_option(driver.find_element(By.NAME, 'showchart'), 'True')
|
||||
btn_apply_chart = wait.until(EC.element_to_be_clickable((By.NAME, "apply_chart")))
|
||||
click_option(driver.find_element(By.NAME, "showchart"), "True")
|
||||
btn_apply_chart.click()
|
||||
time.sleep(1)
|
||||
|
||||
# Apply XMR settings with blank nodes list
|
||||
driver.find_element(By.ID, 'coins-tab').click()
|
||||
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_monero')))
|
||||
el = driver.find_element(By.NAME, 'remotedaemonurls_monero')
|
||||
driver.find_element(By.ID, "coins-tab").click()
|
||||
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, "apply_monero")))
|
||||
el = driver.find_element(By.NAME, "remotedaemonurls_monero")
|
||||
el.clear()
|
||||
btn_apply_monero.click()
|
||||
time.sleep(1)
|
||||
|
||||
with open(settings_path_0) as fs:
|
||||
settings = json.load(fs)
|
||||
assert (len(settings['chainclients']['monero']['remote_daemon_urls']) == 0)
|
||||
assert len(settings["chainclients"]["monero"]["remote_daemon_urls"]) == 0
|
||||
|
||||
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_monero')))
|
||||
el = driver.find_element(By.NAME, 'remotedaemonurls_monero')
|
||||
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, "apply_monero")))
|
||||
el = driver.find_element(By.NAME, "remotedaemonurls_monero")
|
||||
el.clear()
|
||||
el.send_keys('node.xmr.to:18081\nnode1.xmr.to:18082')
|
||||
el.send_keys("node.xmr.to:18081\nnode1.xmr.to:18082")
|
||||
btn_apply_monero.click()
|
||||
time.sleep(1)
|
||||
|
||||
with open(settings_path_0) as fs:
|
||||
settings = json.load(fs)
|
||||
remotedaemonurls = settings['chainclients']['monero']['remote_daemon_urls']
|
||||
assert (len(remotedaemonurls) == 2)
|
||||
remotedaemonurls = settings["chainclients"]["monero"]["remote_daemon_urls"]
|
||||
assert len(remotedaemonurls) == 2
|
||||
|
||||
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_monero')))
|
||||
el = driver.find_element(By.NAME, 'remotedaemonurls_monero')
|
||||
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, "apply_monero")))
|
||||
el = driver.find_element(By.NAME, "remotedaemonurls_monero")
|
||||
el.clear()
|
||||
btn_apply_monero.click()
|
||||
time.sleep(1)
|
||||
|
||||
with open(settings_path_0) as fs:
|
||||
settings = json.load(fs)
|
||||
assert (len(settings['chainclients']['monero']['remote_daemon_urls']) == 0)
|
||||
assert len(settings["chainclients"]["monero"]["remote_daemon_urls"]) == 0
|
||||
|
||||
print('Test Passed!')
|
||||
print("Test Passed!")
|
||||
|
||||
|
||||
def run_tests():
|
||||
@@ -144,5 +148,5 @@ def run_tests():
|
||||
driver.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2022-2023 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -17,47 +18,48 @@ from util import get_driver
|
||||
def test_swap_dir(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}'
|
||||
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']
|
||||
"addr_from": -1,
|
||||
"coin_from": "PART",
|
||||
"coin_to": "XMR",
|
||||
"amt_from": 1,
|
||||
"amt_to": 2,
|
||||
"lockhrs": 24,
|
||||
}
|
||||
read_json_api(node_1_port, "offers/new", offer_data)
|
||||
|
||||
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']
|
||||
"addr_from": -1,
|
||||
"coin_from": "PART",
|
||||
"coin_to": "BTC",
|
||||
"amt_from": 3,
|
||||
"amt_to": 4,
|
||||
"lockhrs": 24,
|
||||
}
|
||||
read_json_api(node_1_port, "offers/new", offer_data)
|
||||
|
||||
# Wait for offer to propagate
|
||||
offers_api_1 = read_json_api(node_1_port, 'offers')
|
||||
print('offers_api_1', offers_api_1)
|
||||
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')
|
||||
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)
|
||||
offers_api_2 = read_json_api(node_2_port, "offers")
|
||||
time.sleep(0.1)
|
||||
print("offers_api_2", offers_api_2)
|
||||
|
||||
driver.get(f'{node1_url}/offers')
|
||||
driver.get(f"{node1_url}/offers")
|
||||
time.sleep(1)
|
||||
|
||||
driver.get(f'{node2_url}/offers')
|
||||
driver.get(f"{node2_url}/offers")
|
||||
time.sleep(300)
|
||||
|
||||
raise ValueError('TODO')
|
||||
raise ValueError("TODO")
|
||||
|
||||
print('Test Passed!')
|
||||
print("Test Passed!")
|
||||
|
||||
|
||||
def run_tests():
|
||||
@@ -68,5 +70,5 @@ def run_tests():
|
||||
driver.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2022-2024 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -16,109 +17,113 @@ from util import get_driver
|
||||
|
||||
|
||||
def test_wallets(driver):
|
||||
base_url = 'http://localhost:12701'
|
||||
node2_url = 'http://localhost:12702'
|
||||
base_url = "http://localhost:12701"
|
||||
node2_url = "http://localhost:12702"
|
||||
|
||||
# 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)
|
||||
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'
|
||||
url = base_url + "/unknown"
|
||||
driver.get(url)
|
||||
p1 = driver.find_element(By.TAG_NAME, 'body')
|
||||
assert ('Error 404' in p1.text)
|
||||
p1 = driver.find_element(By.TAG_NAME, "body")
|
||||
assert "Error 404" in p1.text
|
||||
|
||||
url = base_url + '/static/nothing.png'
|
||||
url = base_url + "/static/nothing.png"
|
||||
driver.get(url)
|
||||
p1 = driver.find_element(By.TAG_NAME, 'body')
|
||||
assert ('Error 404' in p1.text)
|
||||
p1 = driver.find_element(By.TAG_NAME, "body")
|
||||
assert "Error 404" in p1.text
|
||||
|
||||
url = base_url + '/wallet'
|
||||
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)
|
||||
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'
|
||||
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)
|
||||
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')
|
||||
driver.get(base_url + "/wallets")
|
||||
time.sleep(1)
|
||||
driver.refresh()
|
||||
driver.find_element(By.ID, 'refresh').click()
|
||||
driver.find_element(By.ID, "refresh").click()
|
||||
time.sleep(1)
|
||||
driver.refresh()
|
||||
|
||||
print('Finding deposit address of node 2')
|
||||
driver.get(node2_url + '/wallet/PART')
|
||||
e = driver.find_element(By.ID, 'deposit_address')
|
||||
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()
|
||||
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)
|
||||
elements = driver.find_elements(By.CLASS_NAME, 'infomsg')
|
||||
assert (len(elements) == 1)
|
||||
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)
|
||||
assert "Withdrew 10 rtPART (plain to plain) to address" in e.text
|
||||
|
||||
print('Locking UTXO')
|
||||
driver.get(base_url + '/rpc')
|
||||
el = driver.find_element(By.NAME, 'coin_type')
|
||||
for option in el.find_elements(By.TAG_NAME, 'option'):
|
||||
if option.text == 'Particl':
|
||||
print("Locking UTXO")
|
||||
driver.get(base_url + "/rpc")
|
||||
el = driver.find_element(By.NAME, "coin_type")
|
||||
for option in el.find_elements(By.TAG_NAME, "option"):
|
||||
if option.text == "Particl":
|
||||
option.click()
|
||||
break
|
||||
driver.find_element(By.NAME, 'cmd').send_keys('listunspent')
|
||||
driver.find_element(By.NAME, 'apply').click()
|
||||
driver.find_element(By.NAME, "cmd").send_keys("listunspent")
|
||||
driver.find_element(By.NAME, "apply").click()
|
||||
time.sleep(1)
|
||||
|
||||
text_value = driver.find_element(By.NAME, 'result').text
|
||||
utxos = json.loads(text_value.split('\n', 1)[1])
|
||||
text_value = driver.find_element(By.NAME, "result").text
|
||||
utxos = json.loads(text_value.split("\n", 1)[1])
|
||||
|
||||
lock_utxos = [{'txid': utxos[0]['txid'], 'vout': utxos[0]['vout']}]
|
||||
driver.find_element(By.NAME, 'cmd').send_keys('lockunspent false "{}"'.format(dumpje(lock_utxos)))
|
||||
driver.find_element(By.NAME, 'apply').click()
|
||||
lock_utxos = [{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}]
|
||||
driver.find_element(By.NAME, "cmd").send_keys(
|
||||
'lockunspent false "{}"'.format(dumpje(lock_utxos))
|
||||
)
|
||||
driver.find_element(By.NAME, "apply").click()
|
||||
|
||||
print('Check for locked UTXO count')
|
||||
driver.get(base_url + '/wallet/PART')
|
||||
print("Check for locked UTXO count")
|
||||
driver.get(base_url + "/wallet/PART")
|
||||
found = False
|
||||
for i in range(5):
|
||||
try:
|
||||
el = driver.find_element(By.ID, 'locked_utxos')
|
||||
el = driver.find_element(By.ID, "locked_utxos")
|
||||
found = True
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
driver.find_element(By.ID, 'refresh').click()
|
||||
driver.find_element(By.ID, "refresh").click()
|
||||
time.sleep(2)
|
||||
found = True
|
||||
assert (found)
|
||||
assert found
|
||||
driver.refresh()
|
||||
|
||||
print('Unlocking UTXO')
|
||||
driver.get(base_url + '/rpc')
|
||||
el = driver.find_element(By.NAME, 'coin_type')
|
||||
for option in el.find_elements(By.TAG_NAME, 'option'):
|
||||
if option.text == 'Particl':
|
||||
print("Unlocking UTXO")
|
||||
driver.get(base_url + "/rpc")
|
||||
el = driver.find_element(By.NAME, "coin_type")
|
||||
for option in el.find_elements(By.TAG_NAME, "option"):
|
||||
if option.text == "Particl":
|
||||
option.click()
|
||||
break
|
||||
driver.find_element(By.NAME, 'cmd').send_keys('lockunspent true "{}"'.format(dumpje(lock_utxos)))
|
||||
driver.find_element(By.NAME, 'apply').click()
|
||||
driver.find_element(By.NAME, "cmd").send_keys(
|
||||
'lockunspent true "{}"'.format(dumpje(lock_utxos))
|
||||
)
|
||||
driver.find_element(By.NAME, "apply").click()
|
||||
|
||||
print('Test Passed!')
|
||||
print("Test Passed!")
|
||||
|
||||
|
||||
def run_tests():
|
||||
@@ -129,5 +134,5 @@ def run_tests():
|
||||
driver.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
||||
@@ -10,31 +10,34 @@ import os
|
||||
from selenium.webdriver.common.by import By
|
||||
|
||||
|
||||
BSX_0_PORT = int(os.getenv('BSX_0_PORT', 12701))
|
||||
BSX_1_PORT = int(os.getenv('BSX_1_PORT', BSX_0_PORT + 1))
|
||||
BSX_2_PORT = int(os.getenv('BSX_1_PORT', BSX_0_PORT + 2))
|
||||
BSX_0_PORT = int(os.getenv("BSX_0_PORT", 12701))
|
||||
BSX_1_PORT = int(os.getenv("BSX_1_PORT", BSX_0_PORT + 1))
|
||||
BSX_2_PORT = int(os.getenv("BSX_1_PORT", BSX_0_PORT + 2))
|
||||
|
||||
BSX_SELENIUM_DRIVER = os.getenv('BSX_SELENIUM_DRIVER', 'firefox')
|
||||
BSX_SELENIUM_DRIVER = os.getenv("BSX_SELENIUM_DRIVER", "firefox")
|
||||
|
||||
|
||||
def get_driver():
|
||||
if BSX_SELENIUM_DRIVER == 'firefox':
|
||||
if BSX_SELENIUM_DRIVER == "firefox":
|
||||
from selenium.webdriver import Firefox, FirefoxOptions
|
||||
|
||||
driver = Firefox(options=FirefoxOptions())
|
||||
elif BSX_SELENIUM_DRIVER == 'chrome':
|
||||
elif BSX_SELENIUM_DRIVER == "chrome":
|
||||
from selenium.webdriver import Chrome, ChromeOptions
|
||||
|
||||
driver = Chrome(options=ChromeOptions())
|
||||
elif BSX_SELENIUM_DRIVER == 'safari':
|
||||
elif BSX_SELENIUM_DRIVER == "safari":
|
||||
from selenium.webdriver import Safari, SafariOptions
|
||||
|
||||
driver = Safari(options=SafariOptions())
|
||||
else:
|
||||
raise ValueError('Unknown driver ' + BSX_SELENIUM_DRIVER)
|
||||
raise ValueError("Unknown driver " + BSX_SELENIUM_DRIVER)
|
||||
|
||||
return driver
|
||||
|
||||
|
||||
def click_option(el, option_text):
|
||||
for option in el.find_elements(By.TAG_NAME, 'option'):
|
||||
for option in el.find_elements(By.TAG_NAME, "option"):
|
||||
if option.text == option_text:
|
||||
option.click()
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user