Skip to content

Commit

Permalink
add linter recipe and lint all go code (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba authored Aug 27, 2024
1 parent 2cb288e commit c9d09c9
Show file tree
Hide file tree
Showing 135 changed files with 1,187 additions and 968 deletions.
85 changes: 85 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
run:
tests: true
# # timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

linters:
disable-all: true
enable:
- dogsled
- copyloopvar
- errcheck
- gci
- goconst
- gocritic
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- staticcheck
- thelper
- stylecheck
- revive
- typecheck
- unconvert
- unused
- misspell

issues:
exclude-rules:
- text: "unused-parameter"
linters:
- revive
- text: "SA1019:"
linters:
- staticcheck
- text: "Use of weak random number generator"
linters:
- gosec
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
gosec:
excludes:
# Flags for potentially-unsafe casting of ints, similar problem to globally-disabled G103
- G115
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/cometbft/cometbft)
- prefix(github.com/cosmos/ibc-go)
- prefix(github.com/strangelove-ventures/interchaintest)
- prefix(github.com/cosmos/interchain-attestation)

custom-order: true
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
revive:
rules:
- name: if-return
disabled: true
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Ethereum, Solana, and more.
The project is partially funded by the Dorahacks ATOM Economic Zone Quadratic Grant rounds.
You can find project information and contribute to the project here: https://dorahacks.io/aez


## Current status
The project is under development and is not yet ready for production use.

Expand Down Expand Up @@ -57,16 +56,28 @@ A talk about the project can be found here: https://www.youtube.com/watch?v=loNy

TODO: Add rest of prerequisites

* Just
* Go
* Docker (for e2e tests)
* golangci-lint

### Testing

Each module has a unit test suite that can be run with `make test`.

You can also run all unit tests with for all modules with `just test-unit`.

In addition, there is an e2e test suite that can be run using `make interchaintest` (under `testing/`).
Before running the test, however, you need to build the docker images (which is required for every change you make to the code) with `make docker-images`.

### Linting

You can lint all modules with `just lint`.

### Proto generation

If you make changes to the proto files, you need to regenerate the go code with `just proto-gen` (or `make proto-gen` in the module directories).

### Running locally

You can spin up a local testnet using `make serve` (under `testing/`. This spins up two chains, configures a sidecar process, and sets up an IBC connection with clients, connections and channels.
Expand All @@ -79,4 +90,4 @@ This project was originally built by Gjermund Garaba (https://github.com/gjermun
for Celestia's Infinite Space Bazaar to solve the problem of waiting for the dispute period to pass when bridging assets from an optimistic rollup to a receiving chain.

You can find the original working proof of concept code here:
https://github.com/gjermundgaraba/interchain-attestation/tree/9bc691c585697921b84c5467b13996389e6d119f
https://github.com/cosmos/interchain-attestation/tree/9bc691c585697921b84c5467b13996389e6d119f
40 changes: 20 additions & 20 deletions configmodule/api/configmodule/module/v1/module.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions configmodule/autocli.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package configmodule

import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
_ "cosmossdk.io/api/cosmos/crypto/ed25519" // register to that it shows up in protoregistry.GlobalTypes
_ "cosmossdk.io/api/cosmos/crypto/ed25519" // register to that it shows up in protoregistry.GlobalTypes
_ "cosmossdk.io/api/cosmos/crypto/secp256k1" // register to that it shows up in protoregistry.GlobalTypes
_ "cosmossdk.io/api/cosmos/crypto/secp256r1" // register to that it shows up in protoregistry.GlobalTypes
configmodulev1 "github.com/gjermundgaraba/interchain-attestation/configmodule/api/configmodule/v1"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"

configmodulev1 "github.com/cosmos/interchain-attestation/configmodule/api/configmodule/v1"
)

// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
Expand All @@ -25,9 +27,9 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
Short: "Query all attestators",
},
{
RpcMethod: "Attestator",
Use: "attestator [attestator_id]",
Short: "Query attestator by attestator id",
RpcMethod: "Attestator",
Use: "attestator [attestator_id]",
Short: "Query attestator by attestator id",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "attestator_id"}},
},
},
Expand Down
18 changes: 11 additions & 7 deletions configmodule/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package cli

import (
"cosmossdk.io/core/address"
"fmt"
"strings"

"github.com/spf13/cobra"

"cosmossdk.io/core/address"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/version"
"github.com/gjermundgaraba/interchain-attestation/configmodule/types"
coretypes "github.com/gjermundgaraba/interchain-attestation/core/types"
"github.com/spf13/cobra"
"strings"

"github.com/cosmos/interchain-attestation/configmodule/types"
coretypes "github.com/cosmos/interchain-attestation/core/types"
)

func TxCmd(valAddrCodec address.Codec) *cobra.Command {
Expand Down Expand Up @@ -74,7 +78,7 @@ It is the public key that matches with the sidecar private key used to sign atte

msg := &types.MsgRegisterAttestator{
ValidatorAddress: valStr,
AttestatorId: attestationRegistration.AttestatorID,
AttestatorId: attestationRegistration.AttestatorID,
AttestationPublicKey: attestationRegistration.AttestationPublicKey,
}

Expand All @@ -89,4 +93,4 @@ It is the public key that matches with the sidecar private key used to sign atte
flags.AddTxFlagsToCmd(cmd)

return cmd
}
}
32 changes: 19 additions & 13 deletions configmodule/common_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
package configmodule_test

