def test_process_response_strict_send_success(client): """ Tests successful processing of the SUCCESS_PAYMENT_TRANSACTION_JSON """ asset = Asset.objects.create( code="TEST", issuer=TEST_ASSET_ISSUER_PUBLIC_KEY, distribution_seed=TEST_ASSET_DISTRIBUTION_SEED, ) transaction = Transaction.objects.create( asset=asset, stellar_account=Keypair.random().public_key, amount_in=1001, kind=Transaction.KIND.send, status=Transaction.STATUS.pending_sender, memo=SUCCESS_STRICT_SEND_PAYMENT["memo"], protocol=Transaction.PROTOCOL.sep31, receiving_anchor_account=TEST_ASSET_DISTRIBUTION_PUBLIC_KEY, ) json = deepcopy(SUCCESS_STRICT_SEND_PAYMENT) Command.process_response(json, TEST_ASSET_DISTRIBUTION_PUBLIC_KEY) transaction.refresh_from_db() assert transaction.from_address assert transaction.stellar_transaction_id assert transaction.paging_token assert transaction.status == Transaction.STATUS.pending_receiver assert transaction.amount_in == 1001
def test_process_response_success(mock_withdrawal, mock_xdr, client, acc1_usd_withdrawal_transaction_factory): del mock_withdrawal, mock_xdr transaction = acc1_usd_withdrawal_transaction_factory() json = deepcopy(TRANSACTION_JSON) json["successful"] = True json["id"] = transaction.id json["memo"] = format_memo_horizon(transaction.withdraw_memo) Command.process_response(json) transaction.refresh_from_db() assert transaction.status == Transaction.STATUS.completed
def test_withdraw_interactive_success_transaction_successful( mock_check, client, acc1_usd_withdrawal_transaction_factory): """ `GET /transactions/withdraw/webapp` changes transaction to `completed` with successful transaction. """ del mock_check acc1_usd_withdrawal_transaction_factory() response = client.post(WITHDRAW_PATH, {"asset_code": "USD"}, follow=True) content = json.loads(response.content) assert content["type"] == "interactive_customer_info_needed" transaction_id = content["id"] url = content["url"] response = client.get(url) assert response.status_code == 200 assert client.session["authenticated"] is True url, args_str = url.split("?") response = client.post( url + "/submit?" + args_str, { "amount": 50, "bank_account": "123456", "bank": "Bank", "account": "Account" }, ) assert response.status_code == 302 transaction = Transaction.objects.get(id=transaction_id) assert transaction.status == Transaction.STATUS.pending_user_transfer_start withdraw_memo = transaction.withdraw_memo mock_response = { "memo_type": "hash", "memo": format_memo_horizon(withdraw_memo), "successful": True, "id": "c5e8ada72c0e3c248ac7e1ec0ec97e204c06c295113eedbe632020cd6dc29ff8", "envelope_xdr": "AAAAAEU1B1qeJrucdqkbk1mJsnuFaNORfrOAzJyaAy1yzW8TAAAAZAAE2s4AAAABAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAoUKq+1Z2GGB98qurLSmocHafvG6S+YzKNE6oiHIXo6kAAAABVVNEAAAAAACnUE2lfwuFZ+G+dkc+qiL0MwxB0CoR0au324j+JC9exQAAAAAdzWUAAAAAAAAAAAA=", } Command.update_transaction(mock_response, transaction) assert transaction.status == Transaction.STATUS.completed assert transaction.completed_at
def test_process_response_unsuccessful( mock_xdr, client, acc1_usd_withdrawal_transaction_factory): del mock_xdr mock_source_account = mock_envelope.transaction.source.public_key transaction = acc1_usd_withdrawal_transaction_factory(mock_source_account) json = deepcopy(TRANSACTION_JSON) json["successful"] = False json["id"] = transaction.id json["memo"] = transaction.memo Command.process_response(json, None) transaction.refresh_from_db() # the response from horizon should be skipped if unsuccessful assert transaction.status == Transaction.STATUS.pending_user_transfer_start
def test_process_response_unsuccessful( mock_xdr, client, acc1_usd_withdrawal_transaction_factory): del mock_xdr transaction = acc1_usd_withdrawal_transaction_factory() json = deepcopy(TRANSACTION_JSON) json["successful"] = False json["id"] = transaction.id json["memo"] = format_memo_horizon(transaction.withdraw_memo) Command.process_response(json) transaction.refresh_from_db() assert transaction.status == Transaction.STATUS.error assert (transaction.status_message == "The transaction failed to execute on the Stellar network")
def test_process_response_success(mock_xdr, client, acc1_usd_withdrawal_transaction_factory): del mock_xdr mock_source_account = mock_envelope.transaction.source.public_key transaction = acc1_usd_withdrawal_transaction_factory(mock_source_account) json = deepcopy(TRANSACTION_JSON) json["successful"] = True json["id"] = transaction.id json["memo"] = transaction.memo Command.process_response(json, None) transaction.refresh_from_db() assert transaction.from_address assert transaction.stellar_transaction_id assert transaction.status_eta == 0 assert transaction.paging_token assert transaction.status == Transaction.STATUS.pending_anchor
def test_match_with_no_amount(mock_xdr, client, acc1_usd_withdrawal_transaction_factory): del mock_xdr mock_source_account = mock_envelope.transaction.source.public_key transaction = acc1_usd_withdrawal_transaction_factory(mock_source_account) transaction.protocol = Transaction.PROTOCOL.sep6 transaction.amount_in = None transaction.save() json = deepcopy(TRANSACTION_JSON) json["successful"] = True json["id"] = transaction.id json["memo"] = transaction.memo Command.process_response(json, None) transaction.refresh_from_db() assert transaction.status == Transaction.STATUS.pending_anchor assert transaction.amount_in == 50
def test_process_response_unsuccessful(client, acc1_usd_withdrawal_transaction_factory): json = {"successful": False} try: Command.process_response(json, None) except KeyError: assert False, "process_response() did not return for unsuccessful transaction"