diff --git a/cmd/buckets_upgrade_test.go b/cmd/buckets_upgrade_test.go index 0b09aea8a..799bfa508 100644 --- a/cmd/buckets_upgrade_test.go +++ b/cmd/buckets_upgrade_test.go @@ -3,13 +3,14 @@ package cmd import ( + "io" + "testing" + "github.com/formancehq/go-libs/bun/bunconnect" "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/testing/docker" "github.com/formancehq/go-libs/testing/platform/pgtesting" "github.com/stretchr/testify/require" - "io" - "testing" ) func TestBucketsUpgrade(t *testing.T) { diff --git a/internal/api/v1/controllers_transactions_create_test.go b/internal/api/v1/controllers_transactions_create_test.go index 1e146ee32..e1a82f8f6 100644 --- a/internal/api/v1/controllers_transactions_create_test.go +++ b/internal/api/v1/controllers_transactions_create_test.go @@ -2,13 +2,14 @@ package v1 import ( "encoding/json" - "github.com/formancehq/go-libs/time" "math/big" "net/http" "net/http/httptest" "net/url" "testing" + "github.com/formancehq/go-libs/time" + "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/pointer" diff --git a/internal/api/v2/controllers_transactions_create_test.go b/internal/api/v2/controllers_transactions_create_test.go index c484ea161..8772b091d 100644 --- a/internal/api/v2/controllers_transactions_create_test.go +++ b/internal/api/v2/controllers_transactions_create_test.go @@ -1,13 +1,14 @@ package v2 import ( - "github.com/formancehq/go-libs/time" "math/big" "net/http" "net/http/httptest" "net/url" "testing" + "github.com/formancehq/go-libs/time" + "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/pointer" diff --git a/internal/ledger.go b/internal/ledger.go index 2fc2e738e..61e090425 100644 --- a/internal/ledger.go +++ b/internal/ledger.go @@ -2,10 +2,11 @@ package ledger import ( "fmt" - "github.com/formancehq/go-libs/metadata" - "github.com/formancehq/go-libs/time" "regexp" "slices" + + "github.com/formancehq/go-libs/metadata" + "github.com/formancehq/go-libs/time" ) const ( diff --git a/internal/storage/driver/driver_test.go b/internal/storage/driver/driver_test.go index a4dc56ab6..b2b9d037e 100644 --- a/internal/storage/driver/driver_test.go +++ b/internal/storage/driver/driver_test.go @@ -4,13 +4,14 @@ package driver_test import ( "fmt" + "testing" + "github.com/formancehq/go-libs/bun/bunconnect" "github.com/formancehq/go-libs/bun/bundebug" "github.com/formancehq/go-libs/testing/docker" "github.com/formancehq/go-libs/testing/platform/pgtesting" "github.com/formancehq/ledger/internal/storage/driver" "github.com/uptrace/bun" - "testing" "github.com/formancehq/go-libs/logging" "github.com/stretchr/testify/require" diff --git a/internal/storage/ledger/accounts_test.go b/internal/storage/ledger/accounts_test.go index 32c809233..7ed436371 100644 --- a/internal/storage/ledger/accounts_test.go +++ b/internal/storage/ledger/accounts_test.go @@ -4,11 +4,12 @@ package ledger import ( "context" + "math/big" + "testing" + "github.com/formancehq/go-libs/pointer" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/pkg/errors" - "math/big" - "testing" "github.com/formancehq/go-libs/time" diff --git a/internal/storage/ledger/balances.go b/internal/storage/ledger/balances.go index bdb72f34b..a2fe65cd1 100644 --- a/internal/storage/ledger/balances.go +++ b/internal/storage/ledger/balances.go @@ -2,11 +2,12 @@ package ledger import ( "context" - "github.com/formancehq/go-libs/platform/postgres" - "github.com/pkg/errors" "math/big" "strings" + "github.com/formancehq/go-libs/platform/postgres" + "github.com/pkg/errors" + "github.com/formancehq/ledger/internal/tracing" "github.com/formancehq/go-libs/query" diff --git a/internal/storage/ledger/balances_test.go b/internal/storage/ledger/balances_test.go index 1cfe181d4..026946d9f 100644 --- a/internal/storage/ledger/balances_test.go +++ b/internal/storage/ledger/balances_test.go @@ -4,19 +4,21 @@ package ledger import ( "database/sql" + "math/big" + "testing" + "github.com/formancehq/go-libs/metadata" "github.com/formancehq/go-libs/time" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "math/big" - "testing" "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/pointer" + libtime "time" + "github.com/formancehq/go-libs/query" ledger "github.com/formancehq/ledger/internal" "github.com/stretchr/testify/require" - libtime "time" ) func TestBalancesGet(t *testing.T) { diff --git a/internal/storage/ledger/logs_test.go b/internal/storage/ledger/logs_test.go index fe2c50fbd..0895b3c24 100644 --- a/internal/storage/ledger/logs_test.go +++ b/internal/storage/ledger/logs_test.go @@ -5,11 +5,12 @@ package ledger import ( "context" "database/sql" + "math/big" + "testing" + "github.com/alitto/pond" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/pkg/errors" - "math/big" - "testing" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/time" diff --git a/internal/storage/ledger/main_test.go b/internal/storage/ledger/main_test.go index 7c64d1891..5e3c33044 100644 --- a/internal/storage/ledger/main_test.go +++ b/internal/storage/ledger/main_test.go @@ -4,6 +4,9 @@ package ledger import ( "database/sql" + "math/big" + "testing" + "github.com/formancehq/go-libs/bun/bunconnect" "github.com/formancehq/go-libs/bun/bundebug" "github.com/formancehq/go-libs/testing/docker" @@ -12,8 +15,6 @@ import ( "github.com/formancehq/ledger/internal/storage/bucket" systemstore "github.com/formancehq/ledger/internal/storage/system" "github.com/google/go-cmp/cmp" - "math/big" - "testing" "github.com/uptrace/bun/dialect/pgdialect" diff --git a/internal/storage/ledger/moves.go b/internal/storage/ledger/moves.go index 146dd3474..fff1e6398 100644 --- a/internal/storage/ledger/moves.go +++ b/internal/storage/ledger/moves.go @@ -2,10 +2,10 @@ package ledger import ( "context" + "slices" + . "github.com/formancehq/go-libs/collectionutils" ledger "github.com/formancehq/ledger/internal" - "math/big" - "slices" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/platform/postgres" @@ -93,40 +93,6 @@ type Move struct { type Moves []*Move -func (m Moves) volumeUpdates() []AccountsVolumes { - - aggregatedVolumes := make(map[string]map[string][]*Move) - for _, move := range m { - if _, ok := aggregatedVolumes[move.Account]; !ok { - aggregatedVolumes[move.Account] = make(map[string][]*Move) - } - aggregatedVolumes[move.Account][move.Asset] = append(aggregatedVolumes[move.Account][move.Asset], move) - } - - ret := make([]AccountsVolumes, 0) - for account, movesByAsset := range aggregatedVolumes { - for asset, moves := range movesByAsset { - volumes := ledger.NewEmptyVolumes() - for _, move := range moves { - if move.IsSource { - volumes.Output.Add(volumes.Output, (*big.Int)(move.Amount)) - } else { - volumes.Input.Add(volumes.Input, (*big.Int)(move.Amount)) - } - } - ret = append(ret, AccountsVolumes{ - Ledger: moves[0].Ledger, - Account: account, - Asset: asset, - Input: volumes.Input, - Output: volumes.Output, - }) - } - } - - return ret -} - func (m Moves) ComputePostCommitEffectiveVolumes() ledger.PostCommitVolumes { type key struct { Account string diff --git a/internal/storage/ledger/moves_test.go b/internal/storage/ledger/moves_test.go index 0448ac59b..032db120a 100644 --- a/internal/storage/ledger/moves_test.go +++ b/internal/storage/ledger/moves_test.go @@ -5,6 +5,10 @@ package ledger import ( "database/sql" "fmt" + "math/big" + "math/rand" + "testing" + "github.com/alitto/pond" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/logging" @@ -14,9 +18,6 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/pkg/errors" "github.com/stretchr/testify/require" - "math/big" - "math/rand" - "testing" ) func TestMovesInsert(t *testing.T) { diff --git a/internal/storage/ledger/transactions_test.go b/internal/storage/ledger/transactions_test.go index c556f3d1d..4c0b85bcf 100644 --- a/internal/storage/ledger/transactions_test.go +++ b/internal/storage/ledger/transactions_test.go @@ -6,11 +6,12 @@ import ( "context" "database/sql" "fmt" + "math/big" + "testing" + "github.com/formancehq/go-libs/platform/postgres" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/shomali11/xsql" - "math/big" - "testing" "github.com/formancehq/go-libs/time" @@ -19,11 +20,12 @@ import ( "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/pointer" + libtime "time" + "github.com/formancehq/go-libs/metadata" "github.com/formancehq/go-libs/query" ledger "github.com/formancehq/ledger/internal" "github.com/stretchr/testify/require" - libtime "time" ) func TestTransactionsGetWithVolumes(t *testing.T) { diff --git a/internal/storage/ledger/volumes.go b/internal/storage/ledger/volumes.go index d7a5da9c8..d5d65dbf6 100644 --- a/internal/storage/ledger/volumes.go +++ b/internal/storage/ledger/volumes.go @@ -3,9 +3,10 @@ package ledger import ( "context" "fmt" - "github.com/formancehq/go-libs/platform/postgres" "math/big" + "github.com/formancehq/go-libs/platform/postgres" + "github.com/formancehq/ledger/internal/tracing" "github.com/formancehq/go-libs/bun/bunpaginate" diff --git a/internal/storage/ledger/volumes_test.go b/internal/storage/ledger/volumes_test.go index e827b5c9a..ba5203e53 100644 --- a/internal/storage/ledger/volumes_test.go +++ b/internal/storage/ledger/volumes_test.go @@ -4,13 +4,14 @@ package ledger import ( "database/sql" - "github.com/formancehq/go-libs/platform/postgres" - ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "math/big" "testing" libtime "time" + "github.com/formancehq/go-libs/platform/postgres" + ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "github.com/pkg/errors" + "github.com/formancehq/go-libs/time" "github.com/formancehq/go-libs/logging" diff --git a/internal/storage/system/configuration_test.go b/internal/storage/system/configuration_test.go index 42c3f9152..abad9189d 100644 --- a/internal/storage/system/configuration_test.go +++ b/internal/storage/system/configuration_test.go @@ -3,10 +3,11 @@ package system import ( + "testing" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/platform/postgres" "github.com/stretchr/testify/require" - "testing" ) func TestConfiguration(t *testing.T) { diff --git a/internal/storage/system/ledgers_test.go b/internal/storage/system/ledgers_test.go index dc7b35254..ccf2e2940 100644 --- a/internal/storage/system/ledgers_test.go +++ b/internal/storage/system/ledgers_test.go @@ -4,12 +4,13 @@ package system import ( "fmt" + "testing" + "github.com/formancehq/go-libs/bun/bundebug" "github.com/formancehq/go-libs/metadata" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/uptrace/bun" - "testing" "github.com/google/uuid" diff --git a/internal/storage/system/migrations_test.go b/internal/storage/system/migrations_test.go index 4bd16017a..b1fe347e5 100644 --- a/internal/storage/system/migrations_test.go +++ b/internal/storage/system/migrations_test.go @@ -5,6 +5,8 @@ package system import ( "context" "fmt" + "testing" + "github.com/formancehq/go-libs/bun/bunconnect" "github.com/formancehq/go-libs/bun/bundebug" "github.com/formancehq/go-libs/logging" @@ -13,7 +15,6 @@ import ( ledger "github.com/formancehq/ledger/internal" "github.com/stretchr/testify/require" "github.com/uptrace/bun" - "testing" ) type Hook struct { diff --git a/internal/transaction_test.go b/internal/transaction_test.go index c9883aaa8..32d394186 100644 --- a/internal/transaction_test.go +++ b/internal/transaction_test.go @@ -1,10 +1,11 @@ package ledger import ( - "github.com/formancehq/go-libs/time" "math/big" "testing" + "github.com/formancehq/go-libs/time" + "github.com/stretchr/testify/require" ) diff --git a/test/e2e/integration_test.go b/test/e2e/integration_test.go index 8a7b948da..21a77a201 100644 --- a/test/e2e/integration_test.go +++ b/test/e2e/integration_test.go @@ -5,6 +5,9 @@ package test_suite import ( "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" @@ -15,8 +18,6 @@ import ( "github.com/formancehq/stack/ledger/client/models/operations" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "io" - "math/big" ) var _ = Context("Ledger integration tests", func() { diff --git a/test/e2e/stress_test.go b/test/e2e/stress_test.go index e56c7137d..cfb56a263 100644 --- a/test/e2e/stress_test.go +++ b/test/e2e/stress_test.go @@ -5,6 +5,11 @@ package test_suite import ( "context" "fmt" + "math/big" + "math/rand" + "sync" + "sync/atomic" + "github.com/alitto/pond" "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/pointer" @@ -16,10 +21,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/types" - "math/big" - "math/rand" - "sync" - "sync/atomic" ) var _ = Context("Ledger stress tests", func() { diff --git a/test/performance/benchmark_test.go b/test/performance/benchmark_test.go index 19b39e0f2..853e5a793 100644 --- a/test/performance/benchmark_test.go +++ b/test/performance/benchmark_test.go @@ -5,15 +5,15 @@ package performance_test import ( "context" "fmt" + "sort" + "sync/atomic" + "testing" + "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/time" ledger "github.com/formancehq/ledger/internal" "github.com/google/uuid" "github.com/stretchr/testify/require" - "sort" - "sync" - "sync/atomic" - "testing" ) type Iterator interface { @@ -32,8 +32,6 @@ func (c RunConfiguration) String() string { } type Benchmark struct { - mu sync.Mutex - EnvFactories map[string]EnvFactory Scripts map[string]func(int) (string, map[string]string) @@ -41,16 +39,6 @@ type Benchmark struct { b *testing.B } -func (benchmark *Benchmark) addReport(env, script string, report *Report) { - benchmark.mu.Lock() - defer benchmark.mu.Unlock() - - if benchmark.reports[env] == nil { - benchmark.reports[env] = make(map[string]*Report) - } - benchmark.reports[env][script] = report -} - func (benchmark *Benchmark) Run(ctx context.Context) error { for envName, envFactory := range benchmark.EnvFactories { scriptsKeys := collectionutils.Keys(benchmark.Scripts) diff --git a/test/performance/env_core_test.go b/test/performance/env_core_test.go index abf1e24ca..0d60122b5 100644 --- a/test/performance/env_core_test.go +++ b/test/performance/env_core_test.go @@ -4,6 +4,8 @@ package performance_test import ( "context" + "testing" + "github.com/formancehq/go-libs/bun/bunconnect" "github.com/formancehq/go-libs/bun/bundebug" "github.com/formancehq/go-libs/testing/platform/pgtesting" @@ -16,7 +18,6 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/require" "github.com/uptrace/bun" - "testing" ) type CoreEnv struct { diff --git a/test/performance/env_remote_ledger_test.go b/test/performance/env_remote_ledger_test.go index aff7a9227..4b8770836 100644 --- a/test/performance/env_remote_ledger_test.go +++ b/test/performance/env_remote_ledger_test.go @@ -4,6 +4,9 @@ package performance_test import ( "context" + "net/http" + "testing" + "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/time" ledger "github.com/formancehq/ledger/internal" @@ -12,8 +15,6 @@ import ( "github.com/formancehq/stack/ledger/client/models/operations" "github.com/pkg/errors" "github.com/stretchr/testify/require" - "net/http" - "testing" ) type RemoteLedgerEnvFactory struct { diff --git a/test/performance/env_remote_stack_test.go b/test/performance/env_remote_stack_test.go index f93ffc304..84b5ddfd5 100644 --- a/test/performance/env_remote_stack_test.go +++ b/test/performance/env_remote_stack_test.go @@ -4,6 +4,9 @@ package performance_test import ( "context" + "net/http" + "testing" + "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/time" ledger "github.com/formancehq/ledger/internal" @@ -12,8 +15,6 @@ import ( "github.com/formancehq/stack/ledger/client/models/operations" "github.com/pkg/errors" "github.com/stretchr/testify/require" - "net/http" - "testing" ) type RemoteStackEnvFactory struct { @@ -25,7 +26,7 @@ func (r *RemoteStackEnvFactory) Create(ctx context.Context, b *testing.B, ledger client := ledgerclient.New( ledgerclient.WithClient(r.httpClient), - ledgerclient.WithServerURL(r.stackURL + "/api/ledger"), + ledgerclient.WithServerURL(r.stackURL+"/api/ledger"), ) _, err := client.Ledger.V2.CreateLedger(ctx, operations.V2CreateLedgerRequest{ diff --git a/test/performance/env_test.go b/test/performance/env_test.go index c989b09b0..c79d47af3 100644 --- a/test/performance/env_test.go +++ b/test/performance/env_test.go @@ -4,8 +4,9 @@ package performance_test import ( "context" - "github.com/formancehq/ledger/internal" "testing" + + ledger "github.com/formancehq/ledger/internal" ) type TransactionExecutor interface { diff --git a/test/performance/env_testserver_test.go b/test/performance/env_testserver_test.go index fb64d1fea..017e78c7d 100644 --- a/test/performance/env_testserver_test.go +++ b/test/performance/env_testserver_test.go @@ -4,6 +4,10 @@ package performance_test import ( "context" + "io" + "os" + "testing" + "github.com/formancehq/go-libs/pointer" "github.com/formancehq/go-libs/testing/platform/pgtesting" "github.com/formancehq/go-libs/time" @@ -12,9 +16,6 @@ import ( "github.com/formancehq/stack/ledger/client/models/components" "github.com/formancehq/stack/ledger/client/models/operations" "github.com/stretchr/testify/require" - "io" - "os" - "testing" ) type TestServerEnv struct { diff --git a/test/performance/features_test.go b/test/performance/features_test.go index d2da8bc0d..64741c63e 100644 --- a/test/performance/features_test.go +++ b/test/performance/features_test.go @@ -3,10 +3,11 @@ package performance_test import ( - . "github.com/formancehq/go-libs/collectionutils" - ledger "github.com/formancehq/ledger/internal" "slices" "strings" + + . "github.com/formancehq/go-libs/collectionutils" + ledger "github.com/formancehq/ledger/internal" ) func buildAllPossibleConfigurations() []FeatureConfiguration { diff --git a/test/performance/main_test.go b/test/performance/main_test.go index ab93e121f..3dc32dee1 100644 --- a/test/performance/main_test.go +++ b/test/performance/main_test.go @@ -6,14 +6,15 @@ import ( "context" "crypto/tls" "flag" + "net/http" + "testing" + "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/testing/docker" "github.com/formancehq/go-libs/testing/platform/pgtesting" "github.com/formancehq/go-libs/testing/utils" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" - "net/http" - "testing" ) var ( diff --git a/test/performance/report_test.go b/test/performance/report_test.go index 4d1d5a073..aceefb137 100644 --- a/test/performance/report_test.go +++ b/test/performance/report_test.go @@ -3,9 +3,10 @@ package performance_test import ( - "github.com/formancehq/go-libs/time" "sync" "sync/atomic" + + "github.com/formancehq/go-libs/time" ) type Report struct { @@ -16,7 +17,6 @@ type Report struct { transactionsCount int - longestTxLock sync.Mutex longestTransactionID int longestTransactionDuration time.Duration diff --git a/test/performance/write_test.go b/test/performance/write_test.go index 27b8d8e04..e144766d9 100644 --- a/test/performance/write_test.go +++ b/test/performance/write_test.go @@ -4,9 +4,10 @@ package performance_test import ( "fmt" + "testing" + "github.com/formancehq/go-libs/logging" "github.com/stretchr/testify/require" - "testing" ) var scripts = map[string]func(int) (string, map[string]string){