Skip to content

Commit

Permalink
Return error for Horizon.Problem in transaction_async request
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya1702 committed Aug 28, 2024
1 parent 83f648c commit 7910f1f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
17 changes: 16 additions & 1 deletion clients/horizonclient/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,25 @@ func decodeResponse(resp *http.Response, object interface{}, horizonUrl string,
}
setCurrentServerTime(u.Hostname(), resp.Header["Date"], clock)

if resp.Request == nil || resp.Request.URL == nil || resp.Request.URL.Path != "/transactions_async" {
horizonError := &Error{
Response: resp,
}
decodeError := decoder.Decode(&horizonError.Problem)
if decodeError != nil {
err = decoder.Decode(&object)
if err != nil {
return errors.Wrap(err, "error decoding response")
}
return
}
return horizonError
}

// While this part of code assumes that any error < 200 or error >= 300 is a Horizon problem, it is not
// true for the response from /transactions_async endpoint which does give these codes for certain responses
// from core.
if !(resp.StatusCode >= 200 && resp.StatusCode < 300) && (resp.Request == nil || resp.Request.URL == nil || resp.Request.URL.Path != "/transactions_async") {
if !(resp.StatusCode >= 200 && resp.StatusCode < 300) {
horizonError := &Error{
Response: resp,
}
Expand Down
27 changes: 27 additions & 0 deletions services/horizon/internal/integration/txsub_async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/protocols/horizon"
Expand Down Expand Up @@ -131,6 +132,32 @@ func TestAsyncTxSub_SubmissionTryAgainLater(t *testing.T) {
})
}

func TestAsyncTxSub_TransactionMalformed(t *testing.T) {
itest := integration.NewTest(t, integration.Config{
EnableSorobanRPC: true,
HorizonEnvironment: map[string]string{
"MAX_HTTP_REQUEST_SIZE": "1800",
},
})
master := itest.Master()

// establish which account will be contract owner, and load it's current seq
sourceAccount, err := itest.Client().AccountDetail(horizonclient.AccountRequest{
AccountID: itest.Master().Address(),
})
require.NoError(t, err)

installContractOp := assembleInstallContractCodeOp(t, itest.Master().Address(), "soroban_sac_test.wasm")
preFlightOp, minFee := itest.PreflightHostFunctions(&sourceAccount, *installContractOp)
txParams := integration.GetBaseTransactionParamsWithFee(&sourceAccount, minFee+txnbuild.MinBaseFee, &preFlightOp)
require.NoError(t, err)
_, err = itest.AsyncSubmitTransaction(master, txParams)
assert.EqualError(
t, err,
"horizon error: \"Transaction Malformed\" - check horizon.Error.Problem for more information",
)
}

func TestAsyncTxSub_GetOpenAPISpecResponse(t *testing.T) {
itest := integration.NewTest(t, integration.Config{})
res, err := http.Get(itest.AsyncTxSubOpenAPISpecURL())
Expand Down

0 comments on commit 7910f1f

Please sign in to comment.