scripts: Print errors if offer/bid creation fails.

2024-05-20_merge
tecnovert 1 year ago
parent b409fe9f0e
commit 258b730c41
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 4
      scripts/createoffers.py
  2. 34
      tests/basicswap/extended/test_scripts.py

@ -326,6 +326,8 @@ def main():
if args.debug: if args.debug:
print('offer data {}'.format(offer_data)) print('offer data {}'.format(offer_data))
new_offer = read_json_api('offers/new', offer_data) new_offer = read_json_api('offers/new', offer_data)
if 'error' in new_offer:
raise ValueError('Server failed to create offer: {}'.format(new_offer['error']))
print('New offer: {}'.format(new_offer['offer_id'])) print('New offer: {}'.format(new_offer['offer_id']))
if 'offers' not in script_state: if 'offers' not in script_state:
script_state['offers'] = {} script_state['offers'] = {}
@ -516,6 +518,8 @@ def main():
if args.debug: if args.debug:
print('Creating bid: {}'.format(bid_data)) print('Creating bid: {}'.format(bid_data))
new_bid = read_json_api('bids/new', bid_data) new_bid = read_json_api('bids/new', bid_data)
if 'error' in new_bid:
raise ValueError('Server failed to create bid: {}'.format(new_bid['error']))
print('New bid: {} on offer {}'.format(new_bid['bid_id'], offer['offer_id'])) print('New bid: {} on offer {}'.format(new_bid['bid_id'], offer['offer_id']))
bid_id = new_bid['bid_id'] bid_id = new_bid['bid_id']

@ -553,6 +553,40 @@ class Test(unittest.TestCase):
rv_stdout = result.stdout.decode().split('\n') rv_stdout = result.stdout.decode().split('\n')
''' '''
def test_error_messages(self):
waitForServer(self.delay_event, UI_PORT + 0)
waitForServer(self.delay_event, UI_PORT + 1)
# Reset test
clear_offers(self.delay_event, 0)
delete_file(self.node0_statefile)
delete_file(self.node1_statefile)
wait_for_offers(self.delay_event, 1, 0)
node0_test1_config = {
'offers': [
{
'name': 'offer should fail',
'coin_from': 'Particl',
'coin_to': 'XMR',
'amount': 20,
'minrate': 0.05,
'ratetweakpercent': 50000000,
'amount_variable': True,
'address': -1,
'min_coin_from_amt': 20,
'max_coin_to_amt': -1
}
],
}
with open(self.node0_configfile, 'w') as fp:
json.dump(node0_test1_config, fp, indent=4)
logging.info('Test that an offer is created')
result = subprocess.run(self.node0_args, stdout=subprocess.PIPE)
rv_stdout = result.stdout.decode().split('\n')
assert (count_lines_with(rv_stdout, 'Error: Server failed to create offer: To amount above max') == 1)
def test_bid_tracking(self): def test_bid_tracking(self):
waitForServer(self.delay_event, UI_PORT + 0) waitForServer(self.delay_event, UI_PORT + 0)

Loading…
Cancel
Save