def test0_1(self):
        """ Case to create wallet without private key successfully.
        """

        # Given, When
        wallet1, _ = Wallet.create_wallet_by_private_key('password1234*')

        # Then
        self.assertIsNotNone(wallet1.wallet_info, 'wallet_info field is empty.')

        # Given, When
        wallet2, _ = Wallet.create_wallet_by_private_key(
            'password1234*', "df7784bc856bc3e96d5b2733957ea0a47ff39d60aaf8a3406a74b8580e8395cc")

        # Then
        self.assertEqual(wallet2.address, "hx66425784bfddb5b430136b38268c3ce1fb68e8c5")
        self.assertIsNotNone(wallet2.wallet_info, 'wallet_info field is empty.')

        ret = bool(wallet2.transfer_value(
            'password1234*', to_address=wallet1.address,
            value="3300000000000000000", fee=10000000000000000))

        # Then
        self.assertEqual(True, ret)

        # Need to do wait for a while because it takes time to make consensus among nodes.
        # We recommend 0.3 sec at least.
        time.sleep(1)

        balance = wallet1.get_balance()
        self.assertIsNot(balance, 0, "Current balance is 0.")
        self.assertEqual(balance, 3300000000000000000, "Wallet balance is wrong.")
Ejemplo n.º 2
0
    def test3(self):
        """ Case the private key is composed of 32 bytes and transfer several icx twice successfully.

        :return:
        """
        # Given, When
        wallet1, _ = Wallet.create_wallet_by_private_key(
            'password1234*',
            "df7784bc856bc3e96d5b2733957ea0a47ff39d60aaf8a3406a74b8580e8395cc")

        # Then
        self.assertEqual(wallet1.address,
                         "hx66425784bfddb5b430136b38268c3ce1fb68e8c5")
        self.assertIsNotNone(wallet1.wallet_info,
                             'wallet_info field is empty.')

        wallet2, _ = Wallet.create_wallet_by_private_key(
            'password1234*',
            "71fc378d3a3fb92b57474af156f376711a8a89d277c9b60a923a1db75575b1cc")

        # Then
        self.assertIsNotNone(wallet2.wallet_info,
                             'wallet_info field is empty.')
        self.assertEqual(wallet2.address,
                         "hxcc7b1f5fb98ca1eeaf9586bc08048814cb0d4d3d")

        try:

            ret = bool(
                wallet1.transfer_value(
                    'password1234*',
                    to_address="hxcc7b1f5fb98ca1eeaf9586bc08048814cb0d4d3d",
                    value="533000000000000000",
                    fee=10000000000000000))

            # Then
            self.assertEqual(True, ret)
            # Then
            self.assertEqual(True, ret)

            ret2 = bool(
                wallet2.transfer_value(
                    'password1234*',
                    to_address="hx66425784bfddb5b430136b38268c3ce1fb68e8c5",
                    value="22200000000000000",
                    fee=10000000000000000))
            # Then
            self.assertEqual(True, ret2)

        except FileNotFoundError:
            self.assertFalse(True)
Ejemplo n.º 3
0
    def test2(self):
        """ Case the private key is composed of 32 bytes and transfer icx successfully.
        """

        # Given, When
        wallet, _ = Wallet.create_wallet_by_private_key(
            'password1234*',
            "df7784bc856bc3e96d5b2733957ea0a47ff39d60aaf8a3406a74b8580e8395cc")

        # Then
        self.assertIsNotNone(wallet.wallet_info, 'wallet_info field is empty.')
        self.assertEqual(wallet.address,
                         "hx66425784bfddb5b430136b38268c3ce1fb68e8c5")

        try:

            ret = bool(
                wallet.transfer_value(
                    'password1234*',
                    to_address="hxa974f512a510299b53c55535c105ed962fd01ee3",
                    value="50000000000000000000",
                    fee=10000000000000000))

            # Then
            self.assertEqual(True, ret)

        except FileNotFoundError:
            self.assertFalse(True)
