예제 #1
0
def test_fee_charged_to_transfer_rowan_to_erowan(
    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,
):
    basic_transfer_request.ethereum_address = source_ethereum_address
    logging.info(
        f"credentials: {rowan_source_integrationtest_env_credentials}")
    request, credentials = generate_test_account(
        basic_transfer_request,
        rowan_source_integrationtest_env_transfer_request,
        rowan_source_integrationtest_env_credentials,
        target_ceth_balance=10**18,
        target_rowan_balance=10**18)
    # 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"sending rowan to erowan and checking that a ceth fee was charged")
    request.sifchain_symbol = "rowan"
    request.ethereum_symbol = bridgetoken_address
    request.amount = 31500

    # get the starting ceth balance, transfer some rowan to erowan, get the ending ceth
    # balance.  The difference is the fee charged and should be equal to request.ceth_amount

    starting_ceth_balance = test_utilities.get_sifchain_addr_balance(
        request.sifchain_address, request.sifnodecli_node, "ceth")
    burn_lock_functions.transfer_sifchain_to_ethereum(request, credentials)
    ending_ceth_balance = test_utilities.get_sifchain_addr_balance(
        request.sifchain_address, request.sifnodecli_node, "ceth")
    fee = starting_ceth_balance - ending_ceth_balance
    assert fee == test_utilities.lock_gas_cost
예제 #2
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.sifnoded_node, "ceth")
    assert received_ceth_charges == test_utilities.burn_gas_cost
