def test_open_cyano_wallet(self):
     wm = WalletManager()
     cyano_path = os.path.join(os.path.dirname(__file__),
                               'cyano_wallet.json')
     wm.open_wallet(cyano_path, is_create=False)
     self.assertEqual(wm.__dict__['scheme'],
                      SignatureScheme.SHA256withECDSA)
     account = wm.get_account_by_b58_address(
         'ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6', '1234567890')
     self.assertTrue(isinstance(account, Account))
 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)
예제 #3
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()
root_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
wallet_path = os.path.join(root_folder, 'wallet', 'wallet.json')
contracts_folder = os.path.join(root_folder, 'contracts')
contracts_path = os.path.join(contracts_folder, 'interplanetary-album.abi.json')
with open(contracts_path) as f:
    contract_abi = json.loads(f.read())
    entry_point = contract_abi.get('entrypoint', '')
    functions = contract_abi['abi']['functions']
    events = contract_abi.get('events', list())
    abi_info = AbiInfo(contract_address_hex, entry_point, functions, events)
wallet_manager = WalletManager()
wallet_manager.open_wallet(wallet_path)
password = input('password: '******'AKeDu9QW6hfAhwpvCwNNwkEQt1LkUQpBpW', password)
ont_id_acct = wallet_manager.get_control_account_by_index('did:ont:AHBB3LQNpqXjCLathy7vTNgmQ1cGSj8S9Z', 0, password)


class TestSmartContract(unittest.TestCase):
    def test_put_one_item(self):
        ipfs_address = 'QmVwRs3tMPwi8vHqZXfxdgbcJXdmrgViGiy77o9ohef6ss'
        ext = '.jpg'
        put_one_item_func = abi_info.get_function('put_one_item')

        ipfs_address_bytes = ipfs_address.encode('ascii')
        aes_iv, encode_g_tilde, encrypted_ipfs_address = ECIES.encrypt_with_ont_id_in_cbc(ipfs_address_bytes,
                                                                                          ont_id_acct)
        ont_id_acct_bytes = ont_id_acct.get_address().to_array()
        put_one_item_func.set_params_value((ont_id_acct_bytes, encrypted_ipfs_address, ext, aes_iv, encode_g_tilde))
        tx_hash = ontology.neo_vm().send_transaction(contract_address_bytearray, ont_id_acct, acct, gas_limit,