diff --git a/.github/workflows/simulation-tests.yaml b/.github/workflows/simulation-tests.yaml new file mode 100644 index 00000000..9196c8d3 --- /dev/null +++ b/.github/workflows/simulation-tests.yaml @@ -0,0 +1,28 @@ +name: Simulation Tests + +on: + pull_request: + +jobs: + simulation-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.GITAUTH }}" | base64 -d > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + ssh-keyscan github.com >> ~/.ssh/known_hosts + export GOPRIVATE=github.com/circlefin/noble-cctp + git config --global --add url."git@github.com:circlefin/noble-cctp.git".insteadOf "https://github.com/circlefin/noble-cctp" + + - name: Run Unit Tests + run: go test -bench BenchmarkSimulation ./app diff --git a/app/app.go b/app/app.go index 1dbe1213..4894fda2 100644 --- a/app/app.go +++ b/app/app.go @@ -380,7 +380,9 @@ func New( // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper = *app.StakingKeeper.SetHooks(app.SlashingKeeper.Hooks()) + app.StakingKeeper = *app.StakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), + ) // ... other modules keepers @@ -517,7 +519,7 @@ func New( capability.NewAppModule(appCodec, *app.CapabilityKeeper), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, &app.StakingKeeper), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), paramauthorityupgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), @@ -597,11 +599,11 @@ func New( // so that other modules that want to create or claim capabilities afterwards in InitChain // can do so safely. app.mm.SetOrderInitGenesis( - stakingtypes.ModuleName, capabilitytypes.ModuleName, ibctransfertypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, + stakingtypes.ModuleName, tarifftypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, @@ -640,21 +642,10 @@ func New( ) // create the simulation manager and define the order of the modules for deterministic simulations - app.sm = module.NewSimulationManager( - auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), - authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - capability.NewAppModule(appCodec, *app.CapabilityKeeper), - feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, &app.StakingKeeper), - paramauthority.NewAppModule(app.ParamsKeeper), - evidence.NewAppModule(app.EvidenceKeeper), - ibc.NewAppModule(app.IBCKeeper), - transferModule, - tokenfactoryModule, - fiattokenfactorymodule, - ) + overrideModules := map[string]module.AppModuleSimulation{ + authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), + } + app.sm = module.NewSimulationManagerFromAppModules(app.mm.Modules, overrideModules) app.sm.RegisterStoreDecoders() // initialize stores diff --git a/app/simulation_test.go b/app/simulation_test.go index c0c387f6..a9113b60 100644 --- a/app/simulation_test.go +++ b/app/simulation_test.go @@ -41,8 +41,11 @@ type SimApp interface { // Running as go benchmark test: // `go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true` func BenchmarkSimulation(b *testing.B) { - simapp.FlagEnabledValue = true + simapp.FlagNumBlocksValue = 250 + simapp.FlagBlockSizeValue = 50 simapp.FlagCommitValue = true + simapp.FlagVerboseValue = true + simapp.FlagEnabledValue = true config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation") require.NoError(b, err, "simulation setup failed") diff --git a/go.mod b/go.mod index 86cb981b..a7b6b5b5 100644 --- a/go.mod +++ b/go.mod @@ -161,6 +161,9 @@ replace ( // use cosmos-flavored protocol buffers github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 + // use simulation compatible strangelove-ventures/paramauthority + github.com/strangelove-ventures/paramauthority => github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0 + // cometbft github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27 diff --git a/go.sum b/go.sum index 5a74eeff..06d14b3e 100644 --- a/go.sum +++ b/go.sum @@ -767,6 +767,8 @@ github.com/neilotoole/errgroup v0.1.6/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/noble-assets/ibc-go/v3 v3.4.0-huckleberry h1:02oo/GHLGITexbPNUO/jmYa67xE+B5BvNv/i+wufdHI= github.com/noble-assets/ibc-go/v3 v3.4.0-huckleberry/go.mod h1:VwB/vWu4ysT5DN2aF78d17LYmx3omSAdq6gpKvM7XRA= +github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0 h1:+D+62FTPcn63gaFuI8FDeOl5lAUw2b5NvrMfMxOMGiA= +github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0/go.mod h1:31HVpoItQMa4Wj2BimVhQWbIYeb+kdUDJ8MzBEbGj28= github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= @@ -952,8 +954,6 @@ github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+eg github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.5 h1:iXXjziCSAebzuRUPFSnqD7epSDB8LEPgkh9zhbj7ha4= github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.5/go.mod h1:ncgsf5rykh36HkM16BNcKKx1XzVRdWXt+4pph1syDHE= -github.com/strangelove-ventures/paramauthority v1.0.0 h1:kgWsSfkiBh25ZZyt/ZQUwXEVdFknX9YIdEWDm1X7AWg= -github.com/strangelove-ventures/paramauthority v1.0.0/go.mod h1:31HVpoItQMa4Wj2BimVhQWbIYeb+kdUDJ8MzBEbGj28= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= diff --git a/interchaintest/go.mod b/interchaintest/go.mod index 43e2eb87..c46a1914 100644 --- a/interchaintest/go.mod +++ b/interchaintest/go.mod @@ -189,6 +189,8 @@ replace ( // For this nested module, you always want to replace the parent reference with the current worktree. github.com/strangelove-ventures/noble => ../ + github.com/strangelove-ventures/paramauthority => github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0 + // cometbft github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27 diff --git a/interchaintest/go.sum b/interchaintest/go.sum index fe95069e..5ccc5f8a 100644 --- a/interchaintest/go.sum +++ b/interchaintest/go.sum @@ -807,6 +807,8 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/neilotoole/errgroup v0.1.6/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C2S41udRnToE= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0 h1:+D+62FTPcn63gaFuI8FDeOl5lAUw2b5NvrMfMxOMGiA= +github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0/go.mod h1:31HVpoItQMa4Wj2BimVhQWbIYeb+kdUDJ8MzBEbGj28= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -1003,8 +1005,6 @@ github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jH github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/strangelove-ventures/interchaintest/v3 v3.0.0-20230622221919-28c608364e27 h1:oJ9yZIFp3yRTlH8BOLnACrsjR1fPIpHyOoLFjM5VRBc= github.com/strangelove-ventures/interchaintest/v3 v3.0.0-20230622221919-28c608364e27/go.mod h1:dWv7E8XtgidmA/A5Gy9x76qMIygES+SxPTnlWjYUb7g= -github.com/strangelove-ventures/paramauthority v1.0.0 h1:kgWsSfkiBh25ZZyt/ZQUwXEVdFknX9YIdEWDm1X7AWg= -github.com/strangelove-ventures/paramauthority v1.0.0/go.mod h1:31HVpoItQMa4Wj2BimVhQWbIYeb+kdUDJ8MzBEbGj28= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= diff --git a/x/fiattokenfactory/module_simulation.go b/x/fiattokenfactory/module_simulation.go index 3764b74a..7d5c174a 100644 --- a/x/fiattokenfactory/module_simulation.go +++ b/x/fiattokenfactory/module_simulation.go @@ -8,6 +8,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/strangelove-ventures/noble/testutil/sample" tokenfactorysimulation "github.com/strangelove-ventures/noble/x/fiattokenfactory/simulation" @@ -85,15 +87,51 @@ const ( // GenerateGenesisState creates a randomized GenState of the module func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - accs := make([]string, len(simState.Accounts)) - for i, acc := range simState.Accounts { - accs[i] = acc.Address.String() - } - tokenfactoryGenesis := types.GenesisState{ - Params: types.DefaultParams(), - // this line is used by starport scaffolding # simapp/module/genesisState + // x/fiattokenfactory + + genesis := types.GenesisState{ + MintersList: []types.Minters{ + { + Address: authtypes.NewModuleAddress("cctp").String(), + }, + }, + MinterControllerList: []types.MinterController{ + { + Minter: authtypes.NewModuleAddress("cctp").String(), + }, + }, + MintingDenom: &types.MintingDenom{Denom: "uusdc"}, } - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&tokenfactoryGenesis) + + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&genesis) + + // x/bank + + bankGenesisBz := simState.GenState[banktypes.ModuleName] + var bankGenesis banktypes.GenesisState + simState.Cdc.MustUnmarshalJSON(bankGenesisBz, &bankGenesis) + + bankGenesis.DenomMetadata = append(bankGenesis.DenomMetadata, banktypes.Metadata{ + Description: "USD Coin", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "uusdc", + Exponent: 0, + Aliases: []string{"microusdc"}, + }, + { + Denom: "usdc", + Exponent: 6, + Aliases: []string{}, + }, + }, + Base: "uusdc", + Display: "usdc", + Name: "usdc", + Symbol: "USDC", + }) + + simState.GenState[banktypes.ModuleName] = simState.Cdc.MustMarshalJSON(&bankGenesis) } // ProposalContents doesn't return any content functions for governance proposals diff --git a/x/tariff/module_simulation.go b/x/tariff/module_simulation.go new file mode 100644 index 00000000..d4a7ea8d --- /dev/null +++ b/x/tariff/module_simulation.go @@ -0,0 +1,30 @@ +package tariff + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/strangelove-ventures/noble/x/tariff/types" + "math/rand" +) + +var _ module.AppModuleSimulation = AppModule{} + +func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { + genesis := types.DefaultGenesis() + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(genesis) +} + +func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { + return nil +} + +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return nil +} diff --git a/x/tokenfactory/module_simulation.go b/x/tokenfactory/module_simulation.go index 6b5398a9..dad09a17 100644 --- a/x/tokenfactory/module_simulation.go +++ b/x/tokenfactory/module_simulation.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/strangelove-ventures/noble/testutil/sample" tokenfactorysimulation "github.com/strangelove-ventures/noble/x/tokenfactory/simulation" @@ -85,15 +86,46 @@ const ( // GenerateGenesisState creates a randomized GenState of the module func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - accs := make([]string, len(simState.Accounts)) - for i, acc := range simState.Accounts { - accs[i] = acc.Address.String() - } - tokenfactoryGenesis := types.GenesisState{ - Params: types.DefaultParams(), - // this line is used by starport scaffolding # simapp/module/genesisState + // x/tokenfactory + + genesis := types.GenesisState{ + MintingDenom: &types.MintingDenom{Denom: "ufrienzies"}, } - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&tokenfactoryGenesis) + + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&genesis) + + // x/bank + + bankGenesisBz := simState.GenState[banktypes.ModuleName] + var bankGenesis banktypes.GenesisState + simState.Cdc.MustUnmarshalJSON(bankGenesisBz, &bankGenesis) + + bankGenesis.DenomMetadata = append(bankGenesis.DenomMetadata, banktypes.Metadata{ + Description: "Frienzies are an IBC token redeemable exclusively for a physical asset issued by the Noble entity.", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "ufrienzies", + Exponent: 0, + Aliases: []string{"microfrienzies"}, + }, + { + Denom: "mfrienzies", + Exponent: 3, + Aliases: []string{"millifrienzies"}, + }, + { + Denom: "frienzies", + Exponent: 6, + Aliases: []string{}, + }, + }, + Base: "ufrienzies", + Display: "frienzies", + Name: "frienzies", + Symbol: "FRNZ", + }) + + simState.GenState[banktypes.ModuleName] = simState.Cdc.MustMarshalJSON(&bankGenesis) } // ProposalContents doesn't return any content functions for governance proposals