예제 #3
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
예제 #4
0
def test_pools(
        basic_transfer_request: EthereumToSifchainTransferRequest,
        source_ethereum_address: str,
        rowan_source_integrationtest_env_credentials: SifchaincliCredentials,
        rowan_source_integrationtest_env_transfer_request:
    EthereumToSifchainTransferRequest, solidity_json_path):
    # max symbol length in clp is 10
    new_currency_symbol = ("a" +
                           get_shell_output("uuidgen").replace("-", ""))[:8]
    target_new_currency_balance = 5 * 10**18
    logging.info(f"create new currency")
    new_currency = test_utilities.create_new_currency(
        1000 * target_new_currency_balance,
        new_currency_symbol,
        smart_contracts_dir=smart_contracts_dir,
        bridgebank_address=bridgebank_address,
        solidity_json_path=solidity_json_path)
    sifchain_symbol = ("c" + new_currency["newtoken_symbol"]).lower()

    basic_transfer_request.ethereum_address = source_ethereum_address
    basic_transfer_request.check_wait_blocks = True
    target_rowan_balance = 5 * 10**18
    target_ceth_balance = 10**18
    request, credentials = generate_test_account(
        basic_transfer_request,
        rowan_source_integrationtest_env_transfer_request,
        rowan_source_integrationtest_env_credentials,
        target_ceth_balance=target_ceth_balance,
        target_rowan_balance=target_rowan_balance)

    logging.info(
        f"transfer some of the new currency {new_currency_symbol} to the test sifchain address"
    )
    request.ethereum_symbol = new_currency["newtoken_address"]
    request.sifchain_symbol = sifchain_symbol
    request.amount = target_new_currency_balance
    burn_lock_functions.transfer_ethereum_to_sifchain(request)

    sifaddress = request.sifchain_address
    sifchain_fees = 100000  # Should probably make this a constant
    #from_key = credentials.from_key
    # wait for balance
    test_utilities.wait_for_sifchain_addr_balance(
        sifaddress, "rowan", target_rowan_balance,
        basic_transfer_request.sifnodecli_node)
    test_utilities.wait_for_sifchain_addr_balance(
        sifaddress, sifchain_symbol, target_new_currency_balance,
        basic_transfer_request.sifnodecli_node)

    pools = get_pools(basic_transfer_request.sifnodecli_node)
    basic_transfer_request.sifchain_symbol = sifchain_symbol
    basic_transfer_request.sifchain_address = sifaddress
    current_coin_balance = target_new_currency_balance
    current_rowan_balance = target_rowan_balance

    change_amount = 10**19
    basic_transfer_request.amount = change_amount
    # Fail if amount is greater than user has
    txn = create_pool(basic_transfer_request, credentials)
    assert (txn["code"] == 12)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)

    change_amount = 10**17
    basic_transfer_request.amount = change_amount
    # Fail if amount is less than or equal to minimum
    txn = create_pool(basic_transfer_request, credentials)
    assert (txn["code"] == 7)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)

    change_amount = 10**18
    basic_transfer_request.amount = change_amount
    # Only works the first time, fails later.
    txn = create_pool(basic_transfer_request, credentials)
    assert (txn.get("code", 0) == 0)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_coin_balance = current_coin_balance - change_amount
    current_rowan_balance = current_rowan_balance - change_amount - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        sifchain_symbol) == current_coin_balance)

    # check for failure if we try to create a pool twice
    txn = create_pool(basic_transfer_request, credentials)
    assert (txn["code"] == 14)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        sifchain_symbol) == current_coin_balance)

    # ensure we can add liquidity, money gets transferred
    txn = add_pool_liquidity(basic_transfer_request, credentials)
    assert (txn.get("code", 0) == 0)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_coin_balance = current_coin_balance - change_amount
    current_rowan_balance = current_rowan_balance - change_amount - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        sifchain_symbol) == current_coin_balance)

    # check for failure if we try to remove all liquidity
    txn = remove_pool_liquidity(basic_transfer_request, credentials, 10000)
    assert (txn["code"] == 26)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        sifchain_symbol) == current_coin_balance)

    # ensure we can remove liquidity, money gets transferred
    txn = remove_pool_liquidity(basic_transfer_request, credentials, 5000)
    assert (txn.get("code", 0) == 0)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_coin_balance = current_coin_balance + change_amount
    current_rowan_balance = current_rowan_balance + change_amount - sifchain_fees
    #assert(test_utilities.get_sifchain_addr_balance(sifaddress, basic_transfer_request.sifnodecli_node, "rowan") == current_rowan_balance)
    #assert(test_utilities.get_sifchain_addr_balance(sifaddress, basic_transfer_request.sifnodecli_node, sifchain_symbol) == current_ceth_balance)
    # no slippage if pool is perfectly balanced.

    # TODO: compute this precisely?
    slip_pct = 0.01
    balance = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, "rowan")
    slip_cost = (slip_pct * current_rowan_balance)
    assert (balance >= current_rowan_balance - slip_cost
            and balance <= current_rowan_balance + slip_cost)
    current_rowan_balance = balance
    balance = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, sifchain_symbol)
    slip_cost = (slip_pct * current_coin_balance)
    assert (balance >= current_coin_balance - slip_cost
            and balance <= current_coin_balance + slip_cost)
    current_coin_balance = balance

    # check for failure if we try to add too much liquidity
    basic_transfer_request.amount = 10**19
    txn = add_pool_liquidity(basic_transfer_request, credentials)
    assert (txn["code"] == 25)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        sifchain_symbol) == current_coin_balance)

    # check for failure if we try to remove too much liquidity, only occurs now if not 100% liquidity provider
    """
    txn = remove_pool_liquidity(basic_transfer_request, credentials, 10000)
    assert(txn["code"] == 3)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert(test_utilities.get_sifchain_addr_balance(sifaddress, basic_transfer_request.sifnodecli_node, "rowan") == current_rowan_balance)
    assert(test_utilities.get_sifchain_addr_balance(sifaddress, basic_transfer_request.sifnodecli_node, sifchain_symbol) == current_coin_balance)
    """

    # check for failure if we try to swap too much for user
    txn = swap_pool(basic_transfer_request, "rowan", sifchain_symbol,
                    credentials)
    assert (txn["code"] == 27)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        sifchain_symbol) == current_coin_balance)

    # check for failure if we try to swap too much for pool
    basic_transfer_request.amount = 5 * 10**17
    txn = swap_pool(basic_transfer_request, "rowan", sifchain_symbol,
                    credentials)
    assert (txn["code"] == 31)
    get_pools(basic_transfer_request.sifnodecli_node)
    current_rowan_balance = current_rowan_balance - sifchain_fees
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        "rowan") == current_rowan_balance)
    assert (test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node,
        sifchain_symbol) == current_coin_balance)

    # now try to do a swap that works
    change_amount = 10**15
    basic_transfer_request.amount = change_amount
    txn = swap_pool(basic_transfer_request, "rowan", sifchain_symbol,
                    credentials)
    # TODO: compute this precisely?
    slip_pct = 0.01
    balance = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, "rowan")
    assert (balance < current_rowan_balance)
    current_rowan_balance = balance
    balance = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, sifchain_symbol)
    assert (balance > current_coin_balance)
    current_coin_balance = balance
