test(integration): port x/bank tests to server/v2 app (#21912)
This commit is contained in:
@@ -3,6 +3,7 @@ package configurator
|
||||
import (
|
||||
accountsmodulev1 "cosmossdk.io/api/cosmos/accounts/module/v1"
|
||||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
|
||||
runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2"
|
||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
|
||||
authzmodulev1 "cosmossdk.io/api/cosmos/authz/module/v1"
|
||||
@@ -440,3 +441,71 @@ func NewAppConfig(opts ...ModuleOption) depinject.Config {
|
||||
|
||||
return appconfig.Compose(&appv1alpha1.Config{Modules: modules})
|
||||
}
|
||||
|
||||
func NewAppV2Config(opts ...ModuleOption) depinject.Config {
|
||||
cfg := defaultConfig()
|
||||
for _, opt := range opts {
|
||||
opt(cfg)
|
||||
}
|
||||
|
||||
preBlockers := make([]string, 0)
|
||||
beginBlockers := make([]string, 0)
|
||||
endBlockers := make([]string, 0)
|
||||
initGenesis := make([]string, 0)
|
||||
overrides := make([]*runtimev2.StoreKeyConfig, 0)
|
||||
|
||||
for _, s := range cfg.PreBlockersOrder {
|
||||
if _, ok := cfg.ModuleConfigs[s]; ok {
|
||||
preBlockers = append(preBlockers, s)
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range cfg.BeginBlockersOrder {
|
||||
if _, ok := cfg.ModuleConfigs[s]; ok {
|
||||
beginBlockers = append(beginBlockers, s)
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range cfg.EndBlockersOrder {
|
||||
if _, ok := cfg.ModuleConfigs[s]; ok {
|
||||
endBlockers = append(endBlockers, s)
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range cfg.InitGenesisOrder {
|
||||
if _, ok := cfg.ModuleConfigs[s]; ok {
|
||||
initGenesis = append(initGenesis, s)
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := cfg.ModuleConfigs[testutil.AuthModuleName]; ok {
|
||||
overrides = append(overrides, &runtimev2.StoreKeyConfig{ModuleName: testutil.AuthModuleName, KvStoreKey: "acc"})
|
||||
}
|
||||
|
||||
runtimeConfig := &runtimev2.Module{
|
||||
AppName: "TestApp",
|
||||
PreBlockers: preBlockers,
|
||||
BeginBlockers: beginBlockers,
|
||||
EndBlockers: endBlockers,
|
||||
OverrideStoreKeys: overrides,
|
||||
GasConfig: &runtimev2.GasConfig{
|
||||
ValidateTxGasLimit: 100_000,
|
||||
QueryGasLimit: 100_000,
|
||||
SimulationGasLimit: 100_000,
|
||||
},
|
||||
}
|
||||
if cfg.setInitGenesis {
|
||||
runtimeConfig.InitGenesis = initGenesis
|
||||
}
|
||||
|
||||
modules := []*appv1alpha1.ModuleConfig{{
|
||||
Name: "runtime",
|
||||
Config: appconfig.WrapAny(runtimeConfig),
|
||||
}}
|
||||
|
||||
for _, m := range cfg.ModuleConfigs {
|
||||
modules = append(modules, m)
|
||||
}
|
||||
|
||||
return appconfig.Compose(&appv1alpha1.Config{Modules: modules})
|
||||
}
|
||||
|
||||
Vendored
+32
-2
@@ -6,13 +6,15 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
gogoprotoany "github.com/cosmos/gogoproto/types/any"
|
||||
"github.com/cosmos/gogoproto/types/any/test"
|
||||
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/core/gas"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@@ -85,6 +87,7 @@ func DeterministicIterations[request, response proto.Message](
|
||||
if gasOverwrite { // to handle regressions, i.e. check that gas consumption didn't change
|
||||
gasConsumed = ctx.GasMeter().GasConsumed() - before
|
||||
}
|
||||
t.Logf("gas consumed: %d", gasConsumed)
|
||||
|
||||
for i := 0; i < iterCount; i++ {
|
||||
before := ctx.GasMeter().GasConsumed()
|
||||
@@ -94,3 +97,30 @@ func DeterministicIterations[request, response proto.Message](
|
||||
assert.DeepEqual(t, res, prevRes)
|
||||
}
|
||||
}
|
||||
|
||||
func DeterministicIterationsV2[request, response proto.Message](
|
||||
t *testing.T,
|
||||
req request,
|
||||
meterFn func() gas.Meter,
|
||||
queryFn func(request) (response, error),
|
||||
assertGas func(*testing.T, gas.Gas),
|
||||
assertResponse func(*testing.T, response),
|
||||
) {
|
||||
t.Helper()
|
||||
prevRes, err := queryFn(req)
|
||||
gasMeter := meterFn()
|
||||
gasConsumed := gasMeter.Consumed()
|
||||
require.NoError(t, err)
|
||||
assertGas(t, gasConsumed)
|
||||
|
||||
for i := 0; i < iterCount; i++ {
|
||||
res, err := queryFn(req)
|
||||
require.NoError(t, err)
|
||||
sameGas := gasMeter.Consumed()
|
||||
require.Equal(t, gasConsumed, sameGas)
|
||||
require.Equal(t, res, prevRes)
|
||||
if assertResponse != nil {
|
||||
assertResponse(t, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user