tests: Run more tests in ci.

This commit is contained in:
tecnovert 2024-01-28 00:07:07 +02:00
parent 53ceae718b
commit 30a5ea1652
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
7 changed files with 36 additions and 11 deletions

View file

@ -47,3 +47,4 @@ test_task:
- pytest tests/basicswap/test_other.py - pytest tests/basicswap/test_other.py
- pytest tests/basicswap/test_run.py - pytest tests/basicswap/test_run.py
- pytest tests/basicswap/test_reload.py - pytest tests/basicswap/test_reload.py
- pytest tests/basicswap/test_btc_xmr.py -k 'test_01_a or test_01_b or test_02_a or test_02_b'

View file

@ -1207,8 +1207,13 @@ class BasicSwap(BaseApp):
def sendSmsg(self, addr_from: str, addr_to: str, payload_hex: bytes, msg_valid: int) -> bytes: def sendSmsg(self, addr_from: str, addr_to: str, payload_hex: bytes, msg_valid: int) -> bytes:
options = {'decodehex': True, 'ttl_is_seconds': True} options = {'decodehex': True, 'ttl_is_seconds': True}
ro = self.callrpc('smsgsend', [addr_from, addr_to, payload_hex, False, msg_valid, False, options]) try:
return bytes.fromhex(ro['msgid']) ro = self.callrpc('smsgsend', [addr_from, addr_to, payload_hex, False, msg_valid, False, options])
return bytes.fromhex(ro['msgid'])
except Exception as e:
if self.debug:
self.log.error('smsgsend failed {}'.format(json.dumps(ro, indent=4)))
raise e
def is_reverse_ads_bid(self, coin_from) -> bool: def is_reverse_ads_bid(self, coin_from) -> bool:
return coin_from in self.scriptless_coins + self.coins_without_segwit return coin_from in self.scriptless_coins + self.coins_without_segwit
@ -1856,24 +1861,24 @@ class BasicSwap(BaseApp):
est_fee = (fee_rate * tx_vsize) / 1000 est_fee = (fee_rate * tx_vsize) / 1000
return est_fee return est_fee
def withdrawCoin(self, coin_type, value, addr_to, subfee): def withdrawCoin(self, coin_type, value, addr_to, subfee: bool) -> str:
ci = self.ci(coin_type) ci = self.ci(coin_type)
self.log.info('withdrawCoin %s %s to %s %s', value, ci.ticker(), addr_to, ' subfee' if subfee else '') self.log.info('withdrawCoin {} {} to {} {}'.format(value, ci.ticker(), addr_to, ' subfee' if subfee else ''))
txid = ci.withdrawCoin(value, addr_to, subfee) txid = ci.withdrawCoin(value, addr_to, subfee)
self.log.debug('In txn: {}'.format(txid)) self.log.debug('In txn: {}'.format(txid))
return txid return txid
def withdrawLTC(self, type_from, value, addr_to, subfee): def withdrawLTC(self, type_from, value, addr_to, subfee: bool) -> str:
ci = self.ci(Coins.LTC) ci = self.ci(Coins.LTC)
self.log.info('withdrawLTC %s %s to %s %s', value, ci.ticker(), addr_to, ' subfee' if subfee else '') self.log.info('withdrawLTC {} {} to {} {}'.format(value, type_from, addr_to, ' subfee' if subfee else ''))
txid = ci.withdrawCoin(value, type_from, addr_to, subfee) txid = ci.withdrawCoin(value, type_from, addr_to, subfee)
self.log.debug('In txn: {}'.format(txid)) self.log.debug('In txn: {}'.format(txid))
return txid return txid
def withdrawParticl(self, type_from, type_to, value, addr_to, subfee): def withdrawParticl(self, type_from: str, type_to: str, value, addr_to: str, subfee: bool) -> str:
self.log.info('withdrawParticl %s %s to %s %s %s', value, type_from, type_to, addr_to, ' subfee' if subfee else '') self.log.info('withdrawParticl {} {} to {} {} {}'.format(value, type_from, type_to, addr_to, ' subfee' if subfee else ''))
if type_from == 'plain': if type_from == 'plain':
type_from = 'part' type_from = 'part'