Ejemplo n.º 4
0
    def test0(self):
        """ Case when succeed transfer value.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR,
                                          "test_keystore_for_transfer.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)

            ret = bool(
                wallet.transfer_value(
                    password,
                    to_address="hxa974f512a510299b53c55535c105ed962fd01ee2",
                    value="1000000000000000000",
                    fee=10000000000000000))

            # Then
            self.assertEqual(True, ret)

        except FileNotFoundError:
            self.assertFalse(True)
Ejemplo n.º 5
0
    def test0(self):
        """ Case to get block by Height successfully
        """
        # Given, When
        block = Wallet.get_block_by_height(10)

        # Then
        self.assertTrue(validate_block(block))
    def test0(self):
        """ Case to get last block successfully
        """
        # Given, When
        block = Wallet.get_last_block()

        # Then
        self.assertTrue(validate_last_block(block))
    def test0(self):
        """ Case to get block by hash successfully
        """
        # Given, When
        block = Wallet.get_block_by_hash('885b8021826f7e741be7f53bb95b48221e9ab263f377e997b2e47a7b8f4a2a8b')

        # Then
        self.assertTrue(validate_block(block))
    def test4(self):
        """ Case to overwrite keystore file.
        """
        # Given
        password = "******"
        file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        # When
        wallet1, _ = Wallet.create_keystore_file_of_wallet(file_path, password)

        try:
            wallet2, _ = Wallet.create_keystore_file_of_wallet(file_path, password)

        # Then
        except FileExists:  # Raise exception that file exists.
            self.assertTrue(True)

            # Remove used file.
            os.remove(file_path)
    def test0(self):
        """ Case to create wallet successfully.
        """

        # Given, When
        wallet1, _ = Wallet.create_wallet_by_private_key('password1234*','71fc378d3a3fb92b57474af156f376711a8a89d277c9b60a923a1db75575b1cc')

        # Then
        self.assertIsNotNone(wallet1.wallet_info, 'wallet_info field is empty.')
        self.assertEqual(wallet1.address, "hxcc7b1f5fb98ca1eeaf9586bc08048814cb0d4d3d")
    def test1(self):
        """ Case the private key is not composed of 32 bytes.
        """
        try:
            # Given, When
            wallet1, _ = Wallet.create_wallet_by_private_key('password1234*', '71fc378d3a3fb92b57474af156f9d277c9b60a923a1db75575b1cc')

        # Then
        except TypeError:
            self.assertTrue(True)
Ejemplo n.º 11
0
    def test0(self):
        """ Case to verify the wallet address from the wallet generated from private key
        """
        # Given, When
        wallet, _ = Wallet.create_wallet_by_private_key(
            'Adas21312*',
            '71fc378d3a3fb92b57474af156f376711a8a89d277c9b60a923a1db75575b1cc')

        # Then
        self.assertEqual(wallet.get_address(),
                         "hxcc7b1f5fb98ca1eeaf9586bc08048814cb0d4d3d")
    def test6(self):
        """ Case to save the file in the correct format.
        """
        # Given
        password = "******"
        file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        # When
        wallet1, _ = Wallet.create_keystore_file_of_wallet(file_path, password)

        # Then
        self.assertTrue(validate_key_store_file(file_path))
Ejemplo n.º 13
0
    def test3(self):
        """ Case to return the wallet info in keystore file successfully.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        # When
        wallet, _ = Wallet.open_keystore_file_of_wallet(
            keystore_file_path, password)

        # Then
        self.assertTrue(type(wallet.wallet_info) == dict)
Ejemplo n.º 14
0
    def test0(self):
        """ Case to get balance successfully that balance is 0.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        # When
        wallet, _ = Wallet.open_keystore_file_of_wallet(
            keystore_file_path, password)
        balance = wallet.get_balance()

        # Then
        self.assertTrue(type(balance) == int)
    def test1(self):
        """ Case to enter a directory that does not exist.
        """
        # Given
        password = "******"
        file_path = os.path.join(TEST_DIR, 'unknown', "test_keystore.txt")

        try:
            # When
            wallet1, _ = Wallet.create_keystore_file_of_wallet(file_path, password)

        # Then
        except FilePathIsWrong:
            self.assertTrue(True)
    def test2(self):
        """ Case to enter a invalid password.
        """
        # Given
        password = "******"
        file_path = os.path.join(TEST_DIR, "unknown_folder", "test_keystore.txt")

        try:
            # When
            wallet1, _ = Wallet.create_keystore_file_of_wallet(file_path, password)

        # Then
        except PasswordIsNotAcceptable:
            self.assertTrue(True)
    def test3(self):
        """ Case to enter a directory without permission to write file.
        """
        # Given
        password = "******"
        file_path = os.path.join("/", "test_keystore.txt")

        try:
            # When
            wallet1, _ = Wallet.create_keystore_file_of_wallet(file_path, password)

        # Then
        except NoPermissionToWriteFile:
            self.assertTrue(True)
Ejemplo n.º 18
0
    def test1(self):
        """ Case to get balance successfully that balance is more than 0.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR,
                                          "test_keystore_for_transfer.txt")

        # When
        wallet, _ = Wallet.open_keystore_file_of_wallet(
            keystore_file_path, password)
        balance = wallet.get_balance()

        # Then
        self.assertTrue(type(balance) == int and balance > 0)
