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)
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('71fc378d3a3fb92b57474af156f376711a8a89d277c9b60a923a1db75575b1cc') # Then self.assertEqual(wallet.get_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( '71fc378d3a3fb92b57474af156f9d277c9b60a923a1db75575b1cc') # Then except TypeError: self.assertTrue(True)
def test0(self): """ Case to create wallet successfully. """ # Given, When wallet1, _ = Wallet.create_wallet_by_private_key( '71fc378d3a3fb92b57474af156f376711a8a89d277c9b60a923a1db75575b1cc') # Then self.assertEqual(wallet1.address, "hxcc7b1f5fb98ca1eeaf9586bc08048814cb0d4d3d")
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 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))
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)
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 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) print(ret.json()) # Then except AmountIsInvalid: self.assertTrue(False) else: self.assertTrue(True)
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)
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)
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 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)
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 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)
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)
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)
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)
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)
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)
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)
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)
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 test1(self): """ Case to get an address successfully on creating a keystore file of wallet """ file_path = os.path.join(TEST_DIR, "test_keystore.txt") if os.path.isfile(file_path): os.remove(file_path) # Given password = "******" keystore_file_path = os.path.join(TEST_DIR, "test_keystore.txt") try: # When wallet, _ = Wallet.create_keystore_file_of_wallet(keystore_file_path, password) # Then prefix = wallet.get_address()[0:2] self.assertEqual(prefix, "hx") except FileExistsError: self.assertFalse(True) except FilePathIsWrong: self.assertFalse(True)
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)