-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add params for ics27 simulation (#2160) * add param changes for ics27 simulation * account for unadded submodules * fix tests * Update modules/apps/27-interchain-accounts/module.go * add app simulation declaration (cherry picked from commit cd913b8) # Conflicts: # modules/apps/27-interchain-accounts/module.go * fix conflicts Co-authored-by: colin axnér <[email protected]>
- Loading branch information
1 parent
64a996f
commit 08df59d
Showing
3 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package simulation | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
|
||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
gogotypes "github.com/gogo/protobuf/types" | ||
|
||
controllerkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" | ||
controllertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" | ||
hostkeeper "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/keeper" | ||
hosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" | ||
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" | ||
) | ||
|
||
// ParamChanges defines the parameters that can be modified by param change proposals | ||
// on the simulation | ||
func ParamChanges(r *rand.Rand, controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) []simtypes.ParamChange { | ||
var paramChanges []simtypes.ParamChange | ||
if controllerKeeper != nil { | ||
paramChanges = append(paramChanges, simulation.NewSimParamChange(controllertypes.SubModuleName, string(controllertypes.KeyControllerEnabled), | ||
func(r *rand.Rand) string { | ||
controllerEnabled := RandomEnabled(r) | ||
return fmt.Sprintf("%s", types.ModuleCdc.MustMarshalJSON(&gogotypes.BoolValue{Value: controllerEnabled})) //nolint:gosimple | ||
}, | ||
)) | ||
} | ||
|
||
if hostKeeper != nil { | ||
paramChanges = append(paramChanges, simulation.NewSimParamChange(hosttypes.SubModuleName, string(hosttypes.KeyHostEnabled), | ||
func(r *rand.Rand) string { | ||
receiveEnabled := RandomEnabled(r) | ||
return fmt.Sprintf("%s", types.ModuleCdc.MustMarshalJSON(&gogotypes.BoolValue{Value: receiveEnabled})) //nolint:gosimple | ||
}, | ||
)) | ||
} | ||
|
||
return paramChanges | ||
} |
64 changes: 64 additions & 0 deletions
64
modules/apps/27-interchain-accounts/simulation/params_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package simulation_test | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
controllertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" | ||
hosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" | ||
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/simulation" | ||
"github.com/cosmos/ibc-go/v5/testing/simapp" | ||
) | ||
|
||
func TestParamChanges(t *testing.T) { | ||
app := simapp.Setup(false) | ||
|
||
s := rand.NewSource(1) | ||
r := rand.New(s) | ||
|
||
expected := []struct { | ||
composedKey string | ||
key string | ||
simValue string | ||
subspace string | ||
}{ | ||
{fmt.Sprintf("%s/%s", controllertypes.SubModuleName, controllertypes.KeyControllerEnabled), string(controllertypes.KeyControllerEnabled), "false", controllertypes.SubModuleName}, | ||
{fmt.Sprintf("%s/%s", hosttypes.SubModuleName, hosttypes.KeyHostEnabled), string(hosttypes.KeyHostEnabled), "true", hosttypes.SubModuleName}, | ||
} | ||
|
||
paramChanges := simulation.ParamChanges(r, &app.ICAControllerKeeper, &app.ICAHostKeeper) | ||
require.Len(t, paramChanges, 2) | ||
|
||
for i, p := range paramChanges { | ||
require.Equal(t, expected[i].composedKey, p.ComposedKey()) | ||
require.Equal(t, expected[i].key, p.Key()) | ||
require.Equal(t, expected[i].simValue, p.SimValue()(r), p.Key()) | ||
require.Equal(t, expected[i].subspace, p.Subspace()) | ||
} | ||
|
||
paramChanges = simulation.ParamChanges(r, &app.ICAControllerKeeper, nil) | ||
require.Len(t, paramChanges, 1) | ||
|
||
// the second call to paramChanges causing the controller enabled to be changed to true | ||
expected[0].simValue = "true" | ||
|
||
for _, p := range paramChanges { | ||
require.Equal(t, expected[0].composedKey, p.ComposedKey()) | ||
require.Equal(t, expected[0].key, p.Key()) | ||
require.Equal(t, expected[0].simValue, p.SimValue()(r), p.Key()) | ||
require.Equal(t, expected[0].subspace, p.Subspace()) | ||
} | ||
|
||
paramChanges = simulation.ParamChanges(r, nil, &app.ICAHostKeeper) | ||
require.Len(t, paramChanges, 1) | ||
|
||
for _, p := range paramChanges { | ||
require.Equal(t, expected[1].composedKey, p.ComposedKey()) | ||
require.Equal(t, expected[1].key, p.Key()) | ||
require.Equal(t, expected[1].simValue, p.SimValue()(r), p.Key()) | ||
require.Equal(t, expected[1].subspace, p.Subspace()) | ||
} | ||
} |