Ejemplo n.º 19
0
    def test2(self):
        """ Case to enter a invalid password.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)

        # Then
        except PasswordIsWrong:
            self.assertTrue(True)
Ejemplo n.º 20
0
    def test9(self):
        """ Case when balance is same as sum of Amount and Fee.
        """
        # Given
        password = "******"
        keystore_file_path1 = os.path.join(TEST_DIR,
                                           "test_keystore_for_transfer.txt")

        try:
            # When
            wallet1, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path1, password)

            # send the value to the address of keystore file (test_keystore_for_transfer2)
            ret = wallet1.transfer_value(
                password,
                to_address="hx95e12b1f98f9b847175849f51bed5d121e742f6a",
                value="1010000000000000000",
                fee=10000000000000000)

            password = "******"
            keystore_file_path2 = os.path.join(
                TEST_DIR, "test_keystore_for_transfer2.txt")
            wallet2, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path2, password)
            ret = wallet2.transfer_value(
                password,
                to_address="hx66425784bfddb5b430136b38268c3ce1fb68e8c5",
                value="1000000000000000000",
                fee=10000000000000000)

        # Then
        except AmountIsInvalid:
            self.assertTrue(False)
        else:
            self.assertTrue(True)
Ejemplo n.º 21
0
    def test3(self):
        """ Case to return the correct form of wallet information.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(keystore_file_path, password)
            wallet_info = wallet.get_wallet_info(uri)

            # Then
            self.assertTrue(validate_wallet_info(wallet_info))
        except FileNotFoundError:
            self.assertFalse(True)
Ejemplo n.º 22
0
    def test2(self):
        """ Case to return the wallet info in keystore file successfully.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(keystore_file_path, password)
            wallet_info = wallet.get_wallet_info(uri)

            # Then
            self.assertTrue(type(wallet_info) == dict)
        except FileNotFoundError:
            self.assertFalse(True)
Ejemplo n.º 23
0
    def test0(self):
        """ Case to open wallet successfully.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)

            # Then
            prefix = wallet.address[0:2]
            self.assertEqual(prefix, "hx")
        except FileNotFoundError:
            self.assertFalse(True)
Ejemplo n.º 24
0
    def test1(self):
        """ Case to enter a directory that does not exist.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "unknown_folder",
                                          "test_keystore.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)

        # Then
        except FilePathIsWrong:
            self.assertTrue(True)
        except FileNotFoundError:
            self.assertTrue(True)
Ejemplo n.º 25
0
    def test8(self):
        """ Case when Amount is 0.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR,
                                          "test_keystore_for_transfer.txt")
        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)
            ret = wallet.transfer_value(
                password,
                to_address="hxa974f512a510299b53c55535c105ed962fd01ee2",
                value="0",
                fee=10000000000000000)

        # Then
        except AmountIsInvalid:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Ejemplo n.º 26
0
    def test10(self):
        """ Case when wallet address to transfer is same as wallet address to be sent.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR,
                                          "test_keystore_for_transfer.txt")
        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)
            ret = wallet.transfer_value(
                password,
                to_address="hx66425784bfddb5b430136b38268c3ce1fb68e8c5",
                value="0",
                fee=10000000000000000)

        # Then
        except AddressIsSame:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Ejemplo n.º 27
0
    def test1(self):
        """ Case when key_store_file_path is wrong.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR, "./wrong_path")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)
            ret = wallet.transfer_value(
                password,
                to_address="hxa974f512a510299b53c55535c105ed962fd01ee2",
                value="10000000000000000000",
                fee=10000000000000000)

        # Then
        except FilePathIsWrong:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Ejemplo n.º 28
0
    def test3(self):
        """ Case when wallet does not have enough balance.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR,
                                          "test_keystore_for_transfer.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)
            ret = wallet.transfer_value(
                password,
                to_address="hxa974f512a510299b53c55535c105ed962fd01ee2",
                value="10000000000000000000000000000000000000000000000000",
                fee=10000000000000000)

        # Then
        except NotEnoughBalanceInWallet:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
Ejemplo n.º 29
0
    def test2_1(self):
        """ Case when password is not acceptable.
        """
        # Given
        password = "******"
        keystore_file_path = os.path.join(TEST_DIR,
                                          "test_keystore_for_transfer.txt")

        try:
            # When
            wallet, _ = Wallet.open_keystore_file_of_wallet(
                keystore_file_path, password)
            ret = wallet.transfer_value(
                password,
                to_address="hxa974f512a510299b53c55535c105ed962fd01ee2",
                value="1000000000000000000",
                fee=10000000000000000)

        # Then
        except PasswordIsNotAcceptable:
            self.assertTrue(True)
        else:
            self.assertTrue(False)
    def test0(self):
        """ Case to create wallet successfully.
        """
        # Given
        password = "******"
        file_path = os.path.join(TEST_DIR, "test_keystore.txt")

        try:
            # When
            wallet1, _ = Wallet.create_keystore_file_of_wallet(file_path, password)

            # Then
            prefix = wallet1.address[0:2]
            self.assertEqual(prefix, "hx")

        except FilePathIsWrong:
            self.assertFalse(True)
        except PasswordIsNotAcceptable:
            self.assertFalse(True)
        except NoPermissionToWriteFile:
            self.assertFalse(True)

        # Remove used file.
        os.remove(file_path)