Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9e05e4d
Use gotestsum for better visibility on the tests
marcelosalloum Apr 15, 2025
56e2249
Add test coverage validation to the CI.
marcelosalloum Apr 15, 2025
8fafd99
Add linter config.
marcelosalloum Apr 15, 2025
8a88aeb
Reorganize imports with `goimports -local "github.com/stellar/wallet-…
marcelosalloum Apr 15, 2025
437a67e
Apply cache to go-install for improved performance.
marcelosalloum Apr 15, 2025
0c740bd
Add checks for shadow and goimports, and upgrade the version from oth…
marcelosalloum Apr 15, 2025
7be6e3a
Fix all variable shadowing issues
marcelosalloum Apr 15, 2025
b4dcd39
Remove call to `db.RunInTransaction`, since it was not using a databa…
marcelosalloum Apr 15, 2025
424c936
Fix several linter warnings.
marcelosalloum Apr 15, 2025
cd23f4f
Fix several linter warnings. [2]
marcelosalloum Apr 15, 2025
295a0f8
Fix tests that broke after linter-related changes.
marcelosalloum Apr 15, 2025
a45cebb
Bump golangci-lint version in the GH Workspace.
marcelosalloum Apr 15, 2025
c4cc20f
Handle previously unhandled errors and make it explicit that some uti…
marcelosalloum Apr 15, 2025
8a7611c
Start handling a bunch of previously unhandled errors in the unit tes…
marcelosalloum Apr 16, 2025
5ea753a
Fix `GET /tss/transactions/{hash}` that was broken and the issue got …
marcelosalloum Apr 16, 2025
c7a9e13
Fix Sentry tests that were broken but not visibly broken.
marcelosalloum Apr 16, 2025
ea587f8
Make sure all mocks live under a mocks.go file, for consistency.
marcelosalloum Apr 16, 2025
3cbd080
Fix shadowed variable issues that raised after addressing other linte…
marcelosalloum Apr 16, 2025
cb05922
Rename function.
marcelosalloum Apr 16, 2025
390c826
Fix installation command of golangci-lint
marcelosalloum Apr 16, 2025
0f55533
Polish.
marcelosalloum Apr 16, 2025
cb88a27
Merge branch 'main' into marcelo/polish-project-config-and-CI
marcelosalloum Apr 16, 2025
38f1464
Fixes after merge.
marcelosalloum Apr 16, 2025
9bce93a
Drastically reduce unit tests run time from 92s to 23s (4 times faste…
marcelosalloum Apr 16, 2025
58b2e83
Wrapped missing errors, for better traceability.
marcelosalloum Apr 16, 2025
4be7a13
Fix async issue causing tests to fail intermittently.
marcelosalloum Apr 16, 2025
8e00297
Move MockChAccCmdServiceInterface to the mocks.go file, for consisten…
marcelosalloum Apr 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 59 additions & 13 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.23.2"
cache: true
cache-dependency-path: go.sum

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
args: --timeout=5m

- name: ./gomod.sh
run: ./gomod.sh

- name: exhaustive github.com/nishanths/[email protected]
- name: Run `[email protected]`
run: |
go install github.com/golangci/golangci-lint/v2/cmd/[email protected]
golangci-lint run

- name: Run `[email protected]`
run: |
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/[email protected]
shadow ./...

- name: Run `[email protected]`
run: |
go install github.com/nishanths/exhaustive/cmd/[email protected]
exhaustive -default-signifies-exhaustive ./...
- name: deadcode golang.org/x/tools/cmd/deadcode@v0.26.0

- name: Run `deadcode@v0.31.0`
run: |
go install golang.org/x/tools/cmd/deadcode@v0.26.0
go install golang.org/x/tools/cmd/deadcode@v0.31.0
output=$(deadcode -test ./...)
if [[ -n "$output" ]]; then
echo "🚨 Deadcode found:"
Expand All @@ -44,6 +50,20 @@ jobs:
echo "✅ No deadcode found"
fi

- name: Run `[email protected]`
run: |
go install golang.org/x/tools/cmd/[email protected]
# Find all .go files excluding paths containing 'mock' and run goimports
non_compliant_files=$(find . -type f -name "*.go" ! -path "*mock*" | xargs goimports -local "github.com/stellar/stellar-disbursement-platform-backend" -l)

if [ -n "$non_compliant_files" ]; then
echo "🚨 The following files are not compliant with goimports:"
echo "$non_compliant_files"
exit 1
else
echo "✅ All files are compliant with goimports."
fi

build:
runs-on: ubuntu-latest
steps:
Expand All @@ -54,6 +74,8 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.23.2"
cache: true
cache-dependency-path: go.sum

- name: Build Project
run: go build ./...
Expand Down Expand Up @@ -82,7 +104,7 @@ jobs:
PGPASSWORD: postgres
PGDATABASE: postgres
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -91,6 +113,30 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.23.2"
cache: true
cache-dependency-path: go.sum

- name: Install [email protected]
run: go install gotest.tools/[email protected]

- name: Run tests
run: gotestsum --format-hide-empty-pkg --format pkgname-and-test-fails -- -coverprofile=c.out ./... -timeout 3m -coverpkg ./...

- name: Run Tests
run: go test -v -race -cover ./...
- name: Validate Test Coverage Threshold
env:
TESTCOVERAGE_THRESHOLD: 65 # percentage
run: |
echo "Quality Gate: Checking if test coverage is above threshold..."
echo "Threshold: $TESTCOVERAGE_THRESHOLD%"
totalCoverage=`./scripts/exclude_from_coverage.sh && go tool cover -func=c.out | grep total: | grep -Eo '[0-9]+\.[0-9]+'`
echo "Test Coverage: $totalCoverage%"
echo "-------------------------"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 >= $2)}') )); then
echo " $totalCoverage% > $TESTCOVERAGE_THRESHOLD%"
echo "Current test coverage is above threshold 🎉🎉🎉! Please keep up the good work!"
else
echo " $totalCoverage% < $TESTCOVERAGE_THRESHOLD%"
echo "🚨 Current test coverage is below threshold 😱! Please add more unit tests or adjust threshold to a lower value."
echo "Failed 😭"
exit 1
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ captive-core*/
env.sh
.idea
__debug_bin*
c.out
58 changes: 58 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "2"

formatters:
enable:
- gofmt
- gofumpt

settings:
gofmt:
simplify: false

linters:
enable:
- govet
- rowserrcheck
- nilerr
- nilnesserr
- errname
- errorlint
- errcheck
- wrapcheck

settings:
staticcheck:
checks:
- all
- -ST1000
- -QF1008

errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
check-blank: true

exclusions:
paths:
# mocks are ignored
- ".*.mock.*\\.go$"

rules:
- path: _test\.go
linters: [wrapcheck]

- path: (_test\.go|dbtest\.go)$
linters: [errcheck]
text: '\.Close'

# Exclude some `staticcheck` messages.
- linters: [staticcheck]
text: '(QF1008|SqlDB should be SQLDB)'

# Mode of the generated files analysis.
#
# - `strict`: Only fules containing `^// Code generated .* DO NOT EDIT\.$` are excluded.
# - `lax`: Sources containing lines like `autogenerated file`, `code generated`, `do not edit`, etc. are excluded.
# - `disable`: disable the generated files exclusion.
#
# Default: strict
generated: lax
4 changes: 1 addition & 3 deletions .mockery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ formatter: goimports
log-level: info
structname: "{{.Mock}}{{.InterfaceName}}"
pkgname: "{{.SrcPackageName}}"
filename: "mock_{{.InterfaceName | snakecase}}.go"
filename: "mocks.go"
recursive: false
require-template-schema-exists: true
template: testify
Expand All @@ -14,5 +14,3 @@ packages:
github.com/stellar/wallet-backend/cmd:
interfaces:
ChAccCmdServiceInterface:
config:
filename: "channel_account_mocks.go"
4 changes: 3 additions & 1 deletion cmd/channel_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/stellar/wallet-backend/internal/services"
"github.com/stellar/wallet-backend/internal/signing/store"
signingutils "github.com/stellar/wallet-backend/internal/signing/utils"
internalUtils "github.com/stellar/wallet-backend/internal/utils"
)

