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 24, 2023
1 parent 5e1d2e1 commit 0fe0539
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 39 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/simulation-tests.yaml
Original file line number Diff line number Diff line change
@@ -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
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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions interchaintest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
54 changes: 46 additions & 8 deletions x/fiattokenfactory/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
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/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/testutil/sample"
tokenfactorysimulation "github.com/strangelove-ventures/noble/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 0fe0539

Please sign in to comment.