From daffa5824f9c75bce159f28e01dc4ee0d7e76e0e Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Thu, 26 Sep 2024 15:29:04 +0200 Subject: [PATCH] chore: lint --- go.mod | 2 +- go.sum | 4 ++-- internal/account.go | 4 ++-- internal/api/v1/controllers_accounts_count.go | 3 +++ internal/api/v1/controllers_accounts_list.go | 3 +++ internal/api/v1/controllers_balances_list.go | 3 +++ internal/api/v2/controllers_ledgers_list_test.go | 4 ---- internal/log.go | 4 ++-- internal/machine/funding.go | 2 +- internal/machine/vm/machine.go | 12 ++++++------ internal/storage/ledger/accounts.go | 2 +- internal/storage/ledger/store.go | 1 + internal/storage/ledger/transactions.go | 2 +- internal/storage/ledger/transactions_test.go | 7 ++++--- pkg/testserver/server.go | 3 ++- test/e2e/integration_test.go | 5 +++-- test/e2e/stress_test.go | 4 ++-- 17 files changed, 37 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index e6d6b0d0f..99e1e926d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/alitto/pond v1.9.2 github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 github.com/bluele/gcache v0.0.2 - github.com/formancehq/go-libs v1.7.2-0.20240924160248-25cc3741eba3 + github.com/formancehq/go-libs v1.7.2-0.20240926132511-af18433b7404 github.com/formancehq/stack/ledger/client v0.0.0-00010101000000-000000000000 github.com/go-chi/chi/v5 v5.1.0 github.com/go-chi/cors v1.2.1 diff --git a/go.sum b/go.sum index 50d8d5cbc..fa06e7dc1 100644 --- a/go.sum +++ b/go.sum @@ -89,8 +89,8 @@ github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/formancehq/go-libs v1.7.2-0.20240924160248-25cc3741eba3 h1:kVhzD+1pd8U8e423d15DQTscWAD4602VdRomuIebqiE= -github.com/formancehq/go-libs v1.7.2-0.20240924160248-25cc3741eba3/go.mod h1:ynmWBbsdhVyjE+MxneMErtgd/RnNAk892VuIhZE2fps= +github.com/formancehq/go-libs v1.7.2-0.20240926132511-af18433b7404 h1:OJJV0eSxdyjrHDadGYzVkdwrQdoD7d/LSx3G5GlkFK8= +github.com/formancehq/go-libs v1.7.2-0.20240926132511-af18433b7404/go.mod h1:ynmWBbsdhVyjE+MxneMErtgd/RnNAk892VuIhZE2fps= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= diff --git a/internal/account.go b/internal/account.go index 264ba304c..31211b428 100644 --- a/internal/account.go +++ b/internal/account.go @@ -10,8 +10,8 @@ const ( ) type Account struct { - Address string `json:"address,type:varchar"` - Metadata metadata.Metadata `json:"metadata,type:jsonb"` + Address string `json:"address"` + Metadata metadata.Metadata `json:"metadata"` FirstUsage time.Time `json:"-"` InsertionDate time.Time `json:"_"` UpdatedAt time.Time `json:"-"` diff --git a/internal/api/v1/controllers_accounts_count.go b/internal/api/v1/controllers_accounts_count.go index a5fc78f16..d427c9bb1 100644 --- a/internal/api/v1/controllers_accounts_count.go +++ b/internal/api/v1/controllers_accounts_count.go @@ -21,6 +21,9 @@ func countAccounts(w http.ResponseWriter, r *http.Request) { return nil, err } options.QueryBuilder, err = buildAccountsFilterQuery(r) + if err != nil { + return nil, err + } return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil }) if err != nil { diff --git a/internal/api/v1/controllers_accounts_list.go b/internal/api/v1/controllers_accounts_list.go index 342efabb7..a6d7641a2 100644 --- a/internal/api/v1/controllers_accounts_list.go +++ b/internal/api/v1/controllers_accounts_list.go @@ -20,6 +20,9 @@ func listAccounts(w http.ResponseWriter, r *http.Request) { return nil, err } options.QueryBuilder, err = buildAccountsFilterQuery(r) + if err != nil { + return nil, err + } return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil }) if err != nil { diff --git a/internal/api/v1/controllers_balances_list.go b/internal/api/v1/controllers_balances_list.go index 4654d41c3..20c671f50 100644 --- a/internal/api/v1/controllers_balances_list.go +++ b/internal/api/v1/controllers_balances_list.go @@ -20,6 +20,9 @@ func getBalances(w http.ResponseWriter, r *http.Request) { return nil, err } options.QueryBuilder, err = buildAccountsFilterQuery(r) + if err != nil { + return nil, err + } return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil }) if err != nil { diff --git a/internal/api/v2/controllers_ledgers_list_test.go b/internal/api/v2/controllers_ledgers_list_test.go index 8f85155f0..9b6640e13 100644 --- a/internal/api/v2/controllers_ledgers_list_test.go +++ b/internal/api/v2/controllers_ledgers_list_test.go @@ -107,10 +107,6 @@ func TestListLedgers(t *testing.T) { require.Equal(t, http.StatusOK, rec.Code) cursor := api.DecodeCursorResponse[ledger.Ledger](t, rec.Body) - for i, l := range tc.returnData { - tc.returnData[i] = l - } - require.Equal(t, tc.returnData, cursor.Data) } else { require.Equal(t, tc.expectedStatusCode, rec.Code) diff --git a/internal/log.go b/internal/log.go index 1fe2bd617..20f0ac0cc 100644 --- a/internal/log.go +++ b/internal/log.go @@ -266,7 +266,7 @@ func (s *DeleteMetadataLogPayload) UnmarshalJSON(data []byte) error { id, err = strconv.ParseInt(string(x.TargetID), 10, 64) id = int(id.(int64)) default: - return fmt.Errorf("unknown type " + x.TargetType) + return fmt.Errorf("unknown type '%s'", x.TargetType) } if err != nil { return err @@ -320,7 +320,7 @@ func HydrateLog(_type LogType, data []byte) (any, error) { case RevertedTransactionLogType: payload = &RevertedTransactionLogPayload{} default: - return nil, fmt.Errorf("unknown type " + _type.String()) + return nil, fmt.Errorf("unknown type '%s'", _type) } err := json.Unmarshal(data, &payload) if err != nil { diff --git a/internal/machine/funding.go b/internal/machine/funding.go index f3b49e176..a679b58fe 100644 --- a/internal/machine/funding.go +++ b/internal/machine/funding.go @@ -97,7 +97,7 @@ func (f Funding) Take(amount *MonetaryInt) (Funding, Funding, error) { return fp.Account.String() }) - return Funding{}, Funding{}, NewErrInsufficientFund(fmt.Sprintf("account(s) %s had/have insufficient funds", strings.Join(lstAccounts, "|"))) + return Funding{}, Funding{}, NewErrInsufficientFund("account(s) %s had/have insufficient funds", strings.Join(lstAccounts, "|")) } return result, remainder, nil } diff --git a/internal/machine/vm/machine.go b/internal/machine/vm/machine.go index 91a4d6e45..e506668e2 100644 --- a/internal/machine/vm/machine.go +++ b/internal/machine/vm/machine.go @@ -285,7 +285,7 @@ func (m *Machine) tick() (bool, error) { } allotment, err := machine.NewAllotment(portions) if err != nil { - return true, machine.NewErrInvalidScript(err.Error()) + return true, machine.NewErrInvalidScript("%s", err) } m.pushValue(*allotment) @@ -294,7 +294,7 @@ func (m *Machine) tick() (bool, error) { account := pop[machine.AccountAddress](m) funding, err := m.withdrawAll(account, overdraft.Asset, overdraft.Amount) if err != nil { - return true, machine.NewErrInvalidScript(err.Error()) + return true, machine.NewErrInvalidScript("%s", err) } m.pushValue(*funding) @@ -303,7 +303,7 @@ func (m *Machine) tick() (bool, error) { account := pop[machine.AccountAddress](m) funding, err := m.withdrawAlways(account, mon) if err != nil { - return true, machine.NewErrInvalidScript(err.Error()) + return true, machine.NewErrInvalidScript("%s", err) } m.pushValue(*funding) @@ -315,7 +315,7 @@ func (m *Machine) tick() (bool, error) { } result, remainder, err := funding.Take(mon.Amount) if err != nil { - return true, machine.NewErrInsufficientFund(err.Error()) + return true, machine.NewErrInsufficientFund("%s", err) } m.pushValue(remainder) m.pushValue(result) @@ -366,7 +366,7 @@ func (m *Machine) tick() (bool, error) { for i := 0; i < n; i++ { res, err := result.Concat(fundings_rev[n-1-i]) if err != nil { - return true, machine.NewErrInvalidScript(err.Error()) + return true, machine.NewErrInvalidScript("%s", err) } result = res } @@ -637,7 +637,7 @@ func (m *Machine) ResolveResources(ctx context.Context, store Store) error { func (m *Machine) SetVarsFromJSON(vars map[string]string) error { v, err := m.Program.ParseVariablesJSON(vars) if err != nil { - return machine.NewErrInvalidVars(err.Error()) + return machine.NewErrInvalidVars("%s", err) } m.Vars = v return nil diff --git a/internal/storage/ledger/accounts.go b/internal/storage/ledger/accounts.go index aa6db3224..8ed67ab09 100644 --- a/internal/storage/ledger/accounts.go +++ b/internal/storage/ledger/accounts.go @@ -87,7 +87,7 @@ func (account Account) toCore() ledger.ExpandedAccount { } var ( - balanceRegex = regexp.MustCompile("balance\\[(.*)\\]") + balanceRegex = regexp.MustCompile(`balance\\[(.*)\\]`) ) func convertOperatorToSQL(operator string) string { diff --git a/internal/storage/ledger/store.go b/internal/storage/ledger/store.go index 648be1fb0..9d0a7cda7 100644 --- a/internal/storage/ledger/store.go +++ b/internal/storage/ledger/store.go @@ -3,6 +3,7 @@ package ledger import ( "context" "fmt" + "github.com/formancehq/go-libs/platform/postgres" "github.com/formancehq/ledger/internal/tracing" diff --git a/internal/storage/ledger/transactions.go b/internal/storage/ledger/transactions.go index 4731f902e..546aa618f 100644 --- a/internal/storage/ledger/transactions.go +++ b/internal/storage/ledger/transactions.go @@ -31,7 +31,7 @@ import ( ) var ( - metadataRegex = regexp.MustCompile("metadata\\[(.+)\\]") + metadataRegex = regexp.MustCompile(`metadata\\[(.+)\\]`) ) type Transaction struct { diff --git a/internal/storage/ledger/transactions_test.go b/internal/storage/ledger/transactions_test.go index 4c0b85bcf..648bf7825 100644 --- a/internal/storage/ledger/transactions_test.go +++ b/internal/storage/ledger/transactions_test.go @@ -211,12 +211,12 @@ func TestTransactionDeleteMetadata(t *testing.T) { require.Equal(t, metadata.Metadata{"foo2": "bar2"}, tx.Metadata) // delete a not existing metadata - tx1, modified, err = store.DeleteTransactionMetadata(ctx, tx1.ID, "foo1") + _, modified, err = store.DeleteTransactionMetadata(ctx, tx1.ID, "foo1") require.NoError(t, err) require.False(t, modified) // delete metadata of a non existing transaction - tx1, modified, err = store.DeleteTransactionMetadata(ctx, 10, "foo1") + _, modified, err = store.DeleteTransactionMetadata(ctx, 10, "foo1") require.Error(t, err) require.True(t, errors.Is(err, postgres.ErrNotFound)) require.False(t, modified) @@ -480,7 +480,7 @@ func TestTransactionsRevert(t *testing.T) { require.Equal(t, tx1, *revertedTx) // try to revert again - revertedTx, reverted, err = store.RevertTransaction(ctx, tx1.ID) + _, reverted, err = store.RevertTransaction(ctx, tx1.ID) require.NoError(t, err) require.False(t, reverted) @@ -571,6 +571,7 @@ func TestTransactionsList(t *testing.T) { _, _, err = store.UpdateTransactionMetadata(ctx, tx3BeforeRevert.ID, metadata.Metadata{ "additional_metadata": "true", }) + require.NoError(t, err) // refresh tx3 // we can't take the result of the call on RevertTransaction nor UpdateTransactionMetadata as the result does not contains pc(e)v diff --git a/pkg/testserver/server.go b/pkg/testserver/server.go index 18a608ea0..ad87bb9f9 100644 --- a/pkg/testserver/server.go +++ b/pkg/testserver/server.go @@ -3,13 +3,14 @@ package testserver import ( "context" "fmt" - "github.com/uptrace/bun" "io" "net/http" "strings" "testing" "time" + "github.com/uptrace/bun" + "github.com/formancehq/go-libs/bun/bunconnect" "github.com/formancehq/go-libs/httpclient" "github.com/formancehq/go-libs/httpserver" diff --git a/test/e2e/integration_test.go b/test/e2e/integration_test.go index a18aae6fd..7329dc325 100644 --- a/test/e2e/integration_test.go +++ b/test/e2e/integration_test.go @@ -6,6 +6,9 @@ import ( "database/sql" "encoding/json" "fmt" + "io" + "math/big" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/pointer" . "github.com/formancehq/go-libs/testing/api" @@ -17,8 +20,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/uptrace/bun" - "io" - "math/big" ) var _ = Context("Ledger integration tests", func() { diff --git a/test/e2e/stress_test.go b/test/e2e/stress_test.go index cfb56a263..78e0d93b6 100644 --- a/test/e2e/stress_test.go +++ b/test/e2e/stress_test.go @@ -187,11 +187,11 @@ func (h HaveCoherentStateMatcher) Match(actual interface{}) (success bool, err e } func (h HaveCoherentStateMatcher) FailureMessage(_ interface{}) (message string) { - return fmt.Sprintf("server should has coherent state") + return "server should has coherent state" } func (h HaveCoherentStateMatcher) NegatedFailureMessage(_ interface{}) (message string) { - return fmt.Sprintf("server should not has coherent state but has") + return "server should not has coherent state but has" } var _ types.GomegaMatcher = (*HaveCoherentStateMatcher)(nil)