-
Notifications
You must be signed in to change notification settings - Fork 39
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
1 parent
eb8a4b8
commit 5f3ed71
Showing
7 changed files
with
205 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package simulation | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"union/x/differedack/types" | ||
) | ||
|
||
func RandomizedGenState(simstate *module.SimulationState) { | ||
tfGenesis := types.DefaultGenesis() | ||
|
||
_, err := simstate.Cdc.MarshalJSON(tfGenesis) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
simstate.GenState[types.ModuleName] = simstate.Cdc.MustMarshalJSON(tfGenesis) | ||
} |
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,115 @@ | ||
package simulation | ||
|
||
import ( | ||
"context" | ||
"math/rand" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
|
||
appparams "union/app/params" | ||
"union/x/differedack/types" | ||
) | ||
|
||
// Simulation operation weights constants | ||
// | ||
//nolint:gosec | ||
const ( | ||
OpWeightMsgWriteDifferedAck = "op_weight_write_differed_ack" | ||
) | ||
|
||
type AccountKeeper interface { | ||
GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI | ||
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI | ||
} | ||
|
||
type BankKeeper interface { | ||
simulation.BankKeeper | ||
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins | ||
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin | ||
} | ||
|
||
type DifferedAckKeeper interface { | ||
GetParams(ctx sdk.Context) (params types.Params) | ||
} | ||
|
||
func WeightedOperations( | ||
simstate *module.SimulationState, | ||
daKeeper DifferedAckKeeper, | ||
ak AccountKeeper, | ||
bk BankKeeper, | ||
) simulation.WeightedOperations { | ||
var ( | ||
weightMsgWriteDifferedAck int | ||
) | ||
|
||
simstate.AppParams.GetOrGenerate(OpWeightMsgWriteDifferedAck, &weightMsgWriteDifferedAck, nil, | ||
func(_ *rand.Rand) { | ||
weightMsgWriteDifferedAck = appparams.DefaultWeightMsgCreateDenom | ||
}, | ||
) | ||
return simulation.WeightedOperations{ | ||
simulation.NewWeightedOperation( | ||
weightMsgWriteDifferedAck, | ||
SimulateMsgWriteDifferedAck( | ||
daKeeper, | ||
ak, | ||
bk, | ||
), | ||
), | ||
} | ||
} | ||
|
||
func SimulateMsgWriteDifferedAck( | ||
keeper DifferedAckKeeper, | ||
ak AccountKeeper, | ||
bk BankKeeper, | ||
) simtypes.Operation { | ||
return func( | ||
r *rand.Rand, | ||
app *baseapp.BaseApp, | ||
ctx sdk.Context, | ||
accs []simtypes.Account, | ||
chainID string, | ||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { | ||
// TODO: Simulate ack packet | ||
msg := types.MsgWriteDifferedAck{} | ||
|
||
account, _ := simtypes.RandomAcc(r, accs) | ||
|
||
txCtx := BuildOperationInput(r, app, ctx, &msg, account, ak, bk, nil) | ||
|
||
return simulation.GenAndDeliverTxWithRandFees(txCtx) | ||
} | ||
} | ||
|
||
// BuildOperationInput helper to build object | ||
func BuildOperationInput( | ||
r *rand.Rand, | ||
app *baseapp.BaseApp, | ||
ctx sdk.Context, | ||
msg interface { | ||
sdk.Msg | ||
}, | ||
simAccount simtypes.Account, | ||
ak AccountKeeper, | ||
bk BankKeeper, | ||
deposit sdk.Coins, | ||
) simulation.OperationInput { | ||
return simulation.OperationInput{ | ||
R: r, | ||
App: app, | ||
TxGen: appparams.MakeEncodingConfig().TxConfig, | ||
Cdc: nil, | ||
Msg: msg, | ||
Context: ctx, | ||
SimAccount: simAccount, | ||
AccountKeeper: ak, | ||
Bankkeeper: bk, | ||
ModuleName: types.ModuleName, | ||
CoinsSpentInMsg: deposit, | ||
} | ||
} |
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,39 @@ | ||
package types | ||
|
||
import ( | ||
"context" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
) | ||
|
||
type BankKeeper interface { | ||
// Methods imported from bank should be defined here | ||
GetDenomMetaData(ctx context.Context, denom string) (banktypes.Metadata, bool) | ||
SetDenomMetaData(ctx context.Context, denomMetaData banktypes.Metadata) | ||
|
||
HasSupply(ctx context.Context, denom string) bool | ||
IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool) | ||
|
||
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error | ||
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error | ||
MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error | ||
BurnCoins(ctx context.Context, moduleName string, amt sdk.Coins) error | ||
|
||
SendCoins(ctx context.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error | ||
HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool | ||
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins | ||
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins | ||
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin | ||
|
||
BlockedAddr(addr sdk.AccAddress) bool | ||
} | ||
|
||
type AccountKeeper interface { | ||
GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI | ||
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI | ||
} | ||
|
||
// CommunityPoolKeeper defines the contract needed to be fulfilled for community pool interactions. | ||
type CommunityPoolKeeper interface { | ||
FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error | ||
} |
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