diff --git a/.github/.workflows/lint.yml b/.github/.workflows/lint.yml new file mode 100644 index 00000000..de312698 --- /dev/null +++ b/.github/.workflows/lint.yml @@ -0,0 +1,12 @@ +name: Lint +on: [pull_request] +jobs: + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: golangci-lint + uses: reviewdog/action-golangci-lint@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review diff --git a/Makefile b/Makefile index b8c50802..0b56e37b 100644 --- a/Makefile +++ b/Makefile @@ -103,6 +103,21 @@ clean: link-check: @go run github.com/raviqqe/liche -r . --exclude "^http://127.*|^https://riot.im/app*|^http://kava-testnet*|^https://testnet-dex*" + +lint: + golangci-lint run + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s + go mod verify +.PHONY: lint + +format: + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs gofmt -w -s + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs misspell -w + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/tendermint + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/kava-labs/kava +.PHONY: format + ######################################## ### Testing diff --git a/app/app.go b/app/app.go index 4d85810b..0f097d74 100644 --- a/app/app.go +++ b/app/app.go @@ -4,10 +4,11 @@ import ( "io" "os" + dbm "github.com/tendermint/tm-db" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" - dbm "github.com/tendermint/tm-db" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" diff --git a/app/app_test.go b/app/app_test.go index ae3dfbf2..263c16b7 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" db "github.com/tendermint/tm-db" diff --git a/app/sim_test.go b/app/sim_test.go index d6bd256b..18d6e4ec 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -6,6 +6,8 @@ import ( "os" "testing" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/helpers" @@ -20,6 +22,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" + + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" + "github.com/kava-labs/kava/x/auction" "github.com/kava-labs/kava/x/bep3" "github.com/kava-labs/kava/x/cdp" @@ -27,10 +34,6 @@ import ( "github.com/kava-labs/kava/x/kavadist" "github.com/kava-labs/kava/x/pricefeed" validatorvesting "github.com/kava-labs/kava/x/validator-vesting" - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" ) type StoreKeysPrefixes struct { diff --git a/app/test_common.go b/app/test_common.go index f0d4b0e7..78b80486 100644 --- a/app/test_common.go +++ b/app/test_common.go @@ -6,12 +6,13 @@ import ( "github.com/stretchr/testify/require" + tmdb "github.com/tendermint/tm-db" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/libs/log" - tmdb "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/cmd/kvcli/cmd_keys.go b/cmd/kvcli/cmd_keys.go index d1bc35cd..c17d8927 100644 --- a/cmd/kvcli/cmd_keys.go +++ b/cmd/kvcli/cmd_keys.go @@ -3,11 +3,12 @@ package main import ( "fmt" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/spf13/cobra" - "github.com/spf13/viper" "github.com/kava-labs/kava/app" ) diff --git a/cmd/kvcli/main.go b/cmd/kvcli/main.go index 8700f0ac..5c637dd4 100644 --- a/cmd/kvcli/main.go +++ b/cmd/kvcli/main.go @@ -8,13 +8,13 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" @@ -79,7 +79,7 @@ func main() { } } -func queryCmd(cdc *amino.Codec) *cobra.Command { +func queryCmd(cdc *codec.Codec) *cobra.Command { queryCmd := &cobra.Command{ Use: "query", Aliases: []string{"q"}, @@ -102,7 +102,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { return queryCmd } -func txCmd(cdc *amino.Codec) *cobra.Command { +func txCmd(cdc *codec.Codec) *cobra.Command { txCmd := &cobra.Command{ Use: "tx", Short: "Transactions subcommands", diff --git a/cmd/kvd/add_account.go b/cmd/kvd/add_account.go index 36644d58..4ef2307b 100644 --- a/cmd/kvd/add_account.go +++ b/cmd/kvd/add_account.go @@ -9,7 +9,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - validatorvesting "github.com/kava-labs/kava/x/validator-vesting" "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" @@ -22,6 +21,7 @@ import ( authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/vesting" "github.com/cosmos/cosmos-sdk/x/genutil" + validatorvesting "github.com/kava-labs/kava/x/validator-vesting" ) const ( diff --git a/cmd/kvd/main.go b/cmd/kvd/main.go index 148f3ba8..d551ab96 100644 --- a/cmd/kvd/main.go +++ b/cmd/kvd/main.go @@ -7,11 +7,12 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + dbm "github.com/tendermint/tm-db" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" tmtypes "github.com/tendermint/tendermint/types" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/go.mod b/go.mod index 2b057cfa..ed8d8905 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.13 require ( github.com/btcsuite/btcd v0.20.1-beta // indirect github.com/cosmos/cosmos-sdk v0.38.3 + github.com/gogo/protobuf v1.3.1 github.com/gorilla/mux v1.7.3 github.com/spf13/cobra v0.0.6 github.com/spf13/viper v1.6.2 diff --git a/golangci.yml b/golangci.yml new file mode 100644 index 00000000..371e83fa --- /dev/null +++ b/golangci.yml @@ -0,0 +1,52 @@ +run: + tests: false +# # timeout for analysis, e.g. 30s, 5m, default is 1m +# timeout: 5m + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + # - errcheck + - goconst + - gocritic + - gofmt + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - maligned + - misspell + - nakedret + - prealloc + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unused + - misspell + - wsl + +issues: + exclude-rules: + - text: "Use of weak random number generator" + linters: + - gosec + - text: "comment on exported var" + linters: + - golint + +linters-settings: + dogsled: + max-blank-identifiers: 3 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true diff --git a/rest_test/setup/setuptest.go b/rest_test/setup/setuptest.go index 6419b88c..c6d384a3 100644 --- a/rest_test/setup/setuptest.go +++ b/rest_test/setup/setuptest.go @@ -10,6 +10,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/codec" crkeys "github.com/cosmos/cosmos-sdk/crypto/keys" sdk "github.com/cosmos/cosmos-sdk/types" sdkrest "github.com/cosmos/cosmos-sdk/types/rest" @@ -21,11 +22,12 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/staking" + + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp" "github.com/kava-labs/kava/x/pricefeed" - "github.com/tendermint/go-amino" - tmtime "github.com/tendermint/tendermint/types/time" ) func init() { @@ -394,7 +396,7 @@ func getKeybase() crkeys.Keybase { } // sendMsgToBlockchain sends a message to the blockchain via the rest api -func sendMsgToBlockchain(cdc *amino.Codec, address string, keyname string, +func sendMsgToBlockchain(cdc *codec.Codec, address string, keyname string, password string, msg []sdk.Msg, keybase crkeys.Keybase) { // get the account number and sequence number @@ -450,7 +452,7 @@ func sendMsgToBlockchain(cdc *amino.Codec, address string, keyname string, } // getAccountNumberAndSequenceNumber gets an account number and sequence number from the blockchain -func getAccountNumberAndSequenceNumber(cdc *amino.Codec, address string) (accountNumber uint64, sequenceNumber uint64) { +func getAccountNumberAndSequenceNumber(cdc *codec.Codec, address string) (accountNumber uint64, sequenceNumber uint64) { // we need to setup the account number and sequence in order to have a valid transaction resp, err := http.Get("http://localhost:1317/auth/accounts/" + address) diff --git a/x/auction/abci_test.go b/x/auction/abci_test.go index c7274b7b..fed82a39 100644 --- a/x/auction/abci_test.go +++ b/x/auction/abci_test.go @@ -3,11 +3,13 @@ package auction_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/supply" - "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/auction/alias.go b/x/auction/alias.go index 0ac1a7dd..1cbf3593 100644 --- a/x/auction/alias.go +++ b/x/auction/alias.go @@ -12,29 +12,29 @@ import ( // ALIASGEN: github.com/kava-labs/kava/x/auction/types const ( - EventTypeAuctionStart = types.EventTypeAuctionStart - EventTypeAuctionBid = types.EventTypeAuctionBid - EventTypeAuctionClose = types.EventTypeAuctionClose - AttributeValueCategory = types.AttributeValueCategory - AttributeKeyAuctionID = types.AttributeKeyAuctionID - AttributeKeyAuctionType = types.AttributeKeyAuctionType - AttributeKeyBidder = types.AttributeKeyBidder - AttributeKeyBidDenom = types.AttributeKeyBidDenom - AttributeKeyLotDenom = types.AttributeKeyLotDenom - AttributeKeyBidAmount = types.AttributeKeyBidAmount - AttributeKeyLotAmount = types.AttributeKeyLotAmount - AttributeKeyEndTime = types.AttributeKeyEndTime - DefaultNextAuctionID = types.DefaultNextAuctionID - ModuleName = types.ModuleName - StoreKey = types.StoreKey - RouterKey = types.RouterKey - DefaultParamspace = types.DefaultParamspace - QuerierRoute = types.QuerierRoute - DefaultMaxAuctionDuration = types.DefaultMaxAuctionDuration - DefaultBidDuration = types.DefaultBidDuration - QueryGetAuction = types.QueryGetAuction - QueryGetAuctions = types.QueryGetAuctions - QueryGetParams = types.QueryGetParams + EventTypeAuctionStart = types.EventTypeAuctionStart + EventTypeAuctionBid = types.EventTypeAuctionBid + EventTypeAuctionClose = types.EventTypeAuctionClose + AttributeValueCategory = types.AttributeValueCategory + AttributeKeyAuctionID = types.AttributeKeyAuctionID + AttributeKeyAuctionType = types.AttributeKeyAuctionType + AttributeKeyBidder = types.AttributeKeyBidder + AttributeKeyBidDenom = types.AttributeKeyBidDenom + AttributeKeyLotDenom = types.AttributeKeyLotDenom + AttributeKeyBidAmount = types.AttributeKeyBidAmount + AttributeKeyLotAmount = types.AttributeKeyLotAmount + AttributeKeyEndTime = types.AttributeKeyEndTime + DefaultNextAuctionID = types.DefaultNextAuctionID + ModuleName = types.ModuleName + StoreKey = types.StoreKey + RouterKey = types.RouterKey + DefaultParamspace = types.DefaultParamspace + QuerierRoute = types.QuerierRoute + DefaultMaxAuctionDuration = types.DefaultMaxAuctionDuration + DefaultBidDuration = types.DefaultBidDuration + QueryGetAuction = types.QueryGetAuction + QueryGetAuctions = types.QueryGetAuctions + QueryGetParams = types.QueryGetParams ) var ( diff --git a/x/auction/keeper/auctions.go b/x/auction/keeper/auctions.go index c1722dee..c6152652 100644 --- a/x/auction/keeper/auctions.go +++ b/x/auction/keeper/auctions.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/supply" + "github.com/kava-labs/kava/x/auction/types" ) diff --git a/x/auction/keeper/auctions_test.go b/x/auction/keeper/auctions_test.go index c8c19c1b..2da0a9f4 100644 --- a/x/auction/keeper/auctions_test.go +++ b/x/auction/keeper/auctions_test.go @@ -4,11 +4,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/supply" - "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/auction/keeper/bidding_test.go b/x/auction/keeper/bidding_test.go index 9a34cabc..34638194 100644 --- a/x/auction/keeper/bidding_test.go +++ b/x/auction/keeper/bidding_test.go @@ -6,11 +6,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/supply" - "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index da8caf89..7250db4e 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/subspace" + "github.com/tendermint/tendermint/libs/log" "github.com/kava-labs/kava/x/auction/types" diff --git a/x/auction/keeper/keeper_test.go b/x/auction/keeper/keeper_test.go index 4b811bb9..48044b85 100644 --- a/x/auction/keeper/keeper_test.go +++ b/x/auction/keeper/keeper_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/auction/keeper/math_test.go b/x/auction/keeper/math_test.go index ee42c594..6ff02765 100644 --- a/x/auction/keeper/math_test.go +++ b/x/auction/keeper/math_test.go @@ -3,8 +3,9 @@ package keeper import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestSplitIntIntoWeightedBuckets(t *testing.T) { diff --git a/x/auction/keeper/params.go b/x/auction/keeper/params.go index 6d7ddfd5..3ffc3da4 100644 --- a/x/auction/keeper/params.go +++ b/x/auction/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/auction/types" ) diff --git a/x/auction/keeper/querier_test.go b/x/auction/keeper/querier_test.go index fa0d1b9f..20763bc8 100644 --- a/x/auction/keeper/querier_test.go +++ b/x/auction/keeper/querier_test.go @@ -5,18 +5,21 @@ import ( "strings" "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/supply" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/auction/keeper" "github.com/kava-labs/kava/x/auction/types" "github.com/kava-labs/kava/x/cdp" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) const ( diff --git a/x/auction/module.go b/x/auction/module.go index dd1134a0..617ecc82 100644 --- a/x/auction/module.go +++ b/x/auction/module.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" sim "github.com/cosmos/cosmos-sdk/x/simulation" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/auction/client/cli" diff --git a/x/auction/simulation/decoder_test.go b/x/auction/simulation/decoder_test.go index f1109332..e46f2a72 100644 --- a/x/auction/simulation/decoder_test.go +++ b/x/auction/simulation/decoder_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/auction/types/auctions_test.go b/x/auction/types/auctions_test.go index f46968d6..49953cbe 100644 --- a/x/auction/types/auctions_test.go +++ b/x/auction/types/auctions_test.go @@ -4,8 +4,9 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( diff --git a/x/auction/types/genesis_test.go b/x/auction/types/genesis_test.go index 4810741e..4248d6e6 100644 --- a/x/auction/types/genesis_test.go +++ b/x/auction/types/genesis_test.go @@ -3,8 +3,9 @@ package types import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) var testCoin = sdk.NewInt64Coin("test", 20) diff --git a/x/auction/types/msg_test.go b/x/auction/types/msg_test.go index f78e7102..7ac2909c 100644 --- a/x/auction/types/msg_test.go +++ b/x/auction/types/msg_test.go @@ -3,8 +3,9 @@ package types import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestMsgPlaceBid_ValidateBasic(t *testing.T) { diff --git a/x/auction/types/params_test.go b/x/auction/types/params_test.go index 253a180a..f2d65091 100644 --- a/x/auction/types/params_test.go +++ b/x/auction/types/params_test.go @@ -4,8 +4,9 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestParams_Validate(t *testing.T) { diff --git a/x/bep3/client/cli/query.go b/x/bep3/client/cli/query.go index a60e52af..edcca618 100644 --- a/x/bep3/client/cli/query.go +++ b/x/bep3/client/cli/query.go @@ -6,11 +6,13 @@ import ( "strconv" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/spf13/cobra" + tmtime "github.com/tendermint/tendermint/types/time" "github.com/kava-labs/kava/x/bep3/types" diff --git a/x/bep3/client/cli/tx.go b/x/bep3/client/cli/tx.go index 9543d5c2..47c45410 100644 --- a/x/bep3/client/cli/tx.go +++ b/x/bep3/client/cli/tx.go @@ -7,6 +7,8 @@ import ( "strconv" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -14,9 +16,10 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" - "github.com/kava-labs/kava/x/bep3/types" - "github.com/spf13/cobra" + tmtime "github.com/tendermint/tendermint/types/time" + + "github.com/kava-labs/kava/x/bep3/types" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/bep3/client/rest/query.go b/x/bep3/client/rest/query.go index 559919f5..7ae9bc35 100644 --- a/x/bep3/client/rest/query.go +++ b/x/bep3/client/rest/query.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" + "github.com/kava-labs/kava/x/bep3/types" ) diff --git a/x/bep3/client/rest/tx.go b/x/bep3/client/rest/tx.go index 022993e3..2f5a08ae 100644 --- a/x/bep3/client/rest/tx.go +++ b/x/bep3/client/rest/tx.go @@ -4,11 +4,12 @@ import ( "fmt" "net/http" + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" - "github.com/gorilla/mux" "github.com/kava-labs/kava/x/bep3/types" ) diff --git a/x/bep3/genesis_test.go b/x/bep3/genesis_test.go index 7b76af77..e29ef730 100644 --- a/x/bep3/genesis_test.go +++ b/x/bep3/genesis_test.go @@ -3,8 +3,10 @@ package bep3_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" tmtime "github.com/tendermint/tendermint/types/time" diff --git a/x/bep3/integration_test.go b/x/bep3/integration_test.go index bb9bc7c2..1abfd8ee 100644 --- a/x/bep3/integration_test.go +++ b/x/bep3/integration_test.go @@ -4,6 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + tmtime "github.com/tendermint/tendermint/types/time" "github.com/kava-labs/kava/app" diff --git a/x/bep3/keeper/asset_test.go b/x/bep3/keeper/asset_test.go index 9c167289..67447c55 100644 --- a/x/bep3/keeper/asset_test.go +++ b/x/bep3/keeper/asset_test.go @@ -3,13 +3,16 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/bep3/keeper" "github.com/kava-labs/kava/x/bep3/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type AssetTestSuite struct { diff --git a/x/bep3/keeper/integration_test.go b/x/bep3/keeper/integration_test.go index 5e4d4a37..88c38d3f 100644 --- a/x/bep3/keeper/integration_test.go +++ b/x/bep3/keeper/integration_test.go @@ -4,11 +4,13 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/tendermint/tendermint/crypto" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/bep3" "github.com/kava-labs/kava/x/bep3/types" - "github.com/tendermint/tendermint/crypto" - tmtime "github.com/tendermint/tendermint/types/time" ) const ( diff --git a/x/bep3/keeper/keeper.go b/x/bep3/keeper/keeper.go index 3a800422..430f658d 100644 --- a/x/bep3/keeper/keeper.go +++ b/x/bep3/keeper/keeper.go @@ -7,8 +7,10 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/subspace" - "github.com/kava-labs/kava/x/bep3/types" + "github.com/tendermint/tendermint/libs/log" + + "github.com/kava-labs/kava/x/bep3/types" ) // Keeper of the bep3 store diff --git a/x/bep3/keeper/keeper_test.go b/x/bep3/keeper/keeper_test.go index 9837a747..363a0ea3 100644 --- a/x/bep3/keeper/keeper_test.go +++ b/x/bep3/keeper/keeper_test.go @@ -4,13 +4,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/bep3/keeper" "github.com/kava-labs/kava/x/bep3/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) const LongtermStorageDuration = 86400 diff --git a/x/bep3/keeper/params_test.go b/x/bep3/keeper/params_test.go index 3c4bae7d..8c602dba 100644 --- a/x/bep3/keeper/params_test.go +++ b/x/bep3/keeper/params_test.go @@ -4,13 +4,16 @@ import ( "errors" "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/bep3/keeper" "github.com/kava-labs/kava/x/bep3/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type ParamsTestSuite struct { diff --git a/x/bep3/keeper/swap.go b/x/bep3/keeper/swap.go index 58d53121..5f4fc811 100644 --- a/x/bep3/keeper/swap.go +++ b/x/bep3/keeper/swap.go @@ -126,21 +126,23 @@ func (k Keeper) ClaimAtomicSwap(ctx sdk.Context, from sdk.AccAddress, swapID []b case types.Incoming: err := k.DecrementIncomingAssetSupply(ctx, atomicSwap.Amount[0]) if err != nil { - break + return err } err = k.IncrementCurrentAssetSupply(ctx, atomicSwap.Amount[0]) + if err != nil { + return err + } case types.Outgoing: err = k.DecrementOutgoingAssetSupply(ctx, atomicSwap.Amount[0]) if err != nil { - break + return err } err = k.DecrementCurrentAssetSupply(ctx, atomicSwap.Amount[0]) + if err != nil { + return err + } default: - err = fmt.Errorf("invalid swap direction: %s", atomicSwap.Direction.String()) - } - - if err != nil { - return err + return fmt.Errorf("invalid swap direction: %s", atomicSwap.Direction.String()) } // Send intended recipient coins @@ -245,13 +247,13 @@ func (k Keeper) UpdateExpiredAtomicSwaps(ctx sdk.Context) error { } // Emit 'swaps_expired' event - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeSwapsExpired, - sdk.NewAttribute(types.AttributeKeyAtomicSwapIDs, fmt.Sprintf("%s", expiredSwapIDs)), - sdk.NewAttribute(types.AttributeExpirationBlock, fmt.Sprintf("%d", ctx.BlockHeight())), - ), - ) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeSwapsExpired, + sdk.NewAttribute(types.AttributeKeyAtomicSwapIDs, fmt.Sprintf("%s", expiredSwapIDs)), + sdk.NewAttribute(types.AttributeExpirationBlock, fmt.Sprintf("%d", ctx.BlockHeight())), + ), + ) return nil } diff --git a/x/bep3/module.go b/x/bep3/module.go index bf675bff..de15fac9 100644 --- a/x/bep3/module.go +++ b/x/bep3/module.go @@ -4,14 +4,16 @@ import ( "encoding/json" "math/rand" + "github.com/gorilla/mux" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" sim "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/gorilla/mux" - "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/bep3/client/cli" diff --git a/x/bep3/simulation/genesis.go b/x/bep3/simulation/genesis.go index bfac2d88..f2a8e34a 100644 --- a/x/bep3/simulation/genesis.go +++ b/x/bep3/simulation/genesis.go @@ -12,6 +12,7 @@ import ( authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/supply" + "github.com/kava-labs/kava/x/bep3/types" ) diff --git a/x/bep3/types/common_test.go b/x/bep3/types/common_test.go index 57601d1e..2dccb4fe 100644 --- a/x/bep3/types/common_test.go +++ b/x/bep3/types/common_test.go @@ -4,8 +4,10 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/bep3/types" + tmtime "github.com/tendermint/tendermint/types/time" + + "github.com/kava-labs/kava/x/bep3/types" ) func i(in int64) sdk.Int { return sdk.NewInt(in) } diff --git a/x/bep3/types/genesis_test.go b/x/bep3/types/genesis_test.go index b72f9be8..4c2be611 100644 --- a/x/bep3/types/genesis_test.go +++ b/x/bep3/types/genesis_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/bep3/types" - "github.com/stretchr/testify/suite" ) type GenesisTestSuite struct { diff --git a/x/bep3/types/hash.go b/x/bep3/types/hash.go index bcb23fcf..f5772eb0 100644 --- a/x/bep3/types/hash.go +++ b/x/bep3/types/hash.go @@ -8,6 +8,7 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/crypto/tmhash" ) diff --git a/x/bep3/types/hash_test.go b/x/bep3/types/hash_test.go index 0161a059..ebfb0e46 100644 --- a/x/bep3/types/hash_test.go +++ b/x/bep3/types/hash_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/bep3/types" - "github.com/stretchr/testify/suite" ) type HashTestSuite struct { @@ -58,4 +60,4 @@ func (suite *HashTestSuite) TestCalculateSwapID() { func TestHashTestSuite(t *testing.T) { suite.Run(t, new(HashTestSuite)) -} \ No newline at end of file +} diff --git a/x/bep3/types/params_test.go b/x/bep3/types/params_test.go index 65e49cfd..9532cbf5 100644 --- a/x/bep3/types/params_test.go +++ b/x/bep3/types/params_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/bep3/types" - "github.com/stretchr/testify/suite" ) type ParamsTestSuite struct { diff --git a/x/cdp/abci.go b/x/cdp/abci.go index f8c031ce..23410150 100644 --- a/x/cdp/abci.go +++ b/x/cdp/abci.go @@ -4,8 +4,10 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/cdp/types" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/kava-labs/kava/x/cdp/types" ) // BeginBlocker compounds the debt in outstanding cdps and liquidates cdps that are below the required collateralization ratio diff --git a/x/cdp/abci_test.go b/x/cdp/abci_test.go index 74af46da..7f627976 100644 --- a/x/cdp/abci_test.go +++ b/x/cdp/abci_test.go @@ -5,14 +5,17 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/simulation" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/auction" "github.com/kava-labs/kava/x/cdp" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type ModuleTestSuite struct { diff --git a/x/cdp/genesis.go b/x/cdp/genesis.go index 241fdcd7..176554c3 100644 --- a/x/cdp/genesis.go +++ b/x/cdp/genesis.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/cdp/types" ) diff --git a/x/cdp/genesis_test.go b/x/cdp/genesis_test.go index 3d34b7c9..849583eb 100644 --- a/x/cdp/genesis_test.go +++ b/x/cdp/genesis_test.go @@ -5,10 +5,12 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp" - "github.com/stretchr/testify/suite" ) type GenesisTestSuite struct { diff --git a/x/cdp/handler_test.go b/x/cdp/handler_test.go index fd452a65..13509145 100644 --- a/x/cdp/handler_test.go +++ b/x/cdp/handler_test.go @@ -4,11 +4,13 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/app" - "github.com/kava-labs/kava/x/cdp" + abci "github.com/tendermint/tendermint/abci/types" tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" + "github.com/kava-labs/kava/x/cdp" + "github.com/stretchr/testify/suite" ) diff --git a/x/cdp/integration_test.go b/x/cdp/integration_test.go index eb50665c..b258a3e0 100644 --- a/x/cdp/integration_test.go +++ b/x/cdp/integration_test.go @@ -5,10 +5,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp" "github.com/kava-labs/kava/x/pricefeed" - tmtime "github.com/tendermint/tendermint/types/time" ) // Avoid cluttering test cases with long function names @@ -21,11 +22,11 @@ func NewPricefeedGenState(asset string, price sdk.Dec) app.GenesisState { pfGenesis := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: asset + ":usd", BaseAsset: asset, QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: asset + ":usd", BaseAsset: asset, QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: asset + ":usd", OracleAddress: sdk.AccAddress{}, Price: price, @@ -77,18 +78,18 @@ func NewPricefeedGenStateMulti() app.GenesisState { pfGenesis := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, - pricefeed.Market{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: "btc:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("8000.00"), Expiry: time.Now().Add(1 * time.Hour), }, - pricefeed.PostedPrice{ + { MarketID: "xrp:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("0.25"), diff --git a/x/cdp/keeper/auctions.go b/x/cdp/keeper/auctions.go index 67b7b292..5228ef08 100644 --- a/x/cdp/keeper/auctions.go +++ b/x/cdp/keeper/auctions.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/cdp/types" ) @@ -209,7 +210,9 @@ func (k Keeper) GetTotalDebt(ctx sdk.Context, accountName string) sdk.Int { // RunSurplusAndDebtAuctions nets the surplus and debt balances and then creates surplus or debt auctions if the remaining balance is above the auction threshold parameter func (k Keeper) RunSurplusAndDebtAuctions(ctx sdk.Context) error { - k.NetSurplusAndDebt(ctx) + if err := k.NetSurplusAndDebt(ctx); err != nil { + return err + } remainingDebt := k.GetTotalDebt(ctx, types.LiquidatorMacc) params := k.GetParams(ctx) if remainingDebt.GTE(params.DebtAuctionThreshold) { diff --git a/x/cdp/keeper/auctions_test.go b/x/cdp/keeper/auctions_test.go index 59cb45fa..ba276772 100644 --- a/x/cdp/keeper/auctions_test.go +++ b/x/cdp/keeper/auctions_test.go @@ -4,12 +4,14 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/auction" "github.com/kava-labs/kava/x/cdp/keeper" "github.com/kava-labs/kava/x/cdp/types" "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" tmtime "github.com/tendermint/tendermint/types/time" ) diff --git a/x/cdp/keeper/cdp.go b/x/cdp/keeper/cdp.go index 712f817f..7c9fcc5d 100644 --- a/x/cdp/keeper/cdp.go +++ b/x/cdp/keeper/cdp.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/kava-labs/kava/x/cdp/types" ) @@ -198,7 +199,7 @@ func (k Keeper) SetCDP(ctx sdk.Context, cdp types.CDP) error { store := prefix.NewStore(ctx.KVStore(k.key), types.CdpKeyPrefix) db, found := k.GetDenomPrefix(ctx, cdp.Collateral.Denom) if !found { - sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom) + return sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom) } bz := k.cdc.MustMarshalBinaryLengthPrefixed(cdp) store.Set(types.CdpKey(db, cdp.ID), bz) @@ -210,7 +211,7 @@ func (k Keeper) DeleteCDP(ctx sdk.Context, cdp types.CDP) error { store := prefix.NewStore(ctx.KVStore(k.key), types.CdpKeyPrefix) db, found := k.GetDenomPrefix(ctx, cdp.Collateral.Denom) if !found { - sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom) + return sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom) } store.Delete(types.CdpKey(db, cdp.ID)) return nil @@ -431,7 +432,7 @@ func (k Keeper) LoadAugmentedCDP(ctx sdk.Context, cdp types.CDP) (types.Augmente return types.AugmentedCDP{}, err } - // total debt is the sum of all oustanding principal and fees + // total debt is the sum of all outstanding principal and fees var totalDebt int64 totalDebt += cdp.Principal.Amount.Int64() totalDebt += cdp.AccumulatedFees.Amount.Int64() diff --git a/x/cdp/keeper/cdp_test.go b/x/cdp/keeper/cdp_test.go index d98ee299..87d0d8ef 100644 --- a/x/cdp/keeper/cdp_test.go +++ b/x/cdp/keeper/cdp_test.go @@ -5,13 +5,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp/keeper" "github.com/kava-labs/kava/x/cdp/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type CdpTestSuite struct { diff --git a/x/cdp/keeper/deposit.go b/x/cdp/keeper/deposit.go index 735e9b1d..7d1d46bb 100644 --- a/x/cdp/keeper/deposit.go +++ b/x/cdp/keeper/deposit.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/kava-labs/kava/x/cdp/types" ) diff --git a/x/cdp/keeper/deposit_test.go b/x/cdp/keeper/deposit_test.go index 1eb11650..7a1e27d7 100644 --- a/x/cdp/keeper/deposit_test.go +++ b/x/cdp/keeper/deposit_test.go @@ -4,13 +4,16 @@ import ( "errors" "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp/keeper" "github.com/kava-labs/kava/x/cdp/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type DepositTestSuite struct { diff --git a/x/cdp/keeper/draw.go b/x/cdp/keeper/draw.go index 655038a6..1a0b14bc 100644 --- a/x/cdp/keeper/draw.go +++ b/x/cdp/keeper/draw.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/kava-labs/kava/x/cdp/types" ) @@ -141,7 +142,10 @@ func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom stri // and remove the cdp and indexes from the store if cdp.Principal.IsZero() && cdp.AccumulatedFees.IsZero() { k.ReturnCollateral(ctx, cdp) - k.DeleteCDP(ctx, cdp) + if err := k.DeleteCDP(ctx, cdp); err != nil { + return err + } + k.RemoveCdpOwnerIndex(ctx, cdp) // emit cdp close event diff --git a/x/cdp/keeper/draw_test.go b/x/cdp/keeper/draw_test.go index 44a26374..8948ba80 100644 --- a/x/cdp/keeper/draw_test.go +++ b/x/cdp/keeper/draw_test.go @@ -5,13 +5,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp/keeper" "github.com/kava-labs/kava/x/cdp/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type DrawTestSuite struct { diff --git a/x/cdp/keeper/fees.go b/x/cdp/keeper/fees.go index 109ae0af..1d2c4555 100644 --- a/x/cdp/keeper/fees.go +++ b/x/cdp/keeper/fees.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/cdp/types" ) @@ -55,14 +56,27 @@ func (k Keeper) UpdateFeesForAllCdps(ctx sdk.Context, collateralDenom string) er return false } // mint debt coins to the cdp account - k.MintDebtCoins(ctx, types.ModuleName, k.GetDebtDenom(ctx), newFees) + err := k.MintDebtCoins(ctx, types.ModuleName, k.GetDebtDenom(ctx), newFees) + if err != nil { + iterationErr = err + return true + } previousDebt := k.GetTotalPrincipal(ctx, collateralDenom, dp.Denom) newDebt := previousDebt.Add(newFees.Amount) k.SetTotalPrincipal(ctx, collateralDenom, dp.Denom, newDebt) // mint surplus coins divided between the liquidator and savings module accounts. - k.supplyKeeper.MintCoins(ctx, types.LiquidatorMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSurplus))) - k.supplyKeeper.MintCoins(ctx, types.SavingsRateMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSavings))) + err = k.supplyKeeper.MintCoins(ctx, types.LiquidatorMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSurplus))) + if err != nil { + iterationErr = err + return true + } + + err = k.supplyKeeper.MintCoins(ctx, types.SavingsRateMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSavings))) + if err != nil { + iterationErr = err + return true + } // now add the new fees fees to the accumulated fees for the cdp cdp.AccumulatedFees = cdp.AccumulatedFees.Add(newFees) @@ -71,7 +85,7 @@ func (k Keeper) UpdateFeesForAllCdps(ctx sdk.Context, collateralDenom string) er cdp.FeesUpdated = ctx.BlockTime() collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees)) k.RemoveCdpCollateralRatioIndex(ctx, cdp.Collateral.Denom, cdp.ID, oldCollateralToDebtRatio) - err := k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio) + err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio) if err != nil { iterationErr = err return true diff --git a/x/cdp/keeper/fees_test.go b/x/cdp/keeper/fees_test.go index 90513e73..fc2966d0 100644 --- a/x/cdp/keeper/fees_test.go +++ b/x/cdp/keeper/fees_test.go @@ -6,11 +6,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/app" - "github.com/kava-labs/kava/x/cdp/keeper" "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" tmtime "github.com/tendermint/tendermint/types/time" + + "github.com/kava-labs/kava/app" + "github.com/kava-labs/kava/x/cdp/keeper" ) type FeeTestSuite struct { diff --git a/x/cdp/keeper/integration_test.go b/x/cdp/keeper/integration_test.go index f936298d..ae3be395 100644 --- a/x/cdp/keeper/integration_test.go +++ b/x/cdp/keeper/integration_test.go @@ -5,10 +5,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp" "github.com/kava-labs/kava/x/pricefeed" - tmtime "github.com/tendermint/tendermint/types/time" ) // Avoid cluttering test cases with long function names @@ -21,11 +22,11 @@ func NewPricefeedGenState(asset string, price sdk.Dec) app.GenesisState { pfGenesis := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: asset + ":usd", BaseAsset: asset, QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: asset + ":usd", BaseAsset: asset, QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: asset + ":usd", OracleAddress: sdk.AccAddress{}, Price: price, @@ -77,18 +78,18 @@ func NewPricefeedGenStateMulti() app.GenesisState { pfGenesis := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, - pricefeed.Market{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: "btc:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("8000.00"), Expiry: time.Now().Add(1 * time.Hour), }, - pricefeed.PostedPrice{ + { MarketID: "xrp:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("0.25"), diff --git a/x/cdp/keeper/keeper.go b/x/cdp/keeper/keeper.go index f7d3e585..0e028b59 100644 --- a/x/cdp/keeper/keeper.go +++ b/x/cdp/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/subspace" + "github.com/kava-labs/kava/x/cdp/types" ) diff --git a/x/cdp/keeper/keeper_bench_test.go b/x/cdp/keeper/keeper_bench_test.go index 76e61331..cd7bf70c 100644 --- a/x/cdp/keeper/keeper_bench_test.go +++ b/x/cdp/keeper/keeper_bench_test.go @@ -5,11 +5,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp" "github.com/kava-labs/kava/x/cdp/keeper" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) // saving the result to a module level variable ensures the compiler doesn't optimize the test away diff --git a/x/cdp/keeper/params.go b/x/cdp/keeper/params.go index 08a3bc9e..703cd273 100644 --- a/x/cdp/keeper/params.go +++ b/x/cdp/keeper/params.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/cdp/types" ) diff --git a/x/cdp/keeper/querier_test.go b/x/cdp/keeper/querier_test.go index be4c8fa9..879ab5ac 100644 --- a/x/cdp/keeper/querier_test.go +++ b/x/cdp/keeper/querier_test.go @@ -7,16 +7,19 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/simulation" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp/keeper" "github.com/kava-labs/kava/x/cdp/types" pfkeeper "github.com/kava-labs/kava/x/pricefeed/keeper" pftypes "github.com/kava-labs/kava/x/pricefeed/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) const ( diff --git a/x/cdp/keeper/savings.go b/x/cdp/keeper/savings.go index ec9c5944..fe5a8840 100644 --- a/x/cdp/keeper/savings.go +++ b/x/cdp/keeper/savings.go @@ -9,6 +9,7 @@ import ( authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" + auctiontypes "github.com/kava-labs/kava/x/auction/types" "github.com/kava-labs/kava/x/cdp/types" ) diff --git a/x/cdp/keeper/savings_test.go b/x/cdp/keeper/savings_test.go index 5c04b269..a72c5146 100644 --- a/x/cdp/keeper/savings_test.go +++ b/x/cdp/keeper/savings_test.go @@ -3,13 +3,16 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp/keeper" "github.com/kava-labs/kava/x/cdp/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type SavingsTestSuite struct { diff --git a/x/cdp/keeper/seize.go b/x/cdp/keeper/seize.go index 46183f77..67075bc7 100644 --- a/x/cdp/keeper/seize.go +++ b/x/cdp/keeper/seize.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/cdp/types" ) @@ -60,8 +61,7 @@ func (k Keeper) SeizeCollateral(ctx sdk.Context, cdp types.CDP) error { // Delete CDP from state k.RemoveCdpOwnerIndex(ctx, cdp) k.RemoveCdpCollateralRatioIndex(ctx, cdp.Collateral.Denom, cdp.ID, oldCollateralToDebtRatio) - k.DeleteCDP(ctx, cdp) - return nil + return k.DeleteCDP(ctx, cdp) } // LiquidateCdps seizes collateral from all CDPs below the input liquidation ratio diff --git a/x/cdp/keeper/seize_test.go b/x/cdp/keeper/seize_test.go index 92fe3319..45b707b9 100644 --- a/x/cdp/keeper/seize_test.go +++ b/x/cdp/keeper/seize_test.go @@ -6,9 +6,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" tmtime "github.com/tendermint/tendermint/types/time" diff --git a/x/cdp/module.go b/x/cdp/module.go index 9eb8ad3d..49db2add 100644 --- a/x/cdp/module.go +++ b/x/cdp/module.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" sim "github.com/cosmos/cosmos-sdk/x/simulation" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/cdp/client/cli" diff --git a/x/cdp/simulation/decoder_test.go b/x/cdp/simulation/decoder_test.go index cbb78fcd..459d87d7 100644 --- a/x/cdp/simulation/decoder_test.go +++ b/x/cdp/simulation/decoder_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/cdp/simulation/genesis.go b/x/cdp/simulation/genesis.go index a954476e..e0f4591d 100644 --- a/x/cdp/simulation/genesis.go +++ b/x/cdp/simulation/genesis.go @@ -10,6 +10,7 @@ import ( authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/supply" supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" + "github.com/kava-labs/kava/x/cdp/types" ) diff --git a/x/cdp/simulation/utils_test.go b/x/cdp/simulation/utils_test.go index 448366fa..e8634022 100644 --- a/x/cdp/simulation/utils_test.go +++ b/x/cdp/simulation/utils_test.go @@ -3,9 +3,11 @@ package simulation_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/cdp/simulation" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/cdp/simulation" ) func TestShiftDec(t *testing.T) { diff --git a/x/cdp/types/expected_keepers.go b/x/cdp/types/expected_keepers.go index c0e2e3d9..b960ed79 100644 --- a/x/cdp/types/expected_keepers.go +++ b/x/cdp/types/expected_keepers.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" + pftypes "github.com/kava-labs/kava/x/pricefeed/types" ) diff --git a/x/cdp/types/genesis_test.go b/x/cdp/types/genesis_test.go index f894492f..5895e370 100644 --- a/x/cdp/types/genesis_test.go +++ b/x/cdp/types/genesis_test.go @@ -19,4 +19,4 @@ func TestEqualProposalID(t *testing.T) { state2.StartingCdpID = 1 require.Equal(t, state1, state2) require.True(t, state1.Equal(state2)) -} \ No newline at end of file +} diff --git a/x/cdp/types/keys.go b/x/cdp/types/keys.go index 8f4a8097..1469ffa5 100644 --- a/x/cdp/types/keys.go +++ b/x/cdp/types/keys.go @@ -140,7 +140,7 @@ func CollateralRatioKey(denomByte byte, cdpID uint64, ratio sdk.Dec) []byte { // SplitCollateralRatioKey split the collateral ratio key and return the denom, cdp id, and collateral:debt ratio func SplitCollateralRatioKey(key []byte) (denom byte, cdpID uint64, ratio sdk.Dec) { - cdpID = GetCdpIDFromBytes(key[len(key)-8 : len(key)]) + cdpID = GetCdpIDFromBytes(key[len(key)-8:]) split := bytes.Split(key[:len(key)-8], sep) denom = split[0][0] diff --git a/x/cdp/types/keys_test.go b/x/cdp/types/keys_test.go index 935f6415..c016fa18 100644 --- a/x/cdp/types/keys_test.go +++ b/x/cdp/types/keys_test.go @@ -3,8 +3,10 @@ package types import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/crypto/ed25519" ) diff --git a/x/cdp/types/msg_test.go b/x/cdp/types/msg_test.go index ac6beebb..8fb7c50a 100644 --- a/x/cdp/types/msg_test.go +++ b/x/cdp/types/msg_test.go @@ -3,8 +3,9 @@ package types import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) var ( diff --git a/x/cdp/types/params.go b/x/cdp/types/params.go index 430ccdfe..02bf75cb 100644 --- a/x/cdp/types/params.go +++ b/x/cdp/types/params.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/params" + tmtime "github.com/tendermint/tendermint/types/time" ) diff --git a/x/cdp/types/params_test.go b/x/cdp/types/params_test.go index 38879436..5bba5871 100644 --- a/x/cdp/types/params_test.go +++ b/x/cdp/types/params_test.go @@ -5,9 +5,11 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/cdp/types" "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/cdp/types" ) type ParamsTestSuite struct { diff --git a/x/cdp/types/utils_test.go b/x/cdp/types/utils_test.go index 7a32d4e8..48a6947e 100644 --- a/x/cdp/types/utils_test.go +++ b/x/cdp/types/utils_test.go @@ -3,10 +3,10 @@ package types import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestSortableDecBytes(t *testing.T) { diff --git a/x/committee/abci.go b/x/committee/abci.go index 8e1c220e..d6ec639c 100644 --- a/x/committee/abci.go +++ b/x/committee/abci.go @@ -2,6 +2,7 @@ package committee import ( sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" ) diff --git a/x/committee/abci_test.go b/x/committee/abci_test.go index 8750822e..d112bb30 100644 --- a/x/committee/abci_test.go +++ b/x/committee/abci_test.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/committee/client/cli/cli_test.go b/x/committee/client/cli/cli_test.go index 20b6c564..37e5d086 100644 --- a/x/committee/client/cli/cli_test.go +++ b/x/committee/client/cli/cli_test.go @@ -3,9 +3,10 @@ package cli_test import ( "testing" - "github.com/cosmos/cosmos-sdk/codec" "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/committee/client/cli" ) diff --git a/x/committee/client/cli/tx.go b/x/committee/client/cli/tx.go index ea8fc273..d4575a47 100644 --- a/x/committee/client/cli/tx.go +++ b/x/committee/client/cli/tx.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/client/utils" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/params" + "github.com/tendermint/tendermint/crypto" "github.com/kava-labs/kava/x/committee/types" diff --git a/x/committee/genesis.go b/x/committee/genesis.go index af29c0e1..3a0b4110 100644 --- a/x/committee/genesis.go +++ b/x/committee/genesis.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/committee/types" ) diff --git a/x/committee/genesis_test.go b/x/committee/genesis_test.go index c64664eb..5cf8f7de 100644 --- a/x/committee/genesis_test.go +++ b/x/committee/genesis_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/committee/handler_test.go b/x/committee/handler_test.go index 7ae9d781..2b71239e 100644 --- a/x/committee/handler_test.go +++ b/x/committee/handler_test.go @@ -4,10 +4,12 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/params" - "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/committee/keeper/keeper_test.go b/x/committee/keeper/keeper_test.go index 3001eec0..1d712e1c 100644 --- a/x/committee/keeper/keeper_test.go +++ b/x/committee/keeper/keeper_test.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/committee/keeper/proposal_test.go b/x/committee/keeper/proposal_test.go index fb936bf0..5d0e46e7 100644 --- a/x/committee/keeper/proposal_test.go +++ b/x/committee/keeper/proposal_test.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/params" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/committee/keeper/querier.go b/x/committee/keeper/querier.go index 6e33c7c1..ca4ce994 100644 --- a/x/committee/keeper/querier.go +++ b/x/committee/keeper/querier.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/committee/types" diff --git a/x/committee/keeper/querier_test.go b/x/committee/keeper/querier_test.go index 2278fcc6..762bf605 100644 --- a/x/committee/keeper/querier_test.go +++ b/x/committee/keeper/querier_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/committee/module.go b/x/committee/module.go index 84f06265..857d8a1e 100644 --- a/x/committee/module.go +++ b/x/committee/module.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" sim "github.com/cosmos/cosmos-sdk/x/simulation" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/committee/client/cli" diff --git a/x/committee/proposal_handler_test.go b/x/committee/proposal_handler_test.go index 0a97cfc0..4fa97b26 100644 --- a/x/committee/proposal_handler_test.go +++ b/x/committee/proposal_handler_test.go @@ -4,10 +4,12 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" @@ -100,7 +102,7 @@ func (suite *ProposalHandlerTestSuite) TestProposalHandler_ChangeCommittee() { { name: "invalid title", proposal: committee.NewCommitteeChangeProposal( - "A Title That Is Much Too Long And Really Quite Unreasonable Given That It Is Trying To Fullfill The Roll Of An Acceptable Governance Proposal Title That Should Succinctly Communicate The Goal And Contents Of The Proposed Proposal To All Parties Involved", + "A Title That Is Much Too Long And Really Quite Unreasonable Given That It Is Trying To Fulfill The Roll Of An Acceptable Governance Proposal Title That Should Succinctly Communicate The Goal And Contents Of The Proposed Proposal To All Parties Involved", "A proposal description.", suite.testGenesis.Committees[0], ), @@ -177,7 +179,7 @@ func (suite *ProposalHandlerTestSuite) TestProposalHandler_DeleteCommittee() { { name: "invalid title", proposal: committee.NewCommitteeDeleteProposal( - "A Title That Is Much Too Long And Really Quite Unreasonable Given That It Is Trying To Fullfill The Roll Of An Acceptable Governance Proposal Title That Should Succinctly Communicate The Goal And Contents Of The Proposed Proposal To All Parties Involved", + "A Title That Is Much Too Long And Really Quite Unreasonable Given That It Is Trying To Fulfill The Roll Of An Acceptable Governance Proposal Title That Should Succinctly Communicate The Goal And Contents Of The Proposed Proposal To All Parties Involved", "A proposal description.", suite.testGenesis.Committees[1].ID, ), diff --git a/x/committee/simulation/decoder.go b/x/committee/simulation/decoder.go index bcbba73f..954c1f3a 100644 --- a/x/committee/simulation/decoder.go +++ b/x/committee/simulation/decoder.go @@ -2,6 +2,7 @@ package simulation import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/tendermint/tendermint/libs/kv" ) diff --git a/x/committee/types/committee.go b/x/committee/types/committee.go index c240ac52..fcb54720 100644 --- a/x/committee/types/committee.go +++ b/x/committee/types/committee.go @@ -4,9 +4,10 @@ import ( "fmt" "time" + yaml "gopkg.in/yaml.v2" + sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "gopkg.in/yaml.v2" ) const MaxCommitteeDescriptionLength int = 512 @@ -98,7 +99,7 @@ func (c Committee) Validate() error { // PubProposal is the interface that all proposals must fulfill to be submitted to a committee. // Proposal types can be created external to this module. For example a ParamChangeProposal, or CommunityPoolSpendProposal. -// It is pinned to the equivalent type in the gov module to create compatability between proposal types. +// It is pinned to the equivalent type in the gov module to create compatibility between proposal types. type PubProposal govtypes.Content // Proposal is an internal record of a governance proposal submitted to a committee. diff --git a/x/committee/types/committee_test.go b/x/committee/types/committee_test.go index 54204292..18df9f30 100644 --- a/x/committee/types/committee_test.go +++ b/x/committee/types/committee_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/stretchr/testify/suite" ) var _ PubProposal = UnregisteredPubProposal{} @@ -161,7 +162,7 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() { }, }}, }, - pubProposal: UnregisteredPubProposal{govtypes.TextProposal{"A Title", "A description."}}, + pubProposal: UnregisteredPubProposal{govtypes.TextProposal{Title: "A Title", Description: "A description."}}, expectHasPermissions: false, }, } diff --git a/x/committee/types/genesis.go b/x/committee/types/genesis.go index fda51064..a7539a45 100644 --- a/x/committee/types/genesis.go +++ b/x/committee/types/genesis.go @@ -81,7 +81,7 @@ func (gs GenesisState) Validate() error { // check committee exists if !committeeMap[p.CommitteeID] { - return fmt.Errorf("proposal refers to non existant committee; proposal: %+v", p) + return fmt.Errorf("proposal refers to non existent committee; proposal: %+v", p) } // validate pubProposal @@ -94,7 +94,7 @@ func (gs GenesisState) Validate() error { for _, v := range gs.Votes { // check proposal exists if !proposalMap[v.ProposalID] { - return fmt.Errorf("vote refers to non existant proposal; vote: %+v", v) + return fmt.Errorf("vote refers to non existent proposal; vote: %+v", v) } // validate address if v.Voter.Empty() { diff --git a/x/committee/types/genesis_test.go b/x/committee/types/genesis_test.go index d1ba83d7..3cfe64e4 100644 --- a/x/committee/types/genesis_test.go +++ b/x/committee/types/genesis_test.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/tendermint/tendermint/crypto" ) diff --git a/x/committee/types/permissions_test.go b/x/committee/types/permissions_test.go index 8218985f..54baaa10 100644 --- a/x/committee/types/permissions_test.go +++ b/x/committee/types/permissions_test.go @@ -3,9 +3,10 @@ package types import ( "testing" + "github.com/stretchr/testify/suite" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/stretchr/testify/suite" ) type PermissionsTestSuite struct { diff --git a/x/committee/types/proposal.go b/x/committee/types/proposal.go index 426df42d..ebc1baaf 100644 --- a/x/committee/types/proposal.go +++ b/x/committee/types/proposal.go @@ -1,7 +1,7 @@ package types import ( - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" diff --git a/x/incentive/abci.go b/x/incentive/abci.go index e6c0b293..f9786c0f 100644 --- a/x/incentive/abci.go +++ b/x/incentive/abci.go @@ -2,6 +2,7 @@ package incentive import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/incentive/keeper" ) diff --git a/x/incentive/client/cli/query.go b/x/incentive/client/cli/query.go index c9201c53..ea37bd97 100644 --- a/x/incentive/client/cli/query.go +++ b/x/incentive/client/cli/query.go @@ -4,13 +4,15 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + "github.com/kava-labs/kava/x/incentive/types" - "github.com/spf13/cobra" ) // GetQueryCmd returns the cli query commands for the incentive module diff --git a/x/incentive/client/cli/tx.go b/x/incentive/client/cli/tx.go index 559cbd37..5e77d2f0 100644 --- a/x/incentive/client/cli/tx.go +++ b/x/incentive/client/cli/tx.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -12,8 +14,8 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" + "github.com/kava-labs/kava/x/incentive/types" - "github.com/spf13/cobra" ) // GetTxCmd returns the transaction cli commands for the incentive module diff --git a/x/incentive/client/rest/query.go b/x/incentive/client/rest/query.go index e8e0e5e1..3d1b1aed 100644 --- a/x/incentive/client/rest/query.go +++ b/x/incentive/client/rest/query.go @@ -4,10 +4,12 @@ import ( "fmt" "net/http" + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/gorilla/mux" + "github.com/kava-labs/kava/x/incentive/types" ) diff --git a/x/incentive/client/rest/tx.go b/x/incentive/client/rest/tx.go index 13ccd94a..34b2aa96 100644 --- a/x/incentive/client/rest/tx.go +++ b/x/incentive/client/rest/tx.go @@ -3,11 +3,13 @@ package rest import ( "net/http" + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" - "github.com/gorilla/mux" + "github.com/kava-labs/kava/x/incentive/types" ) diff --git a/x/incentive/genesis.go b/x/incentive/genesis.go index 5a38e146..5b14a944 100644 --- a/x/incentive/genesis.go +++ b/x/incentive/genesis.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/incentive/keeper" "github.com/kava-labs/kava/x/incentive/types" ) diff --git a/x/incentive/handler.go b/x/incentive/handler.go index 1fdf8a58..bd8f430e 100644 --- a/x/incentive/handler.go +++ b/x/incentive/handler.go @@ -3,6 +3,7 @@ package incentive import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/kava-labs/kava/x/incentive/keeper" "github.com/kava-labs/kava/x/incentive/types" ) diff --git a/x/incentive/handler_test.go b/x/incentive/handler_test.go index 70253ef3..2e9e809a 100644 --- a/x/incentive/handler_test.go +++ b/x/incentive/handler_test.go @@ -4,13 +4,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/incentive" "github.com/kava-labs/kava/x/kavadist" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) } diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index 3c2aa383..cf7705b7 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/subspace" + "github.com/kava-labs/kava/x/incentive/types" ) diff --git a/x/incentive/keeper/keeper_test.go b/x/incentive/keeper/keeper_test.go index 0d56b2d5..8da12fd6 100644 --- a/x/incentive/keeper/keeper_test.go +++ b/x/incentive/keeper/keeper_test.go @@ -4,15 +4,18 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/incentive/keeper" "github.com/kava-labs/kava/x/incentive/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) // Test suite used for all keeper tests diff --git a/x/incentive/keeper/params.go b/x/incentive/keeper/params.go index ad80a0e8..0d6b6f78 100644 --- a/x/incentive/keeper/params.go +++ b/x/incentive/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/incentive/types" ) diff --git a/x/incentive/keeper/payout.go b/x/incentive/keeper/payout.go index ac3142b8..20b339fe 100644 --- a/x/incentive/keeper/payout.go +++ b/x/incentive/keeper/payout.go @@ -9,6 +9,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" supplyExported "github.com/cosmos/cosmos-sdk/x/supply/exported" + "github.com/kava-labs/kava/x/incentive/types" validatorvesting "github.com/kava-labs/kava/x/validator-vesting" ) diff --git a/x/incentive/keeper/payout_test.go b/x/incentive/keeper/payout_test.go index caefc6dd..cfdfa652 100644 --- a/x/incentive/keeper/payout_test.go +++ b/x/incentive/keeper/payout_test.go @@ -7,12 +7,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/vesting" + + abci "github.com/tendermint/tendermint/abci/types" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp" "github.com/kava-labs/kava/x/incentive/types" "github.com/kava-labs/kava/x/kavadist" validatorvesting "github.com/kava-labs/kava/x/validator-vesting" - abci "github.com/tendermint/tendermint/abci/types" ) func (suite *KeeperTestSuite) setupChain() { diff --git a/x/incentive/keeper/querier.go b/x/incentive/keeper/querier.go index f5a3654c..428c8635 100644 --- a/x/incentive/keeper/querier.go +++ b/x/incentive/keeper/querier.go @@ -4,8 +4,10 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/kava-labs/kava/x/incentive/types" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/kava-labs/kava/x/incentive/types" ) // NewQuerier is the module level router for state queries diff --git a/x/incentive/keeper/querier_test.go b/x/incentive/keeper/querier_test.go index 156d0e8d..9e1e9d17 100644 --- a/x/incentive/keeper/querier_test.go +++ b/x/incentive/keeper/querier_test.go @@ -3,9 +3,10 @@ package keeper_test import ( "strings" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/kava-labs/kava/x/incentive/keeper" "github.com/kava-labs/kava/x/incentive/types" - abci "github.com/tendermint/tendermint/abci/types" ) func (suite *KeeperTestSuite) TestQuerier() { diff --git a/x/incentive/keeper/rewards.go b/x/incentive/keeper/rewards.go index 83faf7b1..9fd11d20 100644 --- a/x/incentive/keeper/rewards.go +++ b/x/incentive/keeper/rewards.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + cdptypes "github.com/kava-labs/kava/x/cdp/types" "github.com/kava-labs/kava/x/incentive/types" ) @@ -19,7 +20,7 @@ func (k Keeper) HandleRewardPeriodExpiry(ctx sdk.Context, rp types.RewardPeriod) // CreateNewRewardPeriod creates a new reward period from the input reward func (k Keeper) CreateNewRewardPeriod(ctx sdk.Context, reward types.Reward) { - // reward periods store the amount of rewards payed PER SECOND + // reward periods store the amount of rewards paid PER SECOND rewardsPerSecond := sdk.NewDecFromInt(reward.AvailableRewards.Amount).Quo(sdk.NewDecFromInt(sdk.NewInt(int64(reward.Duration.Seconds())))).TruncateInt() rewardCoinPerSecond := sdk.NewCoin(reward.AvailableRewards.Denom, rewardsPerSecond) rp := types.RewardPeriod{ diff --git a/x/incentive/keeper/rewards_test.go b/x/incentive/keeper/rewards_test.go index b61cac31..be2951a7 100644 --- a/x/incentive/keeper/rewards_test.go +++ b/x/incentive/keeper/rewards_test.go @@ -4,12 +4,14 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/cdp" "github.com/kava-labs/kava/x/incentive/types" "github.com/kava-labs/kava/x/pricefeed" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) func (suite *KeeperTestSuite) TestExpireRewardPeriod() { @@ -160,11 +162,11 @@ func (suite *KeeperTestSuite) setupCdpChain() { pricefeedGS := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: "bnb:usd", BaseAsset: "bnb", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "bnb:usd", BaseAsset: "bnb", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: "bnb:usd", OracleAddress: sdk.AccAddress{}, Price: d("12.29"), diff --git a/x/incentive/module.go b/x/incentive/module.go index 9c464e00..394e3a88 100644 --- a/x/incentive/module.go +++ b/x/incentive/module.go @@ -4,20 +4,23 @@ import ( "encoding/json" "math/rand" + "github.com/gorilla/mux" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" sim "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/gorilla/mux" + + abci "github.com/tendermint/tendermint/abci/types" + "github.com/kava-labs/kava/x/incentive/client/cli" "github.com/kava-labs/kava/x/incentive/client/rest" "github.com/kava-labs/kava/x/incentive/keeper" "github.com/kava-labs/kava/x/incentive/simulation" "github.com/kava-labs/kava/x/incentive/types" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" ) var ( diff --git a/x/incentive/simulation/decoder.go b/x/incentive/simulation/decoder.go index dda10310..9263de22 100644 --- a/x/incentive/simulation/decoder.go +++ b/x/incentive/simulation/decoder.go @@ -7,6 +7,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/codec" + "github.com/tendermint/tendermint/libs/kv" "github.com/kava-labs/kava/x/incentive/types" diff --git a/x/incentive/simulation/decoder_test.go b/x/incentive/simulation/decoder_test.go index 7eb08ebd..1759f5b3 100644 --- a/x/incentive/simulation/decoder_test.go +++ b/x/incentive/simulation/decoder_test.go @@ -5,9 +5,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/kv" "github.com/kava-labs/kava/x/incentive/types" diff --git a/x/incentive/simulation/genesis.go b/x/incentive/simulation/genesis.go index 88a28bd6..cd6513d1 100644 --- a/x/incentive/simulation/genesis.go +++ b/x/incentive/simulation/genesis.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/kava-labs/kava/x/incentive/types" @@ -126,15 +125,3 @@ func genNextClaimPeriodIds(cps types.ClaimPeriods) types.GenesisClaimPeriodIDs { } return claimPeriodIDs } - -// In a list of accounts, replace the first account found with the same address. If not found, append the account. -func replaceOrAppendAccount(accounts []authexported.GenesisAccount, acc authexported.GenesisAccount) []authexported.GenesisAccount { - newAccounts := accounts - for i, a := range accounts { - if a.GetAddress().Equals(acc.GetAddress()) { - newAccounts[i] = acc - return newAccounts - } - } - return append(newAccounts, acc) -} diff --git a/x/incentive/simulation/operations.go b/x/incentive/simulation/operations.go index 03e143d8..40aeb4bc 100644 --- a/x/incentive/simulation/operations.go +++ b/x/incentive/simulation/operations.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/simapp/helpers" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/vesting" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -51,15 +50,12 @@ func SimulateMsgClaimReward(ak auth.AccountKeeper, sk types.SupplyKeeper, k keep ) (simulation.OperationMsg, []simulation.FutureOperation, error) { // Load only account types that can claim rewards - var accounts []authexported.Account validAccounts := make(map[string]bool) for _, acc := range accs { account := ak.GetAccount(ctx, acc.Address) switch account.(type) { case *vesting.PeriodicVestingAccount, *auth.BaseAccount: // Valid: BaseAccount, PeriodicVestingAccount - accounts = append(accounts, account) validAccounts[account.GetAddress().String()] = true - break default: // Invalid: ValidatorVestingAccount, DelayedVestingAccount, ContinuousVestingAccount break } diff --git a/x/incentive/simulation/params.go b/x/incentive/simulation/params.go index dd47e83f..19cf0e2a 100644 --- a/x/incentive/simulation/params.go +++ b/x/incentive/simulation/params.go @@ -5,6 +5,7 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/kava-labs/kava/x/incentive/types" ) @@ -17,10 +18,7 @@ const ( func genActive(r *rand.Rand) bool { threshold := 80 value := simulation.RandIntBetween(r, 1, 100) - if value > threshold { - return false - } - return true + return value <= threshold } // ParamChanges defines the parameters that can be modified by param change proposals diff --git a/x/incentive/types/account_test.go b/x/incentive/types/account_test.go index 525a3d02..5c1f6560 100644 --- a/x/incentive/types/account_test.go +++ b/x/incentive/types/account_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/kava-labs/kava/x/incentive/types" - "github.com/stretchr/testify/suite" ) type accountTest struct { @@ -22,7 +24,7 @@ type AccountTestSuite struct { func (suite *AccountTestSuite) SetupTest() { tests := []accountTest{ - accountTest{ + { periods: vesting.Periods{ vesting.Period{ Length: int64(100), diff --git a/x/incentive/types/expected_keepers.go b/x/incentive/types/expected_keepers.go index ccb20830..83cb47a6 100644 --- a/x/incentive/types/expected_keepers.go +++ b/x/incentive/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" + cdptypes "github.com/kava-labs/kava/x/cdp/types" ) diff --git a/x/incentive/types/msg_test.go b/x/incentive/types/msg_test.go index dbe06fe7..00eccee8 100644 --- a/x/incentive/types/msg_test.go +++ b/x/incentive/types/msg_test.go @@ -3,10 +3,13 @@ package types_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/incentive/types" "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/crypto" + + "github.com/kava-labs/kava/x/incentive/types" ) type msgTest struct { @@ -23,17 +26,17 @@ type MsgTestSuite struct { func (suite *MsgTestSuite) SetupTest() { tests := []msgTest{ - msgTest{ + { from: sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))), denom: "bnb", expectPass: true, }, - msgTest{ + { from: sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))), denom: "", expectPass: false, }, - msgTest{ + { from: sdk.AccAddress{}, denom: "bnb", expectPass: false, diff --git a/x/incentive/types/params.go b/x/incentive/types/params.go index 524cfb83..17ca6a20 100644 --- a/x/incentive/types/params.go +++ b/x/incentive/types/params.go @@ -7,9 +7,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" + + tmtime "github.com/tendermint/tendermint/types/time" + cdptypes "github.com/kava-labs/kava/x/cdp/types" kavadistTypes "github.com/kava-labs/kava/x/kavadist/types" - tmtime "github.com/tendermint/tendermint/types/time" ) // Parameter keys and default values diff --git a/x/incentive/types/params_test.go b/x/incentive/types/params_test.go index a35a2508..97f3fbc7 100644 --- a/x/incentive/types/params_test.go +++ b/x/incentive/types/params_test.go @@ -5,9 +5,11 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/incentive/types" "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/incentive/types" ) type paramTest struct { @@ -29,7 +31,7 @@ type ParamTestSuite struct { func (suite *ParamTestSuite) SetupTest() { suite.tests = []paramTest{ - paramTest{ + { name: "valid - active", params: types.Params{ Active: true, @@ -49,7 +51,7 @@ func (suite *ParamTestSuite) SetupTest() { contains: "", }, }, - paramTest{ + { name: "valid - inactive", params: types.Params{ Active: false, @@ -69,7 +71,7 @@ func (suite *ParamTestSuite) SetupTest() { contains: "", }, }, - paramTest{ + { name: "duplicate reward", params: types.Params{ Active: true, @@ -97,7 +99,7 @@ func (suite *ParamTestSuite) SetupTest() { contains: "cannot have duplicate reward denoms", }, }, - paramTest{ + { name: "negative reward duration", params: types.Params{ Active: true, @@ -117,7 +119,7 @@ func (suite *ParamTestSuite) SetupTest() { contains: "reward duration must be positive", }, }, - paramTest{ + { name: "negative time lock", params: types.Params{ Active: true, @@ -137,7 +139,7 @@ func (suite *ParamTestSuite) SetupTest() { contains: "reward timelock must be non-negative", }, }, - paramTest{ + { name: "zero claim duration", params: types.Params{ Active: true, @@ -157,7 +159,7 @@ func (suite *ParamTestSuite) SetupTest() { contains: "claim duration must be positive", }, }, - paramTest{ + { name: "zero reward", params: types.Params{ Active: true, @@ -177,7 +179,7 @@ func (suite *ParamTestSuite) SetupTest() { contains: "reward amount must be positive", }, }, - paramTest{ + { name: "empty reward denom", params: types.Params{ Active: true, diff --git a/x/kavadist/genesis.go b/x/kavadist/genesis.go index c4219a02..d1e7d25d 100644 --- a/x/kavadist/genesis.go +++ b/x/kavadist/genesis.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/kavadist/types" ) @@ -35,5 +36,5 @@ func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState { if !found { previousBlockTime = DefaultPreviousBlockTime } - return NewGenesisState(params,previousBlockTime) + return NewGenesisState(params, previousBlockTime) } diff --git a/x/kavadist/keeper/keeper.go b/x/kavadist/keeper/keeper.go index 34faa329..25e9ff1c 100644 --- a/x/kavadist/keeper/keeper.go +++ b/x/kavadist/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/subspace" + "github.com/kava-labs/kava/x/kavadist/types" ) diff --git a/x/kavadist/keeper/mint.go b/x/kavadist/keeper/mint.go index c5d19215..8f909cd7 100644 --- a/x/kavadist/keeper/mint.go +++ b/x/kavadist/keeper/mint.go @@ -2,11 +2,12 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + cdptypes "github.com/kava-labs/kava/x/cdp/types" "github.com/kava-labs/kava/x/kavadist/types" ) -// MintPeriodInflation mints new tokens according to the inflation schedule specified in the paramters +// MintPeriodInflation mints new tokens according to the inflation schedule specified in the parameters func (k Keeper) MintPeriodInflation(ctx sdk.Context) error { params := k.GetParams(ctx) if !params.Active { diff --git a/x/kavadist/keeper/mint_test.go b/x/kavadist/keeper/mint_test.go index c9b77753..48539c61 100644 --- a/x/kavadist/keeper/mint_test.go +++ b/x/kavadist/keeper/mint_test.go @@ -4,13 +4,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" + tmtime "github.com/tendermint/tendermint/types/time" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/kavadist/keeper" "github.com/kava-labs/kava/x/kavadist/types" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmtime "github.com/tendermint/tendermint/types/time" ) type MintTestSuite struct { diff --git a/x/kavadist/keeper/params.go b/x/kavadist/keeper/params.go index 526cb255..fe2c4a11 100644 --- a/x/kavadist/keeper/params.go +++ b/x/kavadist/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/kavadist/types" ) diff --git a/x/kavadist/module.go b/x/kavadist/module.go index f24005c8..e91dae17 100644 --- a/x/kavadist/module.go +++ b/x/kavadist/module.go @@ -12,9 +12,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" sim "github.com/cosmos/cosmos-sdk/x/simulation" + + abci "github.com/tendermint/tendermint/abci/types" + "github.com/kava-labs/kava/x/kavadist/simulation" "github.com/kava-labs/kava/x/kavadist/types" - abci "github.com/tendermint/tendermint/abci/types" ) var ( diff --git a/x/kavadist/simulation/utils_test.go b/x/kavadist/simulation/utils_test.go index 81a76c39..2521bb5f 100644 --- a/x/kavadist/simulation/utils_test.go +++ b/x/kavadist/simulation/utils_test.go @@ -3,8 +3,9 @@ package simulation import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestApproxRoot(t *testing.T) { diff --git a/x/kavadist/types/params.go b/x/kavadist/types/params.go index 9eb01b08..8fa015aa 100644 --- a/x/kavadist/types/params.go +++ b/x/kavadist/types/params.go @@ -6,8 +6,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" - cdptypes "github.com/kava-labs/kava/x/cdp/types" + tmtime "github.com/tendermint/tendermint/types/time" + + cdptypes "github.com/kava-labs/kava/x/cdp/types" ) // Parameter keys and default values diff --git a/x/kavadist/types/params_test.go b/x/kavadist/types/params_test.go index f2e02b90..ff3335bb 100644 --- a/x/kavadist/types/params_test.go +++ b/x/kavadist/types/params_test.go @@ -4,9 +4,11 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/kavadist/types" "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/kavadist/types" ) type paramTest struct { @@ -68,15 +70,15 @@ func (suite *ParamTestSuite) SetupTest() { } suite.tests = []paramTest{ - paramTest{ + { params: p1, expectPass: true, }, - paramTest{ + { params: p2, expectPass: false, }, - paramTest{ + { params: p3, expectPass: false, }, diff --git a/x/pricefeed/client/cli/query.go b/x/pricefeed/client/cli/query.go index b41d388a..73ae9796 100644 --- a/x/pricefeed/client/cli/query.go +++ b/x/pricefeed/client/cli/query.go @@ -3,13 +3,15 @@ package cli import ( "fmt" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/pricefeed/types" - "github.com/spf13/cobra" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/pricefeed/client/cli/tx.go b/x/pricefeed/client/cli/tx.go index 2aec48d6..52e8414d 100644 --- a/x/pricefeed/client/cli/tx.go +++ b/x/pricefeed/client/cli/tx.go @@ -14,8 +14,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" - "github.com/kava-labs/kava/x/pricefeed/types" + tmtime "github.com/tendermint/tendermint/types/time" + + "github.com/kava-labs/kava/x/pricefeed/types" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/pricefeed/client/rest/rest.go b/x/pricefeed/client/rest/rest.go index fa1f5cb7..12c4a863 100644 --- a/x/pricefeed/client/rest/rest.go +++ b/x/pricefeed/client/rest/rest.go @@ -1,9 +1,10 @@ package rest import ( + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/gorilla/mux" ) const ( diff --git a/x/pricefeed/client/rest/tx.go b/x/pricefeed/client/rest/tx.go index 6e0b87e6..06c1cda5 100644 --- a/x/pricefeed/client/rest/tx.go +++ b/x/pricefeed/client/rest/tx.go @@ -5,13 +5,16 @@ import ( "net/http" "time" + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" - "github.com/gorilla/mux" - "github.com/kava-labs/kava/x/pricefeed/types" + tmtime "github.com/tendermint/tendermint/types/time" + + "github.com/kava-labs/kava/x/pricefeed/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/pricefeed/genesis_test.go b/x/pricefeed/genesis_test.go index 968729bc..8c92b209 100644 --- a/x/pricefeed/genesis_test.go +++ b/x/pricefeed/genesis_test.go @@ -4,6 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" "github.com/kava-labs/kava/x/pricefeed" diff --git a/x/pricefeed/integration_test.go b/x/pricefeed/integration_test.go index 4d5f2c76..24629f4c 100644 --- a/x/pricefeed/integration_test.go +++ b/x/pricefeed/integration_test.go @@ -13,18 +13,18 @@ func NewPricefeedGenStateMulti() app.GenesisState { pfGenesis := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, - pricefeed.Market{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: "btc:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("8000.00"), Expiry: time.Now().Add(1 * time.Hour), }, - pricefeed.PostedPrice{ + { MarketID: "xrp:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("0.25"), @@ -39,18 +39,18 @@ func NewPricefeedGenStateWithOracles(addrs []sdk.AccAddress) app.GenesisState { pfGenesis := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: addrs, Active: true}, - pricefeed.Market{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: addrs, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: addrs, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: addrs, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: "btc:usd", OracleAddress: addrs[0], Price: sdk.MustNewDecFromStr("8000.00"), Expiry: time.Now().Add(1 * time.Hour), }, - pricefeed.PostedPrice{ + { MarketID: "xrp:usd", OracleAddress: addrs[0], Price: sdk.MustNewDecFromStr("0.25"), diff --git a/x/pricefeed/keeper/integration_test.go b/x/pricefeed/keeper/integration_test.go index 5594cda8..f9397c97 100644 --- a/x/pricefeed/keeper/integration_test.go +++ b/x/pricefeed/keeper/integration_test.go @@ -13,18 +13,18 @@ func NewPricefeedGenStateMulti() app.GenesisState { pfGenesis := pricefeed.GenesisState{ Params: pricefeed.Params{ Markets: []pricefeed.Market{ - pricefeed.Market{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, - pricefeed.Market{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, + {MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true}, }, }, PostedPrices: []pricefeed.PostedPrice{ - pricefeed.PostedPrice{ + { MarketID: "btc:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("8000.00"), Expiry: time.Now().Add(1 * time.Hour), }, - pricefeed.PostedPrice{ + { MarketID: "xrp:usd", OracleAddress: sdk.AccAddress{}, Price: sdk.MustNewDecFromStr("0.25"), diff --git a/x/pricefeed/keeper/keeper_test.go b/x/pricefeed/keeper/keeper_test.go index 2288fa87..92e33635 100644 --- a/x/pricefeed/keeper/keeper_test.go +++ b/x/pricefeed/keeper/keeper_test.go @@ -4,8 +4,10 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/app" diff --git a/x/pricefeed/keeper/params_test.go b/x/pricefeed/keeper/params_test.go index d4ccc483..3c293c74 100644 --- a/x/pricefeed/keeper/params_test.go +++ b/x/pricefeed/keeper/params_test.go @@ -3,12 +3,15 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/app" - "github.com/kava-labs/kava/x/pricefeed/keeper" "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" tmtime "github.com/tendermint/tendermint/types/time" + + "github.com/kava-labs/kava/app" + "github.com/kava-labs/kava/x/pricefeed/keeper" ) type KeeperTestSuite struct { diff --git a/x/pricefeed/module.go b/x/pricefeed/module.go index 3426a860..c2d9cd9c 100644 --- a/x/pricefeed/module.go +++ b/x/pricefeed/module.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" sim "github.com/cosmos/cosmos-sdk/x/simulation" + abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/pricefeed/client/cli" diff --git a/x/pricefeed/simulation/decoder.go b/x/pricefeed/simulation/decoder.go index e40c1932..cb6b8343 100644 --- a/x/pricefeed/simulation/decoder.go +++ b/x/pricefeed/simulation/decoder.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/codec" + "github.com/tendermint/tendermint/libs/kv" "github.com/kava-labs/kava/x/pricefeed/types" diff --git a/x/pricefeed/simulation/decoder_test.go b/x/pricefeed/simulation/decoder_test.go index 33ef65a8..de524923 100644 --- a/x/pricefeed/simulation/decoder_test.go +++ b/x/pricefeed/simulation/decoder_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/pricefeed/types/msgs_test.go b/x/pricefeed/types/msgs_test.go index 74192420..c9d16fc8 100644 --- a/x/pricefeed/types/msgs_test.go +++ b/x/pricefeed/types/msgs_test.go @@ -3,8 +3,10 @@ package types import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + tmtime "github.com/tendermint/tendermint/types/time" ) diff --git a/x/validator-vesting/abci.go b/x/validator-vesting/abci.go index bd896d56..97a976e4 100644 --- a/x/validator-vesting/abci.go +++ b/x/validator-vesting/abci.go @@ -7,8 +7,10 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/validator-vesting/keeper" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/kava-labs/kava/x/validator-vesting/keeper" ) // BeginBlocker updates the vote signing information for each validator vesting account, updates account when period changes, and updates the previousBlockTime value in the store. diff --git a/x/validator-vesting/abci_test.go b/x/validator-vesting/abci_test.go index dcac8266..a423740a 100644 --- a/x/validator-vesting/abci_test.go +++ b/x/validator-vesting/abci_test.go @@ -4,13 +4,16 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" tmtime "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/x/staking" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" + "github.com/kava-labs/kava/x/validator-vesting/keeper" "github.com/kava-labs/kava/x/validator-vesting/types" ) @@ -260,7 +263,7 @@ func TestBeginBlockerSuccessfulPeriod(t *testing.T) { vva = vvk.GetAccountFromAuthKeeper(ctx, vva.Address) // t.Log(vva.MarshalYAML()) - require.Equal(t, []types.VestingProgress{types.VestingProgress{true, true}, types.VestingProgress{false, false}, types.VestingProgress{false, false}}, vva.VestingPeriodProgress) + require.Equal(t, []types.VestingProgress{{true, true}, {false, false}, {false, false}}, vva.VestingPeriodProgress) } func TestBeginBlockerUnsuccessfulPeriod(t *testing.T) { @@ -320,8 +323,8 @@ func TestBeginBlockerUnsuccessfulPeriod(t *testing.T) { } vva = vvk.GetAccountFromAuthKeeper(ctx, vva.Address) - // check that the period was unsucessful - require.Equal(t, []types.VestingProgress{types.VestingProgress{true, false}, types.VestingProgress{false, false}, types.VestingProgress{false, false}}, vva.VestingPeriodProgress) + // check that the period was unsuccessful + require.Equal(t, []types.VestingProgress{{true, false}, {false, false}, {false, false}}, vva.VestingPeriodProgress) // check that there is debt after the period. require.Equal(t, sdk.Coins{sdk.NewInt64Coin("stake", 30000000)}, vva.DebtAfterFailedVesting) diff --git a/x/validator-vesting/client/rest/query.go b/x/validator-vesting/client/rest/query.go index ebe1de2e..0a9d6704 100644 --- a/x/validator-vesting/client/rest/query.go +++ b/x/validator-vesting/client/rest/query.go @@ -5,9 +5,11 @@ import ( "fmt" "net/http" + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/gorilla/mux" + "github.com/kava-labs/kava/x/validator-vesting/types" ) diff --git a/x/validator-vesting/genesis.go b/x/validator-vesting/genesis.go index e987b00c..00b6fd5f 100644 --- a/x/validator-vesting/genesis.go +++ b/x/validator-vesting/genesis.go @@ -2,6 +2,7 @@ package validatorvesting import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/validator-vesting/types" ) diff --git a/x/validator-vesting/keeper/keeper.go b/x/validator-vesting/keeper/keeper.go index f6bdade1..de51ffdf 100644 --- a/x/validator-vesting/keeper/keeper.go +++ b/x/validator-vesting/keeper/keeper.go @@ -7,8 +7,10 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" - "github.com/kava-labs/kava/x/validator-vesting/types" + "github.com/tendermint/tendermint/libs/log" + + "github.com/kava-labs/kava/x/validator-vesting/types" ) // Keeper of the validatorvesting store @@ -155,34 +157,38 @@ func (k Keeper) ResetCurrentPeriodProgress(ctx sdk.Context, addr sdk.AccAddress) func (k Keeper) HandleVestingDebt(ctx sdk.Context, addr sdk.AccAddress, blockTime time.Time) { vv := k.GetAccountFromAuthKeeper(ctx, addr) - if !vv.DebtAfterFailedVesting.IsZero() { - spendableCoins := vv.SpendableCoins(blockTime) - if spendableCoins.IsAllGTE(vv.DebtAfterFailedVesting) { - if vv.ReturnAddress != nil { - err := k.bk.SendCoins(ctx, addr, vv.ReturnAddress, vv.DebtAfterFailedVesting) - if err != nil { - panic(err) - } - } else { - err := k.supplyKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, vv.DebtAfterFailedVesting) - if err != nil { - panic(err) - } - err = k.supplyKeeper.BurnCoins(ctx, types.ModuleName, vv.DebtAfterFailedVesting) - if err != nil { - panic(err) - } + if vv.DebtAfterFailedVesting.IsZero() { + return + } + spendableCoins := vv.SpendableCoins(blockTime) + if spendableCoins.IsAllGTE(vv.DebtAfterFailedVesting) { + if vv.ReturnAddress != nil { + err := k.bk.SendCoins(ctx, addr, vv.ReturnAddress, vv.DebtAfterFailedVesting) + if err != nil { + panic(err) } - k.ResetDebt(ctx, addr) } else { - // iterate over all delegations made from the validator vesting account and undelegate - // note that we cannot safely undelegate only an amount of shares that covers the debt, - // because the value of those shares could change if a validator gets slashed. - k.stakingKeeper.IterateDelegations(ctx, vv.Address, func(index int64, d stakingexported.DelegationI) (stop bool) { - k.stakingKeeper.Undelegate(ctx, d.GetDelegatorAddr(), d.GetValidatorAddr(), d.GetShares()) - return false - }) + err := k.supplyKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, vv.DebtAfterFailedVesting) + if err != nil { + panic(err) + } + err = k.supplyKeeper.BurnCoins(ctx, types.ModuleName, vv.DebtAfterFailedVesting) + if err != nil { + panic(err) + } } + k.ResetDebt(ctx, addr) + } else { + // iterate over all delegations made from the validator vesting account and undelegate + // note that we cannot safely undelegate only an amount of shares that covers the debt, + // because the value of those shares could change if a validator gets slashed. + k.stakingKeeper.IterateDelegations(ctx, vv.Address, func(index int64, d stakingexported.DelegationI) (stop bool) { + _, err := k.stakingKeeper.Undelegate(ctx, d.GetDelegatorAddr(), d.GetValidatorAddr(), d.GetShares()) + if err != nil { + panic(err) + } + return false + }) } } diff --git a/x/validator-vesting/keeper/keeper_test.go b/x/validator-vesting/keeper/keeper_test.go index c3aaafb8..4f15b003 100644 --- a/x/validator-vesting/keeper/keeper_test.go +++ b/x/validator-vesting/keeper/keeper_test.go @@ -6,11 +6,13 @@ import ( "time" "github.com/stretchr/testify/require" + tmtime "github.com/tendermint/tendermint/types/time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" + "github.com/kava-labs/kava/x/validator-vesting/types" ) @@ -152,7 +154,7 @@ func TestUpdateVestedCoinsProgress(t *testing.T) { ak.SetAccount(ctx, vva) // require all vesting period tracking variables to be zero after validator vesting account is initialized - require.Equal(t, []types.VestingProgress{types.VestingProgress{false, false}, types.VestingProgress{false, false}, types.VestingProgress{false, false}}, vva.VestingPeriodProgress) + require.Equal(t, []types.VestingProgress{{false, false}, {false, false}, {false, false}}, vva.VestingPeriodProgress) // period 0 passes with all blocks signed vva.CurrentPeriodProgress.MissedBlocks = 0 @@ -164,7 +166,7 @@ func TestUpdateVestedCoinsProgress(t *testing.T) { // require that debt is zerox require.Equal(t, sdk.Coins(nil), vva.DebtAfterFailedVesting) // require that the first vesting progress variable is successful - require.Equal(t, []types.VestingProgress{types.VestingProgress{true, true}, types.VestingProgress{false, false}, types.VestingProgress{false, false}}, vva.VestingPeriodProgress) + require.Equal(t, []types.VestingProgress{{true, true}, {false, false}, {false, false}}, vva.VestingPeriodProgress) // require that the missing block counter has reset require.Equal(t, types.CurrentPeriodProgress{0, 0}, vva.CurrentPeriodProgress) @@ -183,7 +185,7 @@ func TestUpdateVestedCoinsProgress(t *testing.T) { // require that debt is zero require.Equal(t, sdk.Coins(nil), vva.DebtAfterFailedVesting) // require that the first vesting progress variable is successful - require.Equal(t, []types.VestingProgress{types.VestingProgress{true, true}, types.VestingProgress{false, false}, types.VestingProgress{false, false}}, vva.VestingPeriodProgress) + require.Equal(t, []types.VestingProgress{{true, true}, {false, false}, {false, false}}, vva.VestingPeriodProgress) // require that the missing block counter has reset require.Equal(t, types.CurrentPeriodProgress{0, 0}, vva.CurrentPeriodProgress) @@ -199,7 +201,7 @@ func TestUpdateVestedCoinsProgress(t *testing.T) { // require that period 1 coins have become debt require.Equal(t, sdk.NewCoins(sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)), vva.DebtAfterFailedVesting) // require that the first vesting progress variable is {true, false} - require.Equal(t, []types.VestingProgress{types.VestingProgress{true, false}, types.VestingProgress{false, false}, types.VestingProgress{false, false}}, vva.VestingPeriodProgress) + require.Equal(t, []types.VestingProgress{{true, false}, {false, false}, {false, false}}, vva.VestingPeriodProgress) // require that the missing block counter has reset require.Equal(t, types.CurrentPeriodProgress{0, 0}, vva.CurrentPeriodProgress) } diff --git a/x/validator-vesting/keeper/test_common.go b/x/validator-vesting/keeper/test_common.go index fbb817ca..356013e4 100644 --- a/x/validator-vesting/keeper/test_common.go +++ b/x/validator-vesting/keeper/test_common.go @@ -9,12 +9,13 @@ import ( "github.com/stretchr/testify/require" + dbm "github.com/tendermint/tm-db" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" tmtime "github.com/tendermint/tendermint/types/time" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" @@ -25,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" + "github.com/kava-labs/kava/x/validator-vesting/types" ) @@ -170,9 +172,12 @@ func ValidatorVestingTestAccount() *types.ValidatorVestingAccount { testConsAddr := sdk.ConsAddress(testPk.Address()) origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := auth.NewBaseAccountWithAddress(testAddr) - bacc.SetCoins(origCoins) + err := bacc.SetCoins(origCoins) + if err != nil { + panic(err) + } vva := types.NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90) - err := vva.Validate() + err = vva.Validate() if err != nil { panic(err) } @@ -194,9 +199,12 @@ func ValidatorVestingTestAccounts(numAccounts int) []*types.ValidatorVestingAcco testConsAddr := sdk.ConsAddress(testPk[i].Address()) origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := auth.NewBaseAccountWithAddress(testAddr[i]) - bacc.SetCoins(origCoins) + err := bacc.SetCoins(origCoins) + if err != nil { + panic(err) + } vva := types.NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90) - err := vva.Validate() + err = vva.Validate() if err != nil { panic(err) } @@ -216,9 +224,12 @@ func ValidatorVestingDelegatorTestAccount(startTime time.Time) *types.ValidatorV testConsAddr := sdk.ConsAddress(testPk.Address()) origCoins := sdk.Coins{sdk.NewInt64Coin(stakeDenom, 60000000)} bacc := auth.NewBaseAccountWithAddress(testAddr) - bacc.SetCoins(origCoins) + err := bacc.SetCoins(origCoins) + if err != nil { + panic(err) + } vva := types.NewValidatorVestingAccount(&bacc, startTime.Unix(), periods, testConsAddr, nil, 90) - err := vva.Validate() + err = vva.Validate() if err != nil { panic(err) } diff --git a/x/validator-vesting/module.go b/x/validator-vesting/module.go index f918d028..70ed1636 100644 --- a/x/validator-vesting/module.go +++ b/x/validator-vesting/module.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/client/context" @@ -13,6 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" sim "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/kava-labs/kava/x/validator-vesting/client/cli" "github.com/kava-labs/kava/x/validator-vesting/client/rest" "github.com/kava-labs/kava/x/validator-vesting/simulation" diff --git a/x/validator-vesting/simulation/decoder.go b/x/validator-vesting/simulation/decoder.go index 7dc83ff6..9cddbb29 100644 --- a/x/validator-vesting/simulation/decoder.go +++ b/x/validator-vesting/simulation/decoder.go @@ -7,8 +7,10 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/kava-labs/kava/x/validator-vesting/types" + "github.com/tendermint/tendermint/libs/kv" + + "github.com/kava-labs/kava/x/validator-vesting/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding auth type diff --git a/x/validator-vesting/simulation/decoder_test.go b/x/validator-vesting/simulation/decoder_test.go index c029499b..e07bdac1 100644 --- a/x/validator-vesting/simulation/decoder_test.go +++ b/x/validator-vesting/simulation/decoder_test.go @@ -5,13 +5,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/kava-labs/kava/x/validator-vesting/types" - "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/kv" + + "github.com/kava-labs/kava/x/validator-vesting/types" ) var ( diff --git a/x/validator-vesting/simulation/genesis.go b/x/validator-vesting/simulation/genesis.go index 414bb0f9..9a39dd5b 100644 --- a/x/validator-vesting/simulation/genesis.go +++ b/x/validator-vesting/simulation/genesis.go @@ -11,6 +11,7 @@ import ( vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/kava-labs/kava/x/validator-vesting/types" ) diff --git a/x/validator-vesting/test_common.go b/x/validator-vesting/test_common.go index fdb4f83f..176d1737 100644 --- a/x/validator-vesting/test_common.go +++ b/x/validator-vesting/test_common.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" + "github.com/kava-labs/kava/x/validator-vesting/keeper" "github.com/kava-labs/kava/x/validator-vesting/types" ) diff --git a/x/validator-vesting/types/validator_vesting_account.go b/x/validator-vesting/types/validator_vesting_account.go index 27eb452e..297e1082 100644 --- a/x/validator-vesting/types/validator_vesting_account.go +++ b/x/validator-vesting/types/validator_vesting_account.go @@ -5,13 +5,14 @@ import ( "errors" "time" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/tendermint/tendermint/crypto" ) diff --git a/x/validator-vesting/types/validator_vesting_account_test.go b/x/validator-vesting/types/validator_vesting_account_test.go index 5bb91d76..a2562e3b 100644 --- a/x/validator-vesting/types/validator_vesting_account_test.go +++ b/x/validator-vesting/types/validator_vesting_account_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/stretchr/testify/require" + tmtime "github.com/tendermint/tendermint/types/time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -254,7 +255,7 @@ func TestGetFailedVestedCoins(t *testing.T) { vva := NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90) vva.VestingPeriodProgress[0] = VestingProgress{true, false} - // require that period 1 coins are failed if the period completed unsucessfully. + // require that period 1 coins are failed if the period completed unsuccessfully. require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, vva.GetFailedVestedCoins(), @@ -362,7 +363,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedVesting) - // successfuly vest period 1 and delegate to two validators + // successfully vest period 1 and delegate to two validators vva = NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90) vva.VestingPeriodProgress[0] = VestingProgress{true, true} vva.TrackDelegation(now.Add(12*time.Hour), sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)})