Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update simulation test #2983

Merged
merged 7 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions app/ante/decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"

coinswaptypes "mods.irisnet.org/modules/coinswap/types"
servicetypes "mods.irisnet.org/modules/service/types"
tokenkeeper "mods.irisnet.org/modules/token/keeper"
tokentypesv1 "mods.irisnet.org/modules/token/types/v1"
tokentypesv1beta1 "mods.irisnet.org/modules/token/types/v1beta1"
Expand Down Expand Up @@ -77,14 +76,7 @@ func (vsd ValidateServiceDecorator) AnteHandle(
simulate bool,
next sdk.AnteHandler,
) (sdk.Context, error) {
for _, msg := range tx.GetMsgs() {
switch msg := msg.(type) {
case *servicetypes.MsgCallService:
if msg.Repeated {
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "currently does not support to create repeatable service invocation")
}
}
}
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved

return next(ctx, tx, simulate)
}

Expand Down
90 changes: 45 additions & 45 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package app
import (
"encoding/json"
"fmt"
"log"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -72,9 +70,9 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
allowedAddrsMap := make(map[string]bool)

for _, addr := range jailAllowedAddrs {
_, err := sdk.ValAddressFromBech32(addr)
_, err := app.InterfaceRegistry().SigningContext().ValidatorAddressCodec().StringToBytes(addr)
if err != nil {
log.Fatal(err)
panic(err)
}
allowedAddrsMap[addr] = true
}
Expand All @@ -85,31 +83,32 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
/* Handle fee distribution state. */

// withdraw all validator commission
app.StakingKeeper.IterateValidators(
ctx,
func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
if _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, sdk.ValAddress(val.GetOperator())); err != nil {
panic(err)
}
return false
},
)
err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err)
}
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz)
return false
})
if err != nil {
panic(err)
}

// withdraw all delegator rewards
dels, err := app.StakingKeeper.GetAllDelegations(ctx)
if err != nil {
panic(err)
}

for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
panic(err)
}

delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
if err != nil {
panic(err)
}
delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)

wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
}

Expand All @@ -124,25 +123,28 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators
app.StakingKeeper.IterateValidators(
err = app.StakingKeeper.IterateValidators(
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
ctx,
func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err)
}
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, sdk.ValAddress(val.GetOperator()))
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz)
if err != nil {
panic(err)
}
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
panic(err)
}

feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
panic(err)
}

if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, sdk.ValAddress(val.GetOperator())); err != nil {
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil {
panic(err)
}
return false
Expand Down Expand Up @@ -174,28 +176,28 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(
ctx,
func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
return false
},
)
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
err = app.StakingKeeper.SetRedelegation(ctx, red)
if err != nil {
panic(err)
}
return false
})

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(
ctx,
func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
return false
},
)
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
err = app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
if err != nil {
panic(err)
}
return false
})

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
Expand All @@ -207,17 +209,15 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, err := app.StakingKeeper.GetValidator(ctx, addr)
if err != nil {
panic(err)
panic("expected validator, not found")
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

if err := app.StakingKeeper.SetValidator(ctx, validator); err != nil {
panic(err)
}
app.StakingKeeper.SetValidator(ctx, validator)
wangjiulian marked this conversation as resolved.
Show resolved Hide resolved
counter++
}

Expand Down
9 changes: 6 additions & 3 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := createApp(logger, db, encfg, fauxMerkleModeOpt)
newApp := createApp(logger, newDB, encfg, fauxMerkleModeOpt)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for InitChain in TestAppImportExport

While error handling for InitChain was added in TestAppSimulationAfterImport, similar error handling is missing in TestAppImportExport. Consider adding consistent error handling across both test functions.

Apply this pattern to TestAppImportExport:

 newApp := createApp(logger, newDB, encfg, fauxMerkleModeOpt)
 require.Equal(t, "IrisApp", newApp.Name())
+
+_, err = newApp.InitChain(&abci.RequestInitChain{
+    AppStateBytes: exported.AppState,
+    ChainId:      AppChainID,
+})
+require.NoError(t, err)

Also applies to: 369-378

require.Equal(t, "IrisApp", newApp.Name())

