mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
add door and ticket test
This commit is contained in:
@@ -54,7 +54,7 @@ class Account: # pylint: disable=too-few-public-methods
|
||||
self.account_id = result_dict['account_id']
|
||||
self.public_key = result_dict['public_key']
|
||||
self.public_key_hex = result_dict['public_key_hex']
|
||||
self.secret_key = result_dict['master_key']
|
||||
self.secret_key = result_dict['master_seed']
|
||||
|
||||
# Accounts are equal if they represent the same account on the ledger
|
||||
# I.e. only check the account_id field for equality.
|
||||
|
||||
117
bin/sidechain/python/tests/door_test.py
Normal file
117
bin/sidechain/python/tests/door_test.py
Normal file
@@ -0,0 +1,117 @@
|
||||
from typing import Dict
|
||||
from app import App
|
||||
from common import XRP
|
||||
from sidechain import Params
|
||||
import sidechain
|
||||
import test_utils
|
||||
import time
|
||||
from transaction import Payment
|
||||
import tst_common
|
||||
|
||||
batch_test_num_accounts = 200
|
||||
|
||||
|
||||
def door_test(mc_app: App, sc_app: App, params: Params):
|
||||
# setup, create accounts on both chains
|
||||
for i in range(batch_test_num_accounts):
|
||||
name = "m_" + str(i)
|
||||
account_main = mc_app.create_account(name)
|
||||
name = "s_" + str(i)
|
||||
account_side = sc_app.create_account(name)
|
||||
mc_app(
|
||||
Payment(account=params.genesis_account,
|
||||
dst=account_main,
|
||||
amt=XRP(20_000)))
|
||||
mc_app.maybe_ledger_accept()
|
||||
account_main_last = mc_app.account_from_alias("m_" +
|
||||
str(batch_test_num_accounts -
|
||||
1))
|
||||
test_utils.wait_for_balance_change(mc_app, account_main_last, XRP(0),
|
||||
XRP(20_000))
|
||||
|
||||
# test
|
||||
to_side_xrp = XRP(1000)
|
||||
to_main_xrp = XRP(100)
|
||||
last_tx_xrp = XRP(343)
|
||||
with test_utils.test_context(mc_app, sc_app, True):
|
||||
# send xchain payment to open accounts on sidechain
|
||||
for i in range(batch_test_num_accounts):
|
||||
name_main = "m_" + str(i)
|
||||
account_main = mc_app.account_from_alias(name_main)
|
||||
name_side = "s_" + str(i)
|
||||
account_side = sc_app.account_from_alias(name_side)
|
||||
memos = [{
|
||||
'Memo': {
|
||||
'MemoData': account_side.account_id_str_as_hex()
|
||||
}
|
||||
}]
|
||||
mc_app(
|
||||
Payment(account=account_main,
|
||||
dst=params.mc_door_account,
|
||||
amt=to_side_xrp,
|
||||
memos=memos))
|
||||
|
||||
while 1:
|
||||
federator_info = sc_app.federator_info()
|
||||
should_loop = False
|
||||
for v in federator_info.values():
|
||||
for c in ['mainchain', 'sidechain']:
|
||||
state = v['info'][c]['listener_info']['state']
|
||||
if state != 'normal':
|
||||
should_loop = True
|
||||
if not should_loop:
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
# wait some time for the door to change
|
||||
door_closing = False
|
||||
door_reopened = False
|
||||
for i in range(batch_test_num_accounts * 2 + 40):
|
||||
server_index = [0]
|
||||
federator_info = sc_app.federator_info(server_index)
|
||||
for v in federator_info.values():
|
||||
door_status = v['info']['mainchain']['door_status']['status']
|
||||
if not door_closing:
|
||||
if door_status != 'open':
|
||||
door_closing = True
|
||||
else:
|
||||
if door_status == 'open':
|
||||
door_reopened = True
|
||||
|
||||
if not door_reopened:
|
||||
time.sleep(1)
|
||||
mc_app.maybe_ledger_accept()
|
||||
else:
|
||||
break
|
||||
|
||||
if not door_reopened:
|
||||
raise ValueError('Expected door status changes did not happen')
|
||||
|
||||
# wait for accounts created on sidechain
|
||||
for i in range(batch_test_num_accounts):
|
||||
name_side = "s_" + str(i)
|
||||
account_side = sc_app.account_from_alias(name_side)
|
||||
test_utils.wait_for_balance_change(sc_app, account_side, XRP(0),
|
||||
to_side_xrp)
|
||||
|
||||
# # try one xchain payment, each direction
|
||||
name_main = "m_" + str(0)
|
||||
account_main = mc_app.account_from_alias(name_main)
|
||||
name_side = "s_" + str(0)
|
||||
account_side = sc_app.account_from_alias(name_side)
|
||||
|
||||
pre_bal = mc_app.get_balance(account_main, XRP(0))
|
||||
sidechain.side_to_main_transfer(mc_app, sc_app, account_side,
|
||||
account_main, to_main_xrp, params)
|
||||
test_utils.wait_for_balance_change(mc_app, account_main, pre_bal,
|
||||
to_main_xrp)
|
||||
|
||||
pre_bal = sc_app.get_balance(account_side, XRP(0))
|
||||
sidechain.main_to_side_transfer(mc_app, sc_app, account_main,
|
||||
account_side, last_tx_xrp, params)
|
||||
test_utils.wait_for_balance_change(sc_app, account_side, pre_bal,
|
||||
last_tx_xrp)
|
||||
|
||||
|
||||
def test_door_operations(configs_dirs_dict: Dict[int, str]):
|
||||
tst_common.test_start(configs_dirs_dict, door_test)
|
||||
74
bin/sidechain/python/tests/tst_common.py
Normal file
74
bin/sidechain/python/tests/tst_common.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import logging
|
||||
import pprint
|
||||
import pytest
|
||||
from multiprocessing import Process, Value
|
||||
from typing import Callable, Dict
|
||||
import sys
|
||||
|
||||
from app import App
|
||||
from common import eprint, disable_eprint, XRP
|
||||
from sidechain import Params
|
||||
import sidechain
|
||||
import test_utils
|
||||
import time
|
||||
|
||||
|
||||
def run(mc_app: App, sc_app: App, params: Params,
|
||||
test_case: Callable[[App, App, Params], None]):
|
||||
# process will run while stop token is non-zero
|
||||
stop_token = Value('i', 1)
|
||||
p = None
|
||||
if mc_app.standalone:
|
||||
p = Process(target=sidechain.close_mainchain_ledgers,
|
||||
args=(stop_token, params))
|
||||
p.start()
|
||||
try:
|
||||
test_case(mc_app, sc_app, params)
|
||||
finally:
|
||||
if p:
|
||||
stop_token.value = 0
|
||||
p.join()
|
||||
sidechain._convert_log_files_to_json(
|
||||
mc_app.get_configs() + sc_app.get_configs(), 'final.json')
|
||||
|
||||
|
||||
def standalone_test(params: Params, test_case: Callable[[App, App, Params],
|
||||
None]):
|
||||
def callback(mc_app: App, sc_app: App):
|
||||
run(mc_app, sc_app, params, test_case)
|
||||
|
||||
sidechain._standalone_with_callback(params,
|
||||
callback,
|
||||
setup_user_accounts=False)
|
||||
|
||||
|
||||
def multinode_test(params: Params, test_case: Callable[[App, App, Params],
|
||||
None]):
|
||||
def callback(mc_app: App, sc_app: App):
|
||||
run(mc_app, sc_app, params, test_case)
|
||||
|
||||
sidechain._multinode_with_callback(params,
|
||||
callback,
|
||||
setup_user_accounts=False)
|
||||
|
||||
|
||||
def test_start(configs_dirs_dict: Dict[int, str],
|
||||
test_case: Callable[[App, App, Params], None]):
|
||||
params = sidechain.Params(configs_dir=configs_dirs_dict[1])
|
||||
|
||||
if err_str := params.check_error():
|
||||
eprint(err_str)
|
||||
sys.exit(1)
|
||||
|
||||
if params.verbose:
|
||||
print("eprint enabled")
|
||||
else:
|
||||
disable_eprint()
|
||||
|
||||
# Set to true to help debug tests
|
||||
test_utils.test_context_verbose_logging = True
|
||||
|
||||
if params.standalone:
|
||||
standalone_test(params, test_case)
|
||||
else:
|
||||
multinode_test(params, test_case)
|
||||
Reference in New Issue
Block a user