Created
January 19, 2020 07:12
-
-
Save jshen13/c51a921c882e0cf131f35016a54d38f1 to your computer and use it in GitHub Desktop.
Harmony tx_gen Testing Script for priority 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import sys | |
import logging | |
import datetime | |
from multiprocessing.pool import ThreadPool | |
import json | |
import logging | |
import harmony_transaction_generator as tx_gen | |
from harmony_transaction_generator import analysis | |
import pyhmy | |
from pyhmy import cli, json_load | |
from pyhmy.logging import ControlledLogger | |
import requests | |
import numpy as np | |
import argparse | |
verbose = True | |
acc_test = 1 | |
acc_test_sink = 1 | |
acc_test2 = 10 | |
start_stop_sleep = 20 | |
wait_sleep = 60 | |
shard_0 = [1, 0, 0] | |
shard_1 = [0, 1, 0] | |
shard_2 = [0, 0, 1] | |
fail_tests = ["test_SBS5", "test_same_CBS4", "test_CBS4", "test_CBS11", "test_CAS18", "test_SBS7"] | |
config_dic = { | |
"AMT_PER_TXN": [1e-9, 1e-3], | |
"NUM_SRC_ACC": acc_test, | |
"NUM_SNK_ACC": 1, | |
"MAX_TXN_GEN_COUNT": 1, | |
"ONLY_CROSS_SHARD": False, | |
"ENFORCE_NONCE": False, # If true, will only generate transactions with a valid nonce | |
"ESTIMATED_GAS_PER_TXN": 1e-3, | |
"INIT_SRC_ACC_BAL_PER_SHARD": 100, | |
"TXN_WAIT_TO_CONFIRM": 60, | |
"MAX_THREAD_COUNT": 8, | |
"ENDPOINTS": ["https://api.s0.pga.hmny.io/", "https://api.s1.pga.hmny.io/", "https://api.s2.pga.hmny.io/"], | |
"SRC_SHARD_WEIGHTS": [ | |
1, | |
1, | |
1 | |
], | |
"SNK_SHARD_WEIGHTS": [ | |
1, | |
1, | |
1 | |
], | |
"CHAIN_ID": "devnet", | |
"REFUND_ACCOUNT": "one12lyngnmael8s6p7cp40rj62x0pu9pgszldvxe9" | |
"" | |
} | |
tx_gen.set_config(config_dic) | |
# ======================================== A to B Tests ======================================== | |
# ================= SBS Tests ======================= | |
def test_SBS1(source_accounts, sink_accounts, fund): | |
config_dic = {"AMT_PER_TXN": [2, 3], | |
"NUM_SRC_ACC": 1, | |
"NUM_SNK_ACC": 1, | |
"MAX_TXN_GEN_COUNT": 1, | |
"ONLY_CROSS_SHARD": False, | |
"ENFORCE_NONCE": False, | |
"ESTIMATED_GAS_PER_TXN": 1e-3, | |
"INIT_SRC_ACC_BAL_PER_SHARD": 100, | |
"TXN_WAIT_TO_CONFIRM": 60, | |
"MAX_THREAD_COUNT": 8, | |
"ENDPOINTS": ["https://api.s0.pga.hmny.io/", "https://api.s1.pga.hmny.io/", | |
"https://api.s2.pga.hmny.io/"], | |
"SRC_SHARD_WEIGHTS": shard_0, | |
"SNK_SHARD_WEIGHTS": shard_0, | |
"CHAIN_ID": "devnet", | |
"REFUND_ACCOUNT": "one12lyngnmael8s6p7cp40rj62x0pu9pgszldvxe9"} | |
tx_gen.set_config(config_dic) | |
test_name = "SBS1" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_SBS3(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-18, 1e-18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
tx_gen.set_config(config_dic) | |
test_name = "SBS3" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = np.float128(source_end_bal) - source_start_bal | |
sink_change = np.float128(sink_end_bal) - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_SBS4(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-9, 1e-9] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
tx_gen.set_config(config_dic) | |
test_name = "SBS4" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_SBS5(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e18, 1e18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
tx_gen.set_config(config_dic) | |
test_name = "SBS5" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
# ============== CBS (A to B) Tests ================== | |
def test_CBS1(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [2, 3] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
config_dic["MAX_TXN_GEN_COUNT"] = 1 | |
tx_gen.set_config(config_dic) | |
test_name = "SBS1" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CBS2(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-18, 1e-18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS2" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = np.float128(source_end_bal) - source_start_bal | |
sink_change = np.float128(sink_end_bal) - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CBS3(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-9, 1e-9] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS3" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CBS4(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e18, 1e18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS4" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CBS8(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [2, 3] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS8" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CBS9(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-18, 1e-18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS9" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = np.float128(source_end_bal) - source_start_bal | |
sink_change = np.float128(sink_end_bal) - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CBS10(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-9, 1e-9] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS10" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CBS11(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e18, 1e18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS11" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
# ================== CAS Tests ========================== | |
def test_CAS15(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [2, 3] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_2 | |
tx_gen.set_config(config_dic) | |
test_name = "CAS15" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CAS16(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-18, 1e-18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_2 | |
tx_gen.set_config(config_dic) | |
test_name = "CAS16" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = np.float128(source_end_bal) - source_start_bal | |
sink_change = np.float128(sink_end_bal) - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CAS17(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-9, 1e-9] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_2 | |
tx_gen.set_config(config_dic) | |
test_name = "CAS17" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
def test_CAS18(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e18, 1e18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_1 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_2 | |
tx_gen.set_config(config_dic) | |
test_name = "CAS15" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
want_fail = False | |
print(f"\n{'=' * 15} Starting {test_name} {'=' * 15}\n") | |
source_shard = find_shard(tx_gen.get_config()["SRC_SHARD_WEIGHTS"]) # check starting balances | |
sink_shard = find_shard(tx_gen.get_config()["SNK_SHARD_WEIGHTS"]) | |
source_start_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_start_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source Start: {source_start_bal} Sink Start: {sink_start_bal}") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
source_end_bal = get_acc_balance(source_accounts[0], source_shard) | |
sink_end_bal = get_acc_balance(sink_accounts[0], sink_shard) | |
print(f"Source End: {source_end_bal} Sink End: {sink_end_bal}") | |
source_change = source_end_bal - source_start_bal | |
sink_change = sink_end_bal - sink_start_bal | |
print(f"Source Change: {source_change}, Sink Change: {sink_change}") | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
if test_name in fail_tests: | |
want_fail = True | |
report["Account Balance Changes"] = f"Source Start: {source_start_bal} \n" \ | |
f"Source End: {source_end_bal}\n" \ | |
f"Source Change: {source_change}\n" \ | |
f"Sink Start: {sink_start_bal}\n " \ | |
f"Sink End: {sink_end_bal}\n" \ | |
f"Sink Change: {sink_change}" | |
result[test_name] = report | |
tests_report[test_name] = print_log(report, test_name, want_fail, | |
check_transaction(source_change, sink_change)) | |
# ======================================== Same Account Tests ======================================== | |
def test_SBS2(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [2, 3] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
test_name = "SBS2" | |
want_fail = False | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
print(f"\n{'=' * 15} Starting Same Account Tests: {test_name} {'=' * 15}\n") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
if test_name in fail_tests: | |
want_fail = True | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
tests_report[test_name] = print_log(report, test_name, want_fail, True) | |
result[test_name] = report | |
def test_same_CBS1(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [2, 3] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
test_name = "SBS2" | |
want_fail = False | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
print(f"\n{'=' * 15} Starting Same Account Tests: {test_name} {'=' * 15}\n") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
if test_name in fail_tests: | |
want_fail = True | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
tests_report[test_name] = print_log(report, test_name, want_fail, True) | |
result[test_name] = report | |
def test_same_CBS2(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-18, 1e-18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS2" | |
want_fail = False | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
print(f"\n{'=' * 15} Starting Same Account Tests: {test_name} {'=' * 15}\n") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
if test_name in fail_tests: | |
want_fail = True | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
tests_report[test_name] = print_log(report, test_name, want_fail, True) | |
result[test_name] = report | |
def test_same_CBS3(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e-9, 1e-9] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
test_name = "CBS3" | |
want_fail = False | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
print(f"\n{'=' * 15} Starting Same Account Tests: {test_name} {'=' * 15}\n") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
if test_name in fail_tests: | |
want_fail = True | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
tests_report[test_name] = print_log(report, test_name, want_fail, True) | |
result[test_name] = report | |
def test_same_CBS4(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [1e18, 1e18] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_1 | |
tx_gen.set_config(config_dic) | |
want_fail = False | |
test_name = "CBS4" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
print(f"\n{'=' * 15} Starting Same Account Tests: {test_name} {'=' * 15}\n") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
if test_name in fail_tests: | |
want_fail = True | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
tests_report[test_name] = print_log(report, test_name, want_fail, True) | |
result[test_name] = report | |
# ======================================== SBS6,7 mult Tests ======================================== | |
def test_SBS6(source_accounts, sink_accounts, fund): | |
config_dic["AMT_PER_TXN"] = [2, 3] | |
config_dic["NUM_SRC_ACC"] = 10 | |
config_dic["NUM_SNK_ACC"] = 1 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
config_dic["MAX_TXN_GEN_COUNT"] = 10 | |
config_dic["ENFORCE_NONCE"] = True | |
tx_gen.set_config(config_dic) | |
want_fail = False | |
test_name = "SBS6" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
print(f"\n{'=' * 15} Starting Multiple Account Tests: {test_name} {'=' * 15}\n") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
if test_name in fail_tests: | |
want_fail = True | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
tests_report[test_name] = print_log(report, test_name, want_fail, True) | |
result[test_name] = report | |
def test_SBS7(source_accounts, sink_accounts, fund): | |
global start_stop_sleep | |
config_dic["AMT_PER_TXN"] = [2, 3] | |
config_dic["NUM_SRC_ACC"] = 1 | |
config_dic["NUM_SNK_ACC"] = 10 | |
config_dic["SRC_SHARD_WEIGHTS"] = shard_0 | |
config_dic["SNK_SHARD_WEIGHTS"] = shard_0 | |
config_dic["MAX_TXN_GEN_COUNT"] = 10 | |
config_dic["ENFORCE_NONCE"] = False | |
tx_gen.set_config(config_dic) | |
start_stop_sleep = 10 | |
want_fail = False | |
test_name = "SBS7" | |
if fund: | |
tx_gen.fund_accounts(source_accounts) | |
print(f"\n{'=' * 15} Starting Multiple Account Tests: {test_name} {'=' * 15}\n") | |
tx_gen_pool = ThreadPool(processes=1) | |
start_time = datetime.datetime.utcnow() # MUST be utc | |
tx_gen_pool.apply_async(lambda: tx_gen.start(source_accounts, sink_accounts)) | |
time.sleep(start_stop_sleep) | |
tx_gen.stop() | |
end_time = datetime.datetime.utcnow() # MUST be utc | |
time.sleep(wait_sleep) | |
if test_name in fail_tests: | |
want_fail = True | |
report = analysis.verify_transactions(tx_gen.Loggers.transaction.filename, start_time, end_time) | |
tests_report[test_name] = print_log(report, test_name, want_fail, True) | |
result[test_name] = report | |
# ================================ Helper Functions ================================ | |
def setup(): | |
assert hasattr(pyhmy, "__version__") | |
assert pyhmy.__version__.major == 20 | |
assert pyhmy.__version__.minor > 0 | |
env = cli.download("./bin/hmy", replace=False) | |
cli.environment.update(env) | |
cli.set_binary("./bin/hmy") | |
def log_writer(interval): | |
while True: | |
tx_gen.write_all_logs() | |
time.sleep(interval) | |
def get_acc_balance(account_name, shard): | |
""" | |
Internal get transaction by has to speed up analysis. | |
Note that this functionality will eventually be migrated to the `pyhmy` | |
""" | |
account_address = cli.get_address(account_name) | |
url = config_dic["ENDPOINTS"][shard] | |
payload = "{\"jsonrpc\": \"2.0\", \"method\": \"hmy_getBalance\", " \ | |
"\"params\": [\"" + account_address + "\", \"latest\"], \"id\": 1}" | |
headers = {'Content-Type': 'application/json'} | |
response = requests.request('POST', url, headers=headers, data=payload, allow_redirects=False, timeout=30) | |
return np.float128(int(json_load(response.content)["result"], 16)) * 1e-18 + 1e-20 | |
def find_shard(shard_list): | |
for counter, i in enumerate(shard_list): | |
if i: | |
return counter | |
def check_transaction(source_change, sink_change): | |
return abs(source_change + sink_change) < 1 and source_change < 0 and sink_change > 0 | |
def print_log(report, test_name, want_fail, transaction_passed): | |
print(f"\n{'=' * 15} {test_name} Result {'=' * 15}\n") | |
failed = report['sent-transaction-report']['failed-sent-transactions-total'] + \ | |
report['received-transaction-report']['failed-transactions-total'] | |
sent_succesful_txn = f"Sent Successful Transactions: {report['sent-transaction-report']['sent-transactions-total']}" | |
sent_failed_txn = f"Sent Failed Transactions: {report['sent-transaction-report']['failed-sent-transactions-total']}" | |
recv_succesful_txn = f"Received Successful Transactions: " \ | |
f"{report['received-transaction-report']['successful-transactions-total']}" | |
recv_failed_txn = f"Received Failed Transactions: " \ | |
f"{report['received-transaction-report']['failed-transactions-total']}" | |
print(sent_succesful_txn, sent_failed_txn, recv_succesful_txn, recv_failed_txn) | |
print(f"\n {'=' * 15} Finished {test_name} {'=' * 15}\n") | |
status = "" | |
if not failed and transaction_passed: | |
status = "PASSED" | |
elif failed and want_fail: | |
status = "PASSED" | |
elif failed and not want_fail: | |
status = "FAILED TRANSACTION" | |
elif not failed and not want_fail and not transaction_passed: | |
status = "FAILED BALANCE TRANSFER" | |
else: | |
status = "FAILED" | |
return f"{status} : {sent_succesful_txn}, {sent_failed_txn}, {recv_succesful_txn}, {recv_failed_txn}" | |
# ================================ Main ================================ | |
all_tests = { | |
"SBS1": test_SBS1, | |
"SBS2": test_SBS2, | |
"SBS3": test_SBS3, | |
"SBS4": test_SBS4, | |
"SBS5": test_SBS5, | |
"SBS6": test_SBS6, | |
"SBS7": test_SBS7, | |
"CBS1_1": test_same_CBS1, | |
"CBS2_1": test_same_CBS2, | |
"CBS3_1": test_same_CBS3, | |
"CBS4_1": test_same_CBS4, | |
"CBS1": test_CBS1, | |
"CBS2": test_CBS2, | |
"CBS3": test_CBS3, | |
"CBS4": test_CBS4, | |
"CBS8": test_CBS8, | |
"CBS9": test_CBS9, | |
"CBS10": test_CBS10, | |
"CBS11": test_CBS11, | |
"CAS15": test_CAS15, | |
"CAS16": test_CAS16, | |
"CAS17": test_CAS17, | |
"CAS18": test_CAS18, | |
} | |
if __name__ == "__main__": | |
setup() | |
tests_report = {} | |
final_report = {} | |
result = {} | |
parser = argparse.ArgumentParser(description="Put individual tests to do") | |
parser.add_argument('-test', action='store', dest="test_list", default="", help='Optional argument to test individual tests') | |
parser.add_argument('-nf', action="store_false",help="Optional argument to specify don't fund") | |
arg = parser.parse_args() | |
if verbose: | |
tx_gen.Loggers.general.logger.addHandler(logging.StreamHandler(sys.stdout)) | |
tx_gen.Loggers.balance.logger.addHandler(logging.StreamHandler(sys.stdout)) | |
tx_gen.Loggers.transaction.logger.addHandler(logging.StreamHandler(sys.stdout)) | |
tx_gen.Loggers.report.logger.addHandler(logging.StreamHandler(sys.stdout)) | |
log_writer_pool = ThreadPool(processes=1) | |
log_writer_pool.apply_async(log_writer, (5,)) | |
config = tx_gen.get_config() | |
tx_gen.load_accounts("./devnet_keys", "", fast_load=True) # <--------------- Place keys in this folder | |
# ===================== tests ===================== | |
source_accounts = tx_gen.create_accounts(acc_test, "src_acc") | |
sink_accounts = tx_gen.create_accounts(acc_test_sink, "snk_acc") | |
mult_source_accounts = None | |
mult_sink_accounts = None | |
done_sbs6 = False | |
done_sbs7 = False | |
fund = False | |
mult_fund = False | |
if arg.nf: | |
fund = True # <--------------- Comment out if accounts are funded already | |
mult_fund = True | |
if arg.test_list: | |
for test in [x.strip() for x in arg.test_list.split(",")]: | |
if test in ["SBS2", "CBS1_1", "CBS2_1", "CBS3_1", "CBS4_1"]: | |
all_tests[test](source_accounts, source_accounts, fund) | |
if fund: | |
fund = False | |
elif test == "SBS6": | |
if done_sbs7: | |
mult_sink_accounts, mult_source_accounts = mult_source_accounts, mult_sink_accounts | |
all_tests[test](mult_source_accounts, mult_sink_accounts, False) | |
else: | |
mult_source_accounts = tx_gen.create_accounts(10, "src_acc") | |
mult_sink_accounts = sink_accounts | |
all_tests[test](mult_source_accounts, mult_sink_accounts, mult_fund) | |
if mult_fund: | |
mult_fund = False | |
elif test == "SBS7": | |
if done_sbs6: | |
mult_sink_accounts, mult_source_accounts = mult_source_accounts, mult_sink_accounts | |
all_tests[test](mult_source_accounts, mult_sink_accounts, False) | |
else: | |
mult_sink_accounts = tx_gen.create_accounts(10, "src_acc") | |
mult_source_accounts = sink_accounts | |
all_tests[test](mult_source_accounts, mult_sink_accounts, mult_fund) | |
if mult_fund: | |
mult_fund = False | |
else: | |
all_tests[test](source_accounts, sink_accounts, fund) | |
if fund: | |
fund = False | |
else: | |
test_SBS1(source_accounts, sink_accounts, fund) | |
if fund: | |
fund = False | |
test_SBS3(source_accounts, sink_accounts, fund) | |
test_SBS4(source_accounts, sink_accounts, fund) | |
test_SBS5(source_accounts, sink_accounts, fund) | |
test_CBS1(source_accounts, sink_accounts, fund) | |
test_CBS2(source_accounts, sink_accounts, fund) | |
test_CBS3(source_accounts, sink_accounts, fund) | |
test_CBS4(source_accounts, sink_accounts, fund) | |
test_CBS8(source_accounts, sink_accounts, fund) | |
test_CBS9(source_accounts, sink_accounts, fund) | |
test_CBS10(source_accounts, sink_accounts, fund) | |
test_CBS11(source_accounts, sink_accounts, fund) | |
test_CAS15(source_accounts, sink_accounts, fund) | |
test_CAS16(source_accounts, sink_accounts, fund) | |
test_CAS17(source_accounts, sink_accounts, fund) | |
test_CAS18(source_accounts, sink_accounts, fund) | |
# ============== Same account tests ==================== | |
test_SBS2(source_accounts, source_accounts, fund) | |
test_same_CBS1(source_accounts, source_accounts, fund) | |
test_same_CBS2(source_accounts, source_accounts, fund) | |
test_same_CBS3(source_accounts, source_accounts, fund) | |
test_same_CBS4(source_accounts, source_accounts, fund) | |
# ============== Multiple accounts tests ==================== | |
source_accounts = tx_gen.create_accounts(10, "src_acc") | |
test_SBS6(source_accounts, sink_accounts, mult_fund) | |
if mult_fund: | |
mult_fund = False | |
source_accounts, sink_accounts = sink_accounts, source_accounts # switch accounts for next test (SBS7) | |
test_SBS7(source_accounts, sink_accounts, mult_fund) | |
print(f"\n{'=' * 25} Test Results {'=' * 25}\n") | |
print(json.dumps(tests_report, indent=4)) | |
print(f"\n{'=' * 25} Tests Finished {'=' * 25}\n") | |
final_report = ControlledLogger(f"final_report_{datetime.datetime.utcnow()}", "./logs/final_report") | |
final_report.info(json.dumps(result, indent=4)) | |
final_report.write() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment