Example #1
0
def test_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,
        bridgetoken_address,
        smart_contracts_dir
):
    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=10 ** 18,
        target_rowan_balance=target_rowan_balance
    )

    logging.info(f"send erowan to ethereum from test account")
    request.ethereum_address, _ = test_utilities.create_ethereum_address(
        smart_contracts_dir, ethereum_network
    )
    request.sifchain_symbol = "rowan"
    request.ethereum_symbol = bridgetoken_address
    request.amount = int(target_rowan_balance / 2)
    burn_lock_functions.transfer_sifchain_to_ethereum(request, credentials)
Example #2
0
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):
    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=0,
        target_rowan_balance=target_rowan_balance)
    time.sleep(10)

    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")

    get_faucet_balance(basic_transfer_request.sifnodecli_node)
    basic_transfer_request.amount = 10**17
    basic_transfer_request.sifchain_symbol = "rowan"
    basic_transfer_request.sifchain_address = sifaddress
    request_faucet_coins(basic_transfer_request, credentials)
    time.sleep(10)
    get_faucet_balance(basic_transfer_request.sifnodecli_node)
    balance = test_utilities.get_sifchain_addr_balance(
        sifaddress, basic_transfer_request.sifnodecli_node, "rowan")
Example #3
0
def test_create_pools(
    basic_transfer_request: EthereumToSifchainTransferRequest,
    source_ethereum_address: str,
    rowan_source_integrationtest_env_credentials: SifchaincliCredentials,
    rowan_source_integrationtest_env_transfer_request:
    EthereumToSifchainTransferRequest):
    basic_transfer_request.ethereum_address = source_ethereum_address
    basic_transfer_request.check_wait_blocks = True
    target_rowan_balance = 10**19
    target_ceth_balance = 10**19
    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)

    sifaddress = request.sifchain_address
    # 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, "ceth", target_ceth_balance,
        basic_transfer_request.sifnodecli_node)

    pools = get_pools(basic_transfer_request.sifnodecli_node)
    change_amount = 10**18
    sifchain_fees = 100000  # Should probably make this a constant
    basic_transfer_request.amount = change_amount
    basic_transfer_request.sifchain_symbol = "ceth"
    basic_transfer_request.sifchain_address = sifaddress
    current_ceth_balance = target_ceth_balance
    current_rowan_balance = target_rowan_balance

    # Only works the first time, fails later.  Make this flexible for manual and private net testing for now.
    if pools is None:
        create_pool(basic_transfer_request, credentials)
        get_pools(basic_transfer_request.sifnodecli_node)
        current_ceth_balance = current_ceth_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,
            "ceth") == current_ceth_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,
        "ceth") == current_ceth_balance)
Example #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))