Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit 0ad7c75

Browse files
authored
lint fixes and add lint to CIDI (#377)
* lint fixes and add lint to CIDI * enable more tests * fix tests * update travis * gomod tidy * update travis golang version * extend golangci deadline * remove wrong fmt and fix the duplicated proto bug
1 parent 7c05e39 commit 0ad7c75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+751
-296
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
run:
2-
deadline: 1m
2+
deadline: 5m
33

44
linters:
55
enable-all: true

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
language: go
2+
go:
3+
- 1.12.9
24
install:
35
- make get_tools
6+
- make get_golangci_lint
47
script:
8+
- make lint
59
- make build
610
- make install
711
- make test

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ benchmark:
4848
GOLANGCI_LINT_VERSION := v1.17.1
4949
GOLANGCI_LINT_HASHSUM := f5fa647a12f658924d9f7d6b9628d505ab118e8e049e43272de6526053ebe08d
5050

51-
get-golangci-lint:
51+
get_golangci_lint:
5252
cd scripts && bash install-golangci-lint.sh $(GOPATH)/bin $(GOLANGCI_LINT_VERSION) $(GOLANGCI_LINT_HASHSUM)
5353

5454
lint:
55-
@golangci-lint run
56-
go mod verify
55+
GO111MODULE=$(GO111MODULE) golangci-lint run
56+
GO111MODULE=$(GO111MODULE) go mod verify
5757

5858
lint-fix:
5959
@echo "--> Running linter auto fix"
60-
@golangci-lint run --fix
61-
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
62-
go mod verify
60+
GO111MODULE=$(GO111MODULE) golangci-lint run --fix
61+
GO111MODULE=$(GO111MODULE) find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
62+
GO111MODULE=$(GO111MODULE) go mod verify
6363

6464
.PHONY: lint lint-fix
6565

app/app.go

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
abci "github.com/tendermint/tendermint/abci/types"
4848
tmtypes "github.com/tendermint/tendermint/types"
4949
dbm "github.com/tendermint/tm-db"
50-
cmn "github.com/tendermint/tmlibs/common"
5150
)
5251

