diff --git a/scripts/createoffers.py b/scripts/createoffers.py index 9db1fea..07236c7 100755 --- a/scripts/createoffers.py +++ b/scripts/createoffers.py @@ -107,7 +107,7 @@ def readConfig(args, known_coins): for i, offer_template in enumerate(offer_templates): num_enabled += 1 if offer_template.get('enabled', True) else 0 if 'name' not in offer_template: - print('naming offer template', i) + print('Naming offer template', i) offer_template['name'] = f'Offer {i}' num_changes += 1 if offer_template.get('min_coin_from_amt', 0) < offer_template['amount']: @@ -121,7 +121,7 @@ def readConfig(args, known_coins): offer_template['coin_to'] = findCoin(offer_template['coin_to'], known_coins) if offer_template['name'] in offer_templates_map: - print('renaming offer template', offer_template['name']) + print('Renaming offer template', offer_template['name']) original_name = offer_template['name'] offset = 2 while f'{original_name}_{offset}' in offer_templates_map: @@ -137,7 +137,7 @@ def readConfig(args, known_coins): for i, bid_template in enumerate(bid_templates): num_enabled += 1 if bid_template.get('enabled', True) else 0 if 'name' not in bid_template: - print('naming bid template', i) + print('Naming bid template', i) bid_template['name'] = f'Bid {i}' num_changes += 1 @@ -152,7 +152,7 @@ def readConfig(args, known_coins): bid_template['coin_to'] = findCoin(bid_template['coin_to'], known_coins) if bid_template['name'] in bid_templates_map: - print('renaming bid template', bid_template['name']) + print('Renaming bid template', bid_template['name']) original_name = bid_template['name'] offset = 2 while f'{original_name}_{offset}' in bid_templates_map: @@ -230,8 +230,10 @@ def main(): sent_offers = read_json_api('sentoffers', {'active': 'active'}) if args.debug and len(offer_templates) > 0: - print('Processing {} offer templates'.format(config['num_enabled_offers'])) + print('Processing {} offer template{}'.format(config['num_enabled_offers'], 's' if config['num_enabled_offers'] != 1 else '')) for offer_template in offer_templates: + if offer_template.get('enabled', True) is False: + continue offers_found = 0 coin_from_data = coins_map[offer_template['coin_from']] @@ -317,9 +319,10 @@ def main(): script_state['delay_next_offer_before'] = int(time.time()) + time_between_offers if args.debug and len(bid_templates) > 0: - print('Processing {} bid templates'.format(config['num_enabled_bids'])) + print('Processing {} bid template{}'.format(config['num_enabled_bids'], 's' if config['num_enabled_bids'] != 1 else '')) for bid_template in bid_templates: - + if bid_template.get('enabled', True) is False: + continue delay_next_bid_before = script_state.get('delay_next_bid_before', 0) if delay_next_bid_before > int(time.time()): print('Delaying bids until {}'.format(delay_next_bid_before)) @@ -372,7 +375,8 @@ def main(): } recieved_offers = read_json_api('offers', offers_options) - print('recieved_offers', recieved_offers) + if args.debug: + print('Recieved Offers', recieved_offers) for offer in recieved_offers: offer_id = offer['offer_id'] @@ -504,7 +508,7 @@ def main(): break # Create max one bid per iteration if args.debug and len(stealthex_swaps) > 0: - print('Processing {} stealthex templates'.format(config['num_enabled_swaps'])) + print('Processing {} stealthex template{}'.format(config['num_enabled_swaps'], 's' if config['num_enabled_swaps'] != 1 else '')) for stealthex_swap in stealthex_swaps: if stealthex_swap.get('enabled', True) is False: continue diff --git a/tests/basicswap/extended/test_scripts.py b/tests/basicswap/extended/test_scripts.py index c0b06ff..ff2e257 100644 --- a/tests/basicswap/extended/test_scripts.py +++ b/tests/basicswap/extended/test_scripts.py @@ -202,6 +202,85 @@ class Test(unittest.TestCase): logging.info('Stopping test') cls.thread_http.stop() + def test_enabled(self): + + waitForServer(self.delay_event, UI_PORT + 0) + waitForServer(self.delay_event, UI_PORT + 1) + + # Test no 'Processing...' messages are shown without config + node0_test_config = {} + with open(self.node0_configfile, 'w') as fp: + json.dump(node0_test_config, fp, indent=4) + result = subprocess.run(self.node0_args, stdout=subprocess.PIPE) + rv_stdout = result.stdout.decode().split('\n') + assert (count_lines_with(rv_stdout, 'Processing') == 0) + + # Test that enabled templates are processed + node0_test_config = { + 'test_mode': True, + 'offers': [ + { + 'name': 'offer example 1', + 'coin_from': 'Particl', + 'coin_to': 'Monero', + 'amount': 20, + 'minrate': 0.05, + 'ratetweakpercent': 5, + 'amount_variable': True, + 'address': -1, + 'min_coin_from_amt': 20, + 'max_coin_to_amt': -1 + }, + ], + 'bids': [ + { + 'coin_from': 'PART', + 'coin_to': 'XMR', + 'amount': 10, + 'maxrate': 0.04, + 'amount_variable': True, + 'address': -1, + 'min_swap_amount': 0.1, + 'max_coin_from_balance': -1, + 'min_coin_to_balance': -1, + }, + ], + 'stealthex': [ + { + 'coin_from': 'XMR', + 'coin_to': 'BTC', + 'min_balance_from': 1, + 'min_amount_tx': 1, + 'max_amount_tx': 5, + 'min_rate': 0.01, + 'refund_address': 'auto', + 'receive_address': 'auto', + 'api_key': 'API_KEY_HERE' + } + ], + } + with open(self.node0_configfile, 'w') as fp: + json.dump(node0_test_config, fp, indent=4) + + result = subprocess.run(self.node0_args, stdout=subprocess.PIPE) + rv_stdout = result.stdout.decode().split('\n') + assert (count_lines_with(rv_stdout, 'Processing 1 offer template') == 1) + assert (count_lines_with(rv_stdout, 'Processing 1 bid template') == 1) + assert (count_lines_with(rv_stdout, 'Processing 1 stealthex template') == 1) + + # Test that disabled templates are not processed + node0_test_config['offers'][0]['enabled'] = False + node0_test_config['bids'][0]['enabled'] = False + node0_test_config['stealthex'][0]['enabled'] = False + with open(self.node0_configfile, 'w') as fp: + json.dump(node0_test_config, fp, indent=4) + + result = subprocess.run(self.node0_args, stdout=subprocess.PIPE) + rv_stdout = result.stdout.decode().split('\n') + assert (count_lines_with(rv_stdout, 'Processing 0 offer templates') == 1) + assert (count_lines_with(rv_stdout, 'Processing 0 bid templates') == 1) + assert (count_lines_with(rv_stdout, 'Processing 0 stealthex templates') == 1) + def test_offers(self): waitForServer(self.delay_event, UI_PORT + 0)