-
Notifications
You must be signed in to change notification settings - Fork 110
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
7 changed files
with
201 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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" | ||
) | ||
|
||
// SimulateMsgRemoveChainParams generates a MsgRemoveChainParams and delivers it. | ||
func SimulateMsgRemoveChainParams(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.TypeMsgRemoveChainParams, err.Error()), nil, nil | ||
} | ||
|
||
authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address) | ||
spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress()) | ||
|
||
supportedChains := k.GetSupportedChains(ctx) | ||
if len(supportedChains) == 0 { | ||
return simtypes.NoOpMsg( | ||
types.ModuleName, | ||
types.TypeMsgRemoveChainParams, | ||
"no supported chains found", | ||
), nil, nil | ||
} | ||
|
||
randomChainId := int64(0) | ||
// remove zeta chain from the supported chains | ||
for { | ||
c := supportedChains[r.Intn(len(supportedChains))] | ||
if !c.IsZetaChain() { | ||
randomChainId = c.ChainId | ||
break | ||
} | ||
} | ||
|
||
msg := types.MsgRemoveChainParams{ | ||
Creator: policyAccount.Address.String(), | ||
ChainId: randomChainId, | ||
} | ||
|
||
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,74 @@ | ||
package simulation | ||
|
||
import ( | ||
"fmt" | ||
"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" | ||
) | ||
|
||
// SimulateMsgResetChainNonces generates a MsgResetChainNonces and delivers it. | ||
func SimulateMsgResetChainNonces(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.TypeMsgResetChainNonces, err.Error()), nil, nil | ||
} | ||
|
||
authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address) | ||
spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress()) | ||
|
||
randomChain, err := GetExternalChain(ctx, k, r, 100) | ||
if err != nil { | ||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgResetChainNonces, err.Error()), nil, fmt.Errorf("error getting external chain") | ||
} | ||
|
||
tss, found := k.GetTSS(ctx) | ||
if !found { | ||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgResetChainNonces, "TSS not found"), nil, fmt.Errorf("TSS not found") | ||
} | ||
pendingNonces, found := k.GetPendingNonces(ctx, tss.TssPubkey, randomChain.ChainId) | ||
if !found { | ||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgResetChainNonces, "Pending nonces not found"), nil, | ||
fmt.Errorf("pending nonces not found for chain %d %s", randomChain.ChainId, randomChain.ChainName) | ||
} | ||
|
||
nonceIncrement := int64(r.Intn(100-1)) + 1 | ||
|
||
msg := types.MsgResetChainNonces{ | ||
Creator: policyAccount.Address.String(), | ||
ChainId: randomChain.ChainId, | ||
ChainNonceHigh: pendingNonces.NonceHigh + nonceIncrement, | ||
ChainNonceLow: pendingNonces.NonceLow + nonceIncrement, | ||
} | ||
|
||
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
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