Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Jan 6, 2025
1 parent d29ed65 commit d42ac1f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 39 deletions.
34 changes: 8 additions & 26 deletions core/testing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package coretesting

import (
"context"
"time"

"cosmossdk.io/core/event"
"cosmossdk.io/core/gas"
"cosmossdk.io/core/header"
Expand All @@ -16,7 +14,7 @@ type dummyKey struct{}
var _ context.Context = &TestContext{}

type TestContext struct {
ctx context.Context
context.Context
}

func Context() TestContext {
Expand All @@ -31,54 +29,38 @@ func Context() TestContext {
}

return TestContext{
ctx: context.WithValue(context.Background(), dummyKey{}, dummy),
Context: context.WithValue(context.Background(), dummyKey{}, dummy),
}
}

func (t TestContext) Deadline() (deadline time.Time, ok bool) {
return t.ctx.Deadline()
}

func (t TestContext) Done() <-chan struct{} {
return t.ctx.Done()
}

func (t TestContext) Err() error {
return t.ctx.Err()
}

func (t TestContext) Value(key any) any {
return t.ctx.Value(key)
}

// WithHeaderInfo sets the header on a testing ctx and returns the updated ctx.
func (t TestContext) WithHeaderInfo(info header.Info) TestContext {
dummy := unwrap(t.ctx)
dummy := unwrap(t.Context)
dummy.header = info

return TestContext{
ctx: context.WithValue(t.ctx, dummyKey{}, dummy),
Context: context.WithValue(t.Context, dummyKey{}, dummy),
}
}

// WithExecMode sets the exec mode on a testing ctx and returns the updated ctx.
func (t TestContext) WithExecMode(mode transaction.ExecMode) TestContext {
dummy := unwrap(t.ctx)
dummy := unwrap(t.Context)
dummy.execMode = mode

return TestContext{
ctx: context.WithValue(t.ctx, dummyKey{}, dummy),
Context: context.WithValue(t.Context, dummyKey{}, dummy),
}
}

// WithGas sets the gas config and meter on a testing ctx and returns the updated ctx.
func (t TestContext) WithGas(gasConfig gas.GasConfig, gasMeter gas.Meter) TestContext {
dummy := unwrap(t.ctx)
dummy := unwrap(t.Context)
dummy.gasConfig = gasConfig
dummy.gasMeter = gasMeter

return TestContext{
ctx: context.WithValue(t.ctx, dummyKey{}, dummy),
Context: context.WithValue(t.Context, dummyKey{}, dummy),
}
}

Expand Down
13 changes: 5 additions & 8 deletions core/testing/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type TestEnvironmentConfig struct {
}

type TestEnvironment struct {
env appmodulev2.Environment
appmodulev2.Environment

memEventsService MemEventsService
memHeaderService MemHeaderService
}
Expand All @@ -30,7 +31,7 @@ func NewTestEnvironment(cfg TestEnvironmentConfig) (TestContext, TestEnvironment
memHeaderService := MemHeaderService{}

env := TestEnvironment{
env: appmodulev2.Environment{
Environment: appmodulev2.Environment{
Logger: cfg.Logger,
BranchService: nil,
EventService: memEventService,
Expand All @@ -47,20 +48,16 @@ func NewTestEnvironment(cfg TestEnvironmentConfig) (TestContext, TestEnvironment
}

// set internal context to point to environment
ctx.ctx = context.WithValue(ctx.ctx, corecontext.EnvironmentContextKey, env.env)
ctx.Context = context.WithValue(ctx.Context, corecontext.EnvironmentContextKey, env.Environment)
return ctx, env
}

func (env TestEnvironment) MemEventsService() MemEventsService {
return env.memEventsService
}

func (env TestEnvironment) Environment() appmodulev2.Environment {
return env.env
}

func (env TestEnvironment) KVStoreService() store.KVStoreService {
return env.env.KVStoreService
return env.Environment.KVStoreService
}

func (env TestEnvironment) HeaderService() MemHeaderService {
Expand Down
9 changes: 5 additions & 4 deletions tests/integration/distribution/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import (
"encoding/json"
"testing"

abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
"github.com/stretchr/testify/suite"

corestore "cosmossdk.io/core/store"
coretesting "cosmossdk.io/core/testing"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
bankkeeper "cosmossdk.io/x/bank/keeper"
"cosmossdk.io/x/distribution/keeper"
"cosmossdk.io/x/distribution/types"
stakingkeeper "cosmossdk.io/x/staking/keeper"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

bankkeeper "cosmossdk.io/x/bank/keeper"
_ "github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
)
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.authKeeper = authKeeper
suite.addrCdc = ac
suite.bankKeeper = keeper.NewBaseKeeper(
env.Environment(),
env.Environment,
encCfg.Codec,
suite.authKeeper,
map[string]bool{addr: true},
Expand Down

0 comments on commit d42ac1f

Please sign in to comment.