Exemple #1
0
 def import_account(project_path, private_key):
     wallet_path_dir = os.path.join(project_path, 'wallet')
     # TODO: the file name 'wallet.json' should be custom defined here
     wallet_path = os.path.join(wallet_path_dir, 'wallet.json')
     if not os.path.exists(wallet_path):
         os.makedirs(wallet_path_dir)
     wallet_manager = WalletManager()
     wallet_manager.open_wallet(wallet_path)
     pwd = Account.get_password()
     try:
         wallet_manager.create_account_from_private_key('', pwd, private_key)
         wallet_manager.write_wallet()
     except ValueError as e:
         print('import account error:')
         print(e.args)
 def test_create_account_from_private_key(self):
     wm = WalletManager()
     path = os.path.join(os.getcwd(), 'test.json')
     wm.open_wallet(path)
     private_key = '75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf'
     label = 'hello_account'
     password = '******'
     account = wm.create_account_from_private_key(label, password,
                                                  private_key)
     wm.save()
     self.assertEqual(account.get_address(),
                      'AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve')
     os.remove(path)
 def test_create_account_from_private_key(self):
     wm = WalletManager()
     wm.create_wallet_file(path)
     try:
         wm.open_wallet(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()