def test_request_faucet_coins(
        basic_transfer_request: EthereumToSifchainTransferRequest,
        source_ethereum_address: str,
        rowan_source_integrationtest_env_credentials: SifchaincliCredentials,
        rowan_source_integrationtest_env_transfer_request:
    EthereumToSifchainTransferRequest, solidity_json_path, operator_address,
        ethereum_network):

    #Generate New Random Currency
    new_currency_symbol = ("a" +
                           get_shell_output("uuidgen").replace("-", ""))[:8]
    target_new_currency_balance = 300000
    new_currency = generate_new_currency(new_currency_symbol,
                                         target_new_currency_balance,
                                         solidity_json_path, operator_address,
                                         ethereum_network)
    sifchain_symbol = ("c" + new_currency["newtoken_symbol"]).lower()

    basic_transfer_request.ethereum_address = source_ethereum_address
    basic_transfer_request.check_wait_blocks = True
    target_rowan_balance = 10**18
    request, credentials = generate_test_account(
        basic_transfer_request,
        rowan_source_integrationtest_env_transfer_request,
        rowan_source_integrationtest_env_credentials,
        target_ceth_balance=100,
        target_rowan_balance=target_rowan_balance)
    #Transfer Newly Generated Currency
    transfer_new_currency(request, sifchain_symbol, new_currency,
                          target_new_currency_balance)

    sifaddress = request.sifchain_address
    logging.info("get balances just to have those commands in the history")
    balance = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, "rowan")
    balance_ceth = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, "ceth")
    balance_new_currency = test_utilities.get_sifchain_addr_balance(
        sifaddress, request.sifnodecli_node, sifchain_symbol)

    assert balance_new_currency == 300000, "new currency balance is wrong in the test account"
    assert balance_ceth == 100, "new ceth currency balance is wrong in the test account"
    assert balance == 10**18, "new rowan currency balance is wrong in the test account"

    logging.info(f"{sifchain_symbol} balance = {balance_new_currency}")
    logging.info(f"ceth  balance = {balance_ceth}")
    logging.info(f"rowan  balance = {balance}")

    #rowan
    start_faucet_rowan_balance = get_currency_faucet_balance(
        "rowan", get_faucet_balance(basic_transfer_request.sifnodecli_node))
    logging.info(get_faucet_balance(basic_transfer_request.sifnodecli_node))
    basic_transfer_request.amount = 50000
    basic_transfer_request.sifchain_symbol = "rowan"
    basic_transfer_request.sifchain_address = sifaddress
    # add
    txn = add_faucet_coins(basic_transfer_request, credentials)
    assert (txn.get("code", 0) == 0)
    after_add_faucet_rowan_balance = get_currency_faucet_balance(
        "rowan", get_faucet_balance(basic_transfer_request.sifnodecli_node))
    assert (
        start_faucet_rowan_balance + 50000 == after_add_faucet_rowan_balance
    ), "faucet balance in rowan should be higher after adding coins to faucet"
    get_faucet_balance(basic_transfer_request.sifnodecli_node)
    # request
    basic_transfer_request.amount = 25000
    txn = request_faucet_coins(basic_transfer_request, credentials)
    assert (txn.get("code", 0) == 0)
    after_request_faucet_rowan_balance = get_currency_faucet_balance(
        "rowan", get_faucet_balance(basic_transfer_request.sifnodecli_node))
    assert (
        start_faucet_rowan_balance +
        25000 == after_request_faucet_rowan_balance
    ), "current faucet balance in rowan should be equal with the initial faucet balance + 25000"
    get_faucet_balance(basic_transfer_request.sifnodecli_node)
    balance = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, "rowan")

    #ceth
    start_faucet_ceth_balance = get_currency_faucet_balance(
        "ceth", get_faucet_balance(basic_transfer_request.sifnodecli_node))
    get_faucet_balance(basic_transfer_request.sifnodecli_node)
    basic_transfer_request.amount = 10
    basic_transfer_request.sifchain_symbol = "ceth"
    basic_transfer_request.sifchain_address = sifaddress
    # add
    txn = add_faucet_coins(basic_transfer_request, credentials)
    assert (txn.get("code", 0) == 0)
    after_add_faucet_ceth_balance = get_currency_faucet_balance(
        "ceth", get_faucet_balance(basic_transfer_request.sifnodecli_node))
    assert (
        start_faucet_ceth_balance + 10 == after_add_faucet_ceth_balance
    ), "faucet balance in ceth should be higher after adding coins to faucet"
    get_faucet_balance(request.sifnodecli_node)
    # request
    basic_transfer_request.amount = 5
    txn = request_faucet_coins(basic_transfer_request, credentials)
    assert (txn.get("code", 0) == 0)
    get_faucet_balance(basic_transfer_request.sifnodecli_node)
    balance_ceth = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, "ceth")

    #random currency
    start_faucet_random_balance = get_currency_faucet_balance(
        sifchain_symbol, get_faucet_balance(request.sifnodecli_node))
    get_faucet_balance(request.sifnodecli_node)
    request.amount = 20000
    request.sifchain_symbol = sifchain_symbol
    request.sifchain_address = sifaddress
    # add
    txn = add_faucet_coins(request, credentials)
    assert (txn.get("code", 0) == 0)
    after_add_faucet_random_balance = get_currency_faucet_balance(
        sifchain_symbol, get_faucet_balance(request.sifnodecli_node))
    assert (
        start_faucet_random_balance + 20000 == after_add_faucet_random_balance
    ), "faucet balance in random currency should be higher after adding coins to faucet"
    get_faucet_balance(request.sifnodecli_node)
    balance_new_currency = test_utilities.get_sifchain_addr_balance(
        sifaddress, request.sifnodecli_node, sifchain_symbol)

    # request
    request.amount = 1000
    txn = request_faucet_coins(request, credentials)
    assert (txn.get("code", 0) == 0)
    get_faucet_balance(request.sifnodecli_node)
    balance_new_currency = test_utilities.get_sifchain_addr_balance(
        sifaddress, request.sifnodecli_node, sifchain_symbol)

    #get faucet balances
    logging.info(
        "get remaining balances just to have those commands in the history")
    assert balance_new_currency == 281000, "new currency balance is wrong in the test account"
    assert balance_ceth == 95, "new ceth currency balance is wrong in the test account"
    assert balance == 999999999999575000, "new rowan currency balance is wrong in the test account"
    logging.info(f"{sifchain_symbol} balance = {balance_new_currency}")
    logging.info(f"ceth  balance = {balance_ceth}")
    logging.info(f"rowan  balance = {balance}")
    logging.info(get_faucet_balance(request.sifnodecli_node))