@@ -16,9 +16,13 @@ import (
16
16
"github.com/cometbft/cometbft/types"
17
17
tmtime "github.com/cometbft/cometbft/types/time"
18
18
19
+ dbm "github.com/cosmos/cosmos-db"
20
+
21
+ "cosmossdk.io/log"
19
22
"cosmossdk.io/math"
20
- "cosmossdk.io/simapp "
23
+ pruningtypes "cosmossdk.io/store/pruning/types "
21
24
25
+ bam "github.com/cosmos/cosmos-sdk/baseapp"
22
26
"github.com/cosmos/cosmos-sdk/client"
23
27
"github.com/cosmos/cosmos-sdk/client/flags"
24
28
"github.com/cosmos/cosmos-sdk/client/tx"
@@ -28,15 +32,20 @@ import (
28
32
"github.com/cosmos/cosmos-sdk/runtime"
29
33
"github.com/cosmos/cosmos-sdk/server"
30
34
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
35
+ servertypes "github.com/cosmos/cosmos-sdk/server/types"
31
36
"github.com/cosmos/cosmos-sdk/testutil"
32
37
"github.com/cosmos/cosmos-sdk/testutil/network"
38
+ simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
33
39
sdk "github.com/cosmos/cosmos-sdk/types"
34
40
"github.com/cosmos/cosmos-sdk/types/module"
41
+ moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
35
42
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
36
43
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
37
44
"github.com/cosmos/cosmos-sdk/x/genutil"
38
45
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
39
46
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
47
+
48
+ gaia "github.com/cosmos/gaia/v25/app"
40
49
)
41
50
42
51
var (
@@ -230,13 +239,13 @@ func initTestnetFiles(
230
239
nodeIDs := make ([]string , args .numValidators )
231
240
valPubKeys := make ([]cryptotypes.PubKey , args .numValidators )
232
241
233
- simappConfig := srvconfig .DefaultConfig ()
234
- simappConfig .MinGasPrices = args .minGasPrices
235
- simappConfig .API .Enable = true
236
- simappConfig .Telemetry .Enabled = true
237
- simappConfig .Telemetry .PrometheusRetentionTime = 60
238
- simappConfig .Telemetry .EnableHostnameLabel = false
239
- simappConfig .Telemetry .GlobalLabels = [][]string {{"chain_id" , args .chainID }}
242
+ gaiadConfig := srvconfig .DefaultConfig ()
243
+ gaiadConfig .MinGasPrices = args .minGasPrices
244
+ gaiadConfig .API .Enable = true
245
+ gaiadConfig .Telemetry .Enabled = true
246
+ gaiadConfig .Telemetry .PrometheusRetentionTime = 60
247
+ gaiadConfig .Telemetry .EnableHostnameLabel = false
248
+ gaiadConfig .Telemetry .GlobalLabels = [][]string {{"chain_id" , args .chainID }}
240
249
241
250
var (
242
251
genAccounts []authtypes.GenesisAccount
@@ -354,7 +363,7 @@ func initTestnetFiles(
354
363
return err
355
364
}
356
365
357
- srvconfig .WriteConfigFile (filepath .Join (nodeDir , "config" , "app.toml" ), simappConfig )
366
+ srvconfig .WriteConfigFile (filepath .Join (nodeDir , "config" , "app.toml" ), gaiadConfig )
358
367
}
359
368
360
369
if err := initGenFiles (clientCtx , mbm , args .chainID , genAccounts , genBalances , genFiles , args .numValidators ); err != nil {
@@ -508,7 +517,7 @@ func writeFile(name string, dir string, contents []byte) error {
508
517
509
518
// startTestnet starts an in-process testnet
510
519
func startTestnet (cmd * cobra.Command , args startArgs ) error {
511
- networkConfig := network .DefaultConfig (simapp . NewTestNetworkFixture )
520
+ networkConfig := network .DefaultConfig (NewTestNetworkFixture )
512
521
513
522
// Default networkConfig.ChainID is random, and we should only override it if chainID provided
514
523
// is non-empty
@@ -548,3 +557,50 @@ func startTestnet(cmd *cobra.Command, args startArgs) error {
548
557
549
558
return nil
550
559
}
560
+
561
+ // NewTestNetworkFixture returns a new gaiad AppConstructor for network simulation tests
562
+ func NewTestNetworkFixture () network.TestFixture {
563
+ dir , err := os .MkdirTemp ("" , "gaia" )
564
+ if err != nil {
565
+ panic (fmt .Sprintf ("failed creating temporary directory: %v" , err ))
566
+ }
567
+ defer os .RemoveAll (dir )
568
+
569
+ app := gaia .NewGaiaApp (
570
+ log .NewNopLogger (),
571
+ dbm .NewMemDB (),
572
+ nil ,
573
+ true ,
574
+ nil ,
575
+ dir ,
576
+ simtestutil .NewAppOptionsWithFlagHome (dir ),
577
+ nil ,
578
+ )
579
+
580
+ appCtr := func (val network.ValidatorI ) servertypes.Application {
581
+ return gaia .NewGaiaApp (
582
+ log .NewNopLogger (),
583
+ dbm .NewMemDB (),
584
+ nil ,
585
+ true ,
586
+ nil ,
587
+ val .GetCtx ().Config .RootDir ,
588
+ simtestutil .NewAppOptionsWithFlagHome (val .GetCtx ().Config .RootDir ),
589
+ nil ,
590
+ bam .SetPruning (pruningtypes .NewPruningOptionsFromString (val .GetAppConfig ().Pruning )),
591
+ bam .SetMinGasPrices (val .GetAppConfig ().MinGasPrices ),
592
+ bam .SetChainID (val .GetCtx ().Viper .GetString (flags .FlagChainID )),
593
+ )
594
+ }
595
+
596
+ return network.TestFixture {
597
+ AppConstructor : appCtr ,
598
+ GenesisState : app .DefaultGenesis (),
599
+ EncodingConfig : moduletestutil.TestEncodingConfig {
600
+ InterfaceRegistry : app .InterfaceRegistry (),
601
+ Codec : app .AppCodec (),
602
+ TxConfig : app .GetTxConfig (),
603
+ Amino : app .LegacyAmino (),
604
+ },
605
+ }
606
+ }
0 commit comments