def test_two_currencies_with_different_capitalization_should_not_interfere_with_each_other(
    smart_contracts_dir,
    bridgebank_address,
    solidity_json_path,
):
    new_account_key = (
        "a" + get_shell_output("uuidgen").replace("-", "").lower())[:5]
    amount = amount_in_wei(9)

    new_currency = create_new_currency(amount, new_account_key,
                                       smart_contracts_dir, bridgebank_address,
                                       solidity_json_path)
    (request1,
     _) = build_request_for_new_sifchain_address(new_currency, amount)
    burn_lock_functions.transfer_ethereum_to_sifchain(request1, 10)
    balance_1 = get_sifchain_addr_balance(request1.sifchain_address,
                                          request1.sifnodecli_node,
                                          request1.sifchain_symbol)
    assert (balance_1 == request1.amount)

    new_currency = create_new_currency(amount, new_account_key.upper(),
                                       smart_contracts_dir, bridgebank_address,
                                       solidity_json_path)
    (request2,
     _) = build_request_for_new_sifchain_address(new_currency, amount + 70000)
    burn_lock_functions.transfer_ethereum_to_sifchain(request2, 10)

    balance_1_again = get_sifchain_addr_balance(request1.sifchain_address,
                                                request1.sifnodecli_node,
                                                request1.sifchain_symbol)

    assert (balance_1 == balance_1_again)
