-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
296 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
"github.com/zeta-chain/node/x/observer/keeper" | ||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
// SimulateMsgDisableCCTX generates a MsgDisableCCTX and delivers it. | ||
func SimulateMsgDisableCCTX(k keeper.Keeper) simtypes.Operation { | ||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string, | ||
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { | ||
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts) | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUpdateKeygen, err.Error()), nil, nil | ||
} | ||
authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address) | ||
spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress()) | ||
|
||
msg := types.MsgDisableCCTX{ | ||
Creator: policyAccount.Address.String(), | ||
DisableInbound: false, | ||
DisableOutbound: true, | ||
} | ||
|
||
err = msg.ValidateBasic() | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), err.Error()), nil, err | ||
} | ||
|
||
txCtx := simulation.OperationInput{ | ||
R: r, | ||
App: app, | ||
TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, | ||
Cdc: nil, | ||
Msg: &msg, | ||
MsgType: msg.Type(), | ||
Context: ctx, | ||
SimAccount: policyAccount, | ||
AccountKeeper: k.GetAuthKeeper(), | ||
Bankkeeper: k.GetBankKeeper(), | ||
ModuleName: types.ModuleName, | ||
CoinsSpentInMsg: spendable, | ||
} | ||
|
||
return simulation.GenAndDeliverTxWithRandFees(txCtx) | ||
} | ||
} |
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,54 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
"github.com/zeta-chain/node/x/observer/keeper" | ||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
// SimulateMsgEnableCCTX generates a MsgEnableCCTX and delivers it. | ||
func SimulateMsgEnableCCTX(k keeper.Keeper) simtypes.Operation { | ||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string, | ||
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { | ||
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts) | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUpdateKeygen, err.Error()), nil, nil | ||
} | ||
authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address) | ||
spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress()) | ||
|
||
msg := types.MsgEnableCCTX{ | ||
Creator: policyAccount.Address.String(), | ||
EnableInbound: true, | ||
EnableOutbound: false, | ||
} | ||
|
||
err = msg.ValidateBasic() | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), err.Error()), nil, err | ||
} | ||
|
||
txCtx := simulation.OperationInput{ | ||
R: r, | ||
App: app, | ||
TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, | ||
Cdc: nil, | ||
Msg: &msg, | ||
MsgType: msg.Type(), | ||
Context: ctx, | ||
SimAccount: policyAccount, | ||
AccountKeeper: k.GetAuthKeeper(), | ||
Bankkeeper: k.GetBankKeeper(), | ||
ModuleName: types.ModuleName, | ||
CoinsSpentInMsg: spendable, | ||
} | ||
|
||
return simulation.GenAndDeliverTxWithRandFees(txCtx) | ||
} | ||
} |
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,65 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
"github.com/zeta-chain/node/testutil/sample" | ||
"github.com/zeta-chain/node/x/observer/keeper" | ||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
// SimulateMsgUpdateKeygen generates a MsgUpdateKeygen and delivers it. | ||
func SimulateMsgUpdateKeygen(k keeper.Keeper) simtypes.Operation { | ||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string, | ||
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { | ||
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts) | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUpdateKeygen, err.Error()), nil, nil | ||
} | ||
|
||
authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address) | ||
spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress()) | ||
|
||
_, found := k.GetKeygen(ctx) | ||
if !found { | ||
kg := sample.KeygenFromRand(r) | ||
k.SetKeygen(ctx, kg) | ||
} | ||
|
||
blockHeighMin := ctx.BlockHeight() + 11 | ||
blockHeighMax := ctx.BlockHeight() + 1000 | ||
keygenBlockHeight := int64(r.Intn(int(blockHeighMax-blockHeighMin))) + blockHeighMin | ||
|
||
msg := types.MsgUpdateKeygen{ | ||
Creator: policyAccount.Address.String(), | ||
Block: keygenBlockHeight, | ||
} | ||
|
||
err = msg.ValidateBasic() | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), err.Error()), nil, err | ||
} | ||
|
||
txCtx := simulation.OperationInput{ | ||
R: r, | ||
App: app, | ||
TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, | ||
Cdc: nil, | ||
Msg: &msg, | ||
MsgType: msg.Type(), | ||
Context: ctx, | ||
SimAccount: policyAccount, | ||
AccountKeeper: k.GetAuthKeeper(), | ||
Bankkeeper: k.GetBankKeeper(), | ||
ModuleName: types.ModuleName, | ||
CoinsSpentInMsg: spendable, | ||
} | ||
|
||
return simulation.GenAndDeliverTxWithRandFees(txCtx) | ||
} | ||
} |
Oops, something went wrong.