def test_get_accounts(self): wm = WalletManager() wm.create_wallet_file(self.path) try: wm.open_wallet(self.path) size = 5 for _ in range(size): wm.create_account(password) accounts = wm.get_wallet().get_accounts() self.assertEqual(len(accounts), size) finally: wm.del_wallet_file()
def test_create_write(self): wm = WalletManager() wm.create_wallet_file(self.path) try: wm.open_wallet(self.path) random_password = utils.get_random_hex_str(10) label = 'label' wm.create_account(random_password, label) default_account = wm.get_default_account_data() self.assertEqual(label, default_account.label) wm.create_identity(random_password, label) default_identity = wm.get_default_identity() self.assertEqual(default_identity.label, label) wm.write_wallet() finally: wm.del_wallet_file()
def test_get_default_account(self): wm = WalletManager() wm.create_wallet_file(self.path) try: wm.open_wallet(self.path) size = 3 for _ in range(size): wm.create_account(password) accounts = wm.get_wallet().get_accounts() self.assertEqual(len(accounts), size) for acct in accounts: wm.get_wallet().set_default_account_by_address( acct.b58_address) default_account = wm.get_default_account_data() self.assertEqual(default_account.b58_address, acct.b58_address) finally: wm.del_wallet_file()
def test_set_default_account_by_index(self): wm = WalletManager() wm.create_wallet_file(self.path) try: wm.open_wallet(self.path) size = 3 for _ in range(size): wm.create_account(password) accounts = wm.get_wallet().get_accounts() self.assertEqual(len(accounts), size) self.assertRaises(SDKException, wm.get_wallet().set_default_account_by_index, size) for index in range(size): wm.get_wallet().set_default_account_by_index(index) default_address = wm.get_wallet().get_default_account_address() self.assertEqual(accounts[index].b58_address, default_address) finally: wm.del_wallet_file()
def test_deep_copy(self): wm = WalletManager() wm.create_wallet_file(self.path) try: wm.open_wallet(self.path) for index in range(5): wm.create_account(password, f'label{index}') wm.write_wallet() self.assertEqual(len(wm.wallet_file.identities), len(wm.wallet_in_mem.identities)) self.assertEqual(len(wm.wallet_file.accounts), len(wm.wallet_in_mem.accounts)) self.assertNotEqual(id(wm.wallet_file), id(wm.wallet_in_mem)) self.assertNotEqual(id(wm.wallet_file.identities), id(wm.wallet_in_mem.identities)) self.assertNotEqual(id(wm.wallet_file.accounts), id(wm.wallet_in_mem.accounts)) self.assertNotEqual(id(wm.wallet_file.scrypt), id(wm.wallet_in_mem.scrypt)) finally: wm.del_wallet_file()
def test_del_account_by_b58_address(self): wm = WalletManager() b58_addr_lst = list() count = 0 for _ in range(5): acct = wm.create_account(password) b58_addr_lst.append(acct.get_address_base58()) count += 1 self.assertEqual(count, wm.get_account_count()) for _ in range(5): wm.del_account_by_b58_address(b58_addr_lst.pop(-1)) wm.get_acct_data_list() count -= 1 self.assertEqual(count, wm.get_account_count())
def test_get_account(self): wallet_manager = WalletManager() acct0 = wallet_manager.create_account(password) self.assertTrue(isinstance(acct0, Account)) b58_address = wallet_manager.wallet_in_mem.default_account_address acct0 = wallet_manager.get_account_by_b58_address( b58_address, password) self.assertEqual(acct0.get_address_base58(), b58_address) self.assertRaises(SDKException, wallet_manager.get_account_by_b58_address, b58_address, 'wrong_password') base64_salt = 'S2JpQ1VyNTNDWlVmS0cxTTNHb2pqdz09' b58_address = 'AHX1wzvdw9Yipk7E9MuLY4GGX4Ym9tHeDe' encrypted_private_key = 'nw7qMrOEDsNurW3dKBruv3iNGeoZppSKe06QoqMZ9S8msoCvtn864rCSvAbgk1oS' label = 'label' acct1 = wallet_manager.import_account(label, encrypted_private_key, password, b58_address, base64_salt) self.assertEqual(b58_address, acct1.b58_address) import_acct = wallet_manager.get_account_by_b58_address( b58_address, password) self.assertEqual(b58_address, import_acct.get_address_base58()) self.assertEqual(base64_salt, acct1.salt)