import (
"testing"

"github.com/stretchr/testify/require"

_ "github.com/cosmos/cosmos-sdk/x/auth" // for side effects
_ "github.com/cosmos/cosmos-sdk/x/bank" // for side effects
_ "github.com/cosmos/cosmos-sdk/x/consensus" // for side effects
_ "github.com/cosmos/cosmos-sdk/x/staking" // for side effects
_ "github.com/cosmos/interchain-attestation/configmodule" // for side effects

appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"cosmossdk.io/core/appconfig"
"cosmossdk.io/depinject"
sdklog "cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
_ "github.com/cosmos/cosmos-sdk/x/auth" // for side effects
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
_ "github.com/cosmos/cosmos-sdk/x/bank" // for side effects
_ "github.com/cosmos/cosmos-sdk/x/consensus" // for side effects
_ "github.com/cosmos/cosmos-sdk/x/staking" // for side effects
_ "github.com/gjermundgaraba/interchain-attestation/configmodule" // for side effects
configmodulemodulev1 "github.com/gjermundgaraba/interchain-attestation/configmodule/api/configmodule/module/v1"
"github.com/gjermundgaraba/interchain-attestation/configmodule/keeper"
"github.com/gjermundgaraba/interchain-attestation/configmodule/types"
"github.com/stretchr/testify/require"
"testing"

configmodulemodulev1 "github.com/cosmos/interchain-attestation/configmodule/api/configmodule/module/v1"
"github.com/cosmos/interchain-attestation/configmodule/keeper"
"github.com/cosmos/interchain-attestation/configmodule/types"
)

type suite struct {
App *runtime.App
App *runtime.App

AccountKeeper authkeeper.AccountKeeper
Keeper keeper.Keeper
AccountKeeper authkeeper.AccountKeeper
Keeper keeper.Keeper
}

func createTestSuite(t *testing.T) suite {
t.Helper()
res := suite{}

app, err := simtestutil.SetupWithConfiguration(
Expand Down
7 changes: 4 additions & 3 deletions configmodule/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package configmodule

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gjermundgaraba/interchain-attestation/configmodule/keeper"
"github.com/gjermundgaraba/interchain-attestation/configmodule/types"

"github.com/cosmos/interchain-attestation/configmodule/keeper"
"github.com/cosmos/interchain-attestation/configmodule/types"
)

func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
Expand Down Expand Up @@ -33,7 +34,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
}

return &types.GenesisState{
Params: &params,
Params: &params,
Attestators: attestators,
}
}
20 changes: 12 additions & 8 deletions configmodule/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package configmodule_test

import (
"testing"

"github.com/stretchr/testify/require"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/gjermundgaraba/interchain-attestation/configmodule"
"github.com/gjermundgaraba/interchain-attestation/configmodule/types"
"github.com/stretchr/testify/require"
"testing"

"github.com/cosmos/interchain-attestation/configmodule"
"github.com/cosmos/interchain-attestation/configmodule/types"
)

func TestGenesis(t *testing.T) {
Expand All @@ -19,14 +22,15 @@ func TestGenesis(t *testing.T) {
pubKey := secp256k1.GenPrivKey().PubKey()
require.NotNil(t, pubKey)
pubKeyAny, err := codectypes.NewAnyWithValue(pubKey)
require.NoError(t, err)

testCases := []struct {
name string
name string
genesis types.GenesisState
// expectedError bool // TODO: Add later when this can fail
} {
}{
{
name: "default",
name: "default",
genesis: *types.DefaultGenesisState(),
},
{
Expand All @@ -35,7 +39,7 @@ func TestGenesis(t *testing.T) {
Params: &types.Params{},
Attestators: []types.Attestator{
{
AttestatorId: []byte("test-attestator-id"),
AttestatorId: []byte("test-attestator-id"),
PublicKey: pubKeyAny,
ConsensusPubkey: consPubKeyAny,
},
Expand Down
6 changes: 3 additions & 3 deletions configmodule/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/gjermundgaraba/interchain-attestation/configmodule
module github.com/cosmos/interchain-attestation/configmodule

go 1.23.0

replace github.com/gjermundgaraba/interchain-attestation/core => ../core
replace github.com/cosmos/interchain-attestation/core => ../core

require (
cosmossdk.io/api v0.7.5
Expand All @@ -19,7 +19,7 @@ require (
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/gogoproto v1.5.0
github.com/cosmos/ibc-go/v9 v9.0.0-beta.1 // indirect; indirect;
github.com/gjermundgaraba/interchain-attestation/core v0.0.0
github.com/cosmos/interchain-attestation/core v0.0.0
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/stretchr/testify v1.9.0
Expand Down
Loading

0 comments on commit c9d09c9

Please sign in to comment.