Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests/integrations): Port gov integration tests with server v2 setup #22850

Merged
merged 12 commits into from
Dec 13, 2024
6 changes: 5 additions & 1 deletion runtime/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"cosmossdk.io/core/branch"
"cosmossdk.io/core/comet"
"cosmossdk.io/core/event"
"cosmossdk.io/core/gas"
"cosmossdk.io/core/header"
"cosmossdk.io/core/registry"
"cosmossdk.io/core/router"
Expand Down Expand Up @@ -214,6 +215,7 @@ func ProvideEnvironment(
kvService store.KVStoreService,
memKvService store.MemoryStoreService,
headerService header.Service,
gasService gas.Service,
eventService event.Service,
branchService branch.Service,
routerBuilder RouterServiceBuilder,
Expand All @@ -222,7 +224,7 @@ func ProvideEnvironment(
Logger: logger,
BranchService: branchService,
EventService: eventService,
GasService: stf.NewGasMeterService(),
GasService: gasService,
HeaderService: headerService,
QueryRouterService: routerBuilder.BuildQueryRouter(),
MsgRouterService: routerBuilder.BuildMsgRouter([]byte(key.Name())),
Expand Down Expand Up @@ -296,6 +298,7 @@ func DefaultServiceBindings() depinject.Config {
eventService = services.NewGenesisEventService(stf.NewEventService())
storeBuilder = root.NewBuilder()
branchService = stf.BranchService{}
gasService = stf.NewGasMeterService()
)
return depinject.Supply(
kvServiceFactory,
Expand All @@ -305,5 +308,6 @@ func DefaultServiceBindings() depinject.Config {
eventService,
storeBuilder,
branchService,
gasService,
)
}
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
cosmossdk.io/x/staking v0.0.0-20240226161501-23359a0b6d91
github.com/cometbft/cometbft/api v1.0.0-rc2
github.com/cosmos/cosmos-db v1.1.0
github.com/gogo/protobuf v1.3.2
github.com/google/go-cmp v0.6.0
github.com/google/gofuzz v1.2.0
github.com/jhump/protoreflect v1.17.0
Expand Down Expand Up @@ -126,7 +127,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down
9 changes: 8 additions & 1 deletion tests/integration/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
corebranch "cosmossdk.io/core/branch"
"cosmossdk.io/core/comet"
corecontext "cosmossdk.io/core/context"
"cosmossdk.io/core/gas"
"cosmossdk.io/core/header"
"cosmossdk.io/core/server"
corestore "cosmossdk.io/core/store"
Expand Down Expand Up @@ -99,6 +100,8 @@
RouterServiceBuilder runtime.RouterServiceBuilder
// HeaderService defines the custom header service to be used in the app.
HeaderService header.Service

GasService gas.Service
}

func DefaultStartUpConfig(t *testing.T) StartupConfig {
Expand Down Expand Up @@ -129,6 +132,7 @@
stf.NewMsgRouterService, stf.NewQueryRouterService(),
),
HeaderService: services.NewGenesisHeaderService(stf.HeaderService{}),
GasService: stf.NewGasMeterService(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add test coverage for GasService integration

While the GasService integration looks good, consider adding specific test cases to verify:

  1. Gas consumption tracking
  2. Gas limit enforcement
  3. Error handling for out-of-gas scenarios

Would you like me to help create these test cases or open a GitHub issue to track this task?

}
}

Expand Down Expand Up @@ -193,9 +197,11 @@
startupConfig.BranchService,
startupConfig.RouterServiceBuilder,
startupConfig.HeaderService,
startupConfig.GasService,
),
depinject.Invoke(
std.RegisterInterfaces,
std.RegisterLegacyAminoCodec,
),
),
append(extraOutputs, &appBuilder, &cdc, &txConfigOptions, &txConfig, &storeBuilder)...); err != nil {
Expand Down Expand Up @@ -336,10 +342,11 @@
require.NoError(t, err)
a.lastHeight++

// update block height if integration context is present
// update block height and block time if integration context is present
iCtx, ok := ctx.Value(contextKey).(*integrationContext)
if ok {
iCtx.header.Height = int64(a.lastHeight)
iCtx.header.Time = time.Now()
Fixed Show fixed Hide fixed
}
return resp, state
}
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/v2/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ type genesisTxCodec struct {
tx.ConfigOptions
}

func NewGenesisTxCodec(txConfigOptions tx.ConfigOptions) *genesisTxCodec {
return &genesisTxCodec{
txConfigOptions,
}
}

// Decode implements transaction.Codec.
func (t *genesisTxCodec) Decode(bz []byte) (stateMachineTx, error) {
var out stateMachineTx
Expand Down
Loading
Loading