Skip to content

Commit

Permalink
replace golint with go vet (#4058)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderZhi authored Jan 24, 2024
1 parent c413634 commit a21265f
Show file tree
Hide file tree
Showing 28 changed files with 79 additions and 83 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ jobs:
id: unittest
shell: bash
run: |
go install golang.org/x/lint/golint@master
go install github.com/dave/courtney@latest
go mod tidy
golint -set_exit_status $(go list ./... | grep -v /vendor/ | grep -v /explorer/idl/ | grep -v /api/idl/)
go vet $(go list ./... | grep -v /vendor/ | grep -v /explorer/idl/ | grep -v /api/idl/)
#go get -u github.com/dave/courtney@038390a12707e2d91979d2ca77a71597f4afe400
./go.test.sh
#make test
Expand Down
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ run:
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 15
maligned:
Expand Down Expand Up @@ -64,7 +62,6 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Go parameters
GOCMD=go
GOLINT=golint
GOVET=$(GOCMD) vet
GOBUILD=$(GOCMD) build
GOINSTALL=$(GOCMD) install
GOCLEAN=$(GOCMD) clean
Expand Down Expand Up @@ -113,7 +113,7 @@ fmt:

.PHONY: lint
lint:
go list ./... | xargs $(GOLINT)
go list ./... | xargs $(GOVET)

.PHONY: lint-rich
lint-rich:
Expand Down
10 changes: 5 additions & 5 deletions action/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ func TestExecutionAccessList(t *testing.T) {
{nil, 10400},
{
types.AccessList{
{common.Address{}, nil},
{Address: common.Address{}, StorageKeys: nil},
}, 12800,
},
{
types.AccessList{
{_c2, []common.Hash{{}, _k1}},
{Address: _c2, StorageKeys: []common.Hash{{}, _k1}},
}, 16600,
},
{
types.AccessList{
{common.Address{}, nil},
{_c1, []common.Hash{_k1, {}, _k3}},
{_c2, []common.Hash{_k2, _k3, _k4, _k1}},
{Address: common.Address{}, StorageKeys: nil},
{Address: _c1, StorageKeys: []common.Hash{_k1, {}, _k3}},
{Address: _c2, StorageKeys: []common.Hash{_k2, _k3, _k4, _k1}},
}, 30900,
},
} {
Expand Down
1 change: 0 additions & 1 deletion action/protocol/execution/evm/evmstatedbadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,6 @@ func (stateDB *StateDBAdapter) ForEachStorage(addr common.Address, cb func(commo
return nil
}
}
return nil
}

// accountState returns an account state
Expand Down
6 changes: 3 additions & 3 deletions action/protocol/poll/governance_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ func TestHandle(t *testing.T) {
var sc3 state.CandidateList
_, err = sm3.State(&sc3, protocol.KeyOption(candKey[:]), protocol.NamespaceOption(protocol.SystemNamespace))
require.NoError(err)
sc3 = append(sc3, &state.Candidate{"1", big.NewInt(10), "2", nil})
sc3 = append(sc3, &state.Candidate{"1", big.NewInt(10), "2", nil})
sc3 = append(sc3, &state.Candidate{Address: "1", Votes: big.NewInt(10), RewardAddress: "2", CanName: nil})
sc3 = append(sc3, &state.Candidate{Address: "1", Votes: big.NewInt(10), RewardAddress: "2", CanName: nil})
act3 := action.NewPutPollResult(1, 1, sc3)
bd := &action.EnvelopeBuilder{}
elp := bd.SetGasLimit(uint64(100000)).
Expand Down Expand Up @@ -508,7 +508,7 @@ func TestHandle(t *testing.T) {
var sc4 state.CandidateList
_, err = sm4.State(&sc4, protocol.KeyOption(candKey[:]), protocol.NamespaceOption(protocol.SystemNamespace))
require.NoError(err)
sc4 = append(sc4, &state.Candidate{"1", big.NewInt(10), "2", nil})
sc4 = append(sc4, &state.Candidate{Address: "1", Votes: big.NewInt(10), RewardAddress: "2", CanName: nil})
act4 := action.NewPutPollResult(1, 1, sc4)
bd4 := &action.EnvelopeBuilder{}
elp4 := bd4.SetGasLimit(uint64(100000)).
Expand Down
6 changes: 3 additions & 3 deletions action/protocol/poll/staking_committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ func TestHandle_StakingCommittee(t *testing.T) {
var sc3 state.CandidateList
_, err = sm3.State(&sc3, protocol.LegacyKeyOption(candidatesutil.ConstructLegacyKey(1)))
require.NoError(err)
sc3 = append(sc3, &state.Candidate{"1", big.NewInt(10), "2", nil})
sc3 = append(sc3, &state.Candidate{"1", big.NewInt(10), "2", nil})
sc3 = append(sc3, &state.Candidate{Address: "1", Votes: big.NewInt(10), RewardAddress: "2", CanName: nil})
sc3 = append(sc3, &state.Candidate{Address: "1", Votes: big.NewInt(10), RewardAddress: "2", CanName: nil})
act3 := action.NewPutPollResult(1, 1, sc3)
bd := &action.EnvelopeBuilder{}
elp := bd.SetGasLimit(uint64(100000)).
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestHandle_StakingCommittee(t *testing.T) {
var sc4 state.CandidateList
_, err = sm4.State(&sc4, protocol.LegacyKeyOption(candidatesutil.ConstructLegacyKey(1)))
require.NoError(err)
sc4 = append(sc4, &state.Candidate{"1", big.NewInt(10), "2", nil})
sc4 = append(sc4, &state.Candidate{Address: "1", Votes: big.NewInt(10), RewardAddress: "2", CanName: nil})
act4 := action.NewPutPollResult(1, 1, sc4)
bd4 := &action.EnvelopeBuilder{}
elp4 := bd4.SetGasLimit(uint64(100000)).
Expand Down
4 changes: 2 additions & 2 deletions action/protocol/staking/ethabi/stake_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type (
}
)

func encodeVoteBucketListToEth(outputs abi.Arguments, buckets iotextypes.VoteBucketList) (string, error) {
func encodeVoteBucketListToEth(outputs abi.Arguments, buckets *iotextypes.VoteBucketList) (string, error) {
args := make([]BucketEth, len(buckets.Buckets))
for i, bucket := range buckets.Buckets {
args[i] = BucketEth{}
Expand Down Expand Up @@ -139,7 +139,7 @@ func encodeCandidateToEth(candidate *iotextypes.CandidateV2) (*CandidateEth, err
return result, nil
}

func encodeBucketTypeListToEth(outputs abi.Arguments, bucketTypes iotextypes.ContractStakingBucketTypeList) (string, error) {
func encodeBucketTypeListToEth(outputs abi.Arguments, bucketTypes *iotextypes.ContractStakingBucketTypeList) (string, error) {
args := make([]BucketTypeEth, len(bucketTypes.BucketTypes))
for i, bt := range bucketTypes.BucketTypes {
args[i] = BucketTypeEth{}
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/staking/ethabi/stake_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ func (r *BucketsStateContext) EncodeToEth(resp *iotexapi.ReadStateResponse) (str
return "", err
}

return encodeVoteBucketListToEth(_bucketsMethod.Outputs, result)
return encodeVoteBucketListToEth(_bucketsMethod.Outputs, &result)
}
2 changes: 1 addition & 1 deletion action/protocol/staking/ethabi/stake_bucketsbycandidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ func (r *BucketsByCandidateStateContext) EncodeToEth(resp *iotexapi.ReadStateRes
return "", err
}

return encodeVoteBucketListToEth(_bucketsByCandidateMethod.Outputs, result)
return encodeVoteBucketListToEth(_bucketsByCandidateMethod.Outputs, &result)
}
2 changes: 1 addition & 1 deletion action/protocol/staking/ethabi/stake_bucketsbyindexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ func (r *BucketsByIndexesStateContext) EncodeToEth(resp *iotexapi.ReadStateRespo
return "", err
}

return encodeVoteBucketListToEth(_bucketsByIndexesMethod.Outputs, result)
return encodeVoteBucketListToEth(_bucketsByIndexesMethod.Outputs, &result)
}
2 changes: 1 addition & 1 deletion action/protocol/staking/ethabi/stake_bucketsbyvoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ func (r *BucketsByVoterStateContext) EncodeToEth(resp *iotexapi.ReadStateRespons
return "", err
}

return encodeVoteBucketListToEth(_bucketsByVoterMethod.Outputs, result)
return encodeVoteBucketListToEth(_bucketsByVoterMethod.Outputs, &result)
}
2 changes: 1 addition & 1 deletion action/protocol/staking/ethabi/stake_composite_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ func (r *CompositeBucketsStateContext) EncodeToEth(resp *iotexapi.ReadStateRespo
return "", err
}

return encodeVoteBucketListToEth(_compositeBucketsMethod.Outputs, result)
return encodeVoteBucketListToEth(_compositeBucketsMethod.Outputs, &result)
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestEncodeCompositeVoteBucketListToEth(t *testing.T) {
UnstakeStartBlockHeight: 1_000_000_002,
}

data, err := encodeVoteBucketListToEth(_compositeBucketsMethod.Outputs, iotextypes.VoteBucketList{
data, err := encodeVoteBucketListToEth(_compositeBucketsMethod.Outputs, &iotextypes.VoteBucketList{
Buckets: buckets,
})
t.Logf("data: %s\n", data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,5 @@ func (r *CompositeBucketsByCandidateStateContext) EncodeToEth(resp *iotexapi.Rea
return "", err
}

return encodeVoteBucketListToEth(_compositeBucketsByCandidateMethod.Outputs, result)
return encodeVoteBucketListToEth(_compositeBucketsByCandidateMethod.Outputs, &result)
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@ func (r *CompositeBucketsByIndexesStateContext) EncodeToEth(resp *iotexapi.ReadS
return "", err
}

return encodeVoteBucketListToEth(_compositeBucketsByIndexesMethod.Outputs, result)
return encodeVoteBucketListToEth(_compositeBucketsByIndexesMethod.Outputs, &result)
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,5 @@ func (r *CompositeBucketsByVoterStateContext) EncodeToEth(resp *iotexapi.ReadSta
return "", err
}

return encodeVoteBucketListToEth(_compositeBucketsByVoterMethod.Outputs, result)
return encodeVoteBucketListToEth(_compositeBucketsByVoterMethod.Outputs, &result)
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ func (r *ContractBucketTypesStateContext) EncodeToEth(resp *iotexapi.ReadStateRe
return "", err
}

return encodeBucketTypeListToEth(_contractBucketTypesMethod.Outputs, result)
return encodeBucketTypeListToEth(_contractBucketTypesMethod.Outputs, &result)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestEncodeBucketTypeListToEth(t *testing.T) {
StakedDuration: 2_000_000,
}

data, err := encodeBucketTypeListToEth(_contractBucketTypesMethod.Outputs, iotextypes.ContractStakingBucketTypeList{
data, err := encodeBucketTypeListToEth(_contractBucketTypesMethod.Outputs, &iotextypes.ContractStakingBucketTypeList{
BucketTypes: bts,
})

Expand Down
10 changes: 5 additions & 5 deletions action/protocol/staking/ethabi/stakebuckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestEncodeVoteBucketListToEth(t *testing.T) {
Owner: "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxf907nt9",
}

data, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, iotextypes.VoteBucketList{
data, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, &iotextypes.VoteBucketList{
Buckets: buckets,
})

Expand All @@ -82,7 +82,7 @@ func TestEncodeVoteBucketListToEthEmptyBuckets(t *testing.T) {

buckets := make([]*iotextypes.VoteBucket, 0)

data, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, iotextypes.VoteBucketList{
data, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, &iotextypes.VoteBucketList{
Buckets: buckets,
})

Expand All @@ -107,7 +107,7 @@ func TestEncodeVoteBucketListToEthErrorCandidateAddress(t *testing.T) {
Owner: "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgce2xkh",
}

_, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, iotextypes.VoteBucketList{
_, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, &iotextypes.VoteBucketList{
Buckets: buckets,
})

Expand All @@ -131,7 +131,7 @@ func TestEncodeVoteBucketListToEthErrorStakedAmount(t *testing.T) {
Owner: "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgce2xkh",
}

_, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, iotextypes.VoteBucketList{
_, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, &iotextypes.VoteBucketList{
Buckets: buckets,
})

Expand All @@ -155,7 +155,7 @@ func TestEncodeVoteBucketListToEthErrorOwner(t *testing.T) {
Owner: "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxgce2xk",
}

_, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, iotextypes.VoteBucketList{
_, err := encodeVoteBucketListToEth(_bucketsMethod.Outputs, &iotextypes.VoteBucketList{
Buckets: buckets,
})

Expand Down
22 changes: 11 additions & 11 deletions api/coreservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestLogsInRange(t *testing.T) {
to, err := strconv.ParseUint(testData.ToBlock, 10, 64)
require.NoError(err)

logs, hashes, err := svr.LogsInRange(logfilter.NewLogFilter(&filter), from, to, uint64(0))
logs, hashes, err := svr.LogsInRange(logfilter.NewLogFilter(filter), from, to, uint64(0))
require.NoError(err)
require.Equal(4, len(logs))
require.Equal(4, len(hashes))
Expand All @@ -59,7 +59,7 @@ func TestLogsInRange(t *testing.T) {
to, err := strconv.ParseUint(testData.ToBlock, 10, 64)
require.NoError(err)

logs, hashes, err := svr.LogsInRange(logfilter.NewLogFilter(&filter), from, to, uint64(0))
logs, hashes, err := svr.LogsInRange(logfilter.NewLogFilter(filter), from, to, uint64(0))
require.NoError(err)
require.Equal(0, len(logs))
require.Equal(0, len(hashes))
Expand All @@ -73,7 +73,7 @@ func TestLogsInRange(t *testing.T) {
to, err := strconv.ParseUint(testData.ToBlock, 10, 64)
require.NoError(err)

logs, hashes, err := svr.LogsInRange(logfilter.NewLogFilter(&filter), from, to, uint64(5001))
logs, hashes, err := svr.LogsInRange(logfilter.NewLogFilter(filter), from, to, uint64(5001))
require.NoError(err)
require.Equal(4, len(logs))
require.Equal(4, len(hashes))
Expand All @@ -87,7 +87,7 @@ func TestLogsInRange(t *testing.T) {
to, err := strconv.ParseUint(testData.ToBlock, 10, 64)
require.NoError(err)

_, _, err = svr.LogsInRange(logfilter.NewLogFilter(&filter), from, to, uint64(0))
_, _, err = svr.LogsInRange(logfilter.NewLogFilter(filter), from, to, uint64(0))
expectedErr := errors.New("invalid start or end height")
require.Error(err)
require.Equal(expectedErr.Error(), err.Error())
Expand All @@ -101,7 +101,7 @@ func TestLogsInRange(t *testing.T) {
to, err := strconv.ParseUint(testData.ToBlock, 10, 64)
require.NoError(err)

_, _, err = svr.LogsInRange(logfilter.NewLogFilter(&filter), from, to, uint64(0))
_, _, err = svr.LogsInRange(logfilter.NewLogFilter(filter), from, to, uint64(0))
expectedErr := errors.New("start block > tip height")
require.Error(err)
require.Equal(expectedErr.Error(), err.Error())
Expand All @@ -122,19 +122,19 @@ func BenchmarkLogsInRange(b *testing.B) {
to, _ := strconv.ParseInt(testData.ToBlock, 10, 64)

b.Run("five workers to extract logs", func(b *testing.B) {
blk.EXPECT().FilterBlocksInRange(logfilter.NewLogFilter(&filter), uint64(from), uint64(to), 0).Return([]uint64{1, 2, 3, 4}, nil).AnyTimes()
blk.EXPECT().FilterBlocksInRange(logfilter.NewLogFilter(filter), uint64(from), uint64(to), 0).Return([]uint64{1, 2, 3, 4}, nil).AnyTimes()
for i := 0; i < b.N; i++ {
svr.LogsInRange(logfilter.NewLogFilter(&filter), uint64(from), uint64(to), uint64(0))
svr.LogsInRange(logfilter.NewLogFilter(filter), uint64(from), uint64(to), uint64(0))
}
})
}

func getTopicsAddress(addr []string, topics [][]string) (iotexapi.LogsFilter, error) {
func getTopicsAddress(addr []string, topics [][]string) (*iotexapi.LogsFilter, error) {
var filter iotexapi.LogsFilter
for _, ethAddr := range addr {
ioAddr, err := ethAddrToIoAddr(ethAddr)
if err != nil {
return iotexapi.LogsFilter{}, err
return nil, err
}
filter.Address = append(filter.Address, ioAddr.String())
}
Expand All @@ -143,14 +143,14 @@ func getTopicsAddress(addr []string, topics [][]string) (iotexapi.LogsFilter, er
for _, str := range tp {
b, err := hexToBytes(str)
if err != nil {
return iotexapi.LogsFilter{}, err
return nil, err
}
topic = append(topic, b)
}
filter.Topics = append(filter.Topics, &iotexapi.Topics{Topic: topic})
}

return filter, nil
return &filter, nil
}

func setupTestCoreService() (CoreService, blockchain.Blockchain, blockdao.BlockDAO, actpool.ActPool, func()) {
Expand Down
Loading

0 comments on commit a21265f

Please sign in to comment.