Ejemplo n.º 1
0
    def test_check_amount_and_fee_is_valid_1(self):
        """Test for function called check_amount_and_fee_is_valid with floating values."""

        count = 0
        test_floating_values = ["123.5", "123.11111110", "100000000000000.12340000"]

        for value in test_floating_values:
            try:
                check_amount_and_fee_is_valid(value, "10000000000000000")
            except AmountIsNotInteger:
                count += 1

        self.assertEqual(count, 3)
Ejemplo n.º 2
0
def transfer_value_with_the_fee(password, fee, decimal_point, to, amount, file_path, url):
    """ Transfer the value to the specific address with the fee.

    :param password: Password including alphabet character, number, and special character.
    If the user doesn't give password with -p, then CLI will show the prompt and user need to type the password.
    :param fee: Transaction fee.
    :param decimal_point: A user can change the decimal point to express all numbers including fee and amount.
    :param to: Address of wallet to receive the asset.
    :param amount: Amount of money. *The decimal point number is valid up to tenth power of 18. *
    :param file_path: File path for the keystore file of the wallet.
    :param url: Api url. type(str)
    :return:
    """
    try:
        url = f'{url}v2'
        validate_key_store_file(file_path)
        private_key_bytes = __key_from_key_store(file_path, bytes(password, 'utf-8'))
        user_address = get_address_by_privkey(private_key_bytes)

        validate_address(user_address)
        validate_address(to)

        method = 'icx_sendTransaction'

        amount_wei = icx_str_to_wei(amount)
        fixed_amount = int(floor_point(amount_wei, decimal_point))

        fee_wei = get_fee_wei(fee)
        fixed_fee = int(floor_point(fee_wei, decimal_point))

        check_amount_and_fee_is_valid(fixed_amount, fixed_fee)

        params = __make_params(user_address, to, fixed_amount, fixed_fee, method, private_key_bytes)
        payload = create_jsonrpc_request_content(0, method, params)

        # Request the balance repeatedly until we get the response from ICON network.
        request_gen = request_generator(url)
        balance = __get_balance_after_trasfer(user_address, url, request_gen)
        check_balance_enough(balance, amount, fee)
        next(request_gen)
        response = request_gen.send(payload)
        return response

    except FileNotFoundError:
        print("File does not exists.")
        raise FilePathIsWrong
    except IsADirectoryError:
        print(f"{file_path} is a directory.")
        raise FilePathIsWrong
    except ValueError:
        raise PasswordIsWrong
Ejemplo n.º 3
0
    def test_check_amount_and_fee_is_valid_2(self):
        """Test for function called check_amount_and_fee_is_valid with integer values."""

        test_integer_values = ["100000000000000123444", "12300000333000000000","12345678901234567"]

        for value in test_integer_values:
            self.assertEqual(check_amount_and_fee_is_valid(value, "10000000000000000"), (int(value), 10000000000000000))