Skip to content

Commit

Permalink
Delete unused simulator code (#1671)
Browse files Browse the repository at this point in the history
* Delete unused simulator code

* Add hourly epochs to the x/epochs DefaultGenesis

* Add changelog

* Delete the unused x/gamm/simulation folder

* Fix epochs module tests for updated DefaultGenesis
  • Loading branch information
ValarDragon authored Jun 6, 2022
1 parent d80c2af commit f21e29e
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 608 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### golang API breaks

* [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface
* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Remove methods that constitute AppModuleSimulation APIs for several modules' AppModules, which implemented no-ops
* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Add hourly epochs to `x/epochs` DefaultGenesis.
* [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface, instead use simapp.App
* [#1630](https://github.com/osmosis-labs/osmosis/pull/1630) Delete the v043_temp module, now that we're on an updated SDK version.


Expand All @@ -56,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1230] Stableswap CFMM equations
* [#1429] solver for multi-asset CFMM


## [v9.0.0 - Nitrogen](https://github.com/osmosis-labs/osmosis/releases/tag/v9.0.0)

The Nitrogen release brings with it a number of features enabling further cosmwasm development work in Osmosis.
Expand Down
4 changes: 0 additions & 4 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ func simulationModules(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
gamm.NewAppModule(appCodec, *app.GAMMKeeper, app.AccountKeeper, app.BankKeeper),
txfees.NewAppModule(appCodec, *app.TxFeesKeeper),
gov.NewAppModule(appCodec, *app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper, app.BankKeeper),
slashing.NewAppModule(appCodec, *app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper),
Expand All @@ -256,7 +254,6 @@ func simulationModules(
incentives.NewAppModule(appCodec, *app.IncentivesKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper),
lockup.NewAppModule(appCodec, *app.LockupKeeper, app.AccountKeeper, app.BankKeeper),
poolincentives.NewAppModule(appCodec, *app.PoolIncentivesKeeper),
epochs.NewAppModule(appCodec, *app.EpochsKeeper),
superfluid.NewAppModule(
appCodec,
*app.SuperfluidKeeper,
Expand All @@ -267,7 +264,6 @@ func simulationModules(
app.GAMMKeeper,
app.EpochsKeeper,
),
tokenfactory.NewAppModule(appCodec, *app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
app.TransferModule,
}
}
Expand Down
16 changes: 5 additions & 11 deletions x/epochs/keeper/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ import (
func (suite *KeeperTestSuite) TestEpochLifeCycle() {
suite.SetupTest()

epochInfo := types.EpochInfo{
Identifier: "monthly",
StartTime: time.Time{},
Duration: time.Hour * 24 * 30,
CurrentEpoch: 0,
CurrentEpochStartTime: time.Time{},
EpochCountingStarted: false,
}
epochInfo := types.NewGenesisEpochInfo("monthly", time.Hour*24*30)
suite.App.EpochsKeeper.SetEpochInfo(suite.Ctx, epochInfo)
epochInfoSaved := suite.App.EpochsKeeper.GetEpochInfo(suite.Ctx, "monthly")
suite.Require().Equal(epochInfo, epochInfoSaved)

allEpochs := suite.App.EpochsKeeper.AllEpochInfos(suite.Ctx)
suite.Require().Len(allEpochs, 3)
suite.Require().Len(allEpochs, 4)
suite.Require().Equal(allEpochs[0].Identifier, "day") // alphabetical order
suite.Require().Equal(allEpochs[1].Identifier, "monthly")
suite.Require().Equal(allEpochs[2].Identifier, "week")
suite.Require().Equal(allEpochs[1].Identifier, "hour")
suite.Require().Equal(allEpochs[2].Identifier, "monthly")
suite.Require().Equal(allEpochs[3].Identifier, "week")
}
22 changes: 7 additions & 15 deletions x/epochs/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@ func TestEpochsExportGenesis(t *testing.T) {
chainStartHeight := ctx.BlockHeight()

genesis := app.EpochsKeeper.ExportGenesis(ctx)
require.Len(t, genesis.Epochs, 2)
require.Len(t, genesis.Epochs, 3)

require.Equal(t, genesis.Epochs[0].Identifier, "day")
require.Equal(t, genesis.Epochs[0].StartTime, chainStartTime)
require.Equal(t, genesis.Epochs[0].Duration, time.Hour*24)
require.Equal(t, genesis.Epochs[0].CurrentEpoch, int64(0))
require.Equal(t, genesis.Epochs[0].CurrentEpochStartHeight, chainStartHeight)
require.Equal(t, genesis.Epochs[0].CurrentEpochStartTime, chainStartTime)
require.Equal(t, genesis.Epochs[0].EpochCountingStarted, false)
require.Equal(t, genesis.Epochs[1].Identifier, "week")
require.Equal(t, genesis.Epochs[1].StartTime, chainStartTime)
require.Equal(t, genesis.Epochs[1].Duration, time.Hour*24*7)
require.Equal(t, genesis.Epochs[1].CurrentEpoch, int64(0))
require.Equal(t, genesis.Epochs[1].CurrentEpochStartHeight, chainStartHeight)
require.Equal(t, genesis.Epochs[1].CurrentEpochStartTime, chainStartTime)
require.Equal(t, genesis.Epochs[1].EpochCountingStarted, false)
expectedEpochs := types.DefaultGenesis().Epochs
for i := 0; i < len(expectedEpochs); i++ {
expectedEpochs[i].CurrentEpochStartHeight = chainStartHeight
expectedEpochs[i].CurrentEpochStartTime = chainStartTime
}
require.Equal(t, expectedEpochs, genesis.Epochs)
}

func TestEpochsInitGenesis(t *testing.T) {
Expand Down
41 changes: 4 additions & 37 deletions x/epochs/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
gocontext "context"
"time"

"github.com/osmosis-labs/osmosis/v7/x/epochs/types"
)
Expand All @@ -11,42 +10,10 @@ func (suite *KeeperTestSuite) TestQueryEpochInfos() {
suite.SetupTest()
queryClient := suite.queryClient

chainStartTime := suite.Ctx.BlockHeader().Time
epochInfo := types.EpochInfo{
Identifier: "day",
StartTime: chainStartTime,
Duration: time.Hour * 24,
CurrentEpoch: 0,
CurrentEpochStartTime: chainStartTime,
EpochCountingStarted: false,
}
suite.App.EpochsKeeper.SetEpochInfo(suite.Ctx, epochInfo)
epochInfo = types.EpochInfo{
Identifier: "week",
StartTime: chainStartTime,
Duration: time.Hour * 24 * 7,
CurrentEpoch: 0,
CurrentEpochStartTime: chainStartTime,
EpochCountingStarted: false,
}
suite.App.EpochsKeeper.SetEpochInfo(suite.Ctx, epochInfo)

// Invalid param
// Check that querying epoch infos on default genesis returns the default genesis epoch infos
epochInfosResponse, err := queryClient.EpochInfos(gocontext.Background(), &types.QueryEpochsInfoRequest{})
suite.Require().NoError(err)
suite.Require().Len(epochInfosResponse.Epochs, 2)

// check if EpochInfos are correct
suite.Require().Equal(epochInfosResponse.Epochs[0].Identifier, "day")
suite.Require().Equal(epochInfosResponse.Epochs[0].StartTime, chainStartTime)
suite.Require().Equal(epochInfosResponse.Epochs[0].Duration, time.Hour*24)
suite.Require().Equal(epochInfosResponse.Epochs[0].CurrentEpoch, int64(0))
suite.Require().Equal(epochInfosResponse.Epochs[0].CurrentEpochStartTime, chainStartTime)
suite.Require().Equal(epochInfosResponse.Epochs[0].EpochCountingStarted, false)
suite.Require().Equal(epochInfosResponse.Epochs[1].Identifier, "week")
suite.Require().Equal(epochInfosResponse.Epochs[1].StartTime, chainStartTime)
suite.Require().Equal(epochInfosResponse.Epochs[1].Duration, time.Hour*24*7)
suite.Require().Equal(epochInfosResponse.Epochs[1].CurrentEpoch, int64(0))
suite.Require().Equal(epochInfosResponse.Epochs[1].CurrentEpochStartTime, chainStartTime)
suite.Require().Equal(epochInfosResponse.Epochs[1].EpochCountingStarted, false)
suite.Require().Len(epochInfosResponse.Epochs, 3)
expectedEpochs := types.DefaultGenesis().Epochs
suite.Require().Equal(expectedEpochs, epochInfosResponse.Epochs)
}
31 changes: 0 additions & 31 deletions x/epochs/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"

"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
Expand All @@ -16,11 +15,9 @@ import (
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

"github.com/osmosis-labs/osmosis/v7/x/epochs/client/cli"
"github.com/osmosis-labs/osmosis/v7/x/epochs/keeper"
"github.com/osmosis-labs/osmosis/v7/x/epochs/simulation"
"github.com/osmosis-labs/osmosis/v7/x/epochs/types"
"github.com/osmosis-labs/osmosis/v7/x/mint/client/rest"
)
Expand Down Expand Up @@ -163,33 +160,5 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val
return []abci.ValidatorUpdate{}
}

// ___________________________________________________________________________

// AppModuleSimulation functions

// GenerateGenesisState creates a randomized GenState of the pool-incentives module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}

// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

// RandomizedParams creates randomized pool-incentives param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
}

// RegisterStoreDecoder registers a decoder for supply module's types.
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil // TODO
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
56 changes: 0 additions & 56 deletions x/epochs/simulation/genesis.go

This file was deleted.

3 changes: 2 additions & 1 deletion x/epochs/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ func NewGenesisState(epochs []EpochInfo) *GenesisState {
// DefaultGenesis returns the default Capability genesis state.
func DefaultGenesis() *GenesisState {
epochs := []EpochInfo{
NewGenesisEpochInfo("day", time.Hour*24), // alphabetical order
NewGenesisEpochInfo("hour", time.Hour),
NewGenesisEpochInfo("week", time.Hour*24*7),
NewGenesisEpochInfo("day", time.Hour*24),
}
return NewGenesisState(epochs)
}
Expand Down
39 changes: 2 additions & 37 deletions x/gamm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"

"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
Expand All @@ -16,20 +15,17 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/osmosis-labs/osmosis/v7/x/gamm/client/cli"
"github.com/osmosis-labs/osmosis/v7/x/gamm/keeper"
"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v7/x/gamm/simulation"
"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)

type AppModuleBasic struct {
Expand Down Expand Up @@ -160,36 +156,5 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val
return []abci.ValidatorUpdate{}
}

// ___________________________________________________________________________

// AppModuleSimulation functions

// GenerateGenesisState creates a randomized GenState of the gamm module.
// However, at launch the gamm module has no state, hence this is a no-op.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
// simulation.RandomizedGenState(simState)
}

// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

// RandomizedParams creates randomized gamm param changes for the simulator.
// There are no params that we view as sensible to randomize at the moment.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
// return simulation.ParamChanges(r)
}

// RegisterStoreDecoder registers a decoder for supply module's types.
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
}

// WeightedOperations returns all the simulation operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return simulation.WeightedOperations(simState.AppParams, simState.Cdc, am.ak, am.bk, am.keeper)
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
Loading

0 comments on commit f21e29e

Please sign in to comment.