From e64f91688ea30a8adb3178e9a25ad994db6c8ea5 Mon Sep 17 00:00:00 2001 From: dongsam Date: Thu, 16 Sep 2021 23:39:02 +0900 Subject: [PATCH] feat: add budget module on simapp (#118) * feat: add global keys prefix for the current epoch days * test: add test for key store prefixes * chore: fix broken store prefix test, rename EpochDays to NextEpochDays * test: add more tests and update address to have 20 bytes * test: remove comments * test: update epoch days to next epoch days * test: add handler tests * refactor: add comment for global current epoch days * test: apply module testing suit * test: remove tests for deprecated PlansByFarmerIndex * feat: move mustParseRFC3339 function to utils #109 * docs: update spec docs * feat: adding test for end blocker * chore: rename GlobalCurrentEpochDays to CurrentEpochDays and refactor codes * test: improve code coverage * chore: apply code review feedbacks and suggestions * feat: add gRPC query and cli for current epoch days * feat: add budget module on simapp * fix: apply code review feedbacks and suggestions * fix: resolve conflicts * fix: gov simulation issue from budget * update: bump budget module version to latest * test: set no-race for cli_test * fix: refactor last_epoch_time Co-authored-by: kogisin --- app/app.go | 41 +++++++++++-------- app/app_test.go | 3 ++ go.mod | 1 + go.sum | 2 + .../tendermint/farming/v1beta1/farming.proto | 10 ++--- .../tendermint/farming/v1beta1/genesis.proto | 28 ++++++------- proto/tendermint/farming/v1beta1/query.proto | 10 ++--- x/farming/keeper/epoch.go | 4 +- x/farming/module.go | 11 +---- x/farming/simulation/genesis.go | 5 --- x/farming/spec/02_state.md | 2 +- x/farming/types/keys.go | 6 +-- x/farming/types/utils.go | 2 +- x/farming/types/utils_test.go | 20 +++++++++ 14 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 x/farming/types/utils_test.go diff --git a/app/app.go b/app/app.go index 13719dcd..bd2627a6 100644 --- a/app/app.go +++ b/app/app.go @@ -12,6 +12,7 @@ import ( "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" + "github.com/tendermint/budget/x/budget" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" @@ -85,6 +86,9 @@ import ( upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + budgetkeeper "github.com/tendermint/budget/x/budget/keeper" + budgettypes "github.com/tendermint/budget/x/budget/types" + farmingparams "github.com/tendermint/farming/app/params" "github.com/tendermint/farming/x/farming" farmingclient "github.com/tendermint/farming/x/farming/client" @@ -125,8 +129,8 @@ var ( evidence.AppModuleBasic{}, authzmodule.AppModuleBasic{}, vesting.AppModuleBasic{}, + budget.AppModuleBasic{}, farming.AppModuleBasic{}, - // todo: farming ordering ) // module account permissions @@ -137,8 +141,9 @@ var ( stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, - farmingtypes.ModuleName: {authtypes.Minter}, - // todo: farming Staking Reserve Coin TBD + budgettypes.ModuleName: nil, + // TODO: remove minter permission for farming module, currently it used only for simulation + farmingtypes.ModuleName: {authtypes.Minter}, } ) @@ -176,6 +181,7 @@ type FarmingApp struct { AuthzKeeper authzkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper + BudgetKeeper budgetkeeper.Keeper FarmingKeeper farmingkeeper.Keeper // the module manager @@ -217,7 +223,7 @@ func NewFarmingApp( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, farmingtypes.StoreKey, + evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, budgettypes.StoreKey, farmingtypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -282,11 +288,15 @@ func NewFarmingApp( app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.BaseApp.MsgServiceRouter()) + app.BudgetKeeper = budgetkeeper.NewKeeper( + appCodec, keys[budgettypes.StoreKey], app.GetSubspace(budgettypes.ModuleName), app.AccountKeeper, + app.BankKeeper, app.ModuleAccountAddrs(), + ) + app.FarmingKeeper = farmingkeeper.NewKeeper( appCodec, keys[farmingtypes.StoreKey], app.GetSubspace(farmingtypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.ModuleAccountAddrs(), ) - // todo: farming ordering // register the proposal types govRouter := govtypes.NewRouter() @@ -295,7 +305,6 @@ func NewFarmingApp( AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). AddRoute(farmingtypes.RouterKey, farming.NewPublicPlanProposal(app.FarmingKeeper)) - // todo: implementing... govKeeper := govkeeper.NewKeeper( appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, @@ -338,14 +347,14 @@ func NewFarmingApp( gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + budget.NewAppModule(appCodec, app.BudgetKeeper, app.AccountKeeper, app.BankKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), params.NewAppModule(app.ParamsKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - farming.NewAppModule(appCodec, app.FarmingKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), - // todo: farming ordering + farming.NewAppModule(appCodec, app.FarmingKeeper, app.AccountKeeper, app.BankKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -354,15 +363,13 @@ func NewFarmingApp( // NOTE: staking module is required if HistoricalEntries param > 0 // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) app.mm.SetOrderBeginBlockers( - upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, - evidencetypes.ModuleName, stakingtypes.ModuleName, farmingtypes.ModuleName, - // todo: farming ordering + upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, budgettypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, + evidencetypes.ModuleName, stakingtypes.ModuleName, ) app.mm.SetOrderEndBlockers( crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, farmingtypes.ModuleName, - // todo: farming ordering ) // NOTE: The genutils module must occur after staking so that pools are @@ -374,8 +381,7 @@ func NewFarmingApp( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, farmingtypes.ModuleName, - // todo: farming ordering + feegrant.ModuleName, budgettypes.ModuleName, farmingtypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) @@ -397,14 +403,15 @@ func NewFarmingApp( feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), + budget.NewAppModule(appCodec, app.BudgetKeeper, app.AccountKeeper, app.BankKeeper), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), evidence.NewAppModule(app.EvidenceKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - farming.NewAppModule(appCodec, app.FarmingKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), - // todo: farming ordering + budget.NewAppModule(appCodec, app.BudgetKeeper, app.AccountKeeper, app.BankKeeper), + farming.NewAppModule(appCodec, app.FarmingKeeper, app.AccountKeeper, app.BankKeeper), ) app.sm.RegisterStoreDecoders() @@ -602,7 +609,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(farmingtypes.ModuleName) - // todo: farming ordering + paramsKeeper.Subspace(budgettypes.ModuleName) return paramsKeeper } diff --git a/app/app_test.go b/app/app_test.go index 7a457598..773d208b 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "github.com/tendermint/budget/x/budget" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/tests/mocks" @@ -187,6 +188,7 @@ func TestRunMigrations(t *testing.T) { "crisis": crisis.AppModule{}.ConsensusVersion(), "genutil": genutil.AppModule{}.ConsensusVersion(), "capability": capability.AppModule{}.ConsensusVersion(), + "budget": budget.AppModule{}.ConsensusVersion(), "farming": farming.AppModule{}.ConsensusVersion(), }, ) @@ -240,6 +242,7 @@ func TestInitGenesisOnMigration(t *testing.T) { "crisis": crisis.AppModule{}.ConsensusVersion(), "genutil": genutil.AppModule{}.ConsensusVersion(), "capability": capability.AppModule{}.ConsensusVersion(), + "budget": budget.AppModule{}.ConsensusVersion(), "farming": farming.AppModule{}.ConsensusVersion(), }, ) diff --git a/go.mod b/go.mod index ca987141..172144b1 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 + github.com/tendermint/budget v0.0.0-20210916135401-7d1b338fa02d github.com/tendermint/tendermint v0.34.12 github.com/tendermint/tm-db v0.6.4 google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c diff --git a/go.sum b/go.sum index 04c3555a..f1de5ea9 100644 --- a/go.sum +++ b/go.sum @@ -742,6 +742,8 @@ github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzH github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s= github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= +github.com/tendermint/budget v0.0.0-20210916135401-7d1b338fa02d h1:d8DzeS7BmajE8/IbYvns4vDtgJ6RJRkrLU1T1+N5bn8= +github.com/tendermint/budget v0.0.0-20210916135401-7d1b338fa02d/go.mod h1:49m91ZgK5qDsIXs5EHNeBrXXrb3XXaDQuFWvmiKxyyY= github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RMWx1aInLzndwxKalgi5rTqgfXxOxbEI= github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= diff --git a/proto/tendermint/farming/v1beta1/farming.proto b/proto/tendermint/farming/v1beta1/farming.proto index aa812d07..6679aa86 100644 --- a/proto/tendermint/farming/v1beta1/farming.proto +++ b/proto/tendermint/farming/v1beta1/farming.proto @@ -17,9 +17,9 @@ message Params { // private_plan_creation_fee specifies the fee for plan creation // this fee prevents from spamming and it is collected in the community pool repeated cosmos.base.v1beta1.Coin private_plan_creation_fee = 1 [ - (gogoproto.moretags) = "yaml:\"private_plan_creation_fee\"", + (gogoproto.moretags) = "yaml:\"private_plan_creation_fee\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false + (gogoproto.nullable) = false ]; // next_epoch_days is the epoch length in number of days @@ -160,9 +160,9 @@ message HistoricalRewards { option (gogoproto.goproto_getters) = false; repeated cosmos.base.v1beta1.DecCoin cumulative_unit_rewards = 1 [ - (gogoproto.moretags) = "yaml:\"cumulative_unit_rewards\"", + (gogoproto.moretags) = "yaml:\"cumulative_unit_rewards\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", - (gogoproto.nullable) = false + (gogoproto.nullable) = false ]; } @@ -170,5 +170,5 @@ message HistoricalRewards { // for a staking coin denom. message OutstandingRewards { repeated cosmos.base.v1beta1.DecCoin rewards = 1 - [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false]; + [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false]; } \ No newline at end of file diff --git a/proto/tendermint/farming/v1beta1/genesis.proto b/proto/tendermint/farming/v1beta1/genesis.proto index 7edcada7..0a5c890c 100644 --- a/proto/tendermint/farming/v1beta1/genesis.proto +++ b/proto/tendermint/farming/v1beta1/genesis.proto @@ -24,39 +24,39 @@ message GenesisState { repeated PlanRecord plan_records = 2 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"plan_records\""]; repeated StakingRecord staking_records = 3 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"staking_records\""]; + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"staking_records\""]; repeated QueuedStakingRecord queued_staking_records = 4 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"queued_staking_records\""]; + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"queued_staking_records\""]; repeated HistoricalRewardsRecord historical_rewards_records = 5 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"historical_rewards_records\""]; + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"historical_rewards_records\""]; repeated OutstandingRewardsRecord outstanding_rewards_records = 6 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"outstanding_rewards_records\""]; + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"outstanding_rewards_records\""]; repeated CurrentEpochRecord current_epoch_records = 7 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"current_epoch_records\""]; + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"current_epoch_records\""]; // staking_reserve_coins specifies balance of the staking reserve pool staked in the plans // this param is needed for import/export validation repeated cosmos.base.v1beta1.Coin staking_reserve_coins = 8 [ - (gogoproto.moretags) = "yaml:\"staking_reserve_coins\"", + (gogoproto.moretags) = "yaml:\"staking_reserve_coins\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false + (gogoproto.nullable) = false ]; // reward_pool_coins specifies balance of the reward pool to be distributed in the plans // this param is needed for import/export validation repeated cosmos.base.v1beta1.Coin reward_pool_coins = 9 [ - (gogoproto.moretags) = "yaml:\"reward_pool_coins\"", + (gogoproto.moretags) = "yaml:\"reward_pool_coins\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", - (gogoproto.nullable) = false + (gogoproto.nullable) = false ]; // last_epoch_time specifies the last executed epoch time of the plans google.protobuf.Timestamp last_epoch_time = 10 - [(gogoproto.stdtime) = true, (gogoproto.moretags) = "yaml:\"last_epoch_time\""]; + [(gogoproto.stdtime) = true, (gogoproto.moretags) = "yaml:\"last_epoch_time\""]; // current_epoch_days specifies the epoch used when allocating farming rewards in end blocker uint32 current_epoch_days = 11; @@ -118,21 +118,21 @@ message HistoricalRewardsRecord { uint64 epoch = 2; HistoricalRewards historical_rewards = 3 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"historical_rewards\""]; + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"historical_rewards\""]; } message OutstandingRewardsRecord { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; string staking_coin_denom = 1 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; OutstandingRewards outstanding_rewards = 2 - [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"outstanding_rewards\""]; + [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"outstanding_rewards\""]; } message CurrentEpochRecord { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; string staking_coin_denom = 1 [(gogoproto.moretags) = "yaml:\"staking_coin_denom\""]; diff --git a/proto/tendermint/farming/v1beta1/query.proto b/proto/tendermint/farming/v1beta1/query.proto index 2273e59a..c9393b45 100644 --- a/proto/tendermint/farming/v1beta1/query.proto +++ b/proto/tendermint/farming/v1beta1/query.proto @@ -82,15 +82,15 @@ message QueryPlanResponse { } message QueryStakingsRequest { - string farmer = 1; + string farmer = 1; string staking_coin_denom = 2; } message QueryStakingsResponse { repeated cosmos.base.v1beta1.Coin staked_coins = 1 - [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false]; + [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false]; repeated cosmos.base.v1beta1.Coin queued_coins = 2 - [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false]; + [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false]; } message QueryTotalStakingsRequest { @@ -102,13 +102,13 @@ message QueryTotalStakingsResponse { } message QueryRewardsRequest { - string farmer = 1; + string farmer = 1; string staking_coin_denom = 2; } message QueryRewardsResponse { repeated cosmos.base.v1beta1.Coin rewards = 1 - [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false]; + [(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false]; } // QueryCurrentEpochDaysRequest is the request type for the Query/CurrentEpochDays RPC method. diff --git a/x/farming/keeper/epoch.go b/x/farming/keeper/epoch.go index f833ba47..49e2313b 100644 --- a/x/farming/keeper/epoch.go +++ b/x/farming/keeper/epoch.go @@ -12,7 +12,7 @@ import ( func (k Keeper) GetLastEpochTime(ctx sdk.Context) (time.Time, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.GlobalLastEpochTimeKey) + bz := store.Get(types.LastEpochTimeKey) if bz == nil { return time.Time{}, false } @@ -32,7 +32,7 @@ func (k Keeper) SetLastEpochTime(ctx sdk.Context, t time.Time) { panic(err) } bz := k.cdc.MustMarshal(ts) - store.Set(types.GlobalLastEpochTimeKey, bz) + store.Set(types.LastEpochTimeKey, bz) } func (k Keeper) AdvanceEpoch(ctx sdk.Context) error { diff --git a/x/farming/module.go b/x/farming/module.go index f2b0c627..e3c0ea65 100644 --- a/x/farming/module.go +++ b/x/farming/module.go @@ -17,8 +17,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - //"github.com/tendermint/farming/x/farming/client/rest" "github.com/tendermint/farming/x/farming/client/cli" "github.com/tendermint/farming/x/farming/keeper" @@ -64,10 +62,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEn } // RegisterRESTRoutes registers the REST routes for the farming module. -func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, rtr *mux.Router) { - // TODO: unimplemented - //rest.RegisterHandlers(clientCtx, rtr) -} +func (AppModuleBasic) RegisterRESTRoutes(_ sdkclient.Context, _ *mux.Router) {} // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the farming module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { @@ -98,20 +93,18 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - distrKeeper distrkeeper.Keeper } // NewAppModule creates a new AppModule object func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, distrKeeper distrkeeper.Keeper, + bankKeeper types.BankKeeper, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, accountKeeper: accountKeeper, bankKeeper: bankKeeper, - distrKeeper: distrKeeper, } } diff --git a/x/farming/simulation/genesis.go b/x/farming/simulation/genesis.go index 5ebe9702..5344e5d3 100644 --- a/x/farming/simulation/genesis.go +++ b/x/farming/simulation/genesis.go @@ -3,8 +3,6 @@ package simulation // DONTCOVER import ( - "encoding/json" - "fmt" "math/rand" sdk "github.com/cosmos/cosmos-sdk/types" @@ -63,8 +61,5 @@ func RandomizedGenState(simState *module.SimulationState) { FarmingFeeCollector: feeCollector, }, } - - bz, _ := json.MarshalIndent(&farmingGenesis, "", " ") - fmt.Printf("Selected randomly generated farming parameters:\n%s\n", bz) simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&farmingGenesis) } diff --git a/x/farming/spec/02_state.md b/x/farming/spec/02_state.md index a2e60355..eea509f5 100644 --- a/x/farming/spec/02_state.md +++ b/x/farming/spec/02_state.md @@ -118,7 +118,7 @@ The parameters of the Plan state are: ## Epoch -- GlobalLastEpochTime: `[]byte("globalLastEpochTime") -> ProtocolBuffer(Timestamp)` +- LastEpochTime: `[]byte("lastEpochTime") -> ProtocolBuffer(Timestamp)` - CurrentEpochDays: `[]byte("currentEpochDays") -> uint32` diff --git a/x/farming/types/keys.go b/x/farming/types/keys.go index 65050728..56dc0810 100644 --- a/x/farming/types/keys.go +++ b/x/farming/types/keys.go @@ -23,9 +23,9 @@ const ( // keys for farming store prefixes var ( - GlobalPlanIdKey = []byte("globalPlanId") - GlobalLastEpochTimeKey = []byte("globalLastEpochTime") - CurrentEpochDaysKey = []byte("currentEpochDays") + GlobalPlanIdKey = []byte("globalPlanId") + LastEpochTimeKey = []byte("lastEpochTime") + CurrentEpochDaysKey = []byte("currentEpochDays") PlanKeyPrefix = []byte{0x11} diff --git a/x/farming/types/utils.go b/x/farming/types/utils.go index ff9ddb23..f6607416 100644 --- a/x/farming/types/utils.go +++ b/x/farming/types/utils.go @@ -1,6 +1,6 @@ package types -import time "time" +import "time" // ParseTime parses string time to time in RFC3339 format. func ParseTime(s string) time.Time { diff --git a/x/farming/types/utils_test.go b/x/farming/types/utils_test.go new file mode 100644 index 00000000..4ec8b423 --- /dev/null +++ b/x/farming/types/utils_test.go @@ -0,0 +1,20 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/tendermint/farming/x/farming/types" +) + +func TestParseTime(t *testing.T) { + normalCase := "9999-12-31T00:00:00Z" + normalRes, err := time.Parse(time.RFC3339, normalCase) + require.NoError(t, err) + errorCase := "9999-12-31T00:00:00_ErrorCase" + _, err = time.Parse(time.RFC3339, errorCase) + require.PanicsWithError(t, err.Error(), func() { types.ParseTime(errorCase) }) + require.Equal(t, normalRes, types.ParseTime(normalCase)) +}