Skip to content

Commit

Permalink
Fix simulationi staking types missing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
JeancarloBarrios committed Dec 9, 2024
1 parent 3914107 commit 655376f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
8 changes: 5 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
app.ModuleAccountAddrs(),
app.BlockAddresses(),
govModuleAddr,
)
app.StakingKeeper = stakingkeeper.NewKeeper(
Expand Down Expand Up @@ -811,12 +811,14 @@ func (app *RegenApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
}

// ModuleAccountAddrs returns all the app's module account addresses.
func (app *RegenApp) ModuleAccountAddrs() map[string]bool {
// BlockAddresses returns all the app's module account addresses.
func (app *RegenApp) BlockAddresses() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
}
// allow the following addresses to receive funds
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())

return modAccAddrs
}
Expand Down
22 changes: 15 additions & 7 deletions app/simulation/app_import_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package simulation
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/server"
"os"
"runtime/debug"
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -37,6 +37,7 @@ import (

func TestAppImportExport(t *testing.T) {
config := simcli.NewConfigFromFlags()
//config.Commit = true
db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "app-import-export", "sim-1", false, true)
if skip {
t.Skip("skipping app-import-export simulation")
Expand All @@ -47,14 +48,16 @@ func TestAppImportExport(t *testing.T) {
db.Close()
require.NoError(t, os.RemoveAll(dir))
}()
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue

app := regen.NewRegenApp(
logger,
db,
nil,
true,
simcli.FlagPeriodValue,
simtestutil.EmptyAppOptions{},
appOptions,
fauxMerkleModeOpt,
)
require.Equal(t, regen.AppName, app.Name())
Expand Down Expand Up @@ -82,17 +85,17 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, err, "simulation setup failed")

defer func() {
newDB.Close()
require.NoError(t, newDB.Close())
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := regen.NewRegenApp(
log.NewNopLogger(),
newDB,
logger,
db,
nil,
true,
simcli.FlagPeriodValue,
simtestutil.EmptyAppOptions{},
appOptions,
fauxMerkleModeOpt,
)
require.Equal(t, regen.AppName, newApp.Name())
Expand Down Expand Up @@ -138,6 +141,10 @@ func TestAppImportExport(t *testing.T) {
stakingtypes.RedelegationQueueKey,
stakingtypes.ValidatorQueueKey,
stakingtypes.HistoricalInfoKey,
stakingtypes.UnbondingIDKey,
stakingtypes.UnbondingIndexKey,
stakingtypes.UnbondingTypeKey,
stakingtypes.ValidatorUpdatesKey,
}},

// ibc modules
Expand All @@ -149,9 +156,10 @@ func TestAppImportExport(t *testing.T) {
{app.GetKey(ecocredit.ModuleName), newApp.GetKey(ecocredit.ModuleName), [][]byte{}},
}

for _, skp := range storeKeysPrefixes {
for i, skp := range storeKeysPrefixes {
storeA := ctxA.KVStore(skp.A)
storeB := ctxB.KVStore(skp.B)
fmt.Println(i)

failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes)
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")
Expand Down
2 changes: 1 addition & 1 deletion app/simulation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func simulateFromSeed(t *testing.T, app *regen.RegenApp, config simtypes.Config)
simtestutil.AppStateFn(cdc, app.SimulationManager(), genesis),
simtypes.RandomAccounts,
simtestutil.SimulationOperations(app, cdc, config),
app.ModuleAccountAddrs(),
app.BlockAddresses(),
config,
app.AppCodec(),
)
Expand Down

0 comments on commit 655376f

Please sign in to comment.