Skip to content

Commit

Permalink
Migrate modules to sims2
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jul 23, 2024
1 parent d36a935 commit 661c8a2
Show file tree
Hide file tree
Showing 84 changed files with 2,089 additions and 7,394 deletions.
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func NewSimApp(
overrideModules := map[string]module.AppModuleSimulation{
authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AuthKeeper, app.AccountsKeeper, authsims.RandomGenesisAccounts),
}
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules)
app.sm = module.NewSimulationManagerFromAppModules(app.AuthKeeper, app.BankKeeper, app.ModuleManager.Modules, overrideModules)

// create, start, and load the unordered tx manager
utxDataDir := filepath.Join(homePath, "data")
Expand Down
53 changes: 53 additions & 0 deletions tests/integration/bank/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package bank_test

import (
"math/rand"
"testing"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"

authtypes "cosmossdk.io/x/auth/types"
bankkeeper "cosmossdk.io/x/bank/keeper"
banksims "cosmossdk.io/x/bank/simulation"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/simsx"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/stretchr/testify/require"
)

func FuzzBankSend(f *testing.F) {
const n = 1000
simAccs := make([]simtypes.Account, n)
for i := 0; i < n; i++ {
priv := secp256k1.GenPrivKey()
simAccs[i] = simtypes.Account{PrivKey: priv, PubKey: priv.PubKey(), Address: sdk.AccAddress(priv.PubKey().Address())}
}
s := createTestSuiteX(f, simsx.Collect(simAccs, func(a simtypes.Account) simtestutil.GenesisAccount {
return simtestutil.GenesisAccount{
GenesisAccount: authtypes.NewBaseAccount(a.Address, a.PubKey, 0, 0),
Coins: sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1_000_000_000)),
}
}))
bk, ak := s.BankKeeper, s.AccountKeeper
pCtx := s.App.BaseApp.NewContext(false)
bankWithContext := simsx.SpendableCoinserFn(func(addr sdk.AccAddress) sdk.Coins {
return bk.SpendableCoins(pCtx, addr)
})
factory := banksims.MsgSendFactory()
f.Add([]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01})
f.Fuzz(func(t *testing.T, rawSeed []byte) {
if len(rawSeed) < 8 {
t.Skip()
return
}
start := sdk.BigEndianToUint64(rawSeed[0:8])
testData := simsx.NewChainDataSource(rand.New(simulation.NewByteSource(rawSeed[8:], int64(start))), ak, bankWithContext, ak.AddressCodec(), simAccs...)
reporter := simsx.NewBasicSimulationReporter(t).WithScope(factory.MsgType())
ctx, _ := pCtx.CacheContext()
_, msg := factory(ctx, testData, reporter)
_, err := bankkeeper.NewMsgServerImpl(bk).Send(ctx, factory.Cast(msg))
require.NoError(t, err)
})
}
4 changes: 3 additions & 1 deletion tests/integration/bank/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ func TestGRPCQueryAllBalances(t *testing.T) {

for i := 0; i < numCoins; i++ {
coin := getCoin(rt)

if exists, _ := coins.Find(coin.Denom); exists {
t.Skip("duplicate denom")
}
// NewCoins sorts the denoms
coins = sdk.NewCoins(append(coins, coin)...)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func initFixture(t *testing.T) *fixture {

authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper)
distrModule := distribution.NewAppModule(cdc, distrKeeper, accountKeeper, bankKeeper, stakingKeeper, poolKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper)
distrModule := distribution.NewAppModule(cdc, distrKeeper, stakingKeeper)
poolModule := protocolpool.NewAppModule(cdc, poolKeeper, accountKeeper, bankKeeper)

addr := sdk.AccAddress(PKS[0].Address())
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/evidence/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func initFixture(tb testing.TB) *fixture {

authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper)
slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry(), cometInfoService)
evidenceModule := evidence.NewAppModule(cdc, *evidenceKeeper, cometInfoService)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func initFixture(tb testing.TB) *fixture {

authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper)
govModule := gov.NewAppModule(cdc, govKeeper, accountKeeper, bankKeeper, poolKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func initFixture(tb testing.TB) *fixture {
slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), cdc, &codec.LegacyAmino{}, stakingKeeper, authority.String())

bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper)
slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry(), cometInfoService)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func initFixture(tb testing.TB) *fixture {

authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {

authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
Expand Down
Loading

0 comments on commit 661c8a2

Please sign in to comment.