From 4203a0b979610539221fa732638d79fd55d3ee3e Mon Sep 17 00:00:00 2001 From: Prit Sheth <124409873+psheth9@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:02:12 -0700 Subject: [PATCH] Fix lint error in /methods and remove usage of internal error package (#285) * Replace internal error package * Replace internal error package in getEvents * remove nolint * go fmt * Fix lint pt1 * Fix lint pt2 * Fix lint pt3 - remove global var in getEvents * Fix lint pt4 --- .../internal/integrationtest/metrics_test.go | 3 +- .../internal/methods/get_events.go | 22 ++--- .../internal/methods/get_events_test.go | 84 +++++++++---------- .../internal/methods/get_ledger_entry.go | 6 +- .../internal/methods/get_transactions_test.go | 4 +- .../internal/methods/handler_test.go | 21 ++--- .../internal/methods/simulate_transaction.go | 24 ++++-- cmd/soroban-rpc/internal/methods/util_test.go | 6 +- 8 files changed, 88 insertions(+), 82 deletions(-) diff --git a/cmd/soroban-rpc/internal/integrationtest/metrics_test.go b/cmd/soroban-rpc/internal/integrationtest/metrics_test.go index 930a6ed8..59c148ab 100644 --- a/cmd/soroban-rpc/internal/integrationtest/metrics_test.go +++ b/cmd/soroban-rpc/internal/integrationtest/metrics_test.go @@ -8,12 +8,11 @@ import ( "runtime" "testing" + "github.com/pkg/errors" io_prometheus_client "github.com/prometheus/client_model/go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/stellar/go/support/errors" - "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config" "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/integrationtest/infrastructure" ) diff --git a/cmd/soroban-rpc/internal/methods/get_events.go b/cmd/soroban-rpc/internal/methods/get_events.go index 36aefcdb..48290fb7 100644 --- a/cmd/soroban-rpc/internal/methods/get_events.go +++ b/cmd/soroban-rpc/internal/methods/get_events.go @@ -8,10 +8,10 @@ import ( "time" "github.com/creachadair/jrpc2" + "github.com/pkg/errors" "github.com/stellar/go/strkey" "github.com/stellar/go/support/collections/set" - "github.com/stellar/go/support/errors" "github.com/stellar/go/support/log" "github.com/stellar/go/xdr" @@ -80,7 +80,7 @@ func (e eventTypeSet) matches(event xdr.ContractEvent) bool { if len(e) == 0 { return true } - _, ok := e[eventTypeFromXDR[event.Type]] + _, ok := e[getEventTypeFromEventTypeXDR()[event.Type]] return ok } @@ -119,7 +119,7 @@ func (g *GetEventsRequest) Valid(maxLimit uint) error { // Validate the paging limit (if it exists) if g.Pagination != nil && g.Pagination.Cursor != nil { if g.StartLedger != 0 || g.EndLedger != 0 { - return errors.New("ledger ranges and cursor cannot both be set") //nolint:forbidigo + return errors.New("ledger ranges and cursor cannot both be set") } } else if g.StartLedger <= 0 { return errors.New("startLedger must be positive") @@ -160,10 +160,12 @@ const ( EventTypeDiagnostic = "diagnostic" ) -var eventTypeFromXDR = map[xdr.ContractEventType]string{ - xdr.ContractEventTypeSystem: EventTypeSystem, - xdr.ContractEventTypeContract: EventTypeContract, - xdr.ContractEventTypeDiagnostic: EventTypeDiagnostic, +func getEventTypeFromEventTypeXDR() map[xdr.ContractEventType]string { + return map[xdr.ContractEventType]string{ + xdr.ContractEventTypeSystem: EventTypeSystem, + xdr.ContractEventTypeContract: EventTypeContract, + xdr.ContractEventTypeDiagnostic: EventTypeDiagnostic, + } } func getEventTypeXDRFromEventType() map[string]xdr.ContractEventType { @@ -523,7 +525,7 @@ func eventInfoForEvent( return EventInfo{}, errors.New("unknown event version") } - eventType, ok := eventTypeFromXDR[event.Event.Type] + eventType, ok := getEventTypeFromEventTypeXDR()[event.Event.Type] if !ok { return EventInfo{}, fmt.Errorf("unknown XDR ContractEventType type: %d", event.Event.Type) } @@ -600,7 +602,5 @@ func NewGetEventsHandler( logger: logger, ledgerReader: ledgerReader, } - return NewHandler(func(ctx context.Context, request GetEventsRequest) (GetEventsResponse, error) { - return eventsHandler.getEvents(ctx, request) - }) + return NewHandler(eventsHandler.getEvents) } diff --git a/cmd/soroban-rpc/internal/methods/get_events_test.go b/cmd/soroban-rpc/internal/methods/get_events_test.go index 44692304..a7373287 100644 --- a/cmd/soroban-rpc/internal/methods/get_events_test.go +++ b/cmd/soroban-rpc/internal/methods/get_events_test.go @@ -158,7 +158,7 @@ func TestEventTypeSetValid(t *testing.T) { if testCase.expectedError { assert.Error(t, set.valid()) } else { - assert.NoError(t, set.valid()) + require.NoError(t, set.valid()) } }) } @@ -189,9 +189,9 @@ func TestEventTypeSetMarshaling(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { var set eventTypeSet input, err := json.Marshal(testCase.input) - assert.NoError(t, err) + require.NoError(t, err) err = set.UnmarshalJSON(input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, len(testCase.expected), len(set)) for _, val := range testCase.expected { _, ok := set[val] @@ -369,18 +369,18 @@ func TestTopicFilterMatches(t *testing.T) { func TestTopicFilterJSON(t *testing.T) { var got TopicFilter - assert.NoError(t, json.Unmarshal([]byte("[]"), &got)) + require.NoError(t, json.Unmarshal([]byte("[]"), &got)) assert.Equal(t, TopicFilter{}, got) star := "*" - assert.NoError(t, json.Unmarshal([]byte("[\"*\"]"), &got)) + require.NoError(t, json.Unmarshal([]byte("[\"*\"]"), &got)) assert.Equal(t, TopicFilter{{wildcard: &star}}, got) sixtyfour := xdr.Uint64(64) scval := xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &sixtyfour} scvalstr, err := xdr.MarshalBase64(scval) - assert.NoError(t, err) - assert.NoError(t, json.Unmarshal([]byte(fmt.Sprintf("[%q]", scvalstr)), &got)) + require.NoError(t, err) + require.NoError(t, json.Unmarshal([]byte(fmt.Sprintf("[%q]", scvalstr)), &got)) assert.Equal(t, TopicFilter{{scval: &scval}}, got) } @@ -408,38 +408,38 @@ func topicFilterToString(t TopicFilter) string { func TestGetEventsRequestValid(t *testing.T) { // omit startLedger but include cursor var request GetEventsRequest - assert.NoError(t, json.Unmarshal( + require.NoError(t, json.Unmarshal( []byte("{ \"filters\": [], \"pagination\": { \"cursor\": \"0000000021474840576-0000000000\"} }"), &request, )) assert.Equal(t, uint32(0), request.StartLedger) - assert.NoError(t, request.Valid(1000)) + require.NoError(t, request.Valid(1000)) - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{}, Pagination: &PaginationOptions{Cursor: &db.Cursor{}}, }).Valid(1000), "ledger ranges and cursor cannot both be set") - assert.NoError(t, (&GetEventsRequest{ + require.NoError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{}, Pagination: nil, }).Valid(1000)) - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{}, Pagination: &PaginationOptions{Limit: 1001}, }).Valid(1000), "limit must not exceed 1000") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 0, Filters: []EventFilter{}, Pagination: nil, }).Valid(1000), "startLedger must be positive") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ {}, {}, {}, {}, {}, {}, @@ -447,7 +447,7 @@ func TestGetEventsRequestValid(t *testing.T) { Pagination: nil, }).Valid(1000), "maximum 5 filters per request") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ {EventType: map[string]interface{}{"foo": nil}}, @@ -455,7 +455,7 @@ func TestGetEventsRequestValid(t *testing.T) { Pagination: nil, }).Valid(1000), "filter 1 invalid: filter type invalid: if set, type must be either 'system', 'contract' or 'diagnostic'") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ {ContractIDs: []string{ @@ -470,7 +470,7 @@ func TestGetEventsRequestValid(t *testing.T) { Pagination: nil, }).Valid(1000), "filter 1 invalid: maximum 5 contract IDs per filter") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ {ContractIDs: []string{"a"}}, @@ -478,7 +478,7 @@ func TestGetEventsRequestValid(t *testing.T) { Pagination: nil, }).Valid(1000), "filter 1 invalid: contract ID 1 invalid") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ {ContractIDs: []string{"CCVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVINVALID"}}, @@ -486,7 +486,7 @@ func TestGetEventsRequestValid(t *testing.T) { Pagination: nil, }).Valid(1000), "filter 1 invalid: contract ID 1 invalid") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ { @@ -498,7 +498,7 @@ func TestGetEventsRequestValid(t *testing.T) { Pagination: nil, }).Valid(1000), "filter 1 invalid: maximum 5 topics per filter") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ {Topics: []TopicFilter{ @@ -508,7 +508,7 @@ func TestGetEventsRequestValid(t *testing.T) { Pagination: nil, }).Valid(1000), "filter 1 invalid: topic 1 invalid: topic must have at least one segment") - assert.EqualError(t, (&GetEventsRequest{ + require.EqualError(t, (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ {Topics: []TopicFilter{ @@ -530,7 +530,7 @@ func TestGetEvents(t *testing.T) { counter := xdr.ScSymbol("COUNTER") counterScVal := xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &counter} counterXdr, err := xdr.MarshalBase64(counterScVal) - assert.NoError(t, err) + require.NoError(t, err) t.Run("startLedger validation", func(t *testing.T) { contractID := xdr.Hash([32]byte{}) @@ -562,7 +562,7 @@ func TestGetEvents(t *testing.T) { ledgerCloseMeta := ledgerCloseMetaWithEvents(2, now.Unix(), txMeta...) require.NoError(t, ledgerW.InsertLedger(ledgerCloseMeta), "ingestion failed for ledger ") - assert.NoError(t, eventW.InsertEvents(ledgerCloseMeta)) + require.NoError(t, eventW.InsertEvents(ledgerCloseMeta)) require.NoError(t, write.Commit(ledgerCloseMeta)) handler := eventsRPCHandler{ @@ -615,7 +615,7 @@ func TestGetEvents(t *testing.T) { ledgerCloseMeta := ledgerCloseMetaWithEvents(1, now.Unix(), txMeta...) require.NoError(t, ledgerW.InsertLedger(ledgerCloseMeta), "ingestion failed for ledger ") - assert.NoError(t, eventW.InsertEvents(ledgerCloseMeta)) + require.NoError(t, eventW.InsertEvents(ledgerCloseMeta)) require.NoError(t, write.Commit(ledgerCloseMeta)) handler := eventsRPCHandler{ @@ -627,7 +627,7 @@ func TestGetEvents(t *testing.T) { results, err := handler.getEvents(context.TODO(), GetEventsRequest{ StartLedger: 1, }) - assert.NoError(t, err) + require.NoError(t, err) var expected []EventInfo for i := range txMeta { @@ -641,7 +641,7 @@ func TestGetEvents(t *testing.T) { Type: xdr.ScValTypeScvSymbol, Sym: &counter, }) - assert.NoError(t, err) + require.NoError(t, err) expected = append(expected, EventInfo{ EventType: EventTypeContract, Ledger: 1, @@ -676,7 +676,7 @@ func TestGetEvents(t *testing.T) { xdr.Hash([32]byte{}), xdr.Hash([32]byte{1}), } - for i := 0; i < 5; i++ { + for i := range 5 { txMeta = append(txMeta, transactionMetaWithEvents( contractEvent( contractIDs[i%len(contractIDs)], @@ -709,7 +709,7 @@ func TestGetEvents(t *testing.T) { {ContractIDs: []string{strkey.MustEncode(strkey.VersionByteContract, contractIDs[0][:])}}, }, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, uint32(1), results.LatestLedger) expectedIds := []string{ @@ -777,16 +777,16 @@ func TestGetEvents(t *testing.T) { }}, }, }) - assert.NoError(t, err) + require.NoError(t, err) id := db.Cursor{Ledger: 1, Tx: 5, Op: 0, Event: 0}.String() - assert.NoError(t, err) + require.NoError(t, err) scVal := xdr.ScVal{ Type: xdr.ScValTypeScvU64, U64: &number, } value, err := xdr.MarshalBase64(scVal) - assert.NoError(t, err) + require.NoError(t, err) expected := []EventInfo{ { EventType: EventTypeContract, @@ -924,14 +924,14 @@ func TestGetEvents(t *testing.T) { }, }, }) - assert.NoError(t, err) + require.NoError(t, err) id := db.Cursor{Ledger: 1, Tx: 4, Op: 0, Event: 0}.String() value, err := xdr.MarshalBase64(xdr.ScVal{ Type: xdr.ScValTypeScvU64, U64: &number, }) - assert.NoError(t, err) + require.NoError(t, err) expected := []EventInfo{ { EventType: EventTypeContract, @@ -1004,7 +1004,7 @@ func TestGetEvents(t *testing.T) { {EventType: map[string]interface{}{EventTypeSystem: nil}}, }, }) - assert.NoError(t, err) + require.NoError(t, err) id := db.Cursor{Ledger: 1, Tx: 1, Op: 0, Event: 1}.String() expected := []EventInfo{ @@ -1039,7 +1039,7 @@ func TestGetEvents(t *testing.T) { contractID := xdr.Hash([32]byte{}) var txMeta []xdr.TransactionMeta - for i := 0; i < 180; i++ { + for i := range 180 { number := xdr.Uint64(i) txMeta = append(txMeta, transactionMetaWithEvents( contractEvent( @@ -1067,10 +1067,10 @@ func TestGetEvents(t *testing.T) { Filters: []EventFilter{}, Pagination: &PaginationOptions{Limit: 10}, }) - assert.NoError(t, err) + require.NoError(t, err) var expected []EventInfo - for i := 0; i < 10; i++ { + for i := range 10 { id := db.Cursor{ Ledger: 1, Tx: uint32(i + 1), @@ -1078,7 +1078,7 @@ func TestGetEvents(t *testing.T) { Event: 0, }.String() value, err := xdr.MarshalBase64(txMeta[i].MustV3().SorobanMeta.Events[0].Body.MustV0().Data) - assert.NoError(t, err) + require.NoError(t, err) expected = append(expected, EventInfo{ EventType: EventTypeContract, Ledger: 1, @@ -1168,7 +1168,7 @@ func TestGetEvents(t *testing.T) { Limit: 2, }, }) - assert.NoError(t, err) + require.NoError(t, err) var expected []EventInfo expectedIDs := []string{ @@ -1178,7 +1178,7 @@ func TestGetEvents(t *testing.T) { symbols := datas[1:3] for i, id := range expectedIDs { expectedXdr, err := xdr.MarshalBase64(xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &symbols[i]}) - assert.NoError(t, err) + require.NoError(t, err) expected = append(expected, EventInfo{ EventType: EventTypeContract, Ledger: 5, @@ -1200,7 +1200,7 @@ func TestGetEvents(t *testing.T) { Limit: 2, }, }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, GetEventsResponse{[]EventInfo{}, 5}, results) }) } @@ -1427,7 +1427,7 @@ func newTestDB(tb testing.TB) *db.DB { db, err := db.OpenSQLiteDB(dbPath) require.NoError(tb, err) tb.Cleanup(func() { - assert.NoError(tb, db.Close()) + require.NoError(tb, db.Close()) }) return db } diff --git a/cmd/soroban-rpc/internal/methods/get_ledger_entry.go b/cmd/soroban-rpc/internal/methods/get_ledger_entry.go index 7e87217a..24186c31 100644 --- a/cmd/soroban-rpc/internal/methods/get_ledger_entry.go +++ b/cmd/soroban-rpc/internal/methods/get_ledger_entry.go @@ -14,14 +14,14 @@ import ( "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/xdr2json" ) -// Deprecated. Use GetLedgerEntriesRequest instead. +// GetLedgerEntryRequest Deprecated: Use GetLedgerEntriesRequest instead. // TODO(https://github.com/stellar/soroban-tools/issues/374) remove after getLedgerEntries is deployed. type GetLedgerEntryRequest struct { Key string `json:"key"` Format string `json:"xdrFormat"` } -// Deprecated. Use GetLedgerEntriesResponse instead. +// GetLedgerEntryResponse Deprecated: Use GetLedgerEntriesResponse instead. // TODO(https://github.com/stellar/soroban-tools/issues/374) remove after getLedgerEntries is deployed. type GetLedgerEntryResponse struct { EntryXDR string `json:"xdr"` @@ -35,7 +35,7 @@ type GetLedgerEntryResponse struct { } // NewGetLedgerEntryHandler returns a json rpc handler to retrieve the specified ledger entry from stellar core -// Deprecated. use NewGetLedgerEntriesHandler instead. +// Deprecated: use NewGetLedgerEntriesHandler instead // TODO(https://github.com/stellar/soroban-tools/issues/374) remove after getLedgerEntries is deployed. func NewGetLedgerEntryHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntryReader) jrpc2.Handler { return NewHandler(func(ctx context.Context, request GetLedgerEntryRequest) (GetLedgerEntryResponse, error) { diff --git a/cmd/soroban-rpc/internal/methods/get_transactions_test.go b/cmd/soroban-rpc/internal/methods/get_transactions_test.go index 86304147..5a90202f 100644 --- a/cmd/soroban-rpc/internal/methods/get_transactions_test.go +++ b/cmd/soroban-rpc/internal/methods/get_transactions_test.go @@ -69,7 +69,7 @@ func TestGetTransactions_DefaultLimit(t *testing.T) { assert.Equal(t, toid.New(5, 2, 1).String(), response.Cursor) // assert transactions result - assert.Equal(t, 10, len(response.Transactions)) + assert.Len(t, response.Transactions, 10) } func TestGetTransactions_DefaultLimitExceedsLatestLedger(t *testing.T) { @@ -179,7 +179,7 @@ func TestGetTransactions_CustomLimitAndCursor(t *testing.T) { assert.Equal(t, toid.New(3, 1, 1).String(), response.Cursor) // assert transactions result - assert.Equal(t, 3, len(response.Transactions)) + assert.Len(t, response.Transactions, 3) assert.Equal(t, uint32(2), response.Transactions[0].Ledger) assert.Equal(t, uint32(2), response.Transactions[1].Ledger) assert.Equal(t, uint32(3), response.Transactions[2].Ledger) diff --git a/cmd/soroban-rpc/internal/methods/handler_test.go b/cmd/soroban-rpc/internal/methods/handler_test.go index 564f7f51..aba88d4e 100644 --- a/cmd/soroban-rpc/internal/methods/handler_test.go +++ b/cmd/soroban-rpc/internal/methods/handler_test.go @@ -7,6 +7,7 @@ import ( "github.com/creachadair/jrpc2" "github.com/creachadair/jrpc2/handler" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type Request struct { @@ -15,7 +16,7 @@ type Request struct { func TestNewHandlerNoArrayParameters(t *testing.T) { callCount := 0 - f := func(ctx context.Context, request Request) error { + f := func(_ context.Context, request Request) error { callCount++ assert.Equal(t, "bar", request.Parameter) return nil @@ -27,15 +28,15 @@ func TestNewHandlerNoArrayParameters(t *testing.T) { "params": { "parameter": "bar" } }` requests, err := jrpc2.ParseRequests([]byte(objectRequest)) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, requests, 1) finalObjectRequest := requests[0].ToRequest() // object parameters should work with our handlers customHandler := NewHandler(f) _, err = customHandler(context.Background(), finalObjectRequest) - assert.NoError(t, err) - assert.Equal(t, 1, callCount) + require.NoError(t, err) + require.Equal(t, 1, callCount) arrayRequest := `{ "jsonrpc": "2.0", @@ -44,17 +45,17 @@ func TestNewHandlerNoArrayParameters(t *testing.T) { "params": ["bar"] }` requests, err = jrpc2.ParseRequests([]byte(arrayRequest)) - assert.NoError(t, err) - assert.Len(t, requests, 1) + require.NoError(t, err) + require.Len(t, requests, 1) finalArrayRequest := requests[0].ToRequest() // Array requests should work with the normal handler, but not with our handlers stdHandler := handler.New(f) _, err = stdHandler(context.Background(), finalArrayRequest) - assert.NoError(t, err) - assert.Equal(t, 2, callCount) + require.NoError(t, err) + require.Equal(t, 2, callCount) _, err = customHandler(context.Background(), finalArrayRequest) - assert.Error(t, err) - assert.Contains(t, err.Error(), "invalid parameters") + require.Error(t, err) + require.Contains(t, err.Error(), "invalid parameters") } diff --git a/cmd/soroban-rpc/internal/methods/simulate_transaction.go b/cmd/soroban-rpc/internal/methods/simulate_transaction.go index 8d0a5fe4..b4a332ce 100644 --- a/cmd/soroban-rpc/internal/methods/simulate_transaction.go +++ b/cmd/soroban-rpc/internal/methods/simulate_transaction.go @@ -30,7 +30,8 @@ type SimulateTransactionCost struct { MemoryBytes uint64 `json:"memBytes,string"` } -// SimulateHostFunctionResult contains the simulation result of each HostFunction within the single InvokeHostFunctionOp allowed in a Transaction +// SimulateHostFunctionResult contains the simulation result of each HostFunction +// within the single InvokeHostFunctionOp allowed in a Transaction type SimulateHostFunctionResult struct { AuthXDR []string `json:"auth,omitempty"` AuthJSON []json.RawMessage `json:"authJson,omitempty"` @@ -213,12 +214,16 @@ type SimulateTransactionResponse struct { EventsXDR []string `json:"events,omitempty"` // DiagnosticEvent XDR in base64 EventsJSON []json.RawMessage `json:"eventsJson,omitempty"` - MinResourceFee int64 `json:"minResourceFee,string,omitempty"` - Results []SimulateHostFunctionResult `json:"results,omitempty"` // an array of the individual host function call results - Cost SimulateTransactionCost `json:"cost,omitempty"` // the effective cpu and memory cost of the invoked transaction execution. - RestorePreamble *RestorePreamble `json:"restorePreamble,omitempty"` // If present, it indicates that a prior RestoreFootprint is required - StateChanges []LedgerEntryChange `json:"stateChanges,omitempty"` // If present, it indicates how the state (ledger entries) will change as a result of the transaction execution. - LatestLedger uint32 `json:"latestLedger"` + MinResourceFee int64 `json:"minResourceFee,string,omitempty"` + // an array of the individual host function call results + Results []SimulateHostFunctionResult `json:"results,omitempty"` + // the effective cpu and memory cost of the invoked transaction execution. + Cost SimulateTransactionCost `json:"cost,omitempty"` + // If present, it indicates that a prior RestoreFootprint is required + RestorePreamble *RestorePreamble `json:"restorePreamble,omitempty"` + // If present, it indicates how the state (ledger entries) will change as a result of the transaction execution. + StateChanges []LedgerEntryChange `json:"stateChanges,omitempty"` + LatestLedger uint32 `json:"latestLedger"` } type PreflightGetter interface { @@ -260,7 +265,8 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge case xdr.OperationTypeExtendFootprintTtl, xdr.OperationTypeRestoreFootprint: if txEnvelope.Type != xdr.EnvelopeTypeEnvelopeTypeTx && txEnvelope.V1.Tx.Ext.V != 1 { return SimulateTransactionResponse{ - Error: "To perform a SimulateTransaction for ExtendFootprintTtl or RestoreFootprint operations, SorobanTransactionData must be provided", + Error: "To perform a SimulateTransaction for ExtendFootprintTtl or RestoreFootprint operations," + + " SorobanTransactionData must be provided", } } footprint = txEnvelope.V1.Tx.Ext.SorobanData.Resources.Footprint @@ -374,7 +380,7 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge } stateChanges := make([]LedgerEntryChange, len(result.LedgerEntryDiff)) - for i := 0; i < len(stateChanges); i++ { + for i := range stateChanges { if err := stateChanges[i].FromXDRDiff(result.LedgerEntryDiff[i], request.Format); err != nil { return SimulateTransactionResponse{ Error: err.Error(), diff --git a/cmd/soroban-rpc/internal/methods/util_test.go b/cmd/soroban-rpc/internal/methods/util_test.go index b183a318..399224e4 100644 --- a/cmd/soroban-rpc/internal/methods/util_test.go +++ b/cmd/soroban-rpc/internal/methods/util_test.go @@ -85,10 +85,10 @@ func createMockLedgerCloseMeta(ledgerSequence uint32) xdr.LedgerCloseMeta { func NewTestDB(tb testing.TB) *db.DB { tmp := tb.TempDir() dbPath := path.Join(tmp, "db.sqlite") - db, err := db.OpenSQLiteDB(dbPath) + dbConn, err := db.OpenSQLiteDB(dbPath) require.NoError(tb, err) tb.Cleanup(func() { - require.NoError(tb, db.Close()) + require.NoError(tb, dbConn.Close()) }) - return db + return dbConn }