def test_add_control_by_private_key(self): wm = WalletManager() wm.create_wallet_file(path) try: wm.open_wallet(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()
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, gas_price, put_one_item_func, False)