5352
const (
@@ -187,7 +186,7 @@ func NewLinoBlockchain(
187186
lb.CapKeyVoteStore, lb.CapKeyInfraStore, lb.CapKeyDeveloperStore, lb.CapKeyGlobalStore,
188187
lb.CapKeyParamStore, lb.CapKeyProposalStore, lb.CapKeyReputationV2Store, lb.CapKeyBandwidthStore)
189188
if err := lb.LoadLatestVersion(lb.CapKeyMainStore); err != nil {
190-
cmn.Exit(err.Error())
189+
panic(err)
191190
}
192191

193192
lb.Seal()
@@ -420,8 +419,14 @@ func (lb *LinoBlockchain) beginBlocker(ctx sdk.Context, req abci.RequestBeginBlo
420419
panic(err)
421420
}
422421
if chainStartTime == 0 {
423-
lb.globalManager.SetChainStartTime(ctx, ctx.BlockHeader().Time.Unix())
424-
lb.globalManager.SetLastBlockTime(ctx, ctx.BlockHeader().Time.Unix())
422+
err := lb.globalManager.SetChainStartTime(ctx, ctx.BlockHeader().Time.Unix())
423+
if err != nil {
424+
panic(err)
425+
}
426+
err = lb.globalManager.SetLastBlockTime(ctx, ctx.BlockHeader().Time.Unix())
427+
if err != nil {
428+
panic(err)
429+
}
425430
chainStartTime = ctx.BlockHeader().Time.Unix()
426431
}
427432

@@ -461,13 +466,16 @@ func (lb *LinoBlockchain) executeTimeEvents(ctx sdk.Context) {
461466
for i := lastBlockTime; i < currentTime; i++ {
462467
if timeEvents := lb.globalManager.GetTimeEventListAtTime(ctx, i); timeEvents != nil {
463468
lb.executeEvents(ctx, timeEvents.Events)
464-
lb.globalManager.RemoveTimeEventList(ctx, i)
469+
err := lb.globalManager.RemoveTimeEventList(ctx, i)
470+
if err != nil {
471+
panic(err)
472+
}
465473
}
466474
}
467475
}
468476

469477
// execute events in list based on their type
470-
func (lb *LinoBlockchain) executeEvents(ctx sdk.Context, eventList []types.Event) sdk.Error {
478+
func (lb *LinoBlockchain) executeEvents(ctx sdk.Context, eventList []types.Event) {
471479
for _, event := range eventList {
472480
switch e := event.(type) {
473481
case posttypes.RewardEvent:
@@ -492,7 +500,6 @@ func (lb *LinoBlockchain) executeEvents(ctx sdk.Context, eventList []types.Event
492500
ctx.Logger().Error(fmt.Sprintf("skipping event: %+v", e))
493501
}
494502
}
495-
return nil
496503
}
497504

498505
// udpate validator set and renew reputation round
@@ -542,15 +549,27 @@ func (lb *LinoBlockchain) increaseMinute(ctx sdk.Context) {
542549
// execute hourly event, distribute inflation to validators and
543550
// add hourly inflation to content creator reward pool
544551
func (lb *LinoBlockchain) executeHourlyEvent(ctx sdk.Context) {
545-
lb.globalManager.DistributeHourlyInflation(ctx)
552+
err := lb.globalManager.DistributeHourlyInflation(ctx)
553+
if err != nil {
554+
panic(err)
555+
}
546556
lb.distributeInflationToValidator(ctx)
547-
lb.bandwidthManager.ReCalculateAppBandwidthInfo(ctx)
557+
err = lb.bandwidthManager.ReCalculateAppBandwidthInfo(ctx)
558+
if err != nil {
559+
panic(err)
560+
}
548561
}
549562

550563
// execute daily event, record consumption friction and lino power
551564
func (lb *LinoBlockchain) executeDailyEvent(ctx sdk.Context) {
552-
lb.globalManager.RecordConsumptionAndLinoStake(ctx)
553-
lb.bandwidthManager.DecayMaxMPS(ctx)
565+
err := lb.globalManager.RecordConsumptionAndLinoStake(ctx)
566+
if err != nil {
567+
panic(err)
568+
}
569+
err = lb.bandwidthManager.DecayMaxMPS(ctx)
570+
if err != nil {
571+
panic(err)
572+
}
554573
}
555574

556575
// execute monthly event, distribute inflation to infra and application
@@ -564,7 +583,7 @@ func (lb *LinoBlockchain) executeMonthlyEvent(ctx sdk.Context) {
564583

565584
}
566585

567-
func (lb *LinoBlockchain) executeAnnuallyEvent(ctx sdk.Context) {
586+
func (lb *LinoBlockchain) executeAnnuallyEvent(ctx sdk.Context) { //nolint:unused
568587
if err := lb.globalManager.SetTotalLinoAndRecalculateGrowthRate(ctx); err != nil {
569588
panic(err)
570589
}
@@ -589,7 +608,10 @@ func (lb *LinoBlockchain) distributeInflationToValidator(ctx sdk.Context) {
589608
// though only differs in round?
590609
ratPerValidator = coin.ToDec().Quo(sdk.NewDec(int64(len(lst.OncallValidators) - i)))
591610
coinPerValidator := types.DecToCoin(ratPerValidator)
592-
lb.accountManager.AddCoinToUsername(ctx, validator, coinPerValidator)
611+
err := lb.accountManager.AddCoinToUsername(ctx, validator, coinPerValidator)
612+
if err != nil {
613+
panic(err)
614+
}
593615
coin = coin.Minus(coinPerValidator)
594616
}
595617
}
@@ -609,7 +631,10 @@ func (lb *LinoBlockchain) distributeInflationToInfraProvider(ctx sdk.Context) {
609631
totalDistributedInflation := types.NewCoinFromInt64(0)
610632
for idx, provider := range lst.AllInfraProviders {
611633
if idx == (len(lst.AllInfraProviders) - 1) {
612-
lb.accountManager.AddCoinToUsername(ctx, provider, inflation.Minus(totalDistributedInflation))
634+
err := lb.accountManager.AddCoinToUsername(ctx, provider, inflation.Minus(totalDistributedInflation))
635+
if err != nil {
636+
panic(fmt.Errorf("%s: %s", err, provider))
637+
}
613638
break
614639
}
615640
percentage, err := lb.infraManager.GetUsageWeight(ctx, provider)
@@ -619,7 +644,10 @@ func (lb *LinoBlockchain) distributeInflationToInfraProvider(ctx sdk.Context) {
619644
myShareRat := inflation.ToDec().Mul(percentage)
620645
myShareCoin := types.DecToCoin(myShareRat)
621646
totalDistributedInflation = totalDistributedInflation.Plus(myShareCoin)
622-
lb.accountManager.AddCoinToUsername(ctx, provider, myShareCoin)
647+
err = lb.accountManager.AddCoinToUsername(ctx, provider, myShareCoin)
648+
if err != nil {
649+
panic(err)
650+
}
623651
}
624652
if err := lb.infraManager.ClearUsage(ctx); err != nil {
625653
panic(err)
@@ -660,12 +688,18 @@ func (lb *LinoBlockchain) ExportAppStateAndValidators() (appState json.RawMessag
660688
}
661689
defer f.Close()
662690
jsonbytes, err := lb.cdc.MarshalJSON(exporter(ctx))
663-
f.Write(jsonbytes)
664691
if err != nil {
665692
panic("failed to marshal json for " + filename + " due to " + err.Error())
666693
}
694+
_, err = f.Write(jsonbytes)
695+
if err != nil {
696+
panic(err)
697+
}
667698
fmt.Printf("export for %s done: %d bytes\n", filename, len(jsonbytes))
668-
f.Sync()
699+
err = f.Sync()
700+
if err != nil {
701+
panic(err)
702+
}
669703
}
670704

671705
// TODO(yumin): accountStateFile
@@ -693,7 +727,10 @@ func (lb *LinoBlockchain) ExportAppStateAndValidators() (appState json.RawMessag
693727
exportToFile(voterStateFile, func(ctx sdk.Context) interface{} {
694728
return lb.voteManager.Export(ctx).ToIR()
695729
})
696-
lb.reputationManager.ExportToFile(ctx, exportPath+"reputation")
730+
err = lb.reputationManager.ExportToFile(ctx, exportPath+"reputation")
731+
if err != nil {
732+
panic(err)
733+
}
697734

698735
genesisState := GenesisState{}
699736

app/app_test.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:deadcode,unused
12
package app
23

34
import (
@@ -324,7 +325,10 @@ func TestDistributeInflationToValidators(t *testing.T) {
324325
for i := 0; i < len(expectBalanceList); i++ {
325326
expectBalanceList[i] = expectBaseBalance
326327
}
327-
lb.globalManager.DistributeHourlyInflation(ctx)
328+
err := lb.globalManager.DistributeHourlyInflation(ctx)
329+
if err != nil {
330+
panic(err)
331+
}
328332
lb.distributeInflationToValidator(ctx)
329333
// simulate app
330334
// hourly inflation
@@ -467,8 +471,11 @@ func TestDistributeInflationToInfraProvider(t *testing.T) {
467471
}
468472
infra, _ := infraStorage.GetInfraProvider(ctx, types.AccountKey("infra"+strconv.Itoa(i)))
469473
infra.Usage = cs.consumptionList[i]
470-
infraStorage.SetInfraProvider(ctx, types.AccountKey("infra"+strconv.Itoa(i)), infra)
471-
totalWeight = totalWeight + cs.consumptionList[i]
474+
err = infraStorage.SetInfraProvider(ctx, types.AccountKey("infra"+strconv.Itoa(i)), infra)
475+
if err != nil {
476+
panic(err)
477+
}
478+
totalWeight += cs.consumptionList[i]
472479
}
473480
globalStore := globalModel.NewGlobalStorage(lb.CapKeyGlobalStore)
474481
err := globalStore.SetInflationPool(ctx, &globalModel.InflationPool{
@@ -532,7 +539,10 @@ func TestDistributeInflationToInfraProvider(t *testing.T) {
532539
if err != nil {
533540
t.Errorf("%s: failed to set past minutes, got err %v", testName, err)
534541
}
535-
err = lb.infraManager.RegisterInfraProvider(ctx, "Lino")
542+
_ = lb.accountManager.CreateAccount(
543+
ctx, types.AccountKey("lino"),
544+
secp256k1.GenPrivKey().PubKey(), secp256k1.GenPrivKey().PubKey())
545+
err = lb.infraManager.RegisterInfraProvider(ctx, "lino")
536546
if err != nil {
537547
t.Errorf("%s: failed to register infra provider, got err %v", testName, err)
538548
}
@@ -624,9 +634,15 @@ func TestIncreaseMinute(t *testing.T) {
624634
for i := 1; i < types.MinutesPerMonth/10; i++ {
625635
// simulate add lino stake and friction at previous block
626636
ctx := lb.BaseApp.NewContext(true, abci.Header{Time: time.Unix(int64((i-1)*60), 0)})
627-
lb.globalManager.AddLinoStakeToStat(ctx, types.NewCoinFromInt64(1))
628-
lb.globalManager.AddFrictionAndRegisterContentRewardEvent(
637+
err := lb.globalManager.AddLinoStakeToStat(ctx, types.NewCoinFromInt64(1))
638+
if err != nil {
639+
panic(err)
640+
}
641+
err = lb.globalManager.AddFrictionAndRegisterContentRewardEvent(
629642
ctx, posttypes.RewardEvent{}, types.NewCoinFromInt64(2), types.NewMiniDollar(1))
643+
if err != nil {
644+
panic(err)
645+
}
630646
expectLinoStakeStat.TotalConsumptionFriction =
631647
expectLinoStakeStat.TotalConsumptionFriction.Plus(types.NewCoinFromInt64(2))
632648
expectLinoStakeStat.UnclaimedFriction =

app/genesis.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ import (
1717
tmtypes "github.com/tendermint/tendermint/types"
1818
)
1919

20-
var (
21-
flagName = "name"
22-
flagClientHome = "home-client"
23-
flagOWK = "owk"
24-
)
25-
2620
// genesis state for blockchain
2721
type GenesisState struct {
2822
LoadPrevStates bool `json:"load_prev_states"`

app/genesis_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestGetGenesisJson(t *testing.T) {
142142
appState, err := wire.MarshalJSONIndent(cdc, genesisState)
143143
assert.Nil(t, err)
144144
appGenesisState := new(GenesisState)
145-
err = cdc.UnmarshalJSON([]byte(appState), appGenesisState)
145+
err = cdc.UnmarshalJSON(appState, appGenesisState)
146146
assert.Nil(t, err)
147147

148148
assert.Equal(t, genesisState, *appGenesisState)

client/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func parsePrivKey(key string) (crypto.PrivKey, error) {
2121
if err != nil {
2222
return privKey, err
2323
}
24-
privKey, _ = cryptoAmino.PrivKeyFromBytes(privKeyBytes)
24+
privKey, err = cryptoAmino.PrivKeyFromBytes(privKeyBytes)
2525
if err != nil {
2626
return privKey, err
2727
}

cmd/lino/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ func main() {
4545
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
4646

4747
executor := cli.PrepareBaseCmd(rootCmd, "BC", app.DefaultNodeHome)
48-
executor.Execute()
48+
err := executor.Execute()
49+
if err != nil {
50+
panic(err)
51+
}
4952
}
5053

5154
func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, traceStore io.Writer,

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ require (
1515
github.com/tendermint/go-amino v0.15.0
1616
github.com/tendermint/tendermint v0.32.2
1717
github.com/tendermint/tm-db v0.1.1
18-
github.com/tendermint/tmlibs v0.9.0
1918
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 // indirect
20-
google.golang.org/appengine v1.4.0 // indirect
2119
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
2220
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ github.com/tendermint/tendermint v0.32.2 h1:FvZWdksfDg/65vKKr5Lgo57keARFnmhrUEXH
187187
github.com/tendermint/tendermint v0.32.2/go.mod h1:NwMyx58S8VJ7tEpFKqRVlVWKO9N9zjTHu+Dx96VsnOE=
188188
github.com/tendermint/tm-db v0.1.1 h1:G3Xezy3sOk9+ekhjZ/kjArYIs1SmwV+1OUgNkj7RgV0=
189189
github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw=
190-
github.com/tendermint/tmlibs v0.9.0 h1:3aU/D2v3aecqpODOuBXCfi950bHTefD5Pps5X3XuJDc=
191-
github.com/tendermint/tmlibs v0.9.0/go.mod h1:4L0tAKpLTioy14VnmbXYTLIJN0pCMiehxDMdN6zZfM8=
192190
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
193191
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
194192
github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8=

param/holder_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:unused
12
package param
23

34
import (
@@ -21,7 +22,10 @@ func getContext() sdk.Context {
2122
db := dbm.NewMemDB()
2223
ms := store.NewCommitMultiStore(db)
2324
ms.MountStoreWithDB(TestKVStoreKey, sdk.StoreTypeIAVL, db)
24-
ms.LoadLatestVersion()
25+
err := ms.LoadLatestVersion()
26+
if err != nil {
27+
panic(err)
28+
}
2529

2630
return sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
2731
}
@@ -206,7 +210,10 @@ func TestInitParam(t *testing.T) {
206210
ph := NewParamHolder(TestKVStoreKey)
207211
ctx := getContext()
208212

209-
ph.InitParam(ctx)
213+
err := ph.InitParam(ctx)
214+
if err != nil {
215+
panic(err)
216+
}
210217

211218
globalAllocationParam := GlobalAllocationParam{
212219
GlobalGrowthRate: types.NewDecFromRat(98, 1000),

test/test_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func CreateAccount(
202202
numOfLino string) {
203203

204204
registerMsg := acctypes.NewRegisterMsg(
205-
GenesisUser, accountName, types.LNO(numOfLino),
205+
GenesisUser, accountName, numOfLino,
206206
resetPriv.PubKey(), transactionPriv.PubKey(), appPriv.PubKey())
207207
SignCheckDeliver(t, lb, registerMsg, seq, true, GenesisTransactionPriv, time.Now().Unix())
208208
}

test/validator/deposit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestRegisterValidatorOneByOne(t *testing.T) {
7474
test.SignCheckDeliver(t, lb, voteDepositMsg, 0, true, newAccountTransactionPriv, baseTime)
7575

7676
valDepositMsg := val.NewValidatorDepositMsg(
77-
newAccountName, types.LNO(strconv.Itoa(120000+100*seq)), newValidatorPriv.PubKey(), "")
77+
newAccountName, strconv.Itoa(120000+100*seq), newValidatorPriv.PubKey(), "")
7878
test.SignCheckDeliver(t, lb, valDepositMsg, 1, true, newAccountTransactionPriv, baseTime)
7979
test.CheckOncallValidatorList(t, newAccountName, true, lb)
8080
test.CheckAllValidatorList(t, newAccountName, true, lb)

0 commit comments

Comments
 (0)