mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
api: Fix offers path.
This commit is contained in:
@@ -38,7 +38,7 @@ from basicswap.rpc_xmr import (
|
||||
from basicswap.rpc import (
|
||||
callrpc,
|
||||
)
|
||||
from tests.basicswap.mnemonics import mnemonics
|
||||
from tests.basicswap.mnemonics import mnemonics as test_mnemonics
|
||||
from tests.basicswap.common import (
|
||||
waitForServer,
|
||||
)
|
||||
@@ -68,7 +68,7 @@ UI_PORT = 12700 + PORT_OFS
|
||||
BASE_PART_RPC_PORT = 19792
|
||||
BASE_BTC_RPC_PORT = 19796
|
||||
|
||||
NUM_NODES = 3
|
||||
NUM_NODES = int(os.getenv('NUM_NODES', 3))
|
||||
EXTRA_CONFIG_JSON = json.loads(os.getenv('EXTRA_CONFIG_JSON', '{}'))
|
||||
|
||||
|
||||
@@ -78,6 +78,14 @@ if not len(logger.handlers):
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
|
||||
def recursive_update_dict(base, new_vals):
|
||||
for key, value in new_vals.items():
|
||||
if key in base and isinstance(value, dict):
|
||||
recursive_update_dict(base[key], value)
|
||||
else:
|
||||
base[key] = value
|
||||
|
||||
|
||||
def callpartrpc(node_id, method, params=[], wallet=None, base_rpc_port=BASE_PART_RPC_PORT + PORT_OFS):
|
||||
auth = 'test_part_{0}:test_part_pwd_{0}'.format(node_id)
|
||||
return callrpc(base_rpc_port + node_id, auth, method, params, wallet)
|
||||
@@ -113,7 +121,9 @@ class Test(unittest.TestCase):
|
||||
|
||||
random.seed(time.time())
|
||||
|
||||
logging.info('Preparing %d nodes.', NUM_NODES)
|
||||
for i in range(NUM_NODES):
|
||||
logging.info('Preparing node: %d.', i)
|
||||
client_path = os.path.join(test_path, 'client{}'.format(i))
|
||||
config_path = os.path.join(client_path, cfg.CONFIG_FILENAME)
|
||||
if RESET_TEST:
|
||||
@@ -133,11 +143,12 @@ class Test(unittest.TestCase):
|
||||
'-datadir="{}"'.format(client_path),
|
||||
'-bindir="{}"'.format(os.path.join(test_path, 'bin')),
|
||||
'-portoffset={}'.format(i + PORT_OFS),
|
||||
'-particl_mnemonic="{}"'.format(mnemonics[i]),
|
||||
'-regtest',
|
||||
'-withcoins=monero,bitcoin',
|
||||
'-noextractover',
|
||||
'-xmrrestoreheight=0']
|
||||
if i < len(test_mnemonics):
|
||||
testargs.append('-particl_mnemonic="{}"'.format(test_mnemonics[i]))
|
||||
with patch.object(sys, 'argv', testargs):
|
||||
prepareSystem.main()
|
||||
|
||||
@@ -208,6 +219,9 @@ class Test(unittest.TestCase):
|
||||
settings['chainclients']['bitcoin']['rpcuser'] = 'test_btc_' + str(i)
|
||||
settings['chainclients']['bitcoin']['rpcpassword'] = 'test_btc_pwd_' + str(i)
|
||||
|
||||
extra_config = EXTRA_CONFIG_JSON.get('sc{}'.format(i), {})
|
||||
recursive_update_dict(settings, extra_config)
|
||||
|
||||
with open(config_path, 'w') as fp:
|
||||
json.dump(settings, fp, indent=4)
|
||||
|
||||
@@ -230,8 +244,8 @@ class Test(unittest.TestCase):
|
||||
self.processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
|
||||
self.processes[-1].start()
|
||||
|
||||
waitForServer(self.delay_event, UI_PORT + 0)
|
||||
waitForServer(self.delay_event, UI_PORT + 1)
|
||||
for i in range(NUM_NODES):
|
||||
waitForServer(self.delay_event, UI_PORT + i)
|
||||
|
||||
wallets = json.loads(urlopen('http://127.0.0.1:{}/json/wallets'.format(UI_PORT + 1)).read())
|
||||
|
||||
|
||||
@@ -82,6 +82,15 @@ class Test(XmrTestBase):
|
||||
assert(len(offers) == 1)
|
||||
offer0 = offers[0]
|
||||
|
||||
post_data = {
|
||||
'coin_from': '1'
|
||||
}
|
||||
test_post_offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers', data=parse.urlencode(post_data).encode()).read())
|
||||
assert(len(test_post_offers) == 2)
|
||||
post_data['coin_from'] = '2'
|
||||
test_post_offers = json.loads(urlopen('http://127.0.0.1:12701/json/offers', data=parse.urlencode(post_data).encode()).read())
|
||||
assert(len(test_post_offers) == 0)
|
||||
|
||||
bid_data = {
|
||||
'offer_id': offer0_id,
|
||||
'amount_from': offer0['amount_from']}
|
||||
|
||||
Reference in New Issue
Block a user