diff --git a/.golangci.yml b/.golangci.yml index 3ebcd0b..dfc19ca 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,31 +1,123 @@ run: tests: true - timeout: 10m + timeout: 15m + sort-results: true + allow-parallel-runners: true + exclude-dir: testutil/testdata linters: disable-all: true enable: - - exportloopref + - bodyclose + - canonicalheader + - copyloopvar - errcheck - - gci + - dogsled - goconst - gocritic + - gci + - gocheckcompilerdirectives - gofumpt - gosec - gosimple - govet - ineffassign + - maintidx - misspell - nakedret + - nestif + - nilerr + - nolintlint - staticcheck - - maintidx - - thelper - - typecheck - - stylecheck - revive - - typecheck + - stylecheck - tenv + - typecheck + - tagalign + - tagliatelle + - thelper # too many positives with table tests that have custom setup(*testing.T) + - testifylint + - perfsprint # + - promlinter + - protogetter - unconvert - - unparam - unused - - misspell + - unparam + - usestdlibvars + - zerologlint + +issues: + exclude-files: + - server/grpc/gogoreflection/fix_registration.go + - x/wasm/migrations/v2/legacy_types.go + - ".*\\.pb\\.go$" + - ".*\\.pb\\.gw\\.\\.go$" + - ".*\\.pulsar\\.go$" + + max-issues-per-linter: 10000 + max-same-issues: 10000 + +linters-settings: + gci: + custom-order: true + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(cosmossdk.io) + - prefix(github.com/cosmos/cosmos-sdk) + - prefix(github.com/CosmWasm/wasmd) + + gosec: + # To select a subset of rules to run. + # Available rules: https://github.com/securego/gosec#available-rules + # Default: [] - means include all rules + includes: + # - G101 # Look for hard coded credentials + - G102 # Bind to all interfaces + - G103 # Audit the use of unsafe block + - G104 # Audit errors not checked + - G106 # Audit the use of ssh.InsecureIgnoreHostKey + - G107 # Url provided to HTTP request as taint input + - G108 # Profiling endpoint automatically exposed on /debug/pprof + - G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32 + - G110 # Potential DoS vulnerability via decompression bomb + - G111 # Potential directory traversal + - G112 # Potential slowloris attack + - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772) + - G114 # Use of net/http serve function that has no support for setting timeouts + - G201 # SQL query construction using format string + - G202 # SQL query construction using string concatenation + - G203 # Use of unescaped data in HTML templates + - G204 # Audit use of command execution + - G301 # Poor file permissions used when creating a directory + - G302 # Poor file permissions used with chmod + - G303 # Creating tempfile using a predictable path + - G304 # File path provided as taint input + - G305 # File traversal when extracting zip/tar archive + - G306 # Poor file permissions used when writing to a new file + - G307 # Deferring a method which returns an error + - G401 # Detect the usage of DES, RC4, MD5 or SHA1 + - G402 # Look for bad TLS connection settings + - G403 # Ensure minimum RSA key length of 2048 bits + - G404 # Insecure random number source (rand) + - G501 # Import blocklist: crypto/md5 + - G502 # Import blocklist: crypto/des + - G503 # Import blocklist: crypto/rc4 + - G504 # Import blocklist: net/http/cgi + - G505 # Import blocklist: crypto/sha1 + - G601 # Implicit memory aliasing of items from a range statement + misspell: + locale: US + gofumpt: + extra-rules: true + dogsled: + max-blank-identifiers: 6 + maligned: + suggest-new: true + nolintlint: + allow-unused: false + allow-leading-space: true + require-explanation: false + require-specific: false + gosimple: + checks: ["all"] diff --git a/broadcast/broadcast.go b/broadcast/broadcast.go index 0a139f8..c28a39e 100644 --- a/broadcast/broadcast.go +++ b/broadcast/broadcast.go @@ -5,11 +5,20 @@ import ( "fmt" "log" - sdkmath "cosmossdk.io/math" - wasmd "github.com/CosmWasm/wasmd/x/wasm" cometrpc "github.com/cometbft/cometbft/rpc/client/http" coretypes "github.com/cometbft/cometbft/rpc/core/types" tmtypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/ibc-go/modules/apps/callbacks/testing/simapp/params" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v8/modules/core" + hardhatbank "github.com/somatic-labs/hardhat/modules/bank" + hardhatibc "github.com/somatic-labs/hardhat/modules/ibc" + wasm "github.com/somatic-labs/hardhat/modules/wasm" + types "github.com/somatic-labs/hardhat/types" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -21,14 +30,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/cosmos/ibc-go/modules/apps/callbacks/testing/simapp/params" - "github.com/cosmos/ibc-go/v8/modules/apps/transfer" - transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v8/modules/core" - hardhatbank "github.com/somatic-labs/hardhat/modules/bank" - hardhatibc "github.com/somatic-labs/hardhat/modules/ibc" - wasm "github.com/somatic-labs/hardhat/modules/wasm" - types "github.com/somatic-labs/hardhat/types" + + wasmd "github.com/CosmWasm/wasmd/x/wasm" ) var cdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) @@ -38,8 +41,8 @@ func init() { banktypes.RegisterInterfaces(cdc.InterfaceRegistry()) } -func SendTransactionViaRPC(config types.Config, rpcEndpoint string, chainID string, sequence, accnum uint64, - privKey cryptotypes.PrivKey, pubKey cryptotypes.PubKey, fromAddress string, msgType string, +func SendTransactionViaRPC(config types.Config, rpcEndpoint, chainID string, sequence, accnum uint64, + privKey cryptotypes.PrivKey, pubKey cryptotypes.PubKey, fromAddress, msgType string, msgParams types.MsgParams, ) (response *coretypes.ResultBroadcastTx, txbody string, err error) { encodingConfig := params.MakeTestEncodingConfig() diff --git a/client/grpc_client.go b/client/grpc_client.go index de0cec2..2b61742 100644 --- a/client/grpc_client.go +++ b/client/grpc_client.go @@ -3,10 +3,11 @@ package client import ( "context" - sdk "github.com/cosmos/cosmos-sdk/types" - tx "github.com/cosmos/cosmos-sdk/types/tx" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + + sdk "github.com/cosmos/cosmos-sdk/types" + tx "github.com/cosmos/cosmos-sdk/types/tx" ) type GRPCClient struct { @@ -15,7 +16,7 @@ type GRPCClient struct { } func NewGRPCClient(grpcEndpoint string) (*GRPCClient, error) { - conn, err := grpc.Dial(grpcEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.NewClient(grpcEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, err } diff --git a/lib/lib.go b/lib/lib.go index f1a93f5..a5e600a 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -14,8 +14,9 @@ import ( "time" "github.com/BurntSushi/toml" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/somatic-labs/hardhat/types" + + sdk "github.com/cosmos/cosmos-sdk/types" ) var client = &http.Client{ @@ -143,7 +144,7 @@ func GenerateRandomStringOfLength(n int) (string, error) { return string(b), nil } -func GenerateRandomAccount(prefix string) (sdk.AccAddress, error) { +func GenerateRandomAccount() (sdk.AccAddress, error) { // Generate 20 random bytes randomBytes := make([]byte, 20) _, err := rand.Read(randomBytes) diff --git a/lib/privkey.go b/lib/privkey.go index 3f2adf7..cabed57 100644 --- a/lib/privkey.go +++ b/lib/privkey.go @@ -3,10 +3,11 @@ package lib import ( "fmt" + types "github.com/somatic-labs/hardhat/types" + "github.com/cosmos/cosmos-sdk/crypto/hd" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - types "github.com/somatic-labs/hardhat/types" ) func GetPrivKey(config types.Config, mnemonic []byte) (cryptotypes.PrivKey, cryptotypes.PubKey, string) { diff --git a/main.go b/main.go index 41b2c0e..fdcbf6f 100644 --- a/main.go +++ b/main.go @@ -11,10 +11,11 @@ import ( "github.com/BurntSushi/toml" coretypes "github.com/cometbft/cometbft/rpc/core/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/somatic-labs/hardhat/broadcast" "github.com/somatic-labs/hardhat/lib" "github.com/somatic-labs/hardhat/types" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) const ( diff --git a/modules/bank/send.go b/modules/bank/send.go index 340b043..f10d6a9 100644 --- a/modules/bank/send.go +++ b/modules/bank/send.go @@ -3,11 +3,13 @@ package bank import ( "fmt" + "github.com/somatic-labs/hardhat/lib" + types "github.com/somatic-labs/hardhat/types" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/somatic-labs/hardhat/lib" - types "github.com/somatic-labs/hardhat/types" ) func CreateBankSendMsg(config types.Config, fromAddress string, msgParams types.MsgParams) (sdk.Msg, string, error) { @@ -19,7 +21,7 @@ func CreateBankSendMsg(config types.Config, fromAddress string, msgParams types. toAccAddress, err := sdk.AccAddressFromBech32(msgParams.ToAddress) if err != nil { fmt.Println("invalid to address, spamming random new accounts") - toAccAddress, err = lib.GenerateRandomAccount(config.Prefix) + toAccAddress, err = lib.GenerateRandomAccount() if err != nil { return nil, "", fmt.Errorf("error generating random account: %w", err) } diff --git a/modules/ibc/transfer.go b/modules/ibc/transfer.go index 4bf63b9..d9125cb 100644 --- a/modules/ibc/transfer.go +++ b/modules/ibc/transfer.go @@ -5,12 +5,14 @@ import ( "fmt" "strings" - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" lib "github.com/somatic-labs/hardhat/lib" types "github.com/somatic-labs/hardhat/types" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func CreateIBCTransferMsg(config types.Config, fromAddress string, msgParams types.MsgParams) (sdk.Msg, string, error) { diff --git a/modules/wasm/wasm.go b/modules/wasm/wasm.go index c64e5b5..d5a2a38 100644 --- a/modules/wasm/wasm.go +++ b/modules/wasm/wasm.go @@ -5,11 +5,14 @@ import ( "fmt" "os" - sdkmath "cosmossdk.io/math" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/somatic-labs/hardhat/lib" types "github.com/somatic-labs/hardhat/types" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) func CreateStoreCodeMsg(config types.Config, sender string, msgParams types.MsgParams) (sdk.Msg, string, error) {