diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a74e7c6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + + - package-ecosystem: gomod + directory: "/" + schedule: + interval: daily + labels: + - "A:automerge" + - dependencies diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..658de67 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +name: Lint +on: + push: + branches: + - main + - release/** + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + golangci: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.20.2 + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..cd205d4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,35 @@ +name: Tests / Code Coverage +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }}-tests + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.20.2 + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + - name: tests + if: env.GIT_DIFF + run: | + make test diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..a001bf3 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,59 @@ +run: + tests: true + timeout: 10m + sort-results: true + allow-parallel-runners: true + concurrency: 4 + +linters: + disable-all: true + enable: + - depguard + - dogsled + - exportloopref + - goconst + - gocritic + - gofumpt + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - nolintlint + - staticcheck + - revive + - stylecheck + - typecheck + - unconvert + - unused + +issues: + exclude-rules: + - text: "Use of weak random number generator" + linters: + - gosec + # - text: "ST1003:" + # linters: + # - stylecheck + # - text: "ST1016:" + # linters: + # - stylecheck + # - text: "leading space" + # linters: + # - nolintlint + + max-issues-per-linter: 10000 + max-same-issues: 10000 + +linters-settings: + dogsled: + max-blank-identifiers: 3 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + nolintlint: + allow-unused: false + allow-leading-space: true + require-explanation: false + require-specific: false diff --git a/Makefile b/Makefile index 6516c0f..dbb1a2b 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,15 @@ PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git) HTTPS_GIT := https://github.com/skip-mev/pob.git DOCKER := $(shell which docker) +############################################################################### +### Tests ### +############################################################################### + +test: + @go test -v ./... + +.PHONY: test + ############################################################################### ### Protobuf ### ############################################################################### diff --git a/abci/abci.go b/abci/abci.go index 4266289..a5531cc 100644 --- a/abci/abci.go +++ b/abci/abci.go @@ -48,7 +48,7 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { totalTxBytes int64 ) - bidTxMap := make(map[string]struct{}) + bidTxMap := make(map[string]struct{}) //nolint bidTxIterator := h.mempool.AuctionBidSelect(ctx) // Attempt to select the highest bid transaction that is valid and whose diff --git a/x/auction/keeper/auction.go b/x/auction/keeper/auction.go index 4257154..1ac7a41 100644 --- a/x/auction/keeper/auction.go +++ b/x/auction/keeper/auction.go @@ -99,15 +99,15 @@ func (k Keeper) ValidateAuctionBundle(ctx sdk.Context, bidder sdk.AccAddress, tr // as long as all subsequent transactions are signed by the bidder. if len(prevSigners) == 0 { if seenBidder { - return fmt.Errorf("bundle contains transactions signed by multiple parties. possible front-running or sandwich attack.") - } else { - seenBidder = true - prevSigners = map[string]bool{bidder.String(): true} - filterSigners(prevSigners, txSigners) + return fmt.Errorf("bundle contains transactions signed by multiple parties; possible front-running or sandwich attack") + } - if len(prevSigners) == 0 { - return fmt.Errorf("bundle contains transactions signed by multiple parties. possible front-running or sandwich attack.") - } + seenBidder = true + prevSigners = map[string]bool{bidder.String(): true} + filterSigners(prevSigners, txSigners) + + if len(prevSigners) == 0 { + return fmt.Errorf("bundle contains transactions signed by multiple parties; possible front-running or sandwich attack") } } } diff --git a/x/auction/keeper/auction_test.go b/x/auction/keeper/auction_test.go index 68187f3..5b0421f 100644 --- a/x/auction/keeper/auction_test.go +++ b/x/auction/keeper/auction_test.go @@ -16,15 +16,15 @@ import ( func (suite *IntegrationTestSuite) TestValidateAuctionMsg() { var ( // Tx building variables - accounts []Account = []Account{} // tracks the order of signers in the bundle - balance sdk.Coins = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10000))) - bid sdk.Coins = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000))) + accounts = []Account{} // tracks the order of signers in the bundle + balance = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(10000))) + bid = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000))) // Auction params - maxBundleSize uint32 = 10 - reserveFee sdk.Coins = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000))) - minBuyInFee sdk.Coins = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000))) - escrowAddress sdk.AccAddress = sdk.AccAddress([]byte("escrow")) + maxBundleSize uint32 = 10 + reserveFee = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000))) + minBuyInFee = sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(1000))) + escrowAddress = sdk.AccAddress([]byte("escrow")) ) rnd := rand.New(rand.NewSource(time.Now().Unix())) @@ -160,11 +160,9 @@ func (suite *IntegrationTestSuite) TestValidateAuctionMsg() { } func (suite *IntegrationTestSuite) TestValidateBundle() { - var ( - // TODO: Update this to be multi-dimensional to test multi-sig - // https://github.com/skip-mev/pob/issues/14 - accounts []Account // tracks the order of signers in the bundle - ) + // TODO: Update this to be multi-dimensional to test multi-sig + // https://github.com/skip-mev/pob/issues/14 + var accounts []Account // tracks the order of signers in the bundle rng := rand.New(rand.NewSource(time.Now().Unix())) bidder := RandomAccounts(rng, 1)[0] diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index 2d83f51..9aee8df 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -7,9 +7,7 @@ import ( "github.com/skip-mev/pob/x/auction/types" ) -var ( - _ types.QueryServer = QueryServer{} -) +var _ types.QueryServer = QueryServer{} // QueryServer defines the auction module's gRPC querier service. type QueryServer struct { diff --git a/x/auction/keeper/msg_server.go b/x/auction/keeper/msg_server.go index 0ebb7cb..ba42fe1 100644 --- a/x/auction/keeper/msg_server.go +++ b/x/auction/keeper/msg_server.go @@ -8,9 +8,7 @@ import ( "github.com/skip-mev/pob/x/auction/types" ) -var ( - _ types.MsgServer = MsgServer{} -) +var _ types.MsgServer = MsgServer{} // MsgServer is the wrapper for the auction module's msg service. type MsgServer struct { diff --git a/x/auction/module.go b/x/auction/module.go index e270aaa..04a3545 100644 --- a/x/auction/module.go +++ b/x/auction/module.go @@ -129,9 +129,10 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // BeginBlock returns the begin blocker for the auction module. -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} //nolint // EndBlock returns the end blocker for the auction module. It returns no validator updates. -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { //nolint return []abci.ValidatorUpdate{} } diff --git a/x/auction/types/keys.go b/x/auction/types/keys.go index acacbde..bdc9ccc 100644 --- a/x/auction/types/keys.go +++ b/x/auction/types/keys.go @@ -18,7 +18,5 @@ const ( prefixParams = iota + 1 ) -var ( - // KeyPrefixParams is the store key for the auction module's parameters. - KeyParams = []byte{prefixParams} -) +// KeyParams is the store key for the auction module's parameters. +var KeyParams = []byte{prefixParams} diff --git a/x/auction/types/msgs_test.go b/x/auction/types/msgs_test.go index 06ae855..2415333 100644 --- a/x/auction/types/msgs_test.go +++ b/x/auction/types/msgs_test.go @@ -72,7 +72,6 @@ func TestMsgAuctionBid(t *testing.T) { for _, tc := range cases { t.Run(tc.description, func(t *testing.T) { - err := tc.msg.ValidateBasic() if tc.expectPass { if err != nil { @@ -115,7 +114,6 @@ func TestMsgUpdateParams(t *testing.T) { for _, tc := range cases { t.Run(tc.description, func(t *testing.T) { - err := tc.msg.ValidateBasic() if tc.expectPass { if err != nil { diff --git a/x/auction/types/params.go b/x/auction/types/params.go index a9b5b0f..fd53732 100644 --- a/x/auction/types/params.go +++ b/x/auction/types/params.go @@ -10,11 +10,11 @@ var ( // TODO: Choose reasonable default values. // // Ref: https://github.com/skip-mev/pob/issues/7 - DefaultMaxBundleSize uint32 = 0 - DefaultEscrowAccountAddress = "" - DefaultReserveFee = sdk.Coins{} - DefaultMinBuyInFee = sdk.Coins{} - DefaultMinBidIncrement = sdk.Coins{} + DefaultMaxBundleSize uint32 + DefaultEscrowAccountAddress string + DefaultReserveFee = sdk.Coins{} + DefaultMinBuyInFee = sdk.Coins{} + DefaultMinBidIncrement = sdk.Coins{} ) // NewParams returns a new Params instance with the provided values.