Script to generate reports from logs, and bug fixes:

* log_report.py is a script to generate debugging reports and combine the logs
of the locally run mainchain and sidechain servers.

* Log address book before pytest start

* Cleanup test utils

* Modify log_analyzer so joins all logs into a single file

* Organize "all" log as a dictionary

* Allow ConfigFile and Section classes to be pickled:
This caused a bug on mac platforms. Linux did not appear to use pickle.

* Add account history command to py scripts

* Add additional logging

* Add support to run sidechains under rr:

This is an undocumented feature to help debugging.
If the environment variable `RIPPLED_SIDECHAIN_RR` is set, it is assumed to
point to the rr executable. Sidechain 0 will then be run under rr.
This commit is contained in:
seelabs
2021-09-30 12:07:35 -04:00
parent d57f88fc18
commit d86b1f8b7d
11 changed files with 486 additions and 123 deletions

View File

@@ -6,45 +6,54 @@ from typing import Dict
import sys
from app import App
from common import Asset, eprint, disable_eprint, XRP
from common import Asset, eprint, disable_eprint, drops, XRP
import interactive
from sidechain import Params
import sidechain
import test_utils
import time
from transaction import Payment, Trust
import tst_common
def simple_xrp_test(mc_app: App, sc_app: App, params: Params):
alice = mc_app.account_from_alias('alice')
adam = sc_app.account_from_alias('adam')
mc_door = mc_app.account_from_alias('door')
sc_door = sc_app.account_from_alias('door')
# main to side
# First txn funds the side chain account
with test_utils.test_context(mc_app, sc_app):
to_send_asset = XRP(1000)
pre_bal = sc_app.get_balance(adam, to_send_asset)
to_send_asset = XRP(9999)
mc_pre_bal = mc_app.get_balance(mc_door, to_send_asset)
sc_pre_bal = sc_app.get_balance(adam, to_send_asset)
sidechain.main_to_side_transfer(mc_app, sc_app, alice, adam,
to_send_asset, params)
test_utils.wait_for_balance_change(sc_app, adam, pre_bal,
test_utils.wait_for_balance_change(mc_app, mc_door, mc_pre_bal,
to_send_asset)
test_utils.wait_for_balance_change(sc_app, adam, sc_pre_bal,
to_send_asset)
for i in range(2):
# even amounts for main to side
for value in range(10, 20, 2):
for value in range(20, 30, 2):
with test_utils.test_context(mc_app, sc_app):
to_send_asset = XRP(value)
pre_bal = sc_app.get_balance(adam, to_send_asset)
to_send_asset = drops(value)
mc_pre_bal = mc_app.get_balance(mc_door, to_send_asset)
sc_pre_bal = sc_app.get_balance(adam, to_send_asset)
sidechain.main_to_side_transfer(mc_app, sc_app, alice, adam,
to_send_asset, params)
test_utils.wait_for_balance_change(sc_app, adam, pre_bal,
test_utils.wait_for_balance_change(mc_app, mc_door, mc_pre_bal,
to_send_asset)
test_utils.wait_for_balance_change(sc_app, adam, sc_pre_bal,
to_send_asset)
# side to main
# odd amounts for side to main
for value in range(9, 19, 2):
for value in range(19, 29, 2):
with test_utils.test_context(mc_app, sc_app):
to_send_asset = XRP(value)
to_send_asset = drops(value)
pre_bal = mc_app.get_balance(alice, to_send_asset)
sidechain.side_to_main_transfer(mc_app, sc_app, adam, alice,
to_send_asset, params)
@@ -108,37 +117,6 @@ def simple_iou_test(mc_app: App, sc_app: App, params: Params):
rcv_asset)
def run(mc_app: App, sc_app: App, params: Params):
# 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:
# TODO: Tests fail without this sleep. Fix this bug.
time.sleep(10)
setup_accounts(mc_app, sc_app, params)
simple_xrp_test(mc_app, sc_app, params)
simple_iou_test(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):
def callback(mc_app: App, sc_app: App):
run(mc_app, sc_app, params)
sidechain._standalone_with_callback(params,
callback,
setup_user_accounts=False)
def setup_accounts(mc_app: App, sc_app: App, params: Params):
# Setup a funded user account on the main chain, and add an unfunded account.
# Setup address book and add a funded account on the mainchain.
@@ -161,31 +139,13 @@ def setup_accounts(mc_app: App, sc_app: App, params: Params):
ed = sc_app.create_account('ed')
def multinode_test(params: Params):
def callback(mc_app: App, sc_app: App):
run(mc_app, sc_app, params)
sidechain._multinode_with_callback(params,
callback,
setup_user_accounts=False)
def run_all(mc_app: App, sc_app: App, params: Params):
setup_accounts(mc_app, sc_app, params)
logging.info(f'mainchain:\n{mc_app.key_manager.to_string()}')
logging.info(f'sidechain:\n{sc_app.key_manager.to_string()}')
simple_xrp_test(mc_app, sc_app, params)
simple_iou_test(mc_app, sc_app, params)
def test_simple_xchain(configs_dirs_dict: Dict[int, str]):
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)
else:
multinode_test(params)
tst_common.test_start(configs_dirs_dict, run_all)