Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply golangci-lint and fix lint error #33

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ GOTOOLS = \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/rakyll/statik
GOBIN ?= $(GOPATH)/bin
all: get_tools get_vendor_deps install test
#all: get_tools get_vendor_deps install test_lint test
all: get_tools get_vendor_deps install lint test


get_tools:
go get github.com/golang/dep/cmd/dep
go get github.com/rakyll/statik
go get github.com/golangci/golangci-lint/cmd/golangci-lint

build: update_terra_lite_docs
ifeq ($(OS),Windows_NT)
Expand Down Expand Up @@ -57,15 +57,13 @@ update_tools:
@echo "--> Updating tools to correct version"
$(MAKE) --always-make get_tools

update_dev_tools:
@echo "--> Downloading linters (this may take awhile)"
$(GOPATH)/src/github.com/alecthomas/gometalinter/scripts/install.sh -b $(GOBIN)
go get -u github.com/tendermint/lint/golint

get_dev_tools: get_tools
@echo "--> Downloading linters (this may take awhile)"
$(GOPATH)/src/github.com/alecthomas/gometalinter/scripts/install.sh -b $(GOBIN)
go get github.com/tendermint/lint/golint
lint: get_tools ci-lint
ci-lint:
golangci-lint run
go vet -composites=false -tests=false ./...
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify

get_vendor_deps: get_tools
@echo "--> Generating vendor directory via dep ensure"
Expand Down Expand Up @@ -166,7 +164,7 @@ localnet-stop:
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: build build_cosmos-sdk-cli build_examples install install_debug dist \
check_tools check_dev_tools get_dev_tools get_vendor_deps draw_deps test test_cli test_unit \
check_tools check_dev_tools get_vendor_deps draw_deps test test_cli test_unit \
test_cover benchmark devdoc_init devdoc devdoc_save devdoc_update \
build-linux build-docker-terradnode localnet-start localnet-stop \
format check-ledger update_tools update_dev_tools
format check-ledger update_dev_tools lint
5 changes: 2 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ func (app *TerraApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.
treasuryTags := treasury.EndBlocker(ctx, app.treasuryKeeper)
tags = append(tags, treasuryTags...)

// TODO: request fixing it to comsmos guys
//app.assertRuntimeInvariants()
app.assertRuntimeInvariants()

return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Expand Down Expand Up @@ -383,7 +382,7 @@ func (app *TerraApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abc
}

// assert runtime invariants
//app.assertRuntimeInvariants()
app.assertRuntimeInvariants()

return abci.ResponseInitChain{
Validators: validators,
Expand Down
2 changes: 0 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (app *TerraApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []s
iter := sdk.KVStoreReversePrefixIterator(store, staking.ValidatorsKey)
counter := int16(0)

var valConsAddrs []sdk.ConsAddress
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.stakingKeeper.GetValidator(ctx, addr)
Expand All @@ -152,7 +151,6 @@ func (app *TerraApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []s
}

validator.UnbondingHeight = 0
valConsAddrs = append(valConsAddrs, validator.ConsAddress())
if applyWhiteList && !whiteListMap[addr.String()] {
validator.Jailed = true
}
Expand Down
5 changes: 0 additions & 5 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
)

var (
// bonded tokens given to genesis validators/accounts
freeFermionsAcc = sdk.NewInt(150)
)

// State to Unmarshal
type GenesisState struct {
Accounts []GenesisAccount `json:"accounts"`
Expand Down
3 changes: 2 additions & 1 deletion cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/common"

"github.com/cosmos/cosmos-sdk/client"
"terra/app"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
)
Expand Down
15 changes: 9 additions & 6 deletions cmd/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func TestEmptyState(t *testing.T) {
outC := make(chan string)
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
_, err := io.Copy(&buf, r)
require.Nil(t, err)
outC <- buf.String()
}()

Expand Down Expand Up @@ -111,13 +112,15 @@ func TestStartStandAlone(t *testing.T) {
svr, err := abciServer.NewServer(svrAddr, "socket", app)
require.Nil(t, err, "error creating listener")
svr.SetLogger(logger.With("module", "abci-server"))
svr.Start()
err = svr.Start()
require.Nil(t, err)

timer := time.NewTimer(time.Duration(2) * time.Second)
select {
case <-timer.C:
svr.Stop()
}

<-timer.C
err = svr.Stop()
require.Nil(t, err)

}

func TestInitNodeValidatorFiles(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/init/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ Example:
return cmd
}

// no-lint
type Node struct {
Name string
Ip string
IP string
}

func makeNodes() ([]Node, error) {
predefined := viper.GetString(flagPredefinedNodes)

if len(predefined) > 0 {
// parse predefined nodes information
re, _ := regexp.Compile("[\\s,]*(\\w+)@([\\d.]+)[\\s,]*")
re, _ := regexp.Compile(`[\s,]*(\w+)@([\d.]+)[\s,]*`)
groups := re.FindAllStringSubmatch(viper.GetString(flagPredefinedNodes), -1)

nodes := make([]Node, len(groups))
Expand Down Expand Up @@ -194,7 +195,7 @@ func initTestnet(config *tmconfig.Config, cdc *codec.Codec) error {
monikers = append(monikers, nodeDirName)
config.Moniker = nodeDirName

ip := nodes[i].Ip
ip := nodes[i].IP
nodeIDs[i], valPubKeys[i], err = InitializeNodeValidatorFiles(config)
if err != nil {
_ = os.RemoveAll(outDir)
Expand Down
1 change: 1 addition & 0 deletions cmd/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/tendermint/tendermint/types"

"terra/app"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
)
Expand Down
1 change: 1 addition & 0 deletions cmd/init/validate_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"terra/app"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/spf13/cobra"
Expand Down
4 changes: 0 additions & 4 deletions x/budget/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ const (
flagDescription = "description"
flagExecutor = "executor"
flagVoter = "voter"
flagOption = "option"
flagNumLimit = "limit"
flagProgram = "program"
flagProgramID = "program-id"

queryRoute = "budget"
)

type program struct {
Expand Down
2 changes: 1 addition & 1 deletion x/budget/client/rest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
r.HandleFunc("/budget/program/submit", submitProgramHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/budget/program/{%s}/withdraw", RestProgramID), voteHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/budget/program/{%s}/withdraw", RestProgramID), withdrawProgramHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/budget/program/{%s}/vote", RestProgramID), voteHandlerFn(cdc, cliCtx)).Methods("POST")

r.HandleFunc(fmt.Sprintf("/budget/program"), queryProgramHandlerFn(cdc, cliCtx)).Methods("GET")
Expand Down
6 changes: 6 additions & 0 deletions x/budget/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
CodeProgramNotFound sdk.CodeType = 4
CodeVoteNotFound sdk.CodeType = 5
CodeInvalidSubmitter sdk.CodeType = 6
CodeRefundFailed sdk.CodeType = 7
)

// nolint
Expand Down Expand Up @@ -51,3 +52,8 @@ func ErrVoteNotFound() sdk.Error {
func ErrInvalidSubmitter(submitter sdk.AccAddress) sdk.Error {
return sdk.NewError(DefaultCodespace, CodeInvalidSubmitter, fmt.Sprintf("Submitter does not match %s", submitter))
}

//
func ErrRefundFailed(submitter sdk.AccAddress, programID uint64) sdk.Error {
return sdk.NewError(DefaultCodespace, CodeRefundFailed, fmt.Sprintf("Refund failed to %s of program %d", submitter.String(), programID))
}
6 changes: 5 additions & 1 deletion x/budget/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func handleMsgWithdrawProgram(ctx sdk.Context, k Keeper, msg MsgWithdrawProgram)
prgmEndBlock := program.getVotingEndBlock(ctx, k)
if k.CandQueueHas(ctx, prgmEndBlock, msg.ProgramID) {
k.CandQueueRemove(ctx, prgmEndBlock, msg.ProgramID)
k.RefundDeposit(ctx, program.Submitter)
err := k.RefundDeposit(ctx, program.Submitter)

if err != nil {
return ErrRefundFailed(msg.Submitter, msg.ProgramID).Result()
}
}

k.DeleteProgram(ctx, msg.ProgramID)
Expand Down
4 changes: 0 additions & 4 deletions x/budget/keeper_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func keyVote(programID uint64, voterAddr sdk.AccAddress) []byte {
return []byte(fmt.Sprintf("%s:%d:%s", prefixVote, programID, voterAddr))
}

func prefixVoteForProgram(programID uint64) []byte {
return []byte(fmt.Sprintf("%s:%d", prefixVote, programID))
}

func prefixCandQueueEndBlock(endBlock int64) []byte {
return []byte(fmt.Sprintf("%s:%020d", prefixCandQueue, endBlock))
}
Expand Down
5 changes: 3 additions & 2 deletions x/budget/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ func TestKeeperDeposit(t *testing.T) {

// Set the balance to equal the default deposit
deposit := sdk.Coins{input.budgetKeeper.GetParams(input.ctx).Deposit}
input.bankKeeper.SetCoins(input.ctx, addrs[0], deposit)
err := input.bankKeeper.SetCoins(input.ctx, addrs[0], deposit)
require.Nil(t, err)

// addr0 has enough coins to pay the deposit
err := input.budgetKeeper.PayDeposit(input.ctx, addrs[0])
err = input.budgetKeeper.PayDeposit(input.ctx, addrs[0])
require.Nil(t, err)

// Doesn't have enough coins to pay the deposit
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ func TestOracleDrop(t *testing.T) {
// Going over dropthreshold should blacklist the price
EndBlocker(input.ctx, input.oracleKeeper)

price, err = input.oracleKeeper.GetLunaSwapRate(input.ctx, assets.KRWDenom)
_, err = input.oracleKeeper.GetLunaSwapRate(input.ctx, assets.KRWDenom)
require.NotNil(t, err)
}
9 changes: 6 additions & 3 deletions x/pay/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,14 @@ func TestHandlerMsgSendTax(t *testing.T) {
require.False(t, res.IsOK(), "expected failed message execution: %v", res.Log)

// Clear coin balances
input.bankKeeper.SetCoins(input.ctx, addrs[0], sdk.Coins{})
input.bankKeeper.SetCoins(input.ctx, addrs[1], sdk.Coins{})
err := input.bankKeeper.SetCoins(input.ctx, addrs[0], sdk.Coins{})
require.Nil(t, err)
err = input.bankKeeper.SetCoins(input.ctx, addrs[1], sdk.Coins{})
require.Nil(t, err)

// Give more coins
input.bankKeeper.AddCoins(input.ctx, addrs[0], sdk.Coins{sdk.NewCoin(assets.SDRDenom, sdk.NewInt(5000))})
_, _, err = input.bankKeeper.AddCoins(input.ctx, addrs[0], sdk.Coins{sdk.NewCoin(assets.SDRDenom, sdk.NewInt(5000))})
require.Nil(t, err)

// Reset tax cap
params.TaxPolicy.Cap = sdk.NewInt64Coin(assets.SDRDenom, 2) // 2 SDR cap
Expand Down
9 changes: 6 additions & 3 deletions x/treasury/end_blocker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package treasury

import (
"fmt"
"terra/types"
"terra/types/assets"
"terra/types/util"
Expand Down Expand Up @@ -98,10 +99,8 @@ func (k Keeper) settleClaims(ctx sdk.Context) (settleTags sdk.Tags) {
switch claim.Class {
case types.OracleClaimClass:
oracleSumWeight = oracleSumWeight.Add(claim.Weight)
break
case types.BudgetClaimClass:
budgetSumWeight = budgetSumWeight.Add(claim.Weight)
break
}
return false
})
Expand All @@ -119,7 +118,11 @@ func (k Keeper) settleClaims(ctx sdk.Context) (settleTags sdk.Tags) {
}

// Credit the recipient's account with the reward
k.mtk.Mint(ctx, claim.Recipient, sdk.NewCoin(assets.SDRDenom, rewardAmt))
err := k.mtk.Mint(ctx, claim.Recipient, sdk.NewCoin(assets.SDRDenom, rewardAmt))
if err != nil {
fmt.Printf("[settleClaims] failed to mint to %s\n", claim.Recipient.String())
return false
}

// We are now done with the claim; remove it from the store
store.Delete(keyClaim(claim.ID()))
Expand Down
18 changes: 6 additions & 12 deletions x/treasury/end_blocker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ func TestEndBlockerTiming(t *testing.T) {
}
}

func randomMacroVariables() (tax, seigniorage, lunaIssuance sdk.Int) {
rand.Seed(int64(time.Now().Nanosecond()))

tax = sdk.NewInt(rand.Int63())
seigniorage = sdk.NewInt(rand.Int63())
lunaIssuance = sdk.NewInt(rand.Int63() % 1000)

return
}

func reset(input testInput) testInput {

// Set blocknum back to 0
Expand All @@ -79,7 +69,10 @@ func reset(input testInput) testInput {

// Give everyone some luna
for _, addr := range addrs {
input.mintKeeper.Mint(input.ctx, addr, sdk.NewCoin(assets.LunaDenom, lunaAmt))
err := input.mintKeeper.Mint(input.ctx, addr, sdk.NewCoin(assets.LunaDenom, lunaAmt))
if err != nil {
panic(err)
}
}

return input
Expand Down Expand Up @@ -191,7 +184,8 @@ func TestEndBlockerSettleClaims(t *testing.T) {

// clear SDR balances for testing; keep luna for policy update safety
for _, addr := range addrs {
input.bankKeeper.SetCoins(input.ctx, addr, sdk.Coins{sdk.NewCoin(assets.LunaDenom, lunaAmt)})
err := input.bankKeeper.SetCoins(input.ctx, addr, sdk.Coins{sdk.NewCoin(assets.LunaDenom, lunaAmt)})
require.Nil(t, err)
}

// Reset reward weight
Expand Down
4 changes: 0 additions & 4 deletions x/treasury/keeper_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func keyTaxCap(denom string) []byte {
return []byte(fmt.Sprintf("%s:%s", prefixTaxCap, denom))
}

func keyIssuance(denom string, epoch sdk.Int) []byte {
return []byte(fmt.Sprintf("%s:%s:%s", prefixIssuance, denom, epoch))
}

func paramKeyTable() params.KeyTable {
return params.NewKeyTable(
paramStoreKeyParams, Params{},
Expand Down
3 changes: 2 additions & 1 deletion x/treasury/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ func TestQueryIssuance(t *testing.T) {
querier := NewQuerier(input.treasuryKeeper)

issuance := sdk.NewInt(1000)
input.mintKeeper.Mint(input.ctx, addrs[0], sdk.NewCoin(assets.SDRDenom, issuance))
err := input.mintKeeper.Mint(input.ctx, addrs[0], sdk.NewCoin(assets.SDRDenom, issuance))
require.Nil(t, err)

queriedIssuance := getQueriedIssuance(t, input.ctx, input.cdc, querier, assets.SDRDenom)

Expand Down