def test_wallet_load_by_private_key(self): """A wallet loads by a private key correctly.""" # Creates a wallet. private_key_object = PrivateKey() private_key = private_key_object.private_key wallet1 = KeyWallet.load(private_key) # Checks a private key as same. self.assertEqual(private_key.hex(), wallet1.get_private_key()) # Checks a wallet's address is correct. self.assertTrue(is_wallet_address(wallet1.get_address())) # Creates the other wallet. private_key_object2 = PrivateKey() private_key2 = private_key_object2.private_key wallet2 = KeyWallet.load(private_key2) # Checks a private key as same. self.assertEqual(private_key2.hex(), wallet2.get_private_key()) # Checks a wallet's address is correct. self.assertTrue(is_wallet_address(wallet2.get_address())) self.assertNotEqual(private_key2, private_key)
def test_wallet_create_successfully(self): """Case both of each wallets are created successfully without a private key.""" wallet1 = KeyWallet.create() wallet2 = KeyWallet.create() self.assertTrue(wallet1.get_address() != wallet2.get_address()) self.assertTrue(is_wallet_address(wallet1.get_address())) self.assertTrue(is_wallet_address(wallet2.get_address()))
def get_balance(self, address: str): """ Returns the ICX balance of the given EOA or SCORE. Delegates to icx_getBalance RPC method. :param address: An address of EOA or SCORE. type(str) :return: Number of ICX coins """ if is_score_address(address) or is_wallet_address(address): params = {'address': address} result = self.__provider.make_request('icx_getBalance', params) return int(remove_0x_prefix(result), 16) else: raise AddressException("Address is wrong.")
def get_balance(self, address: str, full_response: bool = False) -> Union[dict, int]: """ Returns the ICX balance of the given EOA or SCORE. Delegates to icx_getBalance RPC method. :param address: An address of EOA or SCORE. type(str) :param full_response: Boolean to check whether get naive dict or refined data from server :return: Number of ICX coins """ if is_score_address(address) or is_wallet_address(address): params = {'address': address} result = self.__provider.make_request('icx_getBalance', params, full_response) if full_response: return result else: return int(remove_0x_prefix(result), 16) else: raise AddressException("Address is wrong.")