Beispiel #1
0
    def test_submit_transaction_invoice_error(self, grpc_channel, executor,
                                              no_retry_client):
        tx_bytes = b'somebytes'
        future = executor.submit(no_retry_client.submit_solana_transaction,
                                 tx_bytes)

        tx_sig = b'somesig'
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.INVOICE_ERROR,
            signature=model_pb_v4.TransactionSignature(value=tx_sig),
            invoice_errors=[
                model_pb_v3.InvoiceError(
                    op_index=0,
                    invoice=model_pb_v3.Invoice(items=[
                        model_pb_v3.Invoice.LineItem(
                            title='title',
                            amount=10,
                        ),
                    ]),
                    reason=model_pb_v3.InvoiceError.Reason.ALREADY_PAID,
                ),
            ],
        )
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx_bytes

        result = future.result()
        assert result.tx_id == tx_sig
        assert not result.tx_error
        assert result.invoice_errors == resp.invoice_errors
Beispiel #2
0
    def test_submit_transaction_already_submitted(self, grpc_channel, executor,
                                                  retry_client):
        tx_bytes = b'somebytes'
        tx_sig = b'somesig'

        # Receive ALREADY_SUBMITTED on first attempt - should result in an error
        future = executor.submit(retry_client.submit_solana_transaction,
                                 tx_bytes)
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.ALREADY_SUBMITTED,
            signature=model_pb_v4.TransactionSignature(value=tx_sig))
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx_bytes

        with pytest.raises(AlreadySubmittedError):
            future.result()

        future = executor.submit(retry_client.submit_solana_transaction,
                                 tx_bytes)

        # Internal error first attempt: should retry
        md, req, rpc = grpc_channel.take_unary_unary(
            tx_pb_v4.DESCRIPTOR.services_by_name['Transaction'].
            methods_by_name['SubmitTransaction'])
        rpc.terminate(tx_pb_v4.SubmitTransactionResponse(), (),
                      grpc.StatusCode.INTERNAL, '')
        assert req.transaction.value == tx_bytes

        # ALREADY_SUBMITTED second attempt: should look like a success
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.ALREADY_SUBMITTED,
            signature=model_pb_v4.TransactionSignature(value=tx_sig))
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx_bytes

        result = future.result()
        assert result.tx_id == tx_sig
        assert not result.tx_error
        assert not result.invoice_errors
Beispiel #3
0
    def test_submit_transaction_payer_required(self, grpc_channel, executor,
                                               no_retry_client):
        tx = self._gen_tx()
        future = executor.submit(no_retry_client.submit_solana_transaction, tx)

        tx_sig = b'somesig'
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.PAYER_REQUIRED,
            signature=model_pb_v4.TransactionSignature(value=tx_sig))
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx.marshal()

        with pytest.raises(PayerRequiredError):
            future.result()
Beispiel #4
0
    def test_submit_transaction_rejected(self, grpc_channel, executor,
                                         no_retry_client):
        tx_bytes = b'somebytes'
        future = executor.submit(no_retry_client.submit_solana_transaction,
                                 tx_bytes)

        tx_sig = b'somesig'
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.REJECTED,
            signature=model_pb_v4.TransactionSignature(value=tx_sig))
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx_bytes

        with pytest.raises(TransactionRejectedError):
            future.result()
Beispiel #5
0
    def test_submit_transaction(self, grpc_channel, executor, no_retry_client):
        tx_bytes = b'somebytes'
        future = executor.submit(no_retry_client.submit_solana_transaction,
                                 tx_bytes)

        tx_sig = b'somesig'
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.OK,
            signature=model_pb_v4.TransactionSignature(value=tx_sig))
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx_bytes

        result = future.result()
        assert result.tx_id == tx_sig
        assert not result.tx_error
        assert not result.invoice_errors
Beispiel #6
0
    def test_submit_transaction(self, grpc_channel, executor, no_retry_client):
        tx = self._gen_tx()
        il = self._gen_invoice_list()
        future = executor.submit(no_retry_client.submit_solana_transaction, tx,
                                 il)

        tx_sig = b'somesig'
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.OK,
            signature=model_pb_v4.TransactionSignature(value=tx_sig))
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx.marshal()
        assert req.invoice_list == il.to_proto()

        result = future.result()
        assert result.tx_id == tx_sig
        assert not result.errors
        assert not result.invoice_errors
Beispiel #7
0
    def test_submit_transaction_failed(self, grpc_channel, executor,
                                       no_retry_client):
        tx_bytes = b'somebytes'
        future = executor.submit(no_retry_client.submit_solana_transaction,
                                 tx_bytes)

        tx_sig = b'somesig'
        resp = tx_pb_v4.SubmitTransactionResponse(
            result=tx_pb_v4.SubmitTransactionResponse.Result.FAILED,
            signature=model_pb_v4.TransactionSignature(value=tx_sig),
            transaction_error=model_pb_v4.TransactionError(
                reason=model_pb_v4.TransactionError.Reason.BAD_NONCE, ),
        )
        req = self._set_submit_transaction_resp(grpc_channel, resp)
        assert req.transaction.value == tx_bytes

        result = future.result()
        assert result.tx_id == tx_sig
        assert result.tx_error
        assert isinstance(result.tx_error.tx_error, BadNonceError)
        assert not result.tx_error.op_errors
        assert not result.invoice_errors