Skip to content

Commit

Permalink
chore: fix simulation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Oct 19, 2023
1 parent d4e5e04 commit 20e6593
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 36 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/simulation-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Simulation Tests

on:
pull_request:

jobs:
unit-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: Run Unit Tests
run: go test -bench BenchmarkSimulation ./app
27 changes: 9 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231018130830-bf303b3705b1
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231019114513-a6520a57a461
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.5
github.com/strangelove-ventures/paramauthority v1.0.0
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -152,14 +152,17 @@ require (
)

replace (
github.com/circlefin/noble-cctp => github.com/noble-assets/cctp v0.0.0-20231018131215-a07aa6aabfe1
github.com/circlefin/noble-cctp => github.com/noble-assets/cctp v0.0.0-20231019114700-3d5428242889

// huckleberry patch for ibc-go v3
github.com/cosmos/ibc-go/v3 => github.com/noble-assets/ibc-go/v3 v3.4.0-huckleberry

// use cosmos-flavored protocol buffers
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

//
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

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,12 @@ 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/cctp v0.0.0-20231018131215-a07aa6aabfe1 h1:PAW4/KmcTDa4vLZdRDWw5g3olezmTrwCsT559Ympty0=
github.com/noble-assets/cctp v0.0.0-20231018131215-a07aa6aabfe1/go.mod h1:hEq08yRBU0cePndr6v1FbpxacRAcrG6itSxChd0wh00=
github.com/noble-assets/cctp v0.0.0-20231019114700-3d5428242889 h1:yvjNYnMXaWF/E/WiuiY41VJ8fn011D/voaLBuHwdom4=
github.com/noble-assets/cctp v0.0.0-20231019114700-3d5428242889/go.mod h1:Pb30lYT/cjR34/hi8C4W/6acu954bCSg1X0uoG/NzdE=
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=
Expand Down Expand Up @@ -951,12 +953,10 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/spf13/viper v1.14.0 h1:Rg7d3Lo706X9tHsJMUjdiwMpHB7W8WnSVOssIY+JElU=
github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+egj8As=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231018130830-bf303b3705b1 h1:3E6BRPbN6mxIiTEcv2jMHdA6YrMgSVAIIETBfJmf600=
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231018130830-bf303b3705b1/go.mod h1:r9Dvf0pG2TL04AeXKBfZFr1cNkXPlbdqxRkbFFT/BnA=
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231019114513-a6520a57a461 h1:sVN7D3WeI4UmppvJR1VCXY8wDiSJNzUTLkBIl5a+TkM=
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231019114513-a6520a57a461/go.mod h1:r9Dvf0pG2TL04AeXKBfZFr1cNkXPlbdqxRkbFFT/BnA=
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=
Expand Down
2 changes: 1 addition & 1 deletion interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ethereum/go-ethereum v1.12.2
github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845
github.com/strangelove-ventures/interchaintest/v3 v3.0.0-20230622221919-28c608364e27
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231018130830-bf303b3705b1
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231019114513-a6520a57a461
github.com/strangelove-ventures/noble/v4 v4.0.0
github.com/strangelove-ventures/paramauthority v1.0.0
github.com/stretchr/testify v1.8.4
Expand Down
1 change: 1 addition & 0 deletions interchaintest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ github.com/strangelove-ventures/interchaintest/v3 v3.0.0-20230622221919-28c60836
github.com/strangelove-ventures/interchaintest/v3 v3.0.0-20230622221919-28c608364e27/go.mod h1:dWv7E8XtgidmA/A5Gy9x76qMIygES+SxPTnlWjYUb7g=
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231018130830-bf303b3705b1 h1:3E6BRPbN6mxIiTEcv2jMHdA6YrMgSVAIIETBfJmf600=
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231018130830-bf303b3705b1/go.mod h1:r9Dvf0pG2TL04AeXKBfZFr1cNkXPlbdqxRkbFFT/BnA=
github.com/strangelove-ventures/noble/v3 v3.1.1-0.20231019114513-a6520a57a461/go.mod h1:r9Dvf0pG2TL04AeXKBfZFr1cNkXPlbdqxRkbFFT/BnA=
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=
Expand Down
30 changes: 30 additions & 0 deletions x/tariff/module_simulation.go
Original file line number Diff line number Diff line change
@@ -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/v4/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
}
48 changes: 40 additions & 8 deletions x/tokenfactory/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/v4/testutil/sample"
tokenfactorysimulation "github.com/strangelove-ventures/noble/v4/x/tokenfactory/simulation"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 20e6593

Please sign in to comment.