From 258b730c4169ade44dd327b4498f070a8e008fa4 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Sat, 9 Dec 2023 13:25:03 +0200 Subject: [PATCH] scripts: Print errors if offer/bid creation fails. --- scripts/createoffers.py | 4 +++ tests/basicswap/extended/test_scripts.py | 34 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/scripts/createoffers.py b/scripts/createoffers.py index ace0163..7fd12aa 100755 --- a/scripts/createoffers.py +++ b/scripts/createoffers.py @@ -326,6 +326,8 @@ def main(): if args.debug: print('offer data {}'.format(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'])) if 'offers' not in script_state: script_state['offers'] = {} @@ -516,6 +518,8 @@ def main(): if args.debug: print('Creating bid: {}'.format(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'])) bid_id = new_bid['bid_id'] diff --git a/tests/basicswap/extended/test_scripts.py b/tests/basicswap/extended/test_scripts.py index ff2e257..4b4ec9d 100644 --- a/tests/basicswap/extended/test_scripts.py +++ b/tests/basicswap/extended/test_scripts.py @@ -553,6 +553,40 @@ class Test(unittest.TestCase): 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): waitForServer(self.delay_event, UI_PORT + 0)