var genesisState iristypes.GenesisState
Expand Down Expand Up @@ -366,13 +366,16 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := createApp(logger, db, encfg, fauxMerkleModeOpt)
newApp := createApp(logger, newDB, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", newApp.Name())

newApp.InitChain(&abci.RequestInitChain{
_, err = newApp.InitChain(&abci.RequestInitChain{
AppStateBytes: exported.AppState,
ChainId: AppChainID,
})

require.NoError(t, err)

_, _, err = simulation.SimulateFromSeed(
t,
os.Stdout,
Expand Down
25 changes: 15 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ require (
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/iavl v1.2.0 // indirect
github.com/evmos/ethermint v0.22.0
mods.irisnet.org/modules/coinswap v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/farm v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/htlc v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/mt v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/nft v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/oracle v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/random v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/record v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/service v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/token v0.0.0-20241209074433-1380d52b7709
mods.irisnet.org/modules/coinswap v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/farm v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/htlc v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/mt v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/nft v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/oracle v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/random v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/record v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/service v0.0.0-20241217080151-0ad41be03ac6
mods.irisnet.org/modules/token v0.0.0-20241217080151-0ad41be03ac6
)

require (
Expand Down Expand Up @@ -278,5 +278,10 @@ replace (
// stick with compatible version or x/exp in v0.47.x line
// x/exp had a breaking change in further commits
golang.org/x/exp => golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0
//mods.irisnet.org/modules/coinswap => ../irismod/modules/coinswap
//
//// todo test
//mods.irisnet.org/modules/service => ../irismod/modules/service
//mods.irisnet.org/modules/token => ../irismod/modules/token

)
40 changes: 20 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2065,26 +2065,26 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
mods.irisnet.org/api v0.0.0-20241121030837-903540d1123f h1:tJoTbTqFBZUnCLL+juHEuQLNNdftSXwSlqGoKa8OOxw=
mods.irisnet.org/api v0.0.0-20241121030837-903540d1123f/go.mod h1:TpMaRRYSpqsXdeX4gDVFRj9ggedQ60Zcjs4iE2DIhsc=
mods.irisnet.org/modules/coinswap v0.0.0-20241209074433-1380d52b7709 h1:i5lbpX0nC0O8nubflu99ifh716T6kMCvDhhJHsrooFk=
mods.irisnet.org/modules/coinswap v0.0.0-20241209074433-1380d52b7709/go.mod h1:nv52g5ZDWv/C1ydtxLygP2wSYz6M4OuF6BygKy7RqGA=
mods.irisnet.org/modules/farm v0.0.0-20241209074433-1380d52b7709 h1:5bNfktWvUg3FCm8fNO7QAXasGciPLPntz+iKHLh+bKM=
mods.irisnet.org/modules/farm v0.0.0-20241209074433-1380d52b7709/go.mod h1:yYrnhmxDCnvI45u1cpeRZ2GPJUmRK+8KFXDtOJGpENE=
mods.irisnet.org/modules/htlc v0.0.0-20241209074433-1380d52b7709 h1:RJfiSwR9QgbKNqlsonXCw3Unm5mggvIZ2iYVpn4Bew4=
mods.irisnet.org/modules/htlc v0.0.0-20241209074433-1380d52b7709/go.mod h1:2pWkSnxVKCzB3WH+q47rKffY4Plma+mRTGSWd4jfbp8=
mods.irisnet.org/modules/mt v0.0.0-20241209074433-1380d52b7709 h1:MFlghrXXMChdC1xOF9ulfdDzlwdN7UddvMjwaud7W9o=
mods.irisnet.org/modules/mt v0.0.0-20241209074433-1380d52b7709/go.mod h1:Dw1zm350HiRuNjrnwZnV4XGB8PNf1SXmjGJA5Xslg0Q=
mods.irisnet.org/modules/nft v0.0.0-20241209074433-1380d52b7709 h1:VhhLzJknCMQO7HVSVwSVkYKreYm9bk/8P5E8FEZ6KZ8=
mods.irisnet.org/modules/nft v0.0.0-20241209074433-1380d52b7709/go.mod h1:VjySqJfECBW8cApFB8W66Yk6tMR2oJEc7FTDaHfeg8I=
mods.irisnet.org/modules/oracle v0.0.0-20241209074433-1380d52b7709 h1:nDqnB+kyIUkIfRB2LcfdnqDNEnbXHnBIfnEkMWIlO8w=
mods.irisnet.org/modules/oracle v0.0.0-20241209074433-1380d52b7709/go.mod h1:XAGzG55xpV01PwvryVPeaHtARZIqEUJcMv/vxaVcVC0=
mods.irisnet.org/modules/random v0.0.0-20241209074433-1380d52b7709 h1:DWbsZNjeCYzQ6lD7ogoezrHURjc0s4Kkpkn275TGHfo=
mods.irisnet.org/modules/random v0.0.0-20241209074433-1380d52b7709/go.mod h1:1ele5fpZ/rFMbwu1LTz2MwDg3sJDYcCtDW5SDfYRpTg=
mods.irisnet.org/modules/record v0.0.0-20241209074433-1380d52b7709 h1:rmGVgGMdfR8j9jqNfhwDyf5Tsr8IrdaTqxaiHMKnzRU=
mods.irisnet.org/modules/record v0.0.0-20241209074433-1380d52b7709/go.mod h1:n8gRooDvJ5B44EJRZ+UlDz0GcXQeNwjH2tjpnVx7nd8=
mods.irisnet.org/modules/service v0.0.0-20241209074433-1380d52b7709 h1:luRpAYMuG4YYLuf1tUuUzlkEjh41EHc3j5KSiVD82/o=
mods.irisnet.org/modules/service v0.0.0-20241209074433-1380d52b7709/go.mod h1:B1nKRNYn1VLqpvNbmbDSYagqL56sj0MIceXJi/DKg6s=
mods.irisnet.org/modules/token v0.0.0-20241209074433-1380d52b7709 h1:dGuMYcTXIRgmpJHFrSFOV5g4Xc09WSVhz0n8HkbZQoE=
mods.irisnet.org/modules/token v0.0.0-20241209074433-1380d52b7709/go.mod h1:fHJzeEBPhE9vaa4aye90+WFtHjZyGRvkWRpJeBSc9/k=
mods.irisnet.org/modules/coinswap v0.0.0-20241217080151-0ad41be03ac6 h1:8QnufoVSKUdiLPqJwByZF6yz5zt9qyhSaT08No50pMA=
mods.irisnet.org/modules/coinswap v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:nv52g5ZDWv/C1ydtxLygP2wSYz6M4OuF6BygKy7RqGA=
mods.irisnet.org/modules/farm v0.0.0-20241217080151-0ad41be03ac6 h1:SA28lvYjEgOylkZJyuRVDIK4uGBHmtMGJvyAshUJJFk=
mods.irisnet.org/modules/farm v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:yYrnhmxDCnvI45u1cpeRZ2GPJUmRK+8KFXDtOJGpENE=
mods.irisnet.org/modules/htlc v0.0.0-20241217080151-0ad41be03ac6 h1:JPzUkLdXY/0YzlgQ4wsmiI35Karrssb77dopt67qvqU=
mods.irisnet.org/modules/htlc v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:2pWkSnxVKCzB3WH+q47rKffY4Plma+mRTGSWd4jfbp8=
mods.irisnet.org/modules/mt v0.0.0-20241217080151-0ad41be03ac6 h1:DyW+fBjjzJ4/h60sfvL0nkewudIZFRFPGvAZPj+8a+c=
mods.irisnet.org/modules/mt v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:Dw1zm350HiRuNjrnwZnV4XGB8PNf1SXmjGJA5Xslg0Q=
mods.irisnet.org/modules/nft v0.0.0-20241217080151-0ad41be03ac6 h1:RHgx9ggA5/lsNKXvQ7ezJpCfJBhKjlBBAfoaOTKNMnU=
mods.irisnet.org/modules/nft v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:VjySqJfECBW8cApFB8W66Yk6tMR2oJEc7FTDaHfeg8I=
mods.irisnet.org/modules/oracle v0.0.0-20241217080151-0ad41be03ac6 h1:1Xj4j7f639GMZ+MAbwNljQb0DZ5IdXDqQYNoDlppVXk=
mods.irisnet.org/modules/oracle v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:XAGzG55xpV01PwvryVPeaHtARZIqEUJcMv/vxaVcVC0=
mods.irisnet.org/modules/random v0.0.0-20241217080151-0ad41be03ac6 h1:ScX6qHG3V49eQHkeQmJ5awp7I8ixou+obxxWd4/wTcU=
mods.irisnet.org/modules/random v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:1ele5fpZ/rFMbwu1LTz2MwDg3sJDYcCtDW5SDfYRpTg=
mods.irisnet.org/modules/record v0.0.0-20241217080151-0ad41be03ac6 h1:PJu+56Be8F+mPj35jqeMvXl/bRZDtwrF9GL6j0w5ivQ=
mods.irisnet.org/modules/record v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:n8gRooDvJ5B44EJRZ+UlDz0GcXQeNwjH2tjpnVx7nd8=
mods.irisnet.org/modules/service v0.0.0-20241217080151-0ad41be03ac6 h1:U6IzrFgN8GXhdNHXxA5isDgQX7DeSfeVDqvLzs6cc4o=
mods.irisnet.org/modules/service v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:B1nKRNYn1VLqpvNbmbDSYagqL56sj0MIceXJi/DKg6s=
mods.irisnet.org/modules/token v0.0.0-20241217080151-0ad41be03ac6 h1:hlzR6ghnSujPC9VCwrpBVU6cBb+M9KyfbJz5SrnIef8=
mods.irisnet.org/modules/token v0.0.0-20241217080151-0ad41be03ac6/go.mod h1:fHJzeEBPhE9vaa4aye90+WFtHjZyGRvkWRpJeBSc9/k=
mods.irisnet.org/simapp v0.0.0-20241125071105-d76ae25d05d2 h1:9AGZYpMjpk1gItviL31vsehmen119HtcuOKwv8WWpZo=
mods.irisnet.org/simapp v0.0.0-20241125071105-d76ae25d05d2/go.mod h1:t7FSQJkJOgXq1/LdhpBeOu7TS8hLQkAMMx9fL5w53PY=
nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k=
Expand Down
5 changes: 0 additions & 5 deletions sims.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ test-sim-after-import: runsim
@echo "Running Iris simulation-after-import. This may take several minutes..."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 25 5 TestIrisSimulationAfterImport

test-sim-custom-genesis-multi-seed: runsim
@echo "Running multi-seed custom genesis simulation..."
@echo "By default, ${HOME}/.iris/config/genesis.json will be used."
@$(BINDIR)/runsim -Jobs=4 -Genesis=${HOME}/.iris/config/genesis.json 400 5 TestFullIrisSimulation

test-sim-multi-seed-long: runsim
@echo "Running multi-seed application simulation. This may take awhile!"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 500 50 TestFullAppSimulation
Expand Down
Loading