Example #1
0
def test_ceth_receiver_account(
        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,
        validator_address,
        ethbridge_module_address,
        sifchain_admin_account_credentials,
):
    admin_account = test_utilities.get_required_env_var("SIFCHAIN_ADMIN_ACCOUNT")
    ceth_rescue_account, ceth_rescue_account_credentials = integration_env_credentials.create_new_sifaddr_and_credentials()
    basic_transfer_request.sifchain_address = validator_address
    admin_user_credentials = sifchain_admin_account_credentials
    test_utilities.update_ceth_receiver_account(
        receiver_account=ceth_rescue_account,
        admin_account=admin_account,
        transfer_request=basic_transfer_request,
        credentials=admin_user_credentials
    )
    test_fee_charged_to_transfer_rowan_to_erowan(
        basic_transfer_request=basic_transfer_request,
        source_ethereum_address=source_ethereum_address,
        rowan_source_integrationtest_env_credentials=rowan_source_integrationtest_env_credentials,
        rowan_source_integrationtest_env_transfer_request=rowan_source_integrationtest_env_transfer_request,
        ethereum_network=ethereum_network,
        smart_contracts_dir=smart_contracts_dir,
        bridgetoken_address=bridgetoken_address,
    )
    received_ceth_charges = test_utilities.get_sifchain_addr_balance(ceth_rescue_account,
                                                                     basic_transfer_request.sifnodecli_node, "ceth")
    assert received_ceth_charges == test_utilities.burn_gas_cost
Example #2
0
def build_request_for_new_sifchain_address(basic_transfer_request, source_ethereum_address, new_currency, amount):
    sifaddress, credentials = create_new_sifaddr_and_credentials()
    request = copy.deepcopy(basic_transfer_request)
    request.ethereum_symbol = new_currency["newtoken_address"]
    request.ethereum_address = source_ethereum_address
    request.sifchain_symbol = "c" + new_currency["newtoken_symbol"]
    request.sifchain_address = sifaddress
    request.amount = amount
    return request, credentials
Example #3
0
def test_can_create_a_new_token_and_peg_it(
    basic_transfer_request: EthereumToSifchainTransferRequest,
    smart_contracts_dir,
    bridgebank_address,
    solidity_json_path,
    operator_address,
    ethereum_network,
    source_ethereum_address,
):
    json_filename = test_utilities.get_required_env_var("TOKENS_FILE")

    with open(json_filename, mode="r") as json_file:
        contents = json_file.read()
        tokens = json.loads(contents)

    sifaddress, credentials = create_new_sifaddr_and_credentials()
    request = copy.deepcopy(basic_transfer_request)
    request.sifchain_address = sifaddress
    request.ethereum_address = source_ethereum_address
    amount_in_tokens = 10**9  # one billion of the token; note that this is not 1/(10 **18) of a token

    for t in tokens["assets"]:
        if t["symbol"] == "rowan" or t["symbol"] == 'ceth':
            continue
        logging.info(f"token is: {t}")
        try:
            decimals_int = int(t["decimals"])
            amount_in_fractions_of_a_token = amount_in_tokens * (10**
                                                                 decimals_int)
            new_currency = create_new_currency(
                amount=amount_in_fractions_of_a_token,
                symbol=t["symbol"][1:],
                token_name=t["name"],
                decimals=decimals_int,
                smart_contracts_dir=smart_contracts_dir,
                bridgebank_address=bridgebank_address,
                solidity_json_path=solidity_json_path,
                operator_address=operator_address,
                ethereum_network=ethereum_network)
            request.amount = amount_in_fractions_of_a_token
            request.ethereum_symbol = new_currency["newtoken_address"]
            request.sifchain_symbol = "c" + new_currency["newtoken_symbol"]
            burn_lock_functions.send_from_ethereum_to_sifchain(request)
        except Exception as e:
            # it might already exist, so do nothing
            logging.info(f"failed to create token {t}, error was {e}")
Example #4
0
def test_can_create_a_new_token_and_peg_it(
        basic_transfer_request: EthereumToSifchainTransferRequest,
        smart_contracts_dir,
        bridgebank_address,
        solidity_json_path,
        operator_address,
        ethereum_network,
        source_ethereum_address,
):
    json_filename = test_utilities.get_required_env_var("TOKENS_FILE")

    with open(json_filename, mode="r") as json_file:
        contents = json_file.read()
        tokens = json.loads(contents)

    sifaddress, credentials = create_new_sifaddr_and_credentials()
    request = copy.deepcopy(basic_transfer_request)
    request.sifchain_address = sifaddress
    request.ethereum_address = source_ethereum_address
    amount_in_tokens = 10 ** 9  # one billion of the token; note that this is not 1/(10 **18) of a token

    existing_whitelist = test_utilities.get_whitelisted_tokens(request)
    logging.info(f"existing whitelist: {existing_whitelist}")
    existing_tokens = set(map(lambda w: "c" + w["symbol"], existing_whitelist))
    # ceth is special since we can't just mint it or create an ERC20 contract for it
    existing_tokens.add("ceth")
    logging.info(f"requested tokens: {tokens}")
    for t in tokens["assets"]:
        if t["symbol"] in existing_tokens or t["symbol"] == "rowan":
            logging.info(f"token {t} already whitelisted, skipping")
            continue
        logging.info(f"whitelisting token {t}")
        decimals_int = int(t["decimals"])
        amount_in_fractions_of_a_token = amount_in_tokens * (10 ** decimals_int)
        create_new_currency(
            amount=amount_in_fractions_of_a_token,
            symbol=t["symbol"][1:],
            token_name=t["name"],
            decimals=decimals_int,
            smart_contracts_dir=smart_contracts_dir,
            bridgebank_address=bridgebank_address,
            solidity_json_path=solidity_json_path,
            operator_address=operator_address,
            ethereum_network=ethereum_network
        )
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)
def test_sample(basic_transfer_request):
    a, b = create_new_sifaddr_and_credentials()
    logging.info(f"xis: {a}")
    logging.info(f"xis: {b}")
    logging.info(f"basic trransfer: {basic_transfer_request}")