Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package simulation
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/rand"
|
|
"strings"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
|
|
|
"github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
|
|
)
|
|
|
|
// Simulation parameter constants
|
|
const port = "port_id"
|
|
|
|
// RandomEnabled randomized send or receive enabled param with 75% prob of being true.
|
|
func RandomEnabled(r *rand.Rand) bool {
|
|
return r.Int63n(101) <= 75
|
|
}
|
|
|
|
// RandomizedGenState generates a random GenesisState for transfer.
|
|
func RandomizedGenState(simState *module.SimulationState) {
|
|
var portID string
|
|
simState.AppParams.GetOrGenerate(
|
|
port, &portID, simState.Rand,
|
|
func(r *rand.Rand) { portID = strings.ToLower(simtypes.RandStringOfLength(r, 20)) },
|
|
)
|
|
|
|
var sendEnabled bool
|
|
simState.AppParams.GetOrGenerate(
|
|
string(types.KeySendEnabled), &sendEnabled, simState.Rand,
|
|
func(r *rand.Rand) { sendEnabled = RandomEnabled(r) },
|
|
)
|
|
|
|
var receiveEnabled bool
|
|
simState.AppParams.GetOrGenerate(
|
|
string(types.KeyReceiveEnabled), &receiveEnabled, simState.Rand,
|
|
func(r *rand.Rand) { receiveEnabled = RandomEnabled(r) },
|
|
)
|
|
|
|
transferGenesis := types.GenesisState{
|
|
PortId: portID,
|
|
Denoms: types.Denoms{},
|
|
Params: types.NewParams(sendEnabled, receiveEnabled),
|
|
}
|
|
|
|
bz, err := json.MarshalIndent(&transferGenesis, "", " ")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
|
|
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&transferGenesis)
|
|
}
|