// ChAccCmdServiceInterface is the interface for the channel account command service. It is used to allow mocking the
Expand All @@ -32,6 +33,7 @@ type ChAccCmdService struct{}

var _ ChAccCmdServiceInterface = (*ChAccCmdService)(nil)

//nolint:wrapcheck // Skipping wrapcheck because this is just a proxy to the service.
func (s *ChAccCmdService) EnsureChannelAccounts(ctx context.Context, chAccService services.ChannelAccountService, amount int64) error {
return chAccService.EnsureChannelAccounts(ctx, amount)
}
Expand Down Expand Up @@ -126,7 +128,7 @@ func (c *channelAccountCmd) Command(cmdService ChAccCmdServiceInterface) *cobra.
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
defer distAccSigClientOpts.DBConnectionPool.Close()
defer internalUtils.DeferredClose(cmd.Context(), distAccSigClientOpts.DBConnectionPool, "closing distAccSigClient's db connection pool")
amount, err := strconv.Atoi(args[0])
if err != nil {
return fmt.Errorf("invalid [amount] argument=%s", args[0])
Expand Down
10 changes: 4 additions & 6 deletions cmd/channel_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,22 @@ func Test_ChannelAccountsCommand_EnsureCommand(t *testing.T) {
})

t.Run("🟢executes_successfully", func(t *testing.T) {
mChAccService.
On("EnsureChannelAccounts", mock.AnythingOfType("context.backgroundCtx"), mock.AnythingOfType("*services.channelAccountService"), int64(2)).
mChAccService.EXPECT().
EnsureChannelAccounts(mock.AnythingOfType("context.backgroundCtx"), mock.AnythingOfType("*services.channelAccountService"), int64(2)).
Return(nil).
Once()
err := rootCmd.Execute()
require.NoError(t, err)
})

