Esempio n. 1
0
def generate_minimal_test_account(
    base_transfer_request: EthereumToSifchainTransferRequest,
    target_ceth_balance: int = 10**18,
) -> (EthereumToSifchainTransferRequest, SifchaincliCredentials):
    """Creates a test account with ceth and rowan.  The address for the new account is in request.sifchain_address"""
    new_account_key = get_shell_output("uuidgen")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials,
                                                      keyname=new_account_key)
    new_sifaddr = new_addr["address"]
    credentials.from_key = new_addr["name"]

    request: EthereumToSifchainTransferRequest = copy.deepcopy(
        base_transfer_request)
    request.sifchain_address = new_sifaddr
    request.amount = target_ceth_balance
    request.sifchain_symbol = "ceth"
    request.ethereum_symbol = "eth"
    logging.debug(
        f"transfer {target_ceth_balance} eth to {new_sifaddr} from {base_transfer_request.ethereum_address}"
    )
    burn_lock_functions.transfer_ethereum_to_sifchain(request)
    logging.info(
        f"created sifchain addr {new_sifaddr} with {test_utilities.display_currency_value(target_ceth_balance)} ceth"
    )
    return request, credentials
Esempio n. 2
0
def create_new_sifaddr_and_credentials(
) -> (str, SifchaincliCredentials):
    new_account_key = get_shell_output("uuidgen")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials, keyname=new_account_key)
    credentials.from_key = new_addr["name"]
    return new_addr["address"], credentials,
Esempio n. 3
0
def create_new_sifaddr_and_key():
    new_account_key = test_utilities.get_shell_output("uuidgen").replace(
        "-", "")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials,
                                                      keyname=new_account_key)
    return new_addr["address"], new_addr["name"]
Esempio n. 4
0
def generate_test_account(
    base_transfer_request: EthereumToSifchainTransferRequest,
    rowan_source_integrationtest_env_transfer_request:
    EthereumToSifchainTransferRequest,
    rowan_source_integrationtest_env_credentials: SifchaincliCredentials,
    target_ceth_balance: int = 10**18,
    target_rowan_balance: int = 10**18
) -> (EthereumToSifchainTransferRequest, SifchaincliCredentials):
    """Creates a test account with ceth and rowan"""
    new_account_key = get_shell_output("uuidgen")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials,
                                                      keyname=new_account_key)
    new_sifaddr = new_addr["address"]
    credentials.from_key = new_addr["name"]

    initial_rowan = test_utilities.get_sifchain_addr_balance(
        rowan_source_integrationtest_env_transfer_request.sifchain_address,
        rowan_source_integrationtest_env_transfer_request.sifnodecli_node,
        "rowan")

    if target_rowan_balance > 0:
        rowan_request: EthereumToSifchainTransferRequest = copy.deepcopy(
            rowan_source_integrationtest_env_transfer_request)
        rowan_request.sifchain_destination_address = new_sifaddr
        rowan_request.amount = target_rowan_balance
        logging.debug(
            f"transfer {target_rowan_balance} to {new_sifaddr} from {rowan_request.sifchain_address}"
        )
        test_utilities.send_from_sifchain_to_sifchain(
            rowan_request, rowan_source_integrationtest_env_credentials)

    request: EthereumToSifchainTransferRequest = copy.deepcopy(
        base_transfer_request)
    request.sifchain_address = new_sifaddr
    request.amount = target_ceth_balance
    request.sifchain_symbol = "ceth"
    request.ethereum_symbol = "eth"
    logging.debug(
        f"transfer {target_ceth_balance} eth to {new_sifaddr} from {base_transfer_request.ethereum_address}"
    )
    burn_lock_functions.transfer_ethereum_to_sifchain(request)

    ending_rowan = test_utilities.get_sifchain_addr_balance(
        rowan_source_integrationtest_env_transfer_request.sifchain_address,
        rowan_source_integrationtest_env_transfer_request.sifnodecli_node,
        "rowan")

    rowan_used = initial_rowan - ending_rowan
    rowan_fees = rowan_used - target_rowan_balance
    # logging.info(f"rowan fees from source is {rowan_fees}")
    logging.info(
        f"created sifchain addr {new_sifaddr} with {test_utilities.display_currency_value(target_ceth_balance)} ceth and {test_utilities.display_currency_value(target_rowan_balance)} rowan"
    )
    return request, credentials