Пример #2
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
def test_can_create_a_new_token_and_peg_it(
    token_length: int,
    basic_transfer_request: EthereumToSifchainTransferRequest,
    smart_contracts_dir,
    bridgebank_address,
    solidity_json_path,
    operator_address,
    ethereum_network,
    source_ethereum_address,
):
    new_account_key = (
        "a" + get_shell_output("uuidgen").replace("-", ""))[:token_length]
    token_name = new_account_key
    amount = amount_in_wei(9)
    new_currency = create_new_currency(amount=amount,
                                       symbol=new_account_key,
                                       token_name=token_name,
                                       decimals=18,
                                       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 = build_request_for_new_sifchain_address(basic_transfer_request,
                                                     source_ethereum_address,
                                                     new_currency, amount / 10)
    burn_lock_functions.transfer_ethereum_to_sifchain(request)
Пример #4
0
def test_transfer_eth_to_ceth_and_back(ropsten_wait_time, rowan_source,
                                       sifnodecli_node,
                                       source_ethereum_address, chain_id):
    eth_transfer, credentials = build_request(sifnodecli_node,
                                              source_ethereum_address,
                                              chain_id)
    # first we have to give the sif address some rowan so it can pay sifchain gas
    rowan_transfer = deepcopy(eth_transfer)
    logging.info(f"rowan_source is {rowan_source}")
    rowan_transfer.sifchain_address = rowan_source
    rowan_transfer.sifchain_destination_address = eth_transfer.sifchain_address
    rowan_transfer.amount = 2000000
    rowan_transfer.sifchain_symbol = "rowan"
    test_utilities.send_from_sifchain_to_sifchain(rowan_transfer, credentials)
    burn_lock_functions.transfer_ethereum_to_sifchain(eth_transfer,
                                                      ropsten_wait_time)
    logging.info(f"send ceth back to {eth_transfer.ethereum_address}")
    return_request = deepcopy(eth_transfer)
    # don't transfer ceth => eth to the BridgeBank address since BridgeBank is responsible for paying gas.
    # That means you can't just see if the exact transfer went through.
    return_request.ethereum_address, _ = test_utilities.create_ethereum_address(
        smart_contracts_dir, ethereum_network)
    return_request.amount = amount
    burn_lock_functions.transfer_sifchain_to_ethereum(return_request,
                                                      credentials,
                                                      ropsten_wait_time)
def transfer_new_currency(request, symbol, currency, amount):
    logging.info(
        f"transfer some of the new currency {symbol} to the test sifchain address"
    )
    request.ethereum_symbol = currency["newtoken_address"]
    request.sifchain_symbol = symbol
    request.amount = amount
    burn_lock_functions.transfer_ethereum_to_sifchain(request)
Пример #6
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
def test_can_use_a_token_with_a_dash_in_the_name(
    smart_contracts_dir,
    bridgebank_address,
    solidity_json_path,
):
    n = "a-b"
    new_currency = create_new_currency(amount_in_wei(10), n,
                                       smart_contracts_dir, bridgebank_address,
                                       solidity_json_path)
    (request, _) = build_request_for_new_sifchain_address(new_currency, 60000)
    burn_lock_functions.transfer_ethereum_to_sifchain(request, 10)
Пример #8
0
def test_transfer_eth_to_ceth_using_replay_blocks(integration_dir,
                                                  smart_contracts_dir,
                                                  ensure_relayer_restart):
    starting_block = test_utilities.current_ethereum_block_number(
        smart_contracts_dir)
    logging.info("stopping ebrelayer")
    test_utilities.get_shell_output("pkill -9 ebrelayer || true")
    request, credentials = build_request()
    logging.info("(no transactions should happen without a relayer)")
    # test_utilities.whitelist_token(request.ethereum_symbol, request.smart_contracts_dir, True)
    logging.info(
        f"send {request.amount / 10**18} eth ({request.amount} wei) to {request.sifchain_address}"
    )
    test_utilities.send_from_ethereum_to_sifchain(request)
    # test_utilities.get_shell_output(f"{integration_dir}/sifchain_start_ebrelayer.sh")

    logging.info("replay blocks using ebrelayer replayEthereum")
    ews = test_utilities.get_required_env_var("ETHEREUM_WEBSOCKET_ADDRESS")
    bra = test_utilities.get_required_env_var("BRIDGE_REGISTRY_ADDRESS")
    mon = test_utilities.get_required_env_var("MONIKER")
    mn = test_utilities.get_required_env_var("MNEMONIC")
    cn = test_utilities.get_required_env_var("CHAINNET")
    ending_block = test_utilities.current_ethereum_block_number(
        smart_contracts_dir) + 1
    cmd = f"""ebrelayer replayEthereum tcp://0.0.0.0:26657 {ews} {bra} {mon} '{mn}' {starting_block} {ending_block} 1 2 --chain-id {cn} --gas 5000000000000 \
  --gas-prices 0.5rowan"""
    test_utilities.get_shell_output(cmd)
    time.sleep(15)
    logging.info(
        f"check the ending balance of {request.sifchain_address} after replaying blocks"
    )
    ending_balance = test_utilities.get_sifchain_addr_balance(
        request.sifchain_address, request.sifnodecli_node,
        request.sifchain_symbol)
    assert (ending_balance == request.amount)

    # now do it again
    test_utilities.get_shell_output(cmd)
    time.sleep(5)
    ending_balance2 = test_utilities.get_sifchain_addr_balance(
        request.sifchain_address, request.sifnodecli_node,
        request.sifchain_symbol)
    assert (ending_balance2 == request.amount)

    # now start ebrelayer and do another transfer
    test_utilities.advance_n_ethereum_blocks(test_utilities.n_wait_blocks + 1,
                                             smart_contracts_dir)
    test_utilities.get_shell_output(
        f"{integration_dir}/sifchain_start_ebrelayer.sh")
    burn_lock_functions.transfer_ethereum_to_sifchain(request, 15)
    ending_balance3 = test_utilities.get_sifchain_addr_balance(
        request.sifchain_address, request.sifnodecli_node,
        request.sifchain_symbol)
    assert (ending_balance3 == request.amount * 2)
def test_can_create_a_new_token_with_a_long_name_and_peg_it(
    smart_contracts_dir,
    bridgebank_address,
    solidity_json_path,
):
    new_account_key = "ca36e47edfeb28489d8e110fb91d351bcd"
    amount = amount_in_wei(9)
    new_currency = create_new_currency(amount, new_account_key,
                                       smart_contracts_dir, bridgebank_address,
                                       solidity_json_path)
    (request1, _) = build_request(new_currency, amount)
    burn_lock_functions.transfer_ethereum_to_sifchain(request1, 10)
def test_can_create_a_new_token_with_a_one_letter_name_and_peg_it(
    smart_contracts_dir,
    bridgebank_address,
    solidity_json_path,
):
    new_account_key = "a"
    amount = amount_in_wei(9)
    new_currency = create_new_currency(amount, new_account_key,
                                       smart_contracts_dir, bridgebank_address,
                                       solidity_json_path)
    (request1,
     _) = build_request_for_new_sifchain_address(new_currency, amount)
    burn_lock_functions.transfer_ethereum_to_sifchain(request1, 10)
def do_currency_test(
    new_currency_symbol,
    basic_transfer_request: EthereumToSifchainTransferRequest,
    source_ethereum_address: str,
    rowan_source_integrationtest_env_credentials: SifchaincliCredentials,
    rowan_source_integrationtest_env_transfer_request:
    EthereumToSifchainTransferRequest,
    ethereum_network,
    solidity_json_path,
):
    amount = amount_in_wei(9)
    logging.info(f"create new currency")
    new_currency = test_utilities.create_new_currency(
        amount,
        new_currency_symbol,
        new_currency_symbol,
        18,
        smart_contracts_dir=smart_contracts_dir,
        bridgebank_address=bridgebank_address,
        solidity_json_path=solidity_json_path)

    logging.info(
        f"create test account to use with new currency {new_currency_symbol}")
    basic_transfer_request.ethereum_address = source_ethereum_address
    request, credentials = generate_test_account(
        basic_transfer_request,
        rowan_source_integrationtest_env_transfer_request,
        rowan_source_integrationtest_env_credentials,
        target_ceth_balance=10**17,
        target_rowan_balance=10**18)
    test_amount = 39000
    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 = ("c" + new_currency["newtoken_symbol"]).lower()
    request.amount = test_amount
    burn_lock_functions.transfer_ethereum_to_sifchain(request)

    logging.info("send some new currency to ethereum")
    request.ethereum_address, _ = test_utilities.create_ethereum_address(
        smart_contracts_dir, ethereum_network)
    request.amount = test_amount - 1
    burn_lock_functions.transfer_sifchain_to_ethereum(request, credentials)
Пример #12
0
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)
Пример #13
0
def test_can_use_a_token_with_a_dash_in_the_name():
    n = "a-b"
    new_currency = create_new_currency(amount_in_wei(10), n)
    (request, _) = build_request(new_currency, 60000)
    burn_lock_functions.transfer_ethereum_to_sifchain(request, 10)