View file

@ -8,5 +8,5 @@ https://github.com/cirruslabs/cirrus-cli/blob/master/INSTALL.md
Run: Run:
cd basicswap cd basicswap
cirrus run cirrus run -v -o simple

View file

@ -230,6 +230,14 @@ def wait_for_none_active(delay_event, port, wait_for=30):
raise ValueError('wait_for_none_active timed out.') raise ValueError('wait_for_none_active timed out.')
def abandon_all_swaps(delay_event, swap_client) -> None:
logging.info('abandon_all_swaps')
for bid in swap_client.listBids(sent=True):
swap_client.abandonBid(bid[2])
for bid in swap_client.listBids(sent=False):
swap_client.abandonBid(bid[2])
def waitForNumOffers(delay_event, port, offers, wait_for=20): def waitForNumOffers(delay_event, port, offers, wait_for=20):
for i in range(wait_for): for i in range(wait_for):
if delay_event.is_set(): if delay_event.is_set():

View file

@ -31,6 +31,7 @@ from tests.basicswap.util import (
read_json_api, read_json_api,
) )
from tests.basicswap.common import ( from tests.basicswap.common import (
abandon_all_swaps,
wait_for_bid, wait_for_bid,
wait_for_event, wait_for_event,
wait_for_offer, wait_for_offer,
@ -1198,6 +1199,8 @@ class TestBTC(BasicSwapTest):
assert (jsw['locked'] is False) assert (jsw['locked'] is False)
def test_01_full_swap(self): def test_01_full_swap(self):
abandon_all_swaps(test_delay_event, self.swap_clients[0])
wait_for_none_active(test_delay_event, 1800)
js_0 = read_json_api(1800, 'wallets') js_0 = read_json_api(1800, 'wallets')
if not js_0['PART']['encrypted']: if not js_0['PART']['encrypted']:
read_json_api(1800, 'setpassword', {'oldpassword': '', 'newpassword': 'notapassword123'}) read_json_api(1800, 'setpassword', {'oldpassword': '', 'newpassword': 'notapassword123'})

View file

@ -660,7 +660,7 @@ class Test(BaseTest):
js_w2 = read_json_api(1802, 'wallets') js_w2 = read_json_api(1802, 'wallets')
if float(js_w2['PART']['balance']) < 100.0: if float(js_w2['PART']['balance']) < 100.0:
post_json = { post_json = {
'value': 100, 'value': 100.0,
'address': js_w2['PART']['deposit_address'], 'address': js_w2['PART']['deposit_address'],
'subfee': False, 'subfee': False,
} }
@ -678,8 +678,8 @@ class Test(BaseTest):
'subfee': True, 'subfee': True,
} }
json_rv = read_json_api(TEST_HTTP_PORT + 2, 'wallets/part/withdraw', post_json) json_rv = read_json_api(TEST_HTTP_PORT + 2, 'wallets/part/withdraw', post_json)
wait_for_balance(test_delay_event, 'http://127.0.0.1:1802/json/wallets/part', 'balance', 10.0)
assert (len(json_rv['txid']) == 64) assert (len(json_rv['txid']) == 64)
wait_for_balance(test_delay_event, 'http://127.0.0.1:1802/json/wallets/part', 'balance', 10.0)
# Create prefunded ITX # Create prefunded ITX
ci = swap_clients[2].ci(Coins.PART) ci = swap_clients[2].ci(Coins.PART)

View file

@ -336,6 +336,7 @@ class BaseTest(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
test_delay_event.clear()
random.seed(time.time()) random.seed(time.time())
logger.propagate = False logger.propagate = False
@ -618,6 +619,13 @@ class BaseTest(unittest.TestCase):
stopDaemons(cls.btc_daemons) stopDaemons(cls.btc_daemons)
stopDaemons(cls.ltc_daemons) stopDaemons(cls.ltc_daemons)
cls.http_threads.clear()
cls.swap_clients.clear()
cls.part_daemons.clear()
cls.btc_daemons.clear()
cls.ltc_daemons.clear()
cls.xmr_daemons.clear()
super(BaseTest, cls).tearDownClass() super(BaseTest, cls).tearDownClass()
@classmethod @classmethod