diff --git a/.golangci.yml b/.golangci.yml index ffa24d7..e225545 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,69 +1,116 @@ run: - tests: false - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m + tests: true + timeout: 10m linters: disable-all: true enable: - - bodyclose - - depguard - - dogsled + - exportloopref - errcheck + - gci - goconst - gocritic - - gofmt - - goimports + - gofumpt - gosec - gosimple - govet - ineffassign - misspell - nakedret - - nolintlint - - prealloc - staticcheck + - thelper + - typecheck - stylecheck + - revive - typecheck + - tenv - unconvert + # Prefer unparam over revive's unused param. It is more thorough in its checking. - unparam - unused + - misspell issues: exclude-rules: - - text: "Use of weak random number generator" - linters: - - gosec - - text: "comment on exported var" + - text: 'differs only by capitalization to method' linters: - - golint - - text: "don't use an underscore in package name" - linters: - - golint - - text: "ST1003:" - linters: - - stylecheck - # FIXME: Disabled until golangci-lint updates stylecheck with this fix: - # https://github.com/dominikh/go-tools/issues/389 - - text: "ST1016:" - linters: - - stylecheck - - path: "migrations" - text: "SA1019:" + - revive + - text: 'Use of weak random number generator' linters: + - gosec + - linters: - staticcheck + text: "SA1019:" # silence errors on usage of deprecated funcs max-issues-per-linter: 10000 max-same-issues: 10000 linters-settings: - dogsled: - max-blank-identifiers: 3 - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true - nolintlint: - allow-unused: false - allow-leading-space: true - require-explanation: false - require-specific: false + gci: + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - blank # blank imports + - dot # dot imports + - prefix(cosmossdk.io) + - prefix(github.com/cosmos/cosmos-sdk) + - prefix(github.com/cometbft/cometbft) + - prefix(github.com/github.com/envadiv/Passage3D)) + custom-order: true + revive: + enable-all-rules: true + # Do NOT whine about the following, full explanation found in: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#description-of-available-rules + rules: + - name: use-any + disabled: true + - name: if-return + disabled: true + - name: max-public-structs + disabled: true + - name: cognitive-complexity + disabled: true + - name: argument-limit + disabled: true + - name: cyclomatic + disabled: true + - name: file-header + disabled: true + - name: function-length + disabled: true + - name: function-result-limit + disabled: true + - name: line-length-limit + disabled: true + - name: flag-parameter + disabled: true + - name: add-constant + disabled: true + - name: empty-lines + disabled: true + - name: banned-characters + disabled: true + - name: deep-exit + disabled: true + - name: confusing-results + disabled: true + - name: unused-parameter + disabled: true + - name: modifies-value-receiver + disabled: true + - name: early-return + disabled: true + - name: confusing-naming + disabled: true + - name: defer + disabled: true + # Disabled in favour of unparam. + - name: unused-parameter + disabled: true + - name: unhandled-error + disabled: false + arguments: + - 'fmt.Printf' + - 'fmt.Print' + - 'fmt.Println' + - 'myFunction' diff --git a/app/ante.go b/app/ante.go index b44892b..03080ad 100644 --- a/app/ante.go +++ b/app/ante.go @@ -3,13 +3,13 @@ package app import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/ante" ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" - passageante "github.com/envadiv/Passage3D/app/ante" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/ante" ) // HandlerOptions are the options required for constructing a default SDK AnteHandler. diff --git a/app/ante/block.go b/app/ante/block.go index a9d4d62..9f8e09e 100644 --- a/app/ante/block.go +++ b/app/ante/block.go @@ -17,7 +17,7 @@ func NewBlockAccountDecorator() BlockAccountDecorator { return BlockAccountDecorator{} } -func (bad BlockAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (BlockAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { if simulate { return next(ctx, tx, simulate) } diff --git a/app/app.go b/app/app.go index f51e4f9..c010a41 100644 --- a/app/app.go +++ b/app/app.go @@ -9,12 +9,22 @@ import ( "path/filepath" "strings" + "github.com/CosmWasm/wasmd/x/wasm" + wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/cosmos/ibc-go/v4/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v4/modules/core" + porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types" + ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host" + ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" appparams "github.com/envadiv/Passage3D/app/params" "github.com/envadiv/Passage3D/app/upgrades" "github.com/envadiv/Passage3D/app/upgrades/v2.2.0" - "github.com/envadiv/Passage3D/x/claim" - + claimkeeper "github.com/envadiv/Passage3D/x/claim/keeper" + claimtypes "github.com/envadiv/Passage3D/x/claim/types" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -23,13 +33,8 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - "github.com/cosmos/ibc-go/v4/modules/apps/transfer" - ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper" - ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v4/modules/core" - porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types" - ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host" - ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" + // unnamed import of statik for swagger UI support + _ "github.com/cosmos/cosmos-sdk/client/docs/statik" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -99,16 +104,6 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - claimkeeper "github.com/envadiv/Passage3D/x/claim/keeper" - claimtypes "github.com/envadiv/Passage3D/x/claim/types" - - "github.com/CosmWasm/wasmd/x/wasm" - wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - - // unnamed import of statik for swagger UI support - _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) const appName = "passage" @@ -266,7 +261,6 @@ func NewPassageApp( homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig, enabledProposals []wasm.ProposalType, appOpts servertypes.AppOptions, wasmOpts []wasm.Option, baseAppOptions ...func(*baseapp.BaseApp), ) *PassageApp { - appCodec := encodingConfig.Marshaler legacyAmino := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry @@ -450,11 +444,11 @@ func NewPassageApp( // Setting Router will finalize all routes by sealing router // No more routes can be added app.IBCKeeper.SetRouter(ibcRouter) - /**** Module Options ****/ + // *** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment // we prefer to be more strict in what arguments the modules expect. - var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. @@ -628,7 +622,6 @@ func NewPassageApp( TxCounterStoreKey: keys[wasm.StoreKey], }, ) - if err != nil { panic(err) } @@ -656,10 +649,10 @@ func NewPassageApp( } func (app *PassageApp) setupUpgradeHandlers() { - for _, upgrade := range Upgrades { + for _, appUpgrade := range Upgrades { app.UpgradeKeeper.SetUpgradeHandler( - upgrade.UpgradeName, - upgrade.CreateUpgradeHandler( + appUpgrade.UpgradeName, + appUpgrade.CreateUpgradeHandler( app.mm, app.configurator, app.DistrKeeper, @@ -701,7 +694,7 @@ func (app *PassageApp) LoadHeight(height int64) error { } // ModuleAccountAddrs returns all the app's module account addresses. -func (app *PassageApp) ModuleAccountAddrs() map[string]bool { +func (*PassageApp) ModuleAccountAddrs() map[string]bool { modAccAddrs := make(map[string]bool) for acc := range maccPerms { modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true @@ -767,7 +760,7 @@ func (app *PassageApp) SimulationManager() *module.SimulationManager { // RegisterAPIRoutes registers all application module routes with the provided // API server. -func (app *PassageApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { +func (*PassageApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { clientCtx := apiSvr.ClientCtx rpc.RegisterRoutes(clientCtx, apiSvr.Router) // Register legacy tx routes. diff --git a/app/app_test.go b/app/app_test.go index 9f00e40..e7e8bc0 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -5,8 +5,10 @@ import ( "os" "testing" + "github.com/CosmWasm/wasmd/x/wasm" + "github.com/cosmos/ibc-go/v4/modules/apps/transfer" + ibc "github.com/cosmos/ibc-go/v4/modules/core" "github.com/envadiv/Passage3D/x/claim" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -14,10 +16,6 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/cosmos/ibc-go/v4/modules/apps/transfer" - ibc "github.com/cosmos/ibc-go/v4/modules/core" - - "github.com/CosmWasm/wasmd/x/wasm" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/tests/mocks" sdk "github.com/cosmos/cosmos-sdk/types" @@ -41,7 +39,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade" ) -var emptyWasmOpts []wasm.Option = nil +var emptyWasmOpts []wasm.Option func TestSimAppExportAndBlockedAddrs(t *testing.T) { encCfg := MakeEncodingConfig() @@ -129,12 +127,12 @@ func TestRunMigrations(t *testing.T) { // // The loop below is the same as calling `RegisterServices` on // ModuleManager, except that we skip x/bank. - for _, module := range app.mm.Modules { - if module.Name() == banktypes.ModuleName { + for _, appModule := range app.mm.Modules { + if appModule.Name() == banktypes.ModuleName { continue } - module.RegisterServices(app.configurator) + appModule.RegisterServices(app.configurator) } // Initialize the chain diff --git a/app/forks.go b/app/forks.go index b4d1cd0..9995cea 100644 --- a/app/forks.go +++ b/app/forks.go @@ -1,8 +1,9 @@ package app import ( - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" + + sdk "github.com/cosmos/cosmos-sdk/types" ) const forkHeight = 4426144 diff --git a/app/genesis_account_test.go b/app/genesis_account_test.go index 2a9e570..4fd35b1 100644 --- a/app/genesis_account_test.go +++ b/app/genesis_account_test.go @@ -4,13 +4,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto" ) func TestSimGenesisAccountValidate(t *testing.T) { diff --git a/app/sim_bench_test.go b/app/sim_bench_test.go index 5287c43..41689bd 100644 --- a/app/sim_bench_test.go +++ b/app/sim_bench_test.go @@ -5,9 +5,9 @@ import ( "os" "testing" + "github.com/CosmWasm/wasmd/x/wasm" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/CosmWasm/wasmd/x/wasm" "github.com/cosmos/cosmos-sdk/simapp" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" diff --git a/app/sim_test.go b/app/sim_test.go index 1eb07e8..6c7c48a 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -7,13 +7,13 @@ import ( "os" "testing" + "github.com/CosmWasm/wasmd/x/wasm" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/CosmWasm/wasmd/x/wasm" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/helpers" @@ -163,11 +163,13 @@ func TestAppImportExport(t *testing.T) { storeKeysPrefixes := []StoreKeysPrefixes{ {app.keys[authtypes.StoreKey], newApp.keys[authtypes.StoreKey], [][]byte{}}, - {app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], + { + app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], [][]byte{ stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, stakingtypes.HistoricalInfoKey, - }}, // ordering may change but it doesn't matter + }, + }, // ordering may change but it doesn't matter {app.keys[slashingtypes.StoreKey], newApp.keys[slashingtypes.StoreKey], [][]byte{}}, {app.keys[minttypes.StoreKey], newApp.keys[minttypes.StoreKey], [][]byte{}}, {app.keys[distrtypes.StoreKey], newApp.keys[distrtypes.StoreKey], [][]byte{}}, diff --git a/app/test_helpers.go b/app/test_helpers.go index 47e5b54..481ade1 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/CosmWasm/wasmd/x/wasm" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" @@ -16,7 +17,6 @@ import ( tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/CosmWasm/wasmd/x/wasm" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -51,7 +51,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{ }, }, } -var emptyWasmOptions []wasm.Option = nil +var emptyWasmOptions []wasm.Option func setup(withGenesis bool, invCheckPeriod uint) (*PassageApp, GenesisState) { db := dbm.NewMemDB() @@ -91,6 +91,7 @@ func Setup(isCheckTx bool) *PassageApp { // of one consensus engine unit (10^6) in the default token of the simapp from first genesis // account. A Nop logger is set in PassageApp. func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *PassageApp { + t.Helper() app, genesisState := setup(true, 5) // set genesis accounts authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) @@ -222,9 +223,14 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress { // start at 100 so we can make up to 999 test addresses with valid test addresses for i := 100; i < (accNum + 100); i++ { numString := strconv.Itoa(i) - buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string - - buffer.WriteString(numString) // adding on final two digits to make addresses unique + _, err := buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string + if err != nil { + panic(err) + } + _, err = buffer.WriteString(numString) //nolint:revive // adding on final two digits to make addresses unique + if err != nil { + panic(err) + } res, _ := sdk.AccAddressFromHex(buffer.String()) bech := res.String() addr, _ := TestAddr(buffer.String(), bech) @@ -315,6 +321,7 @@ func TestAddr(addr string, bech string) (sdk.AccAddress, error) { // CheckBalance checks the balance of an account. func CheckBalance(t *testing.T, app *PassageApp, addr sdk.AccAddress, balances sdk.Coins) { + t.Helper() ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr))) } @@ -327,7 +334,7 @@ func SignCheckDeliver( t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg, chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { - + t.Helper() tx, err := helpers.GenTx( txCfg, msgs, @@ -411,8 +418,15 @@ func CreateTestPubKeys(numPubKeys int) []cryptotypes.PubKey { // start at 10 to avoid changing 1 to 01, 2 to 02, etc for i := 100; i < (numPubKeys + 100); i++ { numString := strconv.Itoa(i) - buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AF") // base pubkey string - buffer.WriteString(numString) // adding on final two digits to make pubkeys unique + _, err := buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AF") // base pubkey string + if err != nil { + panic(err) + } + + _, err = buffer.WriteString(numString) // adding on final two digits to make pubkeys unique + if err != nil { + panic(err) + } publicKeys = append(publicKeys, NewPubKeyFromHex(buffer.String())) buffer.Reset() } @@ -436,7 +450,7 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) { type EmptyAppOptions struct{} // Get implements AppOptions -func (ao EmptyAppOptions) Get(o string) interface{} { +func (EmptyAppOptions) Get(o string) interface{} { return nil } diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 7143399..aafeed1 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -1,13 +1,14 @@ package upgrades import ( + claim "github.com/envadiv/Passage3D/x/claim/keeper" + store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/module" auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" bank "github.com/cosmos/cosmos-sdk/x/bank/keeper" distribution "github.com/cosmos/cosmos-sdk/x/distribution/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - claim "github.com/envadiv/Passage3D/x/claim/keeper" ) // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal diff --git a/app/upgrades/v2.2.0/claim_records_data.go b/app/upgrades/v2.2.0/claim_records_data.go index 3405e5d..084b2af 100644 --- a/app/upgrades/v2.2.0/claim_records_data.go +++ b/app/upgrades/v2.2.0/claim_records_data.go @@ -1,8 +1,9 @@ package v2 import ( - "github.com/cosmos/cosmos-sdk/types" claimtypes "github.com/envadiv/Passage3D/x/claim/types" + + "github.com/cosmos/cosmos-sdk/types" ) var NewClaimRecords = []*claimtypes.ClaimRecord{ diff --git a/app/upgrades/v2.2.0/upgrade.go b/app/upgrades/v2.2.0/upgrade.go index 90964b8..be31132 100644 --- a/app/upgrades/v2.2.0/upgrade.go +++ b/app/upgrades/v2.2.0/upgrade.go @@ -4,6 +4,10 @@ import ( "fmt" "time" + "github.com/envadiv/Passage3D/app/upgrades" + claim "github.com/envadiv/Passage3D/x/claim/keeper" + claimtypes "github.com/envadiv/Passage3D/x/claim/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -13,13 +17,12 @@ import ( bank "github.com/cosmos/cosmos-sdk/x/bank/keeper" distribution "github.com/cosmos/cosmos-sdk/x/distribution/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/envadiv/Passage3D/app/upgrades" - claim "github.com/envadiv/Passage3D/x/claim/keeper" - claimtypes "github.com/envadiv/Passage3D/x/claim/types" ) -const Name = "v2.2.0" -const upasgDenom = "upasg" +const ( + Name = "v2.2.0" + upasgDenom = "upasg" +) // 150,000,000 $PASG tokens var amount = sdk.NewCoins(sdk.NewCoin(upasgDenom, sdk.NewInt(150000000000000))) @@ -38,7 +41,6 @@ func CreateUpgradeHandler( ak auth.AccountKeeper, ck claim.Keeper, ) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { if err := ExecuteProposal(ctx, ak, bk, ck, dk); err != nil { return nil, err @@ -49,7 +51,7 @@ func CreateUpgradeHandler( } func ExecuteProposal(ctx sdk.Context, ak auth.AccountKeeper, bk bank.Keeper, ck claim.Keeper, dk distribution.Keeper) error { - var sixMonths = time.Hour * 24 * 180 + sixMonths := time.Hour * 24 * 180 vestingAcc, err := sdk.AccAddressFromBech32("pasg105488mw9t3qtp62jhllde28v40xqxpjksjqmvx") if err != nil { diff --git a/cmd/passage/cmd/genaccounts_test.go b/cmd/passage/cmd/genaccounts_test.go index c722ad7..fab8f5d 100644 --- a/cmd/passage/cmd/genaccounts_test.go +++ b/cmd/passage/cmd/genaccounts_test.go @@ -5,21 +5,19 @@ import ( "fmt" "testing" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - sdk "github.com/cosmos/cosmos-sdk/types" - + simcmd "github.com/envadiv/Passage3D/cmd/passage/cmd" "github.com/spf13/viper" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" - simcmd "github.com/envadiv/Passage3D/cmd/passage/cmd" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" @@ -98,7 +96,8 @@ func TestAddGenesisAccountCmd(t *testing.T) { cmd.SetArgs([]string{ tc.addr, tc.denom, - fmt.Sprintf("--%s=home", flags.FlagHome)}) + fmt.Sprintf("--%s=home", flags.FlagHome), + }) if tc.expectErr { require.Error(t, cmd.ExecuteContext(ctx)) diff --git a/cmd/passage/cmd/root.go b/cmd/passage/cmd/root.go index a4c4bdc..b062f7b 100644 --- a/cmd/passage/cmd/root.go +++ b/cmd/passage/cmd/root.go @@ -6,20 +6,17 @@ import ( "os" "path/filepath" + "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/envadiv/Passage3D/app" appparams "github.com/envadiv/Passage3D/app/params" - + "github.com/prometheus/client_golang/prometheus" "github.com/spf13/cast" "github.com/spf13/cobra" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" - serverconfig "github.com/cosmos/cosmos-sdk/server/config" - - "github.com/envadiv/Passage3D/app" - - "github.com/CosmWasm/wasmd/x/wasm" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -28,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/server" + serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/snapshots" "github.com/cosmos/cosmos-sdk/store" @@ -37,7 +35,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" - "github.com/prometheus/client_golang/prometheus" ) // NewRootCmd creates a new root command for simd. It is called once in the @@ -291,14 +288,14 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a // and exports state. func (a appCreator) appExport( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, - appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) { - + appOpts servertypes.AppOptions, +) (servertypes.ExportedApp, error) { var simApp *app.PassageApp homePath, ok := appOpts.Get(flags.FlagHome).(string) if !ok || homePath == "" { return servertypes.ExportedApp{}, errors.New("application home not set") } - var emptyWasmOpts []wasm.Option = nil + var emptyWasmOpts []wasm.Option if height != -1 { simApp = app.NewPassageApp(logger, db, traceStore, false, map[int64]bool{}, homePath, uint(1), a.encCfg, app.GetEnabledProposals(), appOpts, emptyWasmOpts) diff --git a/cmd/passage/cmd/testnet.go b/cmd/passage/cmd/testnet.go index 9e483e8..79fff2c 100644 --- a/cmd/passage/cmd/testnet.go +++ b/cmd/passage/cmd/testnet.go @@ -95,7 +95,7 @@ Example: return cmd } -const nodeDirPerm = 0755 +const nodeDirPerm = 0o755 // Initialize the testnet func InitTestnet( @@ -114,7 +114,6 @@ func InitTestnet( algoStr string, numValidators int, ) error { - if chainID == "" { chainID = "chain-" + tmrand.NewRand().Str(6) } @@ -271,7 +270,6 @@ func initGenFiles( genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string, numValidators int, ) error { - appGenState := mbm.DefaultGenesis(clientCtx.Codec) // set the accounts in the genesis state @@ -321,7 +319,6 @@ func collectGenFiles( nodeIDs []string, valPubKeys []cryptotypes.PubKey, numValidators int, outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator, ) error { - var appState json.RawMessage genTime := tmtime.Now() @@ -387,13 +384,13 @@ func calculateIP(ip string, i int) (string, error) { } func writeFile(name string, dir string, contents []byte) error { - err := tmos.EnsureDir(dir, 0755) + err := tmos.EnsureDir(dir, 0o755) if err != nil { return err } file := filepath.Join(dir, name) - err = tmos.WriteFile(file, contents, 0644) + err = tmos.WriteFile(file, contents, 0o644) if err != nil { return err } diff --git a/go.mod b/go.mod index c601951..78829dd 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ go 1.20 module github.com/envadiv/Passage3D require ( - github.com/CosmWasm/wasmd v0.31.0 + github.com/CosmWasm/wasmd v0.31.0 //hotspot github.com/cosmos/cosmos-sdk v0.45.16 github.com/cosmos/ibc-go/v4 v4.4.2 github.com/golang/mock v1.6.0 @@ -36,7 +36,7 @@ require ( filippo.io/edwards25519 v1.0.0-rc.1 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect - github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect + github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect github.com/CosmWasm/wasmvm v1.2.1 // indirect github.com/DataDog/zstd v1.5.0 // indirect github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect @@ -161,6 +161,4 @@ replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alp // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 -replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 - -replace github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27 +replace github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.29 diff --git a/go.sum b/go.sum index 41c93c4..b8cd3b3 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= -github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= +github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= +github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw= github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w= @@ -207,10 +207,12 @@ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcju github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA= github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= -github.com/cometbft/cometbft v0.34.27 h1:ri6BvmwjWR0gurYjywcBqRe4bbwc3QVs9KRcCzgh/J0= -github.com/cometbft/cometbft v0.34.27/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw= +github.com/cometbft/cometbft v0.34.29 h1:Q4FqMevP9du2pOgryZJHpDV2eA6jg/kMYxBj9ZTY6VQ= +github.com/cometbft/cometbft v0.34.29/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw= github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= +github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4= +github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= github.com/consensys/bavard v0.1.8-0.20210915155054-088da2f7f54a/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q= @@ -230,8 +232,6 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.2 h1:X3OKvWgK9Gsejo0F1qs5l8Qn6xJV/Azg github.com/cosmos/cosmos-proto v1.0.0-beta.2/go.mod h1:+XRCLJ14pr5HFEHIUcn51IKXD1Fy3rkEQqt4WqmN4V0= github.com/cosmos/cosmos-sdk v0.45.16 h1:5ba/Bh5/LE55IwHQuCU4fiG4eXeDKtSWzehXRpaKDcw= github.com/cosmos/cosmos-sdk v0.45.16/go.mod h1:bScuNwWAP0TZJpUf+SHXRU3xGoUPp+X9nAzfeIXts40= -github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 h1:iKclrn3YEOwk4jQHT2ulgzuXyxmzmPczUalMwW4XH9k= -github.com/cosmos/cosmos-sdk/ics23/go v0.8.0/go.mod h1:2a4dBq88TUoqoWAU5eu0lGvpFP3wWDPgdHPargtyw30= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= diff --git a/testutil/network/network.go b/testutil/network/network.go index 3636218..23f9d9d 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -14,6 +14,7 @@ import ( "testing" "time" + "github.com/CosmWasm/wasmd/x/wasm" "github.com/envadiv/Passage3D/app" "github.com/envadiv/Passage3D/app/params" "github.com/stretchr/testify/require" @@ -26,7 +27,6 @@ import ( dbm "github.com/tendermint/tm-db" "google.golang.org/grpc" - "github.com/CosmWasm/wasmd/x/wasm" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" @@ -51,7 +51,7 @@ import ( // package-wide network lock to only allow one test network at a time var lock = new(sync.Mutex) -var emptyWasmOpts []wasm.Option = nil +var emptyWasmOpts []wasm.Option // AppConstructor defines a function which accepts a network configuration and // creates an ABCI Application to provide to Tendermint. @@ -174,6 +174,7 @@ type ( // New creates a new Network for integration tests. func New(t *testing.T, cfg Config) *Network { + t.Helper() // only one caller/test can create and use a network at a time t.Log("acquiring test network lock") lock.Lock() @@ -259,8 +260,8 @@ func New(t *testing.T, cfg Config) *Network { clientDir := filepath.Join(network.BaseDir, nodeDirName, "simcli") gentxsDir := filepath.Join(network.BaseDir, "gentxs") - require.NoError(t, os.MkdirAll(filepath.Join(nodeDir, "config"), 0755)) - require.NoError(t, os.MkdirAll(clientDir, 0755)) + require.NoError(t, os.MkdirAll(filepath.Join(nodeDir, "config"), 0o755)) + require.NoError(t, os.MkdirAll(clientDir, 0o755)) tmCfg.SetRoot(nodeDir) tmCfg.Moniker = nodeDirName diff --git a/testutil/network/util.go b/testutil/network/util.go index 766bae4..a4b6314 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -11,18 +11,16 @@ import ( "github.com/tendermint/tendermint/p2p" pvm "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" - - "github.com/cosmos/cosmos-sdk/server/api" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/cosmos-sdk/x/genutil" - "github.com/tendermint/tendermint/rpc/client/local" "github.com/tendermint/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" + "github.com/cosmos/cosmos-sdk/server/api" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" srvtypes "github.com/cosmos/cosmos-sdk/server/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -155,7 +153,6 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { } func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string) error { - // set the accounts in the genesis state var authGenState authtypes.GenesisState cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[authtypes.ModuleName], &authGenState) diff --git a/x/claim/client/cli/query.go b/x/claim/client/cli/query.go index f3f4438..33cba52 100644 --- a/x/claim/client/cli/query.go +++ b/x/claim/client/cli/query.go @@ -5,13 +5,12 @@ import ( "fmt" "strings" - "github.com/cosmos/cosmos-sdk/version" - "github.com/envadiv/Passage3D/x/claim/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" ) // GetQueryCmd returns the cli query commands for this module @@ -50,7 +49,6 @@ func GetCmdQueryModuleAccountBalance() *cobra.Command { req := &types.QueryModuleAccountBalanceRequest{} res, err := queryClient.ModuleAccountBalance(context.Background(), req) - if err != nil { return err } @@ -80,7 +78,6 @@ func GetCmdQueryParams() *cobra.Command { params := &types.QueryParamsRequest{} res, err := queryClient.Params(context.Background(), params) - if err != nil { return err } @@ -149,7 +146,7 @@ $ %s query claim claimable-for-action pasg1wuanjx7l4mjdm48p5uqarukm3aus508wxmhlj } queryClient := types.NewQueryClient(clientCtx) - _, ok := types.Action_value[args[1]] + _, ok := types.ActionValue[args[1]] if !ok { return fmt.Errorf("invalid action type: %s", args[1]) } diff --git a/x/claim/client/cli/tx.go b/x/claim/client/cli/tx.go index 03e1434..0f22b83 100644 --- a/x/claim/client/cli/tx.go +++ b/x/claim/client/cli/tx.go @@ -3,13 +3,12 @@ package cli import ( "fmt" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/envadiv/Passage3D/x/claim/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" ) // GetTxCmd returns the transaction commands for this module @@ -42,7 +41,7 @@ func CmdInitialClaim() *cobra.Command { return fmt.Errorf("action type is required") } - v, ok := types.Action_value[claimAction] + v, ok := types.ActionValue[claimAction] if !ok { return fmt.Errorf("invalid action type: %s", claimAction) } diff --git a/x/claim/client/testutil/suite.go b/x/claim/client/testutil/suite.go index ffd9146..e389a8d 100644 --- a/x/claim/client/testutil/suite.go +++ b/x/claim/client/testutil/suite.go @@ -15,8 +15,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var addr1 sdk.AccAddress -var addr2 sdk.AccAddress +var ( + addr1 sdk.AccAddress + addr2 sdk.AccAddress +) var claimRecords []claimtypes.ClaimRecord @@ -116,7 +118,7 @@ func (s *IntegrationTestSuite) TestCmdQueryClaimableForAction() { "query claimable-for-action amount", []string{ addr2.String(), - claimtypes.Action_name[0], + claimtypes.ActionName[0], fmt.Sprintf("--%s=json", tmcli.OutputFlag), }, sdk.Coins{sdk.NewCoin(claimtypes.DefaultClaimDenom, sdk.NewInt(20))}, diff --git a/x/claim/genesis.go b/x/claim/genesis.go index ce8f29a..efd0acf 100644 --- a/x/claim/genesis.go +++ b/x/claim/genesis.go @@ -3,10 +3,9 @@ package claim import ( "time" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/envadiv/Passage3D/x/claim/keeper" "github.com/envadiv/Passage3D/x/claim/types" + abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/claim/genesis_test.go b/x/claim/genesis_test.go index e14894e..80e00cb 100644 --- a/x/claim/genesis_test.go +++ b/x/claim/genesis_test.go @@ -4,11 +4,9 @@ import ( "testing" "time" + simapp "github.com/envadiv/Passage3D/app" "github.com/envadiv/Passage3D/x/claim" "github.com/envadiv/Passage3D/x/claim/types" - - simapp "github.com/envadiv/Passage3D/app" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -16,33 +14,35 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var now = time.Now().UTC() -var acc1 = sdk.AccAddress("addr1---------------") -var acc2 = sdk.AccAddress("addr2---------------") -var testGenesis = types.GenesisState{ - ModuleAccountBalance: sdk.NewInt64Coin(types.DefaultClaimDenom, 1500000000), - Params: types.Params{ - AirdropEnabled: true, - AirdropStartTime: now, - DurationUntilDecay: types.DefaultDurationUntilDecay, - DurationOfDecay: types.DefaultDurationOfDecay, - ClaimDenom: types.DefaultClaimDenom, - }, - ClaimRecords: []types.ClaimRecord{ - { - Address: acc1.String(), - ClaimableAmount: []sdk.Coin{ - sdk.NewInt64Coin(types.DefaultClaimDenom, 1000000000), - }, ActionCompleted: []bool{false}, +var ( + now = time.Now().UTC() + acc1 = sdk.AccAddress("addr1---------------") + acc2 = sdk.AccAddress("addr2---------------") + testGenesis = types.GenesisState{ + ModuleAccountBalance: sdk.NewInt64Coin(types.DefaultClaimDenom, 1500000000), + Params: types.Params{ + AirdropEnabled: true, + AirdropStartTime: now, + DurationUntilDecay: types.DefaultDurationUntilDecay, + DurationOfDecay: types.DefaultDurationOfDecay, + ClaimDenom: types.DefaultClaimDenom, }, - { - Address: acc2.String(), - ClaimableAmount: []sdk.Coin{ - sdk.NewInt64Coin(types.DefaultClaimDenom, 500000000), - }, ActionCompleted: []bool{false}, + ClaimRecords: []types.ClaimRecord{ + { + Address: acc1.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 1000000000), + }, ActionCompleted: []bool{false}, + }, + { + Address: acc2.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 500000000), + }, ActionCompleted: []bool{false}, + }, }, - }, -} + } +) func TestClaimInitGenesis(t *testing.T) { app := simapp.Setup(false) diff --git a/x/claim/keeper/claim.go b/x/claim/keeper/claim.go index d7864b7..f4f69a6 100644 --- a/x/claim/keeper/claim.go +++ b/x/claim/keeper/claim.go @@ -3,11 +3,10 @@ package keeper import ( "fmt" - "github.com/cosmos/cosmos-sdk/store/prefix" - "github.com/envadiv/Passage3D/x/claim/types" "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -179,7 +178,6 @@ func (k Keeper) GetClaimableAmountForAction(ctx sdk.Context, addr sdk.AccAddress // GetUserTotalClaimable returns total claimable amount of an address func (k Keeper) GetUserTotalClaimable(ctx sdk.Context, addr sdk.AccAddress) (sdk.Coins, error) { claimRecord, err := k.GetClaimRecord(ctx, addr) - if err != nil { return sdk.Coins{}, err } @@ -189,7 +187,7 @@ func (k Keeper) GetUserTotalClaimable(ctx sdk.Context, addr sdk.AccAddress) (sdk totalClaimable := sdk.Coins{} - for action := range types.Action_name { + for action := range types.ActionName { claimableForAction, err := k.GetClaimableAmountForAction(ctx, addr, action) if err != nil { return sdk.Coins{}, err @@ -238,7 +236,7 @@ func (k Keeper) ClaimCoinsForAction(ctx sdk.Context, addr sdk.AccAddress, action sdk.NewEvent( types.EventTypeClaim, sdk.NewAttribute(sdk.AttributeKeySender, addr.String()), - sdk.NewAttribute(sdk.AttributeKeyAction, types.Action_name[action]), + sdk.NewAttribute(sdk.AttributeKeyAction, types.ActionName[action]), sdk.NewAttribute(sdk.AttributeKeyAmount, claimableAmount.String()), ), }) diff --git a/x/claim/keeper/claim_test.go b/x/claim/keeper/claim_test.go index 239521e..468dd33 100644 --- a/x/claim/keeper/claim_test.go +++ b/x/claim/keeper/claim_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -func (suite *KeeperTestSuite) TestAirdropFlow() { +func (s *KeeperTestSuite) TestAirdropFlow() { addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) addr2 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) addr3 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) @@ -39,63 +39,63 @@ func (suite *KeeperTestSuite) TestAirdropFlow() { }, } - err := suite.app.ClaimKeeper.SetClaimRecords(suite.ctx, claimRecords) - suite.Require().NoError(err) + err := s.app.ClaimKeeper.SetClaimRecords(s.ctx, claimRecords) + s.Require().NoError(err) - coins1, err := suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr1) - suite.Require().NoError(err) - suite.Require().True(coins1.IsAllGTE(sdk.NewCoins(claimRecords[0].ClaimableAmount[0]))) + coins1, err := s.app.ClaimKeeper.GetUserTotalClaimable(s.ctx, addr1) + s.Require().NoError(err) + s.Require().True(coins1.IsAllGTE(sdk.NewCoins(claimRecords[0].ClaimableAmount[0]))) - coins2, err := suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr2) - suite.Require().NoError(err) - suite.Require().True(coins2.IsAllGTE(sdk.NewCoins(claimRecords[1].ClaimableAmount[0]))) + coins2, err := s.app.ClaimKeeper.GetUserTotalClaimable(s.ctx, addr2) + s.Require().NoError(err) + s.Require().True(coins2.IsAllGTE(sdk.NewCoins(claimRecords[1].ClaimableAmount[0]))) - coins3, err := suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr3) - suite.Require().NoError(err) - suite.Require().Equal(coins3, sdk.Coins{}) + coins3, err := s.app.ClaimKeeper.GetUserTotalClaimable(s.ctx, addr3) + s.Require().NoError(err) + s.Require().Equal(coins3, sdk.Coins{}) - _, err = suite.app.ClaimKeeper.ClaimCoinsForAction(suite.ctx, addr4, types.ActionInitialClaim) - suite.Require().NoError(err) + _, err = s.app.ClaimKeeper.ClaimCoinsForAction(s.ctx, addr4, types.ActionInitialClaim) + s.Require().NoError(err) // get balance after rest actions done - coins1 = suite.app.BankKeeper.GetAllBalances(suite.ctx, addr4) - suite.Require().Equal(coins1.String(), sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 1000)).String()) + coins1 = s.app.BankKeeper.GetAllBalances(s.ctx, addr4) + s.Require().Equal(coins1.String(), sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 1000)).String()) // get completed activities - claimRecord, err := suite.app.ClaimKeeper.GetClaimRecord(suite.ctx, addr1) - suite.Require().NoError(err) - for i := range types.Action_name { - suite.Require().False(claimRecord.ActionCompleted[i]) + claimRecord, err := s.app.ClaimKeeper.GetClaimRecord(s.ctx, addr1) + s.Require().NoError(err) + for i := range types.ActionName { + s.Require().False(claimRecord.ActionCompleted[i]) } // do actions // initial claim - action, err := suite.app.ClaimKeeper.ClaimCoinsForAction(suite.ctx, addr1, types.ActionInitialClaim) - suite.Require().NoError(err) - suite.Require().Equal(action.String(), claimRecords[0].ClaimableAmount[0].String()) + action, err := s.app.ClaimKeeper.ClaimCoinsForAction(s.ctx, addr1, types.ActionInitialClaim) + s.Require().NoError(err) + s.Require().Equal(action.String(), claimRecords[0].ClaimableAmount[0].String()) // get balance after rest actions done - coins1 = suite.app.BankKeeper.GetAllBalances(suite.ctx, addr1) - suite.Require().Equal(coins1.String(), sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 1000)).String()) + coins1 = s.app.BankKeeper.GetAllBalances(s.ctx, addr1) + s.Require().Equal(coins1.String(), sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 1000)).String()) // after actions module account balance will decrease (initial : 10000000) -> (9998000) - moduleAccAddr := suite.app.AccountKeeper.GetModuleAddress(types.ModuleName) - coins := suite.app.BankKeeper.GetBalance(suite.ctx, moduleAccAddr, types.DefaultClaimDenom) - suite.Require().Equal(coins.String(), sdk.NewInt64Coin(types.DefaultClaimDenom, 9998000).String()) + moduleAccAddr := s.app.AccountKeeper.GetModuleAddress(types.ModuleName) + coins := s.app.BankKeeper.GetBalance(s.ctx, moduleAccAddr, types.DefaultClaimDenom) + s.Require().Equal(coins.String(), sdk.NewInt64Coin(types.DefaultClaimDenom, 9998000).String()) // get claimable after withdrawing all - coins1, err = suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr1) - suite.Require().NoError(err) + coins1, err = s.app.ClaimKeeper.GetUserTotalClaimable(s.ctx, addr1) + s.Require().NoError(err) fmt.Println(coins1.String()) - suite.Require().True(coins1.Empty()) + s.Require().True(coins1.Empty()) - err = suite.app.ClaimKeeper.EndAirdrop(suite.ctx) - suite.Require().NoError(err) + err = s.app.ClaimKeeper.EndAirdrop(s.ctx) + s.Require().NoError(err) // after airdrop end all module account balance move to community pool account - moduleAccAddr = suite.app.AccountKeeper.GetModuleAddress(types.ModuleName) - coins = suite.app.BankKeeper.GetBalance(suite.ctx, moduleAccAddr, types.DefaultClaimDenom) - suite.Require().Equal(coins.String(), sdk.NewInt64Coin(types.DefaultClaimDenom, 0).String()) + moduleAccAddr = s.app.AccountKeeper.GetModuleAddress(types.ModuleName) + coins = s.app.BankKeeper.GetBalance(s.ctx, moduleAccAddr, types.DefaultClaimDenom) + s.Require().Equal(coins.String(), sdk.NewInt64Coin(types.DefaultClaimDenom, 0).String()) - coins2, err = suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr2) - suite.Require().NoError(err) - suite.Require().Equal(coins2, sdk.Coins{}) + coins2, err = s.app.ClaimKeeper.GetUserTotalClaimable(s.ctx, addr2) + s.Require().NoError(err) + s.Require().Equal(coins2, sdk.Coins{}) } diff --git a/x/claim/keeper/grpc_query.go b/x/claim/keeper/grpc_query.go index b56ed0a..dae1f5f 100644 --- a/x/claim/keeper/grpc_query.go +++ b/x/claim/keeper/grpc_query.go @@ -4,11 +4,10 @@ import ( "context" "fmt" + "github.com/envadiv/Passage3D/x/claim/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/envadiv/Passage3D/x/claim/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -61,7 +60,7 @@ func (k Keeper) ClaimableForAction(goCtx context.Context, req *types.QueryClaima return nil, err } - action, ok := types.Action_value[req.Action] + action, ok := types.ActionValue[req.Action] if !ok { return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid action type: %s", req.Action)) } diff --git a/x/claim/keeper/grpc_query_test.go b/x/claim/keeper/grpc_query_test.go index 814a418..5bf89e4 100644 --- a/x/claim/keeper/grpc_query_test.go +++ b/x/claim/keeper/grpc_query_test.go @@ -10,22 +10,22 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -func (suite *KeeperTestSuite) TestGrpcQueryParams() { - grpcClient := suite.queryClient +func (s *KeeperTestSuite) TestGrpcQueryParams() { + grpcClient := s.queryClient resp, _ := grpcClient.Params(context.Background(), &types.QueryParamsRequest{}) - suite.Require().Equal(resp.GetParams().ClaimDenom, types.DefaultClaimDenom) + s.Require().Equal(resp.GetParams().ClaimDenom, types.DefaultClaimDenom) } -func (suite *KeeperTestSuite) TestGrpcQueryModuleAccountBalance() { - grpcClient := suite.queryClient +func (s *KeeperTestSuite) TestGrpcQueryModuleAccountBalance() { + grpcClient := s.queryClient resp, _ := grpcClient.ModuleAccountBalance(context.Background(), &types.QueryModuleAccountBalanceRequest{}) - suite.Require().Equal(resp.ModuleAccountBalance.String(), sdk.NewCoins(sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(10000000))).String()) + s.Require().Equal(resp.ModuleAccountBalance.String(), sdk.NewCoins(sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(10000000))).String()) } -func (suite *KeeperTestSuite) TestGrpcQueryClaimRecords() { - grpcClient, ctx, k := suite.queryClient, suite.ctx, suite.app.ClaimKeeper +func (s *KeeperTestSuite) TestGrpcQueryClaimRecords() { + grpcClient, ctx, k := s.queryClient, s.ctx, s.app.ClaimKeeper ctx = ctx.WithBlockTime(time.Now()) addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) @@ -45,14 +45,14 @@ func (suite *KeeperTestSuite) TestGrpcQueryClaimRecords() { } err := k.SetClaimRecords(ctx, claimRecords) - suite.Require().NoError(err) + s.Require().NoError(err) resp, err := grpcClient.ClaimRecord(context.Background(), &types.QueryClaimRecordRequest{Address: addr1.String()}) - suite.Require().NoError(err) - suite.Require().Equal(resp.GetClaimRecord(), claimRecords[0]) + s.Require().NoError(err) + s.Require().Equal(resp.GetClaimRecord(), claimRecords[0]) - //// get claim record for action - //actionResp, err := grpcClient.TotalClaimable(context.Background(), &types.QueryTotalClaimableRequest{Address: addr1.String()}) - //suite.Require().NoError(err) - //suite.Require().Equal(actionResp.String(), sdk.NewCoins(sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(100))).String()) + // // get claim record for action + // actionResp, err := grpcClient.TotalClaimable(context.Background(), &types.QueryTotalClaimableRequest{Address: addr1.String()}) + // suite.Require().NoError(err) + // suite.Require().Equal(actionResp.String(), sdk.NewCoins(sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(100))).String()) } diff --git a/x/claim/keeper/keeper.go b/x/claim/keeper/keeper.go index ba64449..756c9c7 100644 --- a/x/claim/keeper/keeper.go +++ b/x/claim/keeper/keeper.go @@ -44,6 +44,6 @@ func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ak authkeeper.AccountKeep } // Logger returns logger -func (k Keeper) Logger(ctx sdk.Context) log.Logger { +func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } diff --git a/x/claim/keeper/keeper_test.go b/x/claim/keeper/keeper_test.go index 1a30399..0b59dab 100644 --- a/x/claim/keeper/keeper_test.go +++ b/x/claim/keeper/keeper_test.go @@ -22,14 +22,14 @@ type KeeperTestSuite struct { app *app.PassageApp } -func (suite *KeeperTestSuite) SetupTest() { - suite.app = app.Setup(false) - suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "passage3d-1", Time: time.Now()}) +func (s *KeeperTestSuite) SetupTest() { + s.app = app.Setup(false) + s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "passage3d-1", Time: time.Now()}) airdropStartTime := time.Now() - suite.app.ClaimKeeper.CreateModuleAccount(suite.ctx, sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(10000000))) + s.app.ClaimKeeper.CreateModuleAccount(s.ctx, sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(10000000))) - suite.app.ClaimKeeper.SetParams(suite.ctx, types.Params{ + s.app.ClaimKeeper.SetParams(s.ctx, types.Params{ AirdropEnabled: true, AirdropStartTime: airdropStartTime, DurationUntilDecay: types.DefaultDurationUntilDecay, @@ -37,13 +37,13 @@ func (suite *KeeperTestSuite) SetupTest() { ClaimDenom: types.DefaultClaimDenom, }) - querier := keeper.Querier{Keeper: suite.app.ClaimKeeper} + querier := keeper.Querier{Keeper: s.app.ClaimKeeper} - queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) + queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.app.InterfaceRegistry()) types.RegisterQueryServer(queryHelper, querier) - suite.queryClient = types.NewQueryClient(queryHelper) + s.queryClient = types.NewQueryClient(queryHelper) - suite.ctx = suite.ctx.WithBlockTime(airdropStartTime) + s.ctx = s.ctx.WithBlockTime(airdropStartTime) } func TestKeeperTestSuite(t *testing.T) { diff --git a/x/claim/keeper/msg_server.go b/x/claim/keeper/msg_server.go index 1e75e6f..6a8d57f 100644 --- a/x/claim/keeper/msg_server.go +++ b/x/claim/keeper/msg_server.go @@ -34,7 +34,7 @@ func (k msgServer) Claim(goCtx context.Context, msg *types.MsgClaim) (*types.Msg return nil, types.ErrAirdropNotEnabled } - claimableCoinsForAction, err := k.Keeper.ClaimCoinsForAction(ctx, sender, types.Action_value[msg.ClaimAction]) + claimableCoinsForAction, err := k.Keeper.ClaimCoinsForAction(ctx, sender, types.ActionValue[msg.ClaimAction]) if err != nil { return nil, err } diff --git a/x/claim/module.go b/x/claim/module.go index 36ac34f..22700a3 100644 --- a/x/claim/module.go +++ b/x/claim/module.go @@ -6,18 +6,16 @@ import ( "fmt" "github.com/envadiv/Passage3D/x/claim/client/cli" - "github.com/envadiv/Passage3D/x/claim/types" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/envadiv/Passage3D/x/claim/keeper" + "github.com/envadiv/Passage3D/x/claim/types" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -40,7 +38,7 @@ func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { return AppModuleBasic{cdc: cdc} } -func (a AppModuleBasic) Name() string { +func (AppModuleBasic) Name() string { return types.ModuleName } @@ -48,19 +46,19 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { types.RegisterLegacyAminoCodec(cdc) } -func (a AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { +func (AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { types.RegisterLegacyAminoCodec(amino) } -func (a AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { +func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } -func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(types.DefaultGenesis()) } -func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { var genState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genState); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) @@ -68,21 +66,21 @@ func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEnc return genState.Validate() } -func (a AppModuleBasic) RegisterRESTRoutes(context client.Context, router *mux.Router) { +func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, router *mux.Router) { } -func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, muxer *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), muxer, types.NewQueryClient(clientCtx)) if err != nil { return } } -func (a AppModuleBasic) GetTxCmd() *cobra.Command { +func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd() } -func (a AppModuleBasic) GetQueryCmd() *cobra.Command { +func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd(types.StoreKey) } @@ -97,10 +95,10 @@ type AppModule struct { keeper keeper.Keeper } -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { +func NewAppModule(cdc codec.Codec, modkeeper keeper.Keeper) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, + keeper: modkeeper, } } @@ -118,17 +116,17 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec) js return jsonCodec.MustMarshalJSON(genState) } -func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} +func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} -func (am AppModule) Route() sdk.Route { +func (AppModule) Route() sdk.Route { return sdk.Route{} } -func (am AppModule) QuerierRoute() string { +func (AppModule) QuerierRoute() string { return types.QuerierRoute } -func (am AppModule) LegacyQuerierHandler(amino *codec.LegacyAmino) sdk.Querier { +func (AppModule) LegacyQuerierHandler(amino *codec.LegacyAmino) sdk.Querier { return nil } @@ -137,7 +135,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) } -func (am AppModule) ConsensusVersion() uint64 { +func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/claim/types/airdrop_actions.go b/x/claim/types/airdrop_actions.go index 54f97de..b6f4a73 100644 --- a/x/claim/types/airdrop_actions.go +++ b/x/claim/types/airdrop_actions.go @@ -7,10 +7,10 @@ const ( InitialClaim = "ActionInitialClaim" ) -var Action_name = map[int32]string{ +var ActionName = map[int32]string{ 0: "ActionInitialClaim", } -var Action_value = map[string]int32{ +var ActionValue = map[string]int32{ "ActionInitialClaim": 0, } diff --git a/x/claim/types/msg_initial_claim.go b/x/claim/types/msg_initial_claim.go index 0d199c6..2e887cc 100644 --- a/x/claim/types/msg_initial_claim.go +++ b/x/claim/types/msg_initial_claim.go @@ -19,11 +19,11 @@ func NewMsgClaim(sender, action string) *MsgClaim { } } -func (msg MsgClaim) Route() string { +func (MsgClaim) Route() string { return RouterKey } -func (msg MsgClaim) Type() string { +func (MsgClaim) Type() string { return TypeMsgClaim }