-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add simulation tests for new param change (#14728)
- Loading branch information
1 parent
1ad8e86
commit d3c3194
Showing
61 changed files
with
933 additions
and
712 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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
) | ||
|
||
// Simulation operation weights constants | ||
const ( | ||
DefaultWeightMsgUpdateParams int = 100 | ||
|
||
OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec | ||
) | ||
|
||
// ProposalMsgs defines the module weighted proposals' contents | ||
func ProposalMsgs() []simtypes.WeightedProposalMsg { | ||
return []simtypes.WeightedProposalMsg{ | ||
simulation.NewWeightedProposalMsg( | ||
OpWeightMsgUpdateParams, | ||
DefaultWeightMsgUpdateParams, | ||
SimulateMsgUpdateParams, | ||
), | ||
} | ||
} | ||
|
||
// SimulateMsgUpdateParams returns a random MsgUpdateParams | ||
func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { | ||
// use the default gov module account address as authority | ||
var authority sdk.AccAddress = address.Module("gov") | ||
|
||
params := types.DefaultParams() | ||
params.MaxMemoCharacters = uint64(simtypes.RandIntBetween(r, 1, 1000)) | ||
params.TxSigLimit = uint64(simtypes.RandIntBetween(r, 1, 1000)) | ||
params.TxSizeCostPerByte = uint64(simtypes.RandIntBetween(r, 1, 1000)) | ||
params.SigVerifyCostED25519 = uint64(simtypes.RandIntBetween(r, 1, 1000)) | ||
params.SigVerifyCostSecp256k1 = uint64(simtypes.RandIntBetween(r, 1, 1000)) | ||
|
||
return &types.MsgUpdateParams{ | ||
Authority: authority.String(), | ||
Params: params, | ||
} | ||
} |
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,45 @@ | ||
package simulation_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
"gotest.tools/v3/assert" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/auth/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
) | ||
|
||
func TestProposalMsgs(t *testing.T) { | ||
// initialize parameters | ||
s := rand.NewSource(1) | ||
r := rand.New(s) | ||
|
||
ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) | ||
accounts := simtypes.RandomAccounts(r, 3) | ||
|
||
// execute ProposalMsgs function | ||
weightedProposalMsgs := simulation.ProposalMsgs() | ||
assert.Assert(t, len(weightedProposalMsgs) == 1) | ||
|
||
w0 := weightedProposalMsgs[0] | ||
|
||
// tests w0 interface: | ||
assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) | ||
assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) | ||
|
||
msg := w0.MsgSimulatorFn()(r, ctx, accounts) | ||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams) | ||
assert.Assert(t, ok) | ||
|
||
assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) | ||
assert.Equal(t, uint64(999), msgUpdateParams.Params.MaxMemoCharacters) | ||
assert.Equal(t, uint64(905), msgUpdateParams.Params.TxSigLimit) | ||
assert.Equal(t, uint64(151), msgUpdateParams.Params.TxSizeCostPerByte) | ||
assert.Equal(t, uint64(213), msgUpdateParams.Params.SigVerifyCostED25519) | ||
assert.Equal(t, uint64(539), msgUpdateParams.Params.SigVerifyCostSecp256k1) | ||
} |
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
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
Oops, something went wrong.