diff --git a/simsx/README.md b/simsx/README.md new file mode 100644 index 0000000000000..676db329db18f --- /dev/null +++ b/simsx/README.md @@ -0,0 +1,44 @@ +# Simsx + +This package introduces some new helper types to simplify message construction for simulations (sims). The focus is on better dev UX for new message factories. +Technically, they are adapters that build upon the existing sims framework. + +#### * [Message factory](https://github.com/cosmos/cosmos-sdk/blob/main/simsx/msg_factory.go) + +Simple functions as factories for dedicated sdk.Msgs. They have access to the context, reporter and test data environment. For example: +```go +func MsgSendFactory() simsx.SimMsgFactoryFn[*types.MsgSend] { + return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgSend) { + from := testData.AnyAccount(reporter, simsx.WithSpendableBalance()) + to := testData.AnyAccount(reporter, simsx.ExcludeAccounts(from)) + coins := from.LiquidBalance().RandSubsetCoins(reporter, simsx.WithSendEnabledCoins()) + return []simsx.SimAccount{from}, types.NewMsgSend(from.AddressBech32, to.AddressBech32, coins) + } +} +``` + + +#### * [Sims registry](https://github.com/cosmos/cosmos-sdk/blob/main/simsx/registry.go) + +A new helper to register message factories with a default weight value. They can be overwritten by a parameters file as before. The registry is passed to the AppModule type. For example: +```go +func (am AppModule) WeightedOperationsX(weights simsx.WeightSource, reg simsx.Registry) { + reg.Add(weights.Get("msg_send", 100), simulation.MsgSendFactory()) + reg.Add(weights.Get("msg_multisend", 10), simulation.MsgMultiSendFactory()) +} +``` +#### * [Reporter](https://github.com/cosmos/cosmos-sdk/blob/main/simsx/reporter.go) +The reporter is a flow control structure that can be used in message factories to skip execution at any point. The idea is similar to the testing.T Skip in Go stdlib. Internally, it converts skip, success and failure events to legacy sim messages. +The reporter also provides some capability to print an execution summary. +It is also used to interact with the test data environment to not have errors checked all the time. +Message factories may want to abort early via +```go +if reporter.IsSkipped() { + return nil, nil +} + +``` + +#### * [Test data environment](https://github.com/cosmos/cosmos-sdk/blob/main/simsx/environment.go) +The test data environment provides simple access to accounts and other test data used in most message factories. It also encapsulates some app internals like bank keeper or address codec. + diff --git a/tests/go.mod b/tests/go.mod index 5f71d75c54b8f..220776558ce67 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -33,6 +33,7 @@ require ( ) require ( + cosmossdk.io/core/testing v0.0.0-00010101000000-000000000000 cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5 cosmossdk.io/x/accounts/defaults/multisig v0.0.0-00010101000000-000000000000 @@ -62,7 +63,6 @@ require ( cloud.google.com/go/iam v1.1.13 // indirect cloud.google.com/go/storage v1.43.0 // indirect cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860 // indirect - cosmossdk.io/core/testing v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/schema v0.2.0 // indirect cosmossdk.io/x/circuit v0.0.0-20230613133644-0a778132a60f // indirect diff --git a/x/distribution/go.mod b/x/distribution/go.mod index b083a5dea6712..cb1bee88588ec 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -24,7 +24,6 @@ require ( github.com/stretchr/testify v1.9.0 google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 google.golang.org/grpc v1.66.1 - gotest.tools/v3 v3.5.1 ) require ( @@ -164,6 +163,7 @@ require ( google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + gotest.tools/v3 v3.5.1 // indirect pgregory.net/rapid v1.1.0 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/x/mint/go.mod b/x/mint/go.mod index df69ad65ce28e..593fd09e1aac8 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -23,7 +23,7 @@ require ( github.com/stretchr/testify v1.9.0 google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 google.golang.org/grpc v1.66.1 - gotest.tools/v3 v3.5.1 + gotest.tools/v3 v3.5.1 // indirect ) require ( diff --git a/x/params/go.mod b/x/params/go.mod index b198da8e56dd6..8efe68afca13b 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -30,8 +30,6 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/schema v0.2.0 // indirect - cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect - cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v0.13.3 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -82,8 +80,6 @@ require ( github.com/google/btree v1.1.2 // indirect github.com/google/flatbuffers v2.0.8+incompatible // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/google/orderedcode v0.0.1 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/gorilla/handlers v1.5.2 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.3 // indirect @@ -94,7 +90,6 @@ require ( github.com/hashicorp/go-metrics v0.5.3 // indirect github.com/hashicorp/go-plugin v1.6.1 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/hdevalence/ed25519consensus v0.2.0 // indirect @@ -105,12 +100,10 @@ require ( github.com/klauspost/compress v1.17.9 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect - github.com/lib/pq v1.10.9 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/minio/highwayhash v1.0.3 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect @@ -127,7 +120,6 @@ require ( github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect - github.com/rs/cors v1.11.0 // indirect github.com/rs/zerolog v1.33.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect