Esempio n. 1
0
def test_eth_to_ceth_and_back_to_eth(
    basic_transfer_request: EthereumToSifchainTransferRequest,
    source_ethereum_address: str,
    rowan_source_integrationtest_env_credentials: SifchaincliCredentials,
    rowan_source_integrationtest_env_transfer_request:
    EthereumToSifchainTransferRequest,
    ethereum_network,
    smart_contracts_dir,
    rowan_amount,
    ceth_amount,
    bridgetoken_address,
):
    # logging.info("shark")
    # x = 4.9908339925e+18
    # s = "{:d}".format(int(x))
    # logging.info(f"xiss: {s}")
    # logging.info(f"xiss: {x}")
    # assert False
    basic_transfer_request.ethereum_address = source_ethereum_address
    basic_transfer_request.check_wait_blocks = True
    logging.info(f"rq: {basic_transfer_request}")
    request, credentials = generate_test_account(
        basic_transfer_request,
        rowan_source_integrationtest_env_transfer_request,
        rowan_source_integrationtest_env_credentials,
        target_ceth_balance=ceth_amount,
        target_rowan_balance=rowan_amount)
    # send some test account ceth back to a new ethereum address
    request.ethereum_address, _ = test_utilities.create_ethereum_address(
        smart_contracts_dir, ethereum_network)
    logging.info(f"get balance of test account")
    test_utilities.get_sifchain_addr_balance(
        request.sifchain_address,
        sifnodecli_node=request.sifnodecli_node,
        denom="ceth")
    logging.info(
        "send erowan back to ethereum chain, saving 100k for ceth transfer fees"
    )
    request.sifchain_symbol = "rowan"
    request.ethereum_symbol = bridgetoken_address
    request.amount = rowan_amount - 200000
    burn_lock_functions.transfer_sifchain_to_ethereum(request, credentials)
    test_utilities.get_eth_balance(request)

    logging.info("send eth back to ethereum chain")
    logging.info("get ceth balance to decide how much to return")
    request.sifchain_symbol = "ceth"
    request.ethereum_symbol = "eth"
    ceth_balance = test_utilities.get_sifchain_addr_balance(
        request.sifchain_address,
        sifnodecli_node=request.sifnodecli_node,
        denom="ceth")
    request.amount = ceth_balance - request.ceth_amount
    burn_lock_functions.transfer_sifchain_to_ethereum(request, credentials)
    logging.info("get final eth balance")
    test_utilities.get_eth_balance(request)
    test_utilities.get_sifchain_addr_balance(
        request.sifchain_address,
        sifnodecli_node=request.sifnodecli_node,
        denom="ceth")
Esempio n. 2
0
def test_eth_to_ceth_and_back_to_eth(
    basic_transfer_request: EthereumToSifchainTransferRequest,
    source_ethereum_address: str,
    rowan_source_integrationtest_env_credentials: SifchaincliCredentials,
    rowan_source_integrationtest_env_transfer_request:
    EthereumToSifchainTransferRequest,
    ethereum_network,
    smart_contracts_dir,
    bridgetoken_address,
    sifchain_fees_int,
):
    basic_transfer_request.ethereum_address = source_ethereum_address
    basic_transfer_request.check_wait_blocks = True
    small_amount = 100

    logging.info(
        "the test account needs enough rowan and ceth for one burn and one lock, make sure it has that"
    )
    request, credentials = generate_test_account(
        basic_transfer_request,
        rowan_source_integrationtest_env_transfer_request,
        rowan_source_integrationtest_env_credentials,
        target_ceth_balance=test_utilities.burn_gas_cost +
        test_utilities.lock_gas_cost + small_amount,
        target_rowan_balance=sifchain_fees_int * 2 + small_amount)
    # send some test account ceth back to a new ethereum address
    request.ethereum_address, _ = test_utilities.create_ethereum_address(
        smart_contracts_dir, ethereum_network)
    request.sifchain_symbol = "rowan"
    request.ethereum_symbol = bridgetoken_address
    request.amount = small_amount
    burn_lock_functions.transfer_sifchain_to_ethereum(request, credentials)
    test_utilities.get_eth_balance(request)

    logging.info("send eth back to ethereum chain")
    request.sifchain_symbol = "ceth"
    request.ethereum_symbol = "eth"
    request.amount = small_amount
    burn_lock_functions.transfer_sifchain_to_ethereum(request, credentials)
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
Esempio n. 4
0
def test_transfer_rowan_to_erowan_and_back(
    ropsten_wait_time,
    rowan_source,
    sifnodecli_node,
    source_ethereum_address,
    chain_id,
    smart_contracts_dir,
    basic_transfer_request: EthereumToSifchainTransferRequest,
    ceth_fee,
    bridgetoken_address,
):
    rq: EthereumToSifchainTransferRequest = deepcopy(basic_transfer_request)
    rq.ethereum_address = "0xa584E4Fd44425937649A52846bF95A783564fCda"
    rq.ethereum_symbol = bridgetoken_address
    bx = test_utilities.get_eth_balance(rq)
    logging.info(f"bx is {bx}")
    raise Exception("stop test")
    logging.info(
        f"transfer rowan from {rowan_source} to a newly created account")
    sifaddr, credentials = create_new_sifaddr_and_credentials()
    rowan_transfer_from_source = deepcopy(basic_transfer_request)
    rowan_transfer_from_source.sifchain_address = rowan_source
    rowan_transfer_from_source.sifchain_destination_address = sifaddr
    amt = 20000000
    rowan_transfer_from_source.amount = amt
    rowan_transfer_from_source.sifchain_symbol = "rowan"
    test_utilities.send_from_sifchain_to_sifchain(rowan_transfer_from_source,
                                                  credentials)

    logging.info(f"add ceth to new sif account to pay lock fees")

    eth_transfer: EthereumToSifchainTransferRequest = deepcopy(
        basic_transfer_request)
    eth_transfer.ethereum_address = source_ethereum_address
    eth_transfer.sifchain_address = sifaddr
    eth_transfer.amount = ceth_fee * 2

    logging.info("get balances just to have those commands in the history")
    try:
        test_utilities.get_sifchain_addr_balance(
            sifaddr, basic_transfer_request.sifnodecli_node, "ceth")
    except Exception as e:
        logging.info(f"got exception while checking balance: {e}")
    test_utilities.get_eth_balance(eth_transfer)

    logging.info("execute transfer of eth => ceth to enable fee payment")
    burn_lock_functions.transfer_ethereum_to_sifchain(eth_transfer,
                                                      ropsten_wait_time)

    ethereum_address, _ = test_utilities.create_ethereum_address(
        smart_contracts_dir, ethereum_network)
    logging.info(
        f"lock rowan from {rowan_transfer_from_source.sifchain_destination_address} to {ethereum_address}"
    )

    rowan_lock: EthereumToSifchainTransferRequest = deepcopy(
        rowan_transfer_from_source)
    rowan_lock.sifchain_address = sifaddr
    rowan_lock.ethereum_address = ethereum_address
    burn_lock_functions.transfer_sifchain_to_ethereum(rowan_lock, credentials,
                                                      ropsten_wait_time)

    logging.info(
        f"send erowan back to {sifaddr} from ethereum {ethereum_address}")
    return_request = deepcopy(rowan_lock)
    return_request.amount = amt / 2
    burn_lock_functions.transfer_sifchain_to_ethereum(return_request,
                                                      credentials,
                                                      ropsten_wait_time)