def test_sifchain_transactions_with_offline_relayer( basic_transfer_request: EthereumToSifchainTransferRequest, rowan_source_integrationtest_env_credentials: test_utilities. SifchaincliCredentials, rowan_source_integrationtest_env_transfer_request: EthereumToSifchainTransferRequest, rowan_source, smart_contracts_dir, source_ethereum_address, integration_dir, ): basic_transfer_request.ethereum_address = source_ethereum_address request, credentials = generate_test_account( basic_transfer_request, rowan_source_integrationtest_env_transfer_request, rowan_source_integrationtest_env_credentials, target_ceth_balance=10**19, target_rowan_balance=10**19, ) logging.info("shut down ebrelayer") time.sleep(10) test_utilities.get_shell_output(f"pkill -9 ebrelayer || true") logging.info("prepare transactions to be sent while ebrelayer is offline") amount = 9000 new_eth_addrs = test_utilities.create_ethereum_addresses( smart_contracts_dir, basic_transfer_request.ethereum_network, 2) request.amount = amount request.sifchain_symbol = "ceth" request.ethereum_symbol = "eth" logging.info("send transactions while ebrelayer is offline") for a in new_eth_addrs: request.ethereum_address = a["address"] sifchain_balance = test_utilities.get_sifchain_addr_balance( request.sifchain_address, request.sifnoded_node, "ceth") logging.info( f"sifchain balance is {sifchain_balance}, request is {request}") test_utilities.send_from_sifchain_to_ethereum(transfer_request=request, credentials=credentials) time.sleep(5) logging.info("restart ebrelayer") test_utilities.get_shell_output( f"{integration_dir}/sifchain_start_ebrelayer.sh") time.sleep(15) test_utilities.advance_n_ethereum_blocks(test_utilities.n_wait_blocks * 2, request.smart_contracts_dir) for a in new_eth_addrs: request.ethereum_address = a["address"] test_utilities.wait_for_eth_balance(request, amount, 600)
def transfer_sifchain_to_ethereum( transfer_request: EthereumToSifchainTransferRequest, credentials: SifchaincliCredentials, max_seconds: int = 90 ): logging.debug(f"transfer_sifchain_to_ethereum_json: {transfer_request.as_json()}") original_log_level = decrease_log_level() ethereum_starting_balance = get_eth_balance(transfer_request) sifchain_starting_balance = get_sifchain_addr_balance( transfer_request.sifchain_address, transfer_request.sifnodecli_node, transfer_request.sifchain_symbol ) status = { "action": "transfer_sifchain_to_ethereum", "ethereum_starting_balance": ethereum_starting_balance, "sifchain_starting_balance": sifchain_starting_balance, } logging.debug(status) force_log_level(original_log_level) raw_output = send_from_sifchain_to_ethereum(transfer_request, credentials) original_log_level = decrease_log_level() target_balance = ethereum_starting_balance + transfer_request.amount wait_for_eth_balance( transfer_request=transfer_request, target_balance=ethereum_starting_balance + transfer_request.amount, max_seconds=max_seconds ) sifchain_ending_balance = get_sifchain_addr_balance( transfer_request.sifchain_address, transfer_request.sifnodecli_node, transfer_request.sifchain_symbol ) result = { **status, "sifchain_ending_balance": sifchain_ending_balance, "ethereum_ending_balance": target_balance, } logging.debug(f"transfer_sifchain_to_ethereum_complete_json: {json.dumps(result)}") force_log_level(original_log_level) return result
def test_bulk_transfers_from_sifchain( basic_transfer_request: EthereumToSifchainTransferRequest, rowan_source_integrationtest_env_credentials: SifchaincliCredentials, rowan_source_integrationtest_env_transfer_request: EthereumToSifchainTransferRequest, smart_contracts_dir, source_ethereum_address, rowan_source, rowan_source_key, bridgebank_address, bridgetoken_address, ethereum_network, ): basic_transfer_request.ethereum_address = source_ethereum_address logging.info(f"transfer_request: {basic_transfer_request}") # account_with_ceth, credentials_for_account_with_ceth = generate_test_account( # base_transfer_request=basic_transfer_request, # rowan_source_integrationtest_env_transfer_request=rowan_source_integrationtest_env_transfer_request, # rowan_source_integrationtest_env_credentials=rowan_source_integrationtest_env_credentials, # target_ceth_balance=5 * 10 ** 18, # target_rowan_balance=50 * 10 ** 18 # ) n_transfers = int(test_utilities.get_optional_env_var("NTRANSFERS", 2)) amount = "{:d}".format(5 * test_utilities.highest_gas_cost) new_addresses_and_keys = list(map(lambda x: create_new_sifaddr_and_key(), range(n_transfers))) logging.info(f"aandk: {new_addresses_and_keys}") new_addresses = list(map(lambda a: a[0], new_addresses_and_keys)) logging.debug(f"new_addresses: {new_addresses}") new_eth_addrs = test_utilities.create_ethereum_addresses(smart_contracts_dir, basic_transfer_request.ethereum_network, len(new_addresses)) logging.info(f"new eth addrs: {new_eth_addrs}") request: EthereumToSifchainTransferRequest = copy.deepcopy(basic_transfer_request) requests = list(map(lambda addr: { "amount": amount, "symbol": test_utilities.NULL_ADDRESS, "sifchain_address": addr }, new_addresses)) request.amount = 5 * test_utilities.highest_gas_cost credentials_for_account_with_ceth = SifchaincliCredentials(from_key=rowan_source_key) for r in requests: request.ethereum_address = source_ethereum_address request.sifchain_address = rowan_source request.sifchain_destination_address = r["sifchain_address"] request.sifchain_symbol = "ceth" request.ethereum_symbol = "eth" logging.warning(f"requestis: {request}") test_utilities.send_from_sifchain_to_sifchain(request, credentials_for_account_with_ceth) time.sleep(3) request.sifchain_symbol = "rowan" request.ethereum_symbol = bridgetoken_address test_utilities.send_from_sifchain_to_sifchain(request, credentials_for_account_with_ceth) time.sleep(3) for a in new_addresses: test_utilities.wait_for_sif_account(a, basic_transfer_request.sifnodecli_node, 90) test_utilities.wait_for_sifchain_addr_balance(a, "ceth", amount, basic_transfer_request.sifnodecli_node, 180) test_utilities.wait_for_sifchain_addr_balance(a, "rowan", amount, basic_transfer_request.sifnodecli_node, 180) text_file = open("pfile.cmds", "w") simple_credentials = SifchaincliCredentials( keyring_passphrase=None, keyring_backend="test", from_key=None, sifnodecli_homedir=None ) logging.info(f"all accounts are on sifchain and have the correct balance") for sifaddr, ethaddr in zip(new_addresses_and_keys, new_eth_addrs): r = copy.deepcopy(basic_transfer_request) r.sifchain_address = sifaddr[0] r.ethereum_address = ethaddr["address"] r.amount = 100 simple_credentials.from_key = sifaddr[1] c = test_utilities.send_from_sifchain_to_ethereum_cmd(r, simple_credentials) text_file.write(f"{c}\n") text_file.close() test_utilities.get_shell_output("cat pfile.cmds | parallel --trim lr -v {}") test_utilities.advance_n_ethereum_blocks(test_utilities.n_wait_blocks, smart_contracts_dir) # test_utilities.get_shell_output("bash -x pfile.cmds") for sifaddr, ethaddr in zip(new_addresses_and_keys, new_eth_addrs): r = copy.deepcopy(basic_transfer_request) r.ethereum_address = ethaddr["address"] r.amount = 100 test_utilities.wait_for_eth_balance(r, 100, 6000 * (n_transfers + 1))
def test_bulk_transfers( basic_transfer_request: EthereumToSifchainTransferRequest, smart_contracts_dir, source_ethereum_address, bridgebank_address, bridgetoken_address, ethereum_network, ): n_transfers = int(test_utilities.get_optional_env_var("NTRANSFERS", 2)) ganache_delay = test_utilities.get_optional_env_var("GANACHE_DELAY", 1) # test_utilities.get_shell_output(f"{integration_dir}/ganache_start.sh {ganache_delay}") amount = "{:d}".format(5 * test_utilities.highest_gas_cost) new_addresses_and_keys = list( map(lambda x: create_new_sifaddr_and_key(), range(n_transfers))) logging.info(f"aandk: {new_addresses_and_keys}") new_addresses = list(map(lambda a: a[0], new_addresses_and_keys)) logging.debug(f"new_addresses: {new_addresses}") new_eth_addrs = test_utilities.create_ethereum_addresses( smart_contracts_dir, basic_transfer_request.ethereum_network, len(new_addresses)) logging.info(f"new eth addrs: {new_eth_addrs}") request: EthereumToSifchainTransferRequest = copy.deepcopy( basic_transfer_request) requests = list( map( lambda addr: { "amount": amount, "symbol": test_utilities.NULL_ADDRESS, "sifchain_address": addr }, new_addresses)) json_requests = json.dumps(requests) test_utilities.run_yarn_command(" ".join([ f"yarn --cwd {smart_contracts_dir}", "integrationtest:sendBulkLockTx", f"--amount {amount}", f"--symbol eth", f"--json_path {request.solidity_json_path}", f"--sifchain_address {new_addresses[0]}", f"--transactions \'{json_requests}\'", f"--ethereum_address {source_ethereum_address}", f"--bridgebank_address {bridgebank_address}", f"--ethereum_network {ethereum_network}", ])) requests = list( map( lambda addr: { "amount": amount, "symbol": bridgetoken_address, "sifchain_address": addr }, new_addresses)) json_requests = json.dumps(requests) yarn_result = test_utilities.run_yarn_command(" ".join([ f"yarn --cwd {smart_contracts_dir}", "integrationtest:sendBulkLockTx", f"--amount {amount}", "--lock_or_burn burn", f"--symbol {bridgetoken_address}", f"--json_path {request.solidity_json_path}", f"--sifchain_address {new_addresses[0]}", f"--transactions \'{json_requests}\'", f"--ethereum_address {source_ethereum_address}", f"--bridgebank_address {bridgebank_address}", f"--ethereum_network {ethereum_network}", ])) logging.info(f"bulk result: {yarn_result}") manual_advance = False if manual_advance: test_utilities.advance_n_ethereum_blocks(test_utilities.n_wait_blocks, smart_contracts_dir) test_utilities.wait_for_ethereum_block_number( yarn_result["blockNumber"] + test_utilities.n_wait_blocks, basic_transfer_request) for a in new_addresses: test_utilities.wait_for_sif_account( a, basic_transfer_request.sifnodecli_node, 90) test_utilities.wait_for_sifchain_addr_balance( a, "ceth", amount, basic_transfer_request.sifnodecli_node, 180) test_utilities.wait_for_sifchain_addr_balance( a, "rowan", amount, basic_transfer_request.sifnodecli_node, 180) text_file = open("pfile.cmds", "w") simple_credentials = SifchaincliCredentials(keyring_passphrase=None, keyring_backend="test", from_key=None, sifnodecli_homedir=None) logging.info(f"all accounts are on sifchain and have the correct balance") for sifaddr, ethaddr in zip(new_addresses_and_keys, new_eth_addrs): r = copy.deepcopy(basic_transfer_request) r.sifchain_address = sifaddr[0] r.ethereum_address = ethaddr["address"] r.amount = 100 simple_credentials.from_key = sifaddr[1] c = test_utilities.send_from_sifchain_to_ethereum_cmd( r, simple_credentials) text_file.write(f"{c}\n") text_file.close() # test_utilities.get_shell_output("cat pfile.cmds | parallel --trim lr -v {}") test_utilities.get_shell_output("bash -x pfile.cmds") for sifaddr, ethaddr in zip(new_addresses_and_keys, new_eth_addrs): r = copy.deepcopy(basic_transfer_request) r.ethereum_address = ethaddr["address"] r.amount = 100 test_utilities.wait_for_eth_balance(r, 100, 300)
def test_bulk_transfers_from_sifchain( basic_transfer_request: EthereumToSifchainTransferRequest, rowan_source_integrationtest_env_credentials: SifchaincliCredentials, rowan_source_integrationtest_env_transfer_request: EthereumToSifchainTransferRequest, smart_contracts_dir, source_ethereum_address, rowan_source, rowan_source_key, bridgebank_address, bridgetoken_address, ethereum_network, sifchain_fees_int, ): test_transfer_amount = 100 # just a tiny number of wei to move to confirm things are working tokens = test_utilities.get_required_env_var("TOKENS", "ceth,rowan").split(",") logging.info(f"tokens to be transferred are: {tokens}") logging.info("create new ethereum and sifchain addresses") basic_transfer_request.ethereum_address = source_ethereum_address n_transfers = int(test_utilities.get_optional_env_var("NTRANSFERS", 2)) n_transactions = n_transfers * len(tokens) new_addresses_and_keys = list(map(lambda x: create_new_sifaddr_and_key(), range(n_transactions))) logging.debug(f"new_addresses_and_keys: {new_addresses_and_keys}") credentials_for_account_with_ceth = SifchaincliCredentials(from_key=rowan_source_key) request: EthereumToSifchainTransferRequest = copy.deepcopy(basic_transfer_request) ceth_amount = n_transactions * (test_utilities.highest_gas_cost + 100) request.amount = ceth_amount request.ethereum_address = source_ethereum_address request.sifchain_address = rowan_source addresses_to_populate = copy.deepcopy(new_addresses_and_keys) test_transfers = [] for a in range(n_transfers): for t in tokens: request.sifchain_destination_address, from_key = addresses_to_populate.pop() # send ceth to pay for the burn request.amount = test_utilities.burn_gas_cost request.sifchain_symbol = "ceth" burn_lock_functions.transfer_sifchain_to_sifchain(request, credentials_for_account_with_ceth) # send rowan to pay the fee request.amount = sifchain_fees_int request.sifchain_symbol = "rowan" burn_lock_functions.transfer_sifchain_to_sifchain(request, credentials_for_account_with_ceth) # send the token itself request.amount = test_transfer_amount request.sifchain_symbol = t burn_lock_functions.transfer_sifchain_to_sifchain(request, credentials_for_account_with_ceth) transfer = (request.sifchain_destination_address, from_key, request.sifchain_symbol, request.amount) test_utilities.get_sifchain_addr_balance(request.sifchain_destination_address, request.sifnodecli_node, t) test_transfers.append(transfer) logging.debug(f"test_transfers is {test_transfers}") text_file = open("pfile.cmds", "w") simple_credentials = SifchaincliCredentials( keyring_passphrase=None, keyring_backend="test", from_key=None, sifnodecli_homedir=None ) logging.info(f"all accounts are on sifchain and have the correct balance") new_eth_addrs = test_utilities.create_ethereum_addresses( smart_contracts_dir, basic_transfer_request.ethereum_network, n_transactions ) logging.debug(f"new eth addrs: {new_eth_addrs}") ethereum_transfers = [] for sifaddr, from_key, sifsymbol, amount in test_transfers: destination_ethereum_address_element = new_eth_addrs.pop() r = copy.deepcopy(basic_transfer_request) r.sifchain_symbol = sifsymbol r.sifchain_address = sifaddr r.ethereum_address = destination_ethereum_address_element["address"] r.amount = amount simple_credentials.from_key = from_key c = test_utilities.send_from_sifchain_to_ethereum_cmd(r, simple_credentials) ethereum_symbol = test_utilities.sifchain_symbol_to_ethereum_symbol(sifsymbol) transfer = (r.ethereum_address, ethereum_symbol, amount) ethereum_transfers.append(transfer) text_file.write(f"{c}\n") text_file.close() test_utilities.get_shell_output("cat pfile.cmds | parallel --trim lr -v {}") whitelist = test_utilities.get_whitelisted_tokens(basic_transfer_request) test_utilities.advance_n_ethereum_blocks(test_utilities.n_wait_blocks, smart_contracts_dir) for ethereum_address, ethereum_symbol, amount in ethereum_transfers: r = copy.deepcopy(basic_transfer_request) r.ethereum_address = ethereum_address r.ethereum_symbol = test_utilities.get_token_ethereum_address( ethereum_symbol, whitelist ) r.amount = amount test_utilities.wait_for_eth_balance( transfer_request=r, target_balance=amount, max_seconds=60 * 60 * 10 )