mirror of
https://github.com/basicswap/basicswap.git
synced 2025-01-03 17:29:26 +00:00
tests: Test script template enabled flags.
This commit is contained in:
parent
06065958b7
commit
0a2133f43f
2 changed files with 92 additions and 9 deletions
|
@ -107,7 +107,7 @@ def readConfig(args, known_coins):
|
||||||
for i, offer_template in enumerate(offer_templates):
|
for i, offer_template in enumerate(offer_templates):
|
||||||
num_enabled += 1 if offer_template.get('enabled', True) else 0
|
num_enabled += 1 if offer_template.get('enabled', True) else 0
|
||||||
if 'name' not in offer_template:
|
if 'name' not in offer_template:
|
||||||
print('naming offer template', i)
|
print('Naming offer template', i)
|
||||||
offer_template['name'] = f'Offer {i}'
|
offer_template['name'] = f'Offer {i}'
|
||||||
num_changes += 1
|
num_changes += 1
|
||||||
if offer_template.get('min_coin_from_amt', 0) < offer_template['amount']:
|
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)
|
offer_template['coin_to'] = findCoin(offer_template['coin_to'], known_coins)
|
||||||
|
|
||||||
if offer_template['name'] in offer_templates_map:
|
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']
|
original_name = offer_template['name']
|
||||||
offset = 2
|
offset = 2
|
||||||
while f'{original_name}_{offset}' in offer_templates_map:
|
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):
|
for i, bid_template in enumerate(bid_templates):
|
||||||
num_enabled += 1 if bid_template.get('enabled', True) else 0
|
num_enabled += 1 if bid_template.get('enabled', True) else 0
|
||||||
if 'name' not in bid_template:
|
if 'name' not in bid_template:
|
||||||
print('naming bid template', i)
|
print('Naming bid template', i)
|
||||||
bid_template['name'] = f'Bid {i}'
|
bid_template['name'] = f'Bid {i}'
|
||||||
num_changes += 1
|
num_changes += 1
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ def readConfig(args, known_coins):
|
||||||
bid_template['coin_to'] = findCoin(bid_template['coin_to'], known_coins)
|
bid_template['coin_to'] = findCoin(bid_template['coin_to'], known_coins)
|
||||||
|
|
||||||
if bid_template['name'] in bid_templates_map:
|
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']
|
original_name = bid_template['name']
|
||||||
offset = 2
|
offset = 2
|
||||||
while f'{original_name}_{offset}' in bid_templates_map:
|
while f'{original_name}_{offset}' in bid_templates_map:
|
||||||
|
@ -230,8 +230,10 @@ def main():
|
||||||
sent_offers = read_json_api('sentoffers', {'active': 'active'})
|
sent_offers = read_json_api('sentoffers', {'active': 'active'})
|
||||||
|
|
||||||
if args.debug and len(offer_templates) > 0:
|
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:
|
for offer_template in offer_templates:
|
||||||
|
if offer_template.get('enabled', True) is False:
|
||||||
|
continue
|
||||||
offers_found = 0
|
offers_found = 0
|
||||||
|
|
||||||
coin_from_data = coins_map[offer_template['coin_from']]
|
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
|
script_state['delay_next_offer_before'] = int(time.time()) + time_between_offers
|
||||||
|
|
||||||
if args.debug and len(bid_templates) > 0:
|
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:
|
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)
|
delay_next_bid_before = script_state.get('delay_next_bid_before', 0)
|
||||||
if delay_next_bid_before > int(time.time()):
|
if delay_next_bid_before > int(time.time()):
|
||||||
print('Delaying bids until {}'.format(delay_next_bid_before))
|
print('Delaying bids until {}'.format(delay_next_bid_before))
|
||||||
|
@ -372,7 +375,8 @@ def main():
|
||||||
}
|
}
|
||||||
|
|
||||||
recieved_offers = read_json_api('offers', offers_options)
|
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:
|
for offer in recieved_offers:
|
||||||
offer_id = offer['offer_id']
|
offer_id = offer['offer_id']
|
||||||
|
@ -504,7 +508,7 @@ def main():
|
||||||
break # Create max one bid per iteration
|
break # Create max one bid per iteration
|
||||||
|
|
||||||
if args.debug and len(stealthex_swaps) > 0:
|
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:
|
for stealthex_swap in stealthex_swaps:
|
||||||
if stealthex_swap.get('enabled', True) is False:
|
if stealthex_swap.get('enabled', True) is False:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -202,6 +202,85 @@ class Test(unittest.TestCase):
|
||||||
logging.info('Stopping test')
|
logging.info('Stopping test')
|
||||||
cls.thread_http.stop()
|
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):
|
def test_offers(self):
|
||||||
|
|
||||||
waitForServer(self.delay_event, UI_PORT + 0)
|
waitForServer(self.delay_event, UI_PORT + 0)
|
||||||
|
|
Loading…
Reference in a new issue