Esempio n. 5
0
def build_request() -> (EthereumToSifchainTransferRequest, SifchaincliCredentials):
    new_account_key = 'user1'
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials, keyname=new_account_key)
    credentials.from_key = new_addr["name"]
    request = EthereumToSifchainTransferRequest(
        sifchain_address=new_addr["address"],
        smart_contracts_dir=smart_contracts_dir,
        ethereum_address=ethereum_address,
        ethereum_private_key_env_var="ETHEREUM_PRIVATE_KEY",
        bridgebank_address=get_required_env_var("BRIDGE_BANK_ADDRESS"),
        ethereum_network=(os.environ.get("ETHEREUM_NETWORK") or ""),
        amount=9 * 10 ** 18,
        ceth_amount=2 * (10 ** 16)
    )
    return request, credentials
Esempio n. 6
0
def build_request(new_currency, amount):
    accounts = ganache_accounts(smart_contracts_dir=smart_contracts_dir)
    new_account_key = get_shell_output("uuidgen")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials,
                                                      keyname=new_account_key)
    credentials.from_key = new_addr["name"]
    request = EthereumToSifchainTransferRequest(
        ethereum_symbol=new_currency["newtoken_address"],
        sifchain_symbol="c" + new_currency["newtoken_symbol"],
        sifchain_address=get_required_env_var("OWNER_ADDR"),
        smart_contracts_dir=smart_contracts_dir,
        ethereum_address=accounts["accounts"][0],
        ethereum_private_key_env_var="ETHEREUM_PRIVATE_KEY",
        bridgebank_address=bridgebank_address,
        bridgetoken_address=bridgetoken_address,
        ethereum_network=(os.environ.get("ETHEREUM_NETWORK") or ""),
        amount=amount,
        ceth_amount=2 * (10**16))

    return (request, credentials)
def test_transfer_eth_to_ceth_without_a_validator_should_throw_exception():
    new_account_key = get_shell_output("uuidgen")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials,
                                                      keyname=new_account_key)
    credentials.from_key = new_addr["name"]
    request = EthereumToSifchainTransferRequest(
        sifchain_address=new_addr["address"],
        smart_contracts_dir=get_required_env_var("SMART_CONTRACTS_DIR"),
        ethereum_address=get_required_env_var("ETHEREUM_ADDRESS"),
        ethereum_private_key_env_var="ETHEREUM_PRIVATE_KEY",
        bridgebank_address=get_required_env_var("BRIDGE_BANK_ADDRESS"),
        ethereum_network=(os.environ.get("ETHEREUM_NETWORK") or ""),
        amount=90000)

    logging.info(
        "try to transfer, but expect a failure since there are no whitelisted validators"
    )
    with pytest.raises(Exception):
        # use a small number for max_retries - on a local system, it shouldn't
        # take more than a second or two for ebrelayer to act
        burn_lock_functions.transfer_ethereum_to_sifchain(request, 3)
Esempio n. 8
0
def build_request(
    sifnodecli_node, source_ethereum_address, chain_id, smart_contracts_dir
) -> (EthereumToSifchainTransferRequest, SifchaincliCredentials):
    new_account_key = get_shell_output("uuidgen")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_addr = burn_lock_functions.create_new_sifaddr(credentials=credentials,
                                                      keyname=new_account_key)
    credentials.from_key = new_addr["name"]
    ceth_fee = 2 * (10**16)
    request = EthereumToSifchainTransferRequest(
        sifchain_address=new_addr["address"],
        smart_contracts_dir=smart_contracts_dir,
        ethereum_private_key_env_var="ETHEREUM_PRIVATE_KEY",
        bridgebank_address=bridgebank_address,
        ethereum_network=ethereum_network,
        amount=amount + ceth_fee,
        ceth_amount=ceth_fee,
        sifnodecli_node=sifnodecli_node,
        manual_block_advance=False,
        chain_id=chain_id,
        sifchain_fees="100000rowan",
    )
    return request, credentials
