Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Jul 3, 2024
1 parent e903d9f commit 14ac05a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
3 changes: 1 addition & 2 deletions e2e/random/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type QueryTestSuite struct {

// SetupSuite sets up test suite
func (s *QueryTestSuite) SetupSuite() {
s.SetModifyConfigFn(func(cfg *network.Config) {
s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) {
var serviceGenState servicetypes.GenesisState
cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenState)

Expand All @@ -43,7 +43,6 @@ func (s *QueryTestSuite) SetupSuite() {
)
cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenState)
})
s.TestSuite.SetupSuite()
}

// TestQueryCmd tests all query command in the nft module
Expand Down
3 changes: 1 addition & 2 deletions e2e/random/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TxTestSuite struct {

// SetupSuite sets up test suite
func (s *TxTestSuite) SetupSuite() {
s.SetModifyConfigFn(func(cfg *network.Config) {
s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) {
var serviceGenState servicetypes.GenesisState
cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenState)

Expand All @@ -42,7 +42,6 @@ func (s *TxTestSuite) SetupSuite() {
)
cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenState)
})
s.TestSuite.SetupSuite()
}

// TestTxCmd tests all tx command in the nft module
Expand Down
3 changes: 1 addition & 2 deletions e2e/service/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type QueryTestSuite struct {

// SetupSuite sets up test suite
func (s *QueryTestSuite) SetupSuite() {
s.SetModifyConfigFn(func(cfg *network.Config) {
s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) {
var serviceGenesisState servicetypes.GenesisState
cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenesisState)

Expand All @@ -36,7 +36,6 @@ func (s *QueryTestSuite) SetupSuite() {
cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenesisState)
cfg.NumValidators = 1
})
s.TestSuite.SetupSuite()
}

// TestQueryCmd tests all query command in the service module
Expand Down
3 changes: 1 addition & 2 deletions e2e/service/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TxTestSuite struct {

// SetupSuite sets up test suite
func (s *TxTestSuite) SetupSuite() {
s.SetModifyConfigFn(func(cfg *network.Config) {
s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) {
var serviceGenesisState servicetypes.GenesisState
cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenesisState)

Expand All @@ -36,7 +36,6 @@ func (s *TxTestSuite) SetupSuite() {
cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenesisState)
cfg.NumValidators = 1
})
s.TestSuite.SetupSuite()
}

// TestQueryCmd tests all query command in the service module
Expand Down
47 changes: 26 additions & 21 deletions e2e/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,44 @@ type ModifyConfigFn = func(cfg *network.Config)
type TestSuite struct {
suite.Suite
simapp.Network
modifyConfigFn ModifyConfigFn

}

// SetupSuite creates a new network for integration tests
func (s *TestSuite) SetupSuite() {
// SetupSuiteWithModifyConfigFn sets up the end-to-end test suite with the given modifyConfigFn.
//
// Parameters:
// - modifyConfigFn: A function that modifies the config for the test suite.
//
// Return type: None.
func (s *TestSuite) SetupSuiteWithModifyConfigFn(modifyConfigFn ModifyConfigFn) {
s.T().Log("setting up e2e test suite")

depInjectOptions := simapp.DepinjectOptions{
Config: AppConfig,
Providers: []interface{}{
keeper.ProvideMockEVM(),
keeper.ProvideMockICS20(),
},
}
if s.modifyConfigFn == nil {
s.Network = simapp.SetupNetwork(s.T(), depInjectOptions)
return
}

cfg, err := simapp.NewConfig(depInjectOptions)
cfg, err := simapp.NewConfig(s.DepinjectOptions())
s.Require().NoError(err)

s.modifyConfigFn(&cfg)
modifyConfigFn(&cfg)
s.Network = simapp.SetupNetworkWithConfig(s.T(), cfg)
}

// SetupSuite creates a new network for integration tests
func (s *TestSuite) SetupSuite() {
s.T().Log("setting up e2e test suite")
s.Network = simapp.SetupNetwork(s.T(), s.DepinjectOptions())
}

// TearDownSuite tears down the integration test suite
func (s *TestSuite) TearDownSuite() {
s.T().Log("tearing down e2e test suite")
s.Network.Cleanup()
}

// SetModifyConfigFn sets the modify config function
func (s *TestSuite) SetModifyConfigFn(fn ModifyConfigFn) {
s.modifyConfigFn = fn
}
// DepinjectOptions returns the depinject options for the test suite
func (s *TestSuite) DepinjectOptions() simapp.DepinjectOptions {
return simapp.DepinjectOptions{
Config: AppConfig,
Providers: []interface{}{
keeper.ProvideMockEVM(),
keeper.ProvideMockICS20(),
},
}
}

0 comments on commit 14ac05a

Please sign in to comment.