diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index b8ddf70a..a51dd836 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.19 # check with 1.19 because it matches dev envs. Does not need to affect go.mod. + go-version: 1.23 # check with 1.19 because it matches dev envs. Does not need to affect go.mod. - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/.golangci.yml b/.golangci.yml index f5735c4f..e6381dbc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,10 +9,9 @@ linters: - copyloopvar - dogsled - errcheck - - exportloopref - gci - goconst - # - gocritic + - gocritic - gofumpt - gosec - gosimple @@ -24,7 +23,7 @@ linters: - nolintlint # - revive - staticcheck - - stylecheck + # - stylecheck - typecheck - unconvert - unparam @@ -34,57 +33,20 @@ linters: # TODO: fix the use of deprecated gov style issues: - exclude-rules: - - text: "SA1019: sdkerrors.Register" - linters: - - staticcheck - - text: "sdkerrors.ABCIInfo is deprecated" - linters: - - staticcheck - - text: "sdkerrors.IsOf is deprecated" - linters: - - staticcheck - - text: "Use WeightedProposalMsg instead" - linters: - - staticcheck - - text: "Use MsgSimulatorFn instead" - linters: - - staticcheck - - text: "Error return value of `flagSet.Set` is not checked" - linters: - - errcheck - - text: "SA1019: sdkerrors.Wrapf is deprecated: functionality of this package has been moved to it's own module" - linters: - - staticcheck - - text: "sdkerrors.Error is deprecated: the type has been moved to cosmossdk.io/errors module" - linters: - - staticcheck - - text: "sdkerrors.Wrap is deprecated" - 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 - - path: "migrations" - text: "SA1019:" - linters: - - staticcheck - max-issues-per-linter: 10000 max-same-issues: 10000 linters-settings: revive: - disable: - - var-naming + rules: + - name: var-naming + severity: warning + disabled: false + exclude: [""] + arguments: + - ["ID"] # AllowList + - ["VM"] # DenyList + - - upperCaseConst: true # Extra parameter (upperCaseConst|skipPackageNameChecks) dogsled: max-blank-identifiers: 3 maligned: diff --git a/internal/api/callbacks.go b/internal/api/callbacks.go index 908055be..1fe27654 100644 --- a/internal/api/callbacks.go +++ b/internal/api/callbacks.go @@ -440,7 +440,7 @@ func cValidateAddress(ptr *C.api_t, src C.U8SliceView, errOut *C.UnmanagedVector if errOut == nil { return C.GoError_BadArgument } - if !(*errOut).is_none { + if !errOut.is_none { panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.") } diff --git a/internal/api/iterator_test.go b/internal/api/iterator_test.go index 31ad6b70..53e25431 100644 --- a/internal/api/iterator_test.go +++ b/internal/api/iterator_test.go @@ -115,7 +115,7 @@ func TestStoreIteratorHitsLimit(t *testing.T) { iter, _ = store.Iterator(nil, nil) _, err = storeIterator(callID, iter, limit) - require.ErrorContains(t, err, "Reached iterator limit (2)") + require.ErrorContains(t, err, "reached iterator limit (2)") endCall(callID) } @@ -216,6 +216,9 @@ func TestQueueIteratorRaces(t *testing.T) { env := MockEnvBin(t) reduceQuery := func(t *testing.T, setup queueData, expected string) { + callID := startCall() + defer endCall(callID) + checksum, querier, api := setup.checksum, setup.querier, setup.api gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT) igasMeter := types.GasMeter(gasMeter) @@ -291,5 +294,5 @@ func TestQueueIteratorLimit(t *testing.T) { query = []byte(`{"open_iterators":{"count":35000}}`) env = MockEnvBin(t) _, _, err = Query(cache, checksum, env, query, &igasMeter, store, api, &querier, gasLimit, TESTING_PRINT_DEBUG) - require.ErrorContains(t, err, "Reached iterator limit (32768)") + require.ErrorContains(t, err, "reached iterator limit (32768)") } diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index eae45e31..62fabbc7 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "math" "os" "path/filepath" "strings" @@ -80,7 +81,7 @@ func TestInitCacheErrorsForBrokenDir(t *testing.T) { }, } _, err := InitCache(config) - require.ErrorContains(t, err, "Could not create base directory") + require.ErrorContains(t, err, "could not create base directory") } func TestInitLockingPreventsConcurrentAccess(t *testing.T) { @@ -108,7 +109,7 @@ func TestInitLockingPreventsConcurrentAccess(t *testing.T) { }, } _, err2 := InitCache(config2) - require.ErrorContains(t, err2, "Could not lock exclusive.lock") + require.ErrorContains(t, err2, "could not lock exclusive.lock") ReleaseCache(cache1) @@ -777,6 +778,9 @@ func TestExecuteStorageLoop(t *testing.T) { // the "sdk gas" * GasMultiplier + the wasm cost should equal the maxGas (or be very close) totalCost := gasReport.UsedInternally + gasMeter2.GasConsumed() + if totalCost > math.MaxInt64 { + t.Fatal("gas cost overflow") + } require.Equal(t, int64(maxGas), int64(totalCost)) } diff --git a/internal/api/memory_test.go b/internal/api/memory_test.go index e6ca02eb..892a6f37 100644 --- a/internal/api/memory_test.go +++ b/internal/api/memory_test.go @@ -1,6 +1,7 @@ package api import ( + "math" "testing" "unsafe" @@ -11,7 +12,9 @@ func TestMakeView(t *testing.T) { data := []byte{0xaa, 0xbb, 0x64} dataView := makeView(data) require.Equal(t, cbool(false), dataView.is_nil) - require.Equal(t, cusize(3), dataView.len) + length := int(dataView.len) + require.Less(t, length, math.MaxInt) + require.Equal(t, 3, length) empty := []byte{} emptyView := makeView(empty) @@ -28,8 +31,12 @@ func TestCreateAndDestroyUnmanagedVector(t *testing.T) { original := []byte{0xaa, 0xbb, 0x64} unmanaged := newUnmanagedVector(original) require.Equal(t, cbool(false), unmanaged.is_none) - require.Equal(t, 3, int(unmanaged.len)) - require.GreaterOrEqual(t, 3, int(unmanaged.cap)) // Rust implementation decides this + length := int(unmanaged.len) + require.Less(t, length, math.MaxInt) + require.Equal(t, 3, length) + cap := int(unmanaged.cap) + require.Less(t, cap, math.MaxInt) + require.GreaterOrEqual(t, cap, 3) // Rust implementation decides this copy := copyAndDestroyUnmanagedVector(unmanaged) require.Equal(t, original, copy) } @@ -39,8 +46,12 @@ func TestCreateAndDestroyUnmanagedVector(t *testing.T) { original := []byte{} unmanaged := newUnmanagedVector(original) require.Equal(t, cbool(false), unmanaged.is_none) - require.Equal(t, 0, int(unmanaged.len)) - require.GreaterOrEqual(t, 0, int(unmanaged.cap)) // Rust implementation decides this + length := int(unmanaged.len) + require.Less(t, length, math.MaxInt) + require.Equal(t, 0, length) + cap := int(unmanaged.cap) + require.Less(t, cap, math.MaxInt) + require.GreaterOrEqual(t, cap, 0) // Rust implementation decides this copy := copyAndDestroyUnmanagedVector(unmanaged) require.Equal(t, original, copy) } @@ -63,14 +74,14 @@ func TestCreateAndDestroyUnmanagedVector(t *testing.T) { func TestCopyDestroyUnmanagedVector(t *testing.T) { { // ptr, cap and len broken. Do not access those values when is_none is true - invalidPtr := unsafe.Pointer(uintptr(42)) //nolint:unsafeptr + invalidPtr := unsafe.Pointer(uintptr(42)) uv := constructUnmanagedVector(cbool(true), cu8_ptr(invalidPtr), cusize(0xBB), cusize(0xAA)) copy := copyAndDestroyUnmanagedVector(uv) require.Nil(t, copy) } { // Capacity is 0, so no allocation happened. Do not access the pointer. - invalidPtr := unsafe.Pointer(uintptr(42)) //nolint:unsafeptr + invalidPtr := unsafe.Pointer(uintptr(42)) uv := constructUnmanagedVector(cbool(false), cu8_ptr(invalidPtr), cusize(0), cusize(0)) copy := copyAndDestroyUnmanagedVector(uv) require.Equal(t, []byte{}, copy) diff --git a/lib_libwasmvm_test.go b/lib_libwasmvm_test.go index f54ca291..83be94e1 100644 --- a/lib_libwasmvm_test.go +++ b/lib_libwasmvm_test.go @@ -76,21 +76,21 @@ func TestStoreCode(t *testing.T) { wasm := []byte{0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00} _, _, err := vm.StoreCode(wasm, TESTING_GAS_LIMIT) - require.ErrorContains(t, err, "Error during static Wasm validation: Wasm contract must contain exactly one memory") + require.ErrorContains(t, err, "Error calling the VM: Error during static Wasm validation: Wasm contract must contain exactly one memory") } // No Wasm { wasm := []byte("foobar") _, _, err := vm.StoreCode(wasm, TESTING_GAS_LIMIT) - require.ErrorContains(t, err, "Wasm bytecode could not be deserialized") + require.ErrorContains(t, err, "bytecode could not be deserialized") } // Empty { wasm := []byte("") _, _, err := vm.StoreCode(wasm, TESTING_GAS_LIMIT) - require.ErrorContains(t, err, "Wasm bytecode could not be deserialized") + require.ErrorContains(t, err, "bytecode could not be deserialized") } // Nil diff --git a/lib_test.go b/lib_test.go index 54b2d329..c2d40c8e 100644 --- a/lib_test.go +++ b/lib_test.go @@ -28,5 +28,5 @@ func TestCreateChecksum(t *testing.T) { // Text file fails _, err = CreateChecksum([]byte("Hello world")) - require.ErrorContains(t, err, "do not start with Wasm magic number") + require.ErrorContains(t, err, "do not start with wasm magic number") } diff --git a/types/msg.go b/types/msg.go index 369a3616..4998c459 100644 --- a/types/msg.go +++ b/types/msg.go @@ -139,7 +139,7 @@ type GovMsg struct { type voteOption int type VoteMsg struct { - ProposalId uint64 `json:"proposal_id"` + ProposalID uint64 `json:"proposal_id"` // Option is the vote option. // // This used to be called "vote", but was changed for consistency with Cosmos SDK. @@ -150,7 +150,7 @@ type VoteMsg struct { func (m *VoteMsg) UnmarshalJSON(data []byte) error { // We need a custom unmarshaler to parse both the "stargate" and "any" variants type InternalVoteMsg struct { - ProposalId uint64 `json:"proposal_id"` + ProposalID uint64 `json:"proposal_id"` Option *voteOption `json:"option"` Vote *voteOption `json:"vote"` // old version } @@ -168,7 +168,7 @@ func (m *VoteMsg) UnmarshalJSON(data []byte) error { } *m = VoteMsg{ - ProposalId: tmp.ProposalId, + ProposalID: tmp.ProposalID, Option: *tmp.Option, } return nil diff --git a/types/msg_test.go b/types/msg_test.go index caf2d453..d26d63c3 100644 --- a/types/msg_test.go +++ b/types/msg_test.go @@ -123,7 +123,7 @@ func TestGovMsgVoteSerialization(t *testing.T) { require.Nil(t, msg.VoteWeighted) require.NotNil(t, msg.Vote) - require.Equal(t, uint64(4), msg.Vote.ProposalId) + require.Equal(t, uint64(4), msg.Vote.ProposalID) require.Equal(t, NoWithVeto, msg.Vote.Option) newDocument := []byte(`{"vote":{"proposal_id":4,"option":"no_with_veto"}}`) diff --git a/types/submessages.go b/types/submessages.go index f258b744..d7d58c07 100644 --- a/types/submessages.go +++ b/types/submessages.go @@ -29,8 +29,8 @@ var toReplyOn = map[string]replyOn{ "never": ReplyNever, } -func (r replyOn) String() string { - return fromReplyOn[r] +func (s replyOn) String() string { + return fromReplyOn[s] } func (s replyOn) MarshalJSON() ([]byte, error) { //nolint:revive