def test_send_and_deserialize_request(factory): client = testnet.create_client() receiver_port = offchain.http_server.get_available_port() sender = testnet.gen_vasp_account(client, "http://localhost:8888") receiver = testnet.gen_vasp_account(client, f"http://localhost:{receiver_port}") sender_client = factory.create_offchain_client(sender, client) receiver_client = factory.create_offchain_client(receiver, client) def process_inbound_request(x_request_id: str, jws_key_address: str, content: bytes): command = receiver_client.process_inbound_request( jws_key_address, content) resp = offchain.reply_request(command.cid) return (200, offchain.jws.serialize(resp, receiver.compliance_key.sign)) offchain.http_server.start_local(receiver_port, process_inbound_request) payment = factory.new_payment_object(sender, receiver) command = offchain.PaymentCommand(payment=payment, my_actor_address=payment.sender.address, inbound=False) resp = sender_client.send_command(command, sender.compliance_key.sign) assert resp
def test_gen_vasp_account(): client = testnet.create_client() account = testnet.gen_vasp_account(client, "http://hello.com") child_vasp = testnet.gen_child_vasp(client, account) assert client.get_account( account.account_address).role.type == "parent_vasp" assert client.get_account( child_vasp.account_address).role.type == "child_vasp"
def test_get_account_transaction_include_events(): client = testnet.create_client() account = testnet.gen_vasp_account(client, "http://baseurl") txn = client.get_account_transaction(account.account_address, 0, include_events=True) assert txn is not None assert isinstance(txn, jsonrpc.Transaction) assert len(txn.events) > 0
def generate(name: str, client: jsonrpc.Client) -> "WalletApp": """generate a WalletApp running on testnet""" offchain_service_port = offchain.http_server.get_available_port() account = testnet.gen_vasp_account(client, f"http://localhost:{offchain_service_port}") w = WalletApp( name=name, jsonrpc_client=client, parent_vasp=account, offchain_service_port=offchain_service_port, ) w.add_child_vasp() return w
def test_get_base_url_and_compliance_key(): client = testnet.create_client() parent_vasp = testnet.gen_vasp_account(client, "http://hello.com") child_vasp = testnet.gen_child_vasp(client, parent_vasp) base_url, key = client.get_base_url_and_compliance_key( child_vasp.account_address) assert base_url == "http://hello.com" assert utils.public_key_bytes( key) == parent_vasp.compliance_public_key_bytes base_url, key = client.get_base_url_and_compliance_key( parent_vasp.account_address) assert base_url == "http://hello.com" assert utils.public_key_bytes( key) == parent_vasp.compliance_public_key_bytes
def test_get_account_transactions_with_events(): client = testnet.create_client() account = testnet.gen_vasp_account(client, "url") txns = client.get_account_transactions(account.account_address, 0, 1, include_events=True) assert txns is not None assert isinstance(txns, list) txn = txns[0] assert isinstance(txn, jsonrpc.Transaction) assert len(txn.events) > 0 script_call = utils.decode_transaction_script(txn) assert type( script_call).__name__ == "ScriptCall__RotateDualAttestationInfo" assert script_call.new_url == b"url"