Skip to content

Commit

Permalink
Merge PR cosmos#4847: Sim refactor 1 move store decoders to modules
Browse files Browse the repository at this point in the history
* move store decoders to modules

* fix

* module pattern

* compile

* update Decoders params

* fix

* address @colin-axner comments

* Update cmd_test.go

* simulation manager

* mino fixes

* cleanup

* Apply suggestions from code review

Co-Authored-By: frog power 4000 <[email protected]>

* address @rigelrozanski comments

* changelog

* Apply suggestions from code review

Co-Authored-By: colin axner <[email protected]>

* restructure modules simulation pkgs

* address @alexanderbez comments

* fix
  • Loading branch information
fedekunze authored and rigelrozanski committed Aug 13, 2019
1 parent 1c9c300 commit d143ce9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 572 deletions.
6 changes: 6 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ type SimApp struct {

// the module manager
mm *module.Manager

// simulation manager
sm *module.SimulationManager
}

// NewSimApp returns a reference to an initialized SimApp.
Expand Down Expand Up @@ -202,6 +205,9 @@ func NewSimApp(
app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())

app.sm = module.NewSimulationManager(app.mm.Modules)
app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
Expand Down
56 changes: 30 additions & 26 deletions sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/bank"
authsimops "github.com/cosmos/cosmos-sdk/x/auth/simulation/operations"
banksimops "github.com/cosmos/cosmos-sdk/x/bank/simulation/operations"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
distrsimops "github.com/cosmos/cosmos-sdk/x/distribution/simulation/operations"
"github.com/cosmos/cosmos-sdk/x/gov"
govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation"
govsimops "github.com/cosmos/cosmos-sdk/x/gov/simulation/operations"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
paramsim "github.com/cosmos/cosmos-sdk/x/params/simulation"
paramsimops "github.com/cosmos/cosmos-sdk/x/params/simulation/operations"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingsim "github.com/cosmos/cosmos-sdk/x/slashing/simulation"
slashingsimops "github.com/cosmos/cosmos-sdk/x/slashing/simulation/operations"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingsim "github.com/cosmos/cosmos-sdk/x/staking/simulation"
stakingsimops "github.com/cosmos/cosmos-sdk/x/staking/simulation/operations"
"github.com/cosmos/cosmos-sdk/x/supply"
)

Expand Down Expand Up @@ -184,7 +184,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
authsim.SimulateDeductFee(app.AccountKeeper, app.SupplyKeeper),
authsimops.SimulateDeductFee(app.AccountKeeper, app.SupplyKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -195,7 +195,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
bank.SimulateMsgSend(app.AccountKeeper, app.BankKeeper),
banksimops.SimulateMsgSend(app.AccountKeeper, app.BankKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -206,7 +206,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
bank.SimulateSingleInputMsgMultiSend(app.AccountKeeper, app.BankKeeper),
banksimops.SimulateSingleInputMsgMultiSend(app.AccountKeeper, app.BankKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -217,7 +217,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
distrsim.SimulateMsgSetWithdrawAddress(app.AccountKeeper, app.DistrKeeper),
distrsimops.SimulateMsgSetWithdrawAddress(app.DistrKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -228,7 +228,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
distrsim.SimulateMsgWithdrawDelegatorReward(app.AccountKeeper, app.DistrKeeper),
distrsimops.SimulateMsgWithdrawDelegatorReward(app.DistrKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -239,7 +239,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
distrsim.SimulateMsgWithdrawValidatorCommission(app.AccountKeeper, app.DistrKeeper),
distrsimops.SimulateMsgWithdrawValidatorCommission(app.DistrKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -250,7 +250,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.GovKeeper, govsim.SimulateTextProposalContent),
govsimops.SimulateSubmittingVotingAndSlashingForProposal(app.GovKeeper, govsimops.SimulateTextProposalContent),
},
{
func(_ *rand.Rand) int {
Expand All @@ -261,7 +261,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.GovKeeper, distrsim.SimulateCommunityPoolSpendProposalContent(app.DistrKeeper)),
govsimops.SimulateSubmittingVotingAndSlashingForProposal(app.GovKeeper, distrsimops.SimulateCommunityPoolSpendProposalContent(app.DistrKeeper)),
},
{
func(_ *rand.Rand) int {
Expand All @@ -272,7 +272,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.GovKeeper, paramsim.SimulateParamChangeProposalContent),
govsimops.SimulateSubmittingVotingAndSlashingForProposal(app.GovKeeper, paramsimops.SimulateParamChangeProposalContent),
},
{
func(_ *rand.Rand) int {
Expand All @@ -283,7 +283,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
govsim.SimulateMsgDeposit(app.GovKeeper),
govsimops.SimulateMsgDeposit(app.GovKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -294,7 +294,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
stakingsim.SimulateMsgCreateValidator(app.AccountKeeper, app.StakingKeeper),
stakingsimops.SimulateMsgCreateValidator(app.AccountKeeper, app.StakingKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -305,7 +305,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
stakingsim.SimulateMsgEditValidator(app.StakingKeeper),
stakingsimops.SimulateMsgEditValidator(app.StakingKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -316,7 +316,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
stakingsim.SimulateMsgDelegate(app.AccountKeeper, app.StakingKeeper),
stakingsimops.SimulateMsgDelegate(app.AccountKeeper, app.StakingKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -327,7 +327,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
stakingsim.SimulateMsgUndelegate(app.AccountKeeper, app.StakingKeeper),
stakingsimops.SimulateMsgUndelegate(app.AccountKeeper, app.StakingKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -338,7 +338,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
stakingsim.SimulateMsgBeginRedelegate(app.AccountKeeper, app.StakingKeeper),
stakingsimops.SimulateMsgBeginRedelegate(app.AccountKeeper, app.StakingKeeper),
},
{
func(_ *rand.Rand) int {
Expand All @@ -349,7 +349,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
})
return v
}(nil),
slashingsim.SimulateMsgUnjail(app.SlashingKeeper),
slashingsimops.SimulateMsgUnjail(app.SlashingKeeper),
},
}
}
Expand Down Expand Up @@ -597,11 +597,15 @@ func TestAppImportExport(t *testing.T) {
storeKeyA := storeKeysPrefix.A
storeKeyB := storeKeysPrefix.B
prefixes := storeKeysPrefix.Prefixes

storeA := ctxA.KVStore(storeKeyA)
storeB := ctxB.KVStore(storeKeyB)
failedKVs := sdk.DiffKVStores(storeA, storeB, prefixes)
fmt.Printf("Compared %d key/value pairs between %s and %s\n", len(failedKVs)/2, storeKeyA, storeKeyB)
require.Len(t, failedKVs, 0, GetSimulationLog(storeKeyA.Name(), app.cdc, newApp.cdc, failedKVs))

failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, prefixes)
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")

fmt.Printf("Compared %d key/value pairs between %s and %s\n", len(failedKVAs), storeKeyA, storeKeyB)
require.Len(t, failedKVAs, 0, GetSimulationLog(storeKeyA.Name(), app.sm.StoreDecoders, app.cdc, failedKVAs, failedKVBs))
}

}
Expand Down
Loading

0 comments on commit d143ce9

Please sign in to comment.