def test_refund_metadata(): txn_version = 12343 reason = diem_types.RefundReason__UserInitiatedFullRefund() ret = txnmetadata.refund_metadata(txn_version, reason) assert ret.hex() == "0400373000000000000003" metadata = diem_types.Metadata.bcs_deserialize(ret) assert metadata.value.value.transaction_version == txn_version assert metadata.value.value.reason == reason
def test_receive_payment_with_refund_metadata_and_invalid_transaction_version( stub_client: RestClient, target_client: RestClient, currency: str, hrp: str, stub_config: AppConfig, diem_client: jsonrpc.Client, invalid_refund_txn_version: int, ) -> None: """ When received a payment transaction with invalid refund metadata, it's up to wallet application to decide how to handle, this test makes sure the wallet application should be able to continue to receive following up valid payment transactions. Test Plan: 1. Generate a valid account identifier from receiver account as payee. 2. Submit payment transaction with refund metadata and invalid txn version. 3. Wait for the transaction executed successfully. 4. Send a valid payment to the account identifier. 5. Assert receiver account received the valid payment. """ amount = 120_000 sender_account = stub_client.create_account(balances={currency: amount}) receiver_account = target_client.create_account() try: receiver_account_identifier = receiver_account.generate_account_identifier( ) receiver_account_address = identifier.decode_account_address( receiver_account_identifier, hrp) reason = diem_types.RefundReason__OtherReason() metadata = txnmetadata.refund_metadata(invalid_refund_txn_version, reason) stub_config.account.submit_and_wait_for_txn( diem_client, stdlib.encode_peer_to_peer_with_metadata_script( currency=utils.currency_code(currency), amount=amount * 2, payee=receiver_account_address, metadata=metadata, metadata_signature=b"", ), ) assert receiver_account.balance(currency) == 0 pay = sender_account.send_payment(currency, amount, payee=receiver_account_identifier) wait_for_payment_transaction_complete(sender_account, pay.id) receiver_account.wait_for_balance(currency, amount) finally: receiver_account.log_events() sender_account.log_events()
def p2p_by_refund( self, currency: str, amount: int, receiver_vasp_address: str, original_txn_version: int, ) -> jsonrpc.Transaction: metadata = txnmetadata.refund_metadata( original_txn_version, diem_types.RefundReason__InvalidSubaddress()) return self._p2p_transfer(currency, amount, receiver_vasp_address, metadata, b"")
def test_receive_payment_with_refund_metadata_and_invalid_transaction_version( sender_account: AccountResource, receiver_account: AccountResource, currency: str, hrp: str, stub_config: AppConfig, diem_client: jsonrpc.Client, pending_income_account: AccountResource, invalid_refund_txn_version: int, ) -> None: """ When received a payment transaction with invalid refund metadata, it's up to wallet application to decide how to handle, this test makes sure the wallet application should be able to continue to receive following up valid payment transactions. Test Plan: 1. Generate a valid payment URI from receiver account. 2. Submit payment transaction with refund metadata and invalid txn version. 3. Wait for the transaction executed successfully. 4. Send a valid payment to the payment URI. 5. Assert receiver account received the valid payment. """ receiver_uri = receiver_account.generate_payment_uri() receiver_account_address: diem_types.AccountAddress = receiver_uri.intent( hrp).account_address reason = diem_types.RefundReason__OtherReason() metadata = txnmetadata.refund_metadata(invalid_refund_txn_version, reason) stub_config.account.submit_and_wait_for_txn( diem_client, stdlib.encode_peer_to_peer_with_metadata_script( currency=utils.currency_code(currency), amount=amount * 2, payee=receiver_account_address, metadata=metadata, metadata_signature=b"", ), ) assert receiver_account.balance(currency) == 0 pay = sender_account.send_payment( currency, amount, payee=receiver_uri.intent(hrp).account_id) wait_for_payment_transaction_complete(sender_account, pay.id) receiver_account.wait_for_balance(currency, amount)
def test_process_incoming_refund_txn() -> None: initial_sender_account = create_account("fake_account") initial_sender_subaddr = generate_new_subaddress(initial_sender_account.id) initial_sender_addr = "lrw_vasp" initial_receiver_addr = "46db232847705e05525db0336fd9f337" meta = refund_metadata( original_transaction_version=1, reason=diem_types.RefundReason__InvalidSubaddress(), ) initial_tx = storage.add_transaction( amount=500, currency=DiemCurrency.XUS, payment_type=TransactionType.EXTERNAL, status=TransactionStatus.COMPLETED, source_id=initial_sender_account.id, source_address=initial_sender_addr, source_subaddress=initial_sender_subaddr, destination_address=initial_receiver_addr, blockchain_version=1, ) assert initial_tx is not None assert initial_tx.blockchain_version == 1 assert storage.get_transaction_by_blockchain_version(1) is not None process_incoming_transaction( sender_address=initial_receiver_addr, receiver_address=initial_sender_addr, sequence=1, amount=500, currency=DiemCurrency.XUS, metadata=diem_types.Metadata__RefundMetadata.bcs_deserialize(meta), blockchain_version=2, ) tx = storage.get_transaction_by_blockchain_version(2) assert tx is not None assert tx.type == TransactionType.REFUND assert tx.original_txn_id == initial_tx.id
def refund_metadata(self, version: int, reason: RefundReason) -> Tuple[bytes, bytes]: return (txnmetadata.refund_metadata(version, reason.to_diem_type()), b"")
def test_refund_metadata(): txn_version = 12343 reason = diem_types.RefundReason__UserInitiatedFullRefund() ret = txnmetadata.refund_metadata(txn_version, reason) assert ret.hex() == "0400373000000000000003"