Esempio n. 9
0
def test_rollback_chain(source_ethereum_address):
    new_account_key = get_shell_output("uuidgen")
    credentials = sifchain_cli_credentials_for_test(new_account_key)
    new_account = burn_lock_functions.create_new_sifaddr(
        credentials=credentials, keyname=new_account_key)
    credentials.from_key = new_account["name"]

    # Any amount will work
    amount = 11000

    request = EthereumToSifchainTransferRequest(
        sifchain_address=new_account["address"],
        smart_contracts_dir=get_required_env_var("SMART_CONTRACTS_DIR"),
        ethereum_address=source_ethereum_address,
        ethereum_private_key_env_var="ETHEREUM_PRIVATE_KEY",
        bridgebank_address=get_required_env_var("BRIDGE_BANK_ADDRESS"),
        ethereum_network=(os.environ.get("ETHEREUM_NETWORK") or ""),
        amount=amount)

    logging.info(f"create account with a balance of {request.amount}")
    burn_lock_functions.transfer_ethereum_to_sifchain(request, 50)

    new_addr = new_account["address"]

    snapshot = get_shell_output(
        f"{test_integration_dir}/snapshot_ganache_chain.sh")
    logging.info(f"created new account, took ganache snapshot {snapshot}")
    initial_user_balance = get_sifchain_addr_balance(new_addr, "",
                                                     request.sifchain_symbol)
    logging.info(f"initial_user_balance {initial_user_balance}")

    transfer_1 = send_from_ethereum_to_sifchain(transfer_request=request)
    logging.info(f"transfer started but it will never complete (by design)")

    logging.info("advance less than wait blocks")
    advance_n_ethereum_blocks(n_wait_blocks / 2, request.smart_contracts_dir)

    # the transaction should not have happened on the sifchain side yet
    # since we haven't waited for the right number of blocks.
    # roll back ganache to the snapshot and try another transfer that
    # should succeed.

    logging.info(
        f"apply snapshot {snapshot} - this eliminates transfer_1 (block {transfer_1})"
    )
    get_shell_output(
        f"{test_integration_dir}/apply_ganache_snapshot.sh {snapshot} 2>&1")

    logging.info("advance past block wait")
    advance_n_ethereum_blocks(n_wait_blocks * 2, request.smart_contracts_dir)
    time.sleep(5)

    second_user_balance = get_sifchain_addr_balance(new_addr, "",
                                                    request.sifchain_symbol)
    if second_user_balance == initial_user_balance:
        logging.info(
            f"got expected outcome of no balance change @ {initial_user_balance}"
        )
    else:
        raise Exception(
            f"balance should be the same after applying snapshot and rolling forward n_wait_blocks * 2.  initial_user_balance: {initial_user_balance} second_user_balance: {second_user_balance}"
        )

    request.amount = 10000

    logging.info(f"sending more eth: {request.amount} to {new_addr}")
    burn_lock_functions.transfer_ethereum_to_sifchain(request)

    # We want to know that ebrelayer will never do a second transaction.
    # We can't know that, so just delay a reasonable amount of time.
    logging.info("delay to give ebrelayer time to make a mistake")
    time.sleep(10)

    balance_after_sleep = get_sifchain_addr_balance(new_addr, "",
                                                    request.sifchain_symbol)
    logging.info(
        f"get_sifchain_addr_balance after sleep is {balance_after_sleep} for {new_addr}"
    )

    expected_balance = initial_user_balance + request.amount
    logging.info(f"look for a balance of {expected_balance}")
    wait_for_sifchain_addr_balance(new_addr, request.sifchain_symbol,
                                   expected_balance, "")