Пример #14
0
import burn_lock_functions

if __name__ == "__main__":
    arg_parser = burn_lock_functions.transfer_argument_parser()
    args = burn_lock_functions.add_credentials_arguments(
        arg_parser).parse_args()
    burn_lock_functions.configure_logging(args)

    logging.debug(f"command line arguments: {sys.argv} {args}")

    request = burn_lock_functions.EthereumToSifchainTransferRequest.from_args(
        args)

    logging.info(f"transferrequestjson: {json.dumps(request.__dict__)}")

    transfer_result = burn_lock_functions.transfer_ethereum_to_sifchain(
        request, max_seconds=30)
    final_balance = transfer_result["sifchain_ending_balance"]

    result = json.dumps({
        "final_balance": final_balance,
        "final_balance_10_18": float(final_balance) / (10**18),
        "transfer_request": request.__dict__,
        "logfile": args.logfile[0],
        "steps": transfer_result
    })

    logging.info(f"transferresultjson: {result}")

    print(result)
Пример #15
0
    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


# if there's an existing user1 key, just remove it.  Otherwise, adding a duplicate key will just hang
try:
    test_utilities.get_shell_output(
        f"sifnoded keys delete user1 --home /home/vagrant/.sifnoded --keyring-backend test -o json"
    )
except:
    logging.debug("no key to delete, this is normal in a fresh environment")
request, credentials = build_request()
# test_utilities.set_lock_burn_limit(smart_contracts_dir, request.ethereum_symbol, request.amount)
burn_lock_functions.transfer_ethereum_to_sifchain(request)
test_utilities.get_sifchain_addr_balance(request.sifchain_address,
                                         request.sifnoded_node, "ceth")
logging.info(f"created account for key {credentials.from_key}")
Пример #16
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
Пример #17
0
def test_can_create_a_new_token_with_a_7_char_name_and_peg_it():
    new_account_key = ("a" + get_shell_output("uuidgen").replace("-", ""))[:7]
    amount = amount_in_wei(9)
    new_currency = create_new_currency(amount, new_account_key)
    (request1, _) = build_request(new_currency, amount)
    burn_lock_functions.transfer_ethereum_to_sifchain(request1, 10)
Пример #18
0
def test_can_create_a_new_token_with_a_long_name_and_peg_it():
    new_account_key = "ca36e47edfeb28489d8e110fb91d351bcd"
    amount = amount_in_wei(9)
    new_currency = create_new_currency(amount, new_account_key)
    (request1, _) = build_request(new_currency, amount)
    burn_lock_functions.transfer_ethereum_to_sifchain(request1, 10)
Пример #19
0
def test_can_create_a_new_token_with_a_one_letter_name_and_peg_it():
    new_account_key = "a"
    amount = amount_in_wei(9)
    new_currency = create_new_currency(amount, new_account_key)
    (request1, _) = build_request(new_currency, amount)
    burn_lock_functions.transfer_ethereum_to_sifchain(request1, 10)
Пример #20
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)
Пример #21
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, "")