t.Run("🔴fails_if_ChannelAccountsService_fails", func(t *testing.T) {
mChAccService.
On("EnsureChannelAccounts", mock.AnythingOfType("context.backgroundCtx"), mock.AnythingOfType("*services.channelAccountService"), int64(2)).
mChAccService.EXPECT().
EnsureChannelAccounts(mock.AnythingOfType("context.backgroundCtx"), mock.AnythingOfType("*services.channelAccountService"), int64(2)).
Return(errors.New("foo bar baz")).
Once()
err := rootCmd.Execute()
require.Error(t, err)
assert.ErrorContains(t, err, "ensuring the number of channel accounts is created")
assert.ErrorContains(t, err, "foo bar baz")
})

mChAccService.AssertExpectations(t)
}
1 change: 1 addition & 0 deletions cmd/distribution_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
"github.com/stellar/go/support/config"
"github.com/stellar/go/support/log"

"github.com/stellar/wallet-backend/cmd/utils"
"github.com/stellar/wallet-backend/internal/db"
"github.com/stellar/wallet-backend/internal/services"
Expand Down
1 change: 1 addition & 0 deletions cmd/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"github.com/stellar/go/support/config"
"github.com/stellar/go/support/log"

"github.com/stellar/wallet-backend/cmd/utils"
"github.com/stellar/wallet-backend/internal/apptracker/sentry"
"github.com/stellar/wallet-backend/internal/ingest"
Expand Down
3 changes: 2 additions & 1 deletion cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/stellar/go/support/config"
"github.com/stellar/go/support/log"

"github.com/stellar/wallet-backend/cmd/utils"
"github.com/stellar/wallet-backend/internal/db"
)
Expand Down Expand Up @@ -76,7 +77,7 @@ func (c *migrateCmd) RunMigrateDown(ctx context.Context, databaseURL string, arg
return fmt.Errorf("invalid [count] argument: %s", args[0])
}
if err := executeMigrations(ctx, databaseURL, migrate.Down, count); err != nil {
return fmt.Errorf("executing migrate down: %v", err)
return fmt.Errorf("executing migrate down: %w", err)
}
return nil
}
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions cmd/utils/global_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func StartLedgerOption(configKey *int) *config.ConfigOption {
FlagDefault: 0,
Required: true,
}

}

func EndLedgerOption(configKey *int) *config.ConfigOption {
Expand All @@ -152,7 +151,6 @@ func EndLedgerOption(configKey *int) *config.ConfigOption {
FlagDefault: 0,
Required: true,
}

}

func AWSOptions(awsRegionConfigKey *string, kmsKeyARN *string, required bool) config.ConfigOptions {
Expand Down
13 changes: 10 additions & 3 deletions cmd/utils/password_prompter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ type defaultPasswordPrompter struct {
var _ PasswordPrompter = (*defaultPasswordPrompter)(nil)

func (pp *defaultPasswordPrompter) Run() (string, error) {
fmt.Fprint(pp.stdout, pp.inputLabelText, " ")
_, err := fmt.Fprint(pp.stdout, pp.inputLabelText, " ")
if err != nil {
return "", fmt.Errorf("writing input label text: %w", err)
}

password, err := term.ReadPassword(int(pp.stdin.Fd()))
if err != nil {
return "", err
return "", fmt.Errorf("reading password: %w", err)
}
_, err = fmt.Fprintln(pp.stdout)
if err != nil {
return "", fmt.Errorf("writing newline: %w", err)
}
fmt.Fprintln(pp.stdout)

return string(password), nil
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/utils/tss_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func RPCCallerChannelMaxWorkersOption(configKey *int) *config.ConfigOption {
ConfigKey: configKey,
FlagDefault: 100,
}

}

func ErrorHandlerJitterChannelBufferSizeOption(configKey *int) *config.ConfigOption {
Expand Down Expand Up @@ -58,7 +57,6 @@ func ErrorHandlerNonJitterChannelBufferSizeOption(configKey *int) *config.Config
FlagDefault: 1000,
Required: true,
}

}

func ErrorHandlerNonJitterChannelMaxWorkersOption(configKey *int) *config.ConfigOption {
Expand Down Expand Up @@ -103,7 +101,6 @@ func ErrorHandlerJitterChannelMaxRetriesOptions(configKey *int) *config.ConfigOp
FlagDefault: 3,
Required: true,
}

}

func ErrorHandlerNonJitterChannelMaxRetriesOption(configKey *int) *config.ConfigOption {
Expand Down
10 changes: 9 additions & 1 deletion cmd/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"
"github.com/stellar/go/support/config"

"github.com/stellar/wallet-backend/internal/db"
"github.com/stellar/wallet-backend/internal/signing"
"github.com/stellar/wallet-backend/internal/signing/awskms"
Expand Down Expand Up @@ -41,7 +42,14 @@ type SignatureClientOptions struct {
EncryptionPassphrase string
}

func SignatureClientResolver(signatureClientOpts *SignatureClientOptions) (signing.SignatureClient, error) {
//nolint:wrapcheck // defer is used to wrap the error
func SignatureClientResolver(signatureClientOpts *SignatureClientOptions) (sigClient signing.SignatureClient, err error) {
defer func() {
if err != nil {
err = fmt.Errorf("resolving signature client: %w", err)
}
}()

switch signatureClientOpts.Type {
case signing.EnvSignatureClientType:
return signing.NewEnvSignatureClient(signatureClientOpts.DistributionAccountSecretKey, signatureClientOpts.NetworkPassphrase)
Expand Down
Loading