Ejemplo n.º 1
0
 def test_add_control_by_private_key(self):
     wm = WalletManager()
     wm.create_wallet_file(self.path)
     try:
         wm.open_wallet(self.path)
         private_key = utils.get_random_bytes(32)
         hex_private_key = private_key.hex()
         public_key = Signature.ec_get_public_key_by_private_key(
             private_key, Curve.P256)
         hex_public_key = public_key.hex()
         identity = wm.create_identity('label', password)
         wm.write_wallet()
         wm.add_control_by_hex_private_key(identity.ont_id, password,
                                           hex_private_key)
         ctrl_acct = wm.get_control_account_by_index(
             identity.ont_id, 1, password)
         acct_private_key = ctrl_acct.get_private_key_hex()
         acct_public_key = ctrl_acct.get_public_key_hex()
         self.assertEqual(hex_public_key, acct_public_key)
         self.assertEqual(hex_private_key, acct_private_key)
         ctrl_len_1 = len(wm.wallet_in_mem.identities[0].controls)
         ctrl_len_2 = len(wm.wallet_file.identities[0].controls)
         self.assertEqual(ctrl_len_1, ctrl_len_2 + 1)
     finally:
         wm.del_wallet_file()
Ejemplo n.º 2
0
 def test_open_wallet(self):
     wm = WalletManager()
     self.assertRaises(SDKException, wm.open_wallet)
     wm.create_wallet_file(self.path)
     try:
         wm.open_wallet(self.path)
         self.assertEqual(wm.__dict__['scheme'],
                          SignatureScheme.SHA256withECDSA)
     finally:
         wm.del_wallet_file()
Ejemplo n.º 3
0
 def test_create_identity_from_pri_key(self):
     wm = WalletManager()
     wm.create_wallet_file(self.path)
     try:
         wm.open_wallet(self.path)
         private_key = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
         ide = wm.create_identity_from_private_key("ide", "1", private_key)
         self.assertEqual(ide.label, 'ide')
         self.assertEqual(ide.ont_id,
                          'did:dna:AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve')
     finally:
         wm.del_wallet_file()
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
 def test_create_account_from_private_key(self):
     wm = WalletManager()
     wm.create_wallet_file(self.path)
     try:
         wm.open_wallet(self.path)
         private_key = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
         label = 'hello_account'
         account = wm.create_account_from_private_key(
             password, private_key, label)
         b58_address = 'AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve'
         wm.save()
         self.assertEqual(b58_address, account.b58_address)
     finally:
         wm.del_wallet_file()
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
 def test_import_account(self):
     wm = WalletManager(wallet_path=self.path)
     self.assertEqual(self.path, wm.wallet_path)
     wm.create_wallet_file()
     try:
         wm.open_wallet()
         label = 'label'
         b64_salt = 'MGEzY2Y0MWYyODhhOTQ3MA=='
         encrypted_pri_key = 'E6Yb/UmgAggwqHrj/OVYjVVacVhXiehRctKrxzVE/bi+tZId0AEN2wLoKsahpNq2'
         b58_address = 'AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve'
         account = wm.import_account(label, encrypted_pri_key, password,
                                     b58_address, b64_salt)
         acct = wm.get_account_by_b58_address(b58_address, password)
         self.assertTrue(isinstance(account, AccountData))
         self.assertTrue(isinstance(acct, Account))
         wm.save()
     finally:
         wm.del_wallet_file()
Ejemplo n.º 9
0
 def test_import_identity(self):
     wm = WalletManager()
     wm.create_wallet_file(self.path)
     wm.open_wallet(self.path)
     try:
         private_key = utils.get_random_hex_str(64)
         acct = Account(private_key)
         salt = utils.get_random_hex_str(16)
         scrypt_n = 16384
         encrypted_private_key = acct.export_gcm_encrypted_private_key(
             password, salt, scrypt_n)
         label = 'label'
         b58_address = acct.get_address_base58()
         wm.import_identity(label, encrypted_private_key, password, salt,
                            b58_address)
         identity = wm.get_default_identity()
         self.assertEqual(label, identity.label)
     finally:
         wm.del_wallet_file()
Ejemplo n.º 10
0
 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()
Ejemplo n.º 11
0
 def test_set_default_identity_by_index(self):
     wm = WalletManager()
     wm.create_wallet_file(self.path)
     try:
         wm.open_wallet(self.path)
         size = 3
         for i in range(size):
             private_key = utils.get_random_hex_str(64)
             wm.create_identity_from_private_key("ide", str(i), private_key)
         identities = wm.get_wallet().get_identities()
         self.assertEqual(len(identities), size)
         self.assertRaises(SDKException,
                           wm.get_wallet().set_default_identity_by_index,
                           size)
         for index in range(size):
             wm.get_wallet().set_default_identity_by_index(index)
             default_identity = wm.get_default_identity()
             self.assertEqual(identities[index], default_identity)
     finally:
         wm.del_wallet_file()
Ejemplo n.º 12
0
 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()
Ejemplo n.º 13
0
 def test_set_default_identity_by_ont_id(self):
     wm = WalletManager()
     wm.create_wallet_file(self.path)
     try:
         wm.open_wallet(self.path)
         size = 3
         for i in range(size):
             private_key = utils.get_random_hex_str(64)
             wm.create_identity_from_private_key("ide", str(i), private_key)
         identities = wm.get_wallet().get_identities()
         self.assertEqual(len(identities), size)
         self.assertRaises(SDKException,
                           wm.get_wallet().set_default_identity_by_ont_id,
                           '')
         ont_id_list = list()
         for identity in wm.get_wallet().identities:
             ont_id_list.append(identity.ont_id)
         for _ in range(size * 5):
             rand_ont_id = choice(ont_id_list)
             wm.get_wallet().set_default_identity_by_ont_id(rand_ont_id)
             default_identity = wm.get_default_identity()
             self.assertEqual(rand_ont_id, default_identity.ont_id)
     finally:
         wm.del_wallet_file()