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: use chaintestutil for integration test setup #46

Merged
merged 63 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b305db9
clean
Nov 29, 2023
abe1866
fix
Nov 29, 2023
11cf89a
state query
Nov 29, 2023
c11844d
test:
Nov 29, 2023
8db5ae3
Merge branch 'feat/query-state' into test/integration
Nov 29, 2023
84e8063
wip
Nov 29, 2023
ad9cad8
remove test
Nov 29, 2023
80cffac
Merge branch 'feat/query-state' into test/integration
Nov 29, 2023
c354608
fix
Nov 29, 2023
69f64d2
fix
Nov 29, 2023
83b539f
wip
Nov 29, 2023
642dea1
wrong
Nov 30, 2023
70d9fdc
working
Nov 30, 2023
e31e3a0
fix
Nov 30, 2023
127a2b1
fix
Nov 30, 2023
bc36f96
refactor to use params
Nov 30, 2023
1935d45
clean
Nov 30, 2023
d637493
wip
Dec 1, 2023
0361328
Merge branch 'main' into test/integration
Dec 1, 2023
127629c
fix
Dec 1, 2023
20d1fda
refactor
Dec 1, 2023
b1f618c
fix
Dec 1, 2023
1e2df2f
fix
Dec 1, 2023
d426f2c
rename
Dec 1, 2023
03ce1ff
rename
Dec 1, 2023
afd8766
sample
Dec 1, 2023
1b32f10
encoding
Dec 1, 2023
50313e3
sample
Dec 1, 2023
16854b2
use sample
Dec 1, 2023
aaac5b0
add
Dec 3, 2023
33298b9
network suite
Dec 3, 2023
e6c2b69
wip
Dec 4, 2023
f918b59
refactor
Dec 4, 2023
1a410d8
add feemarket
Dec 4, 2023
3d5ac57
init integration pkg
Dec 4, 2023
9c41daa
update to latest commit
Dec 4, 2023
bcd4e1d
go mod tidy
Dec 4, 2023
5a82c26
Merge branch 'fix/linter' into test/integration-setup
Dec 4, 2023
1b9f50c
lint fix
Dec 4, 2023
bb349f9
use encoding
Dec 4, 2023
36af52a
init
Dec 4, 2023
460ffb4
refactor
Dec 5, 2023
4865616
clean
Dec 5, 2023
4b7b95b
refactor
Dec 5, 2023
b7bff5b
refactor
Dec 5, 2023
aa801df
refactor
Dec 5, 2023
98479ef
Merge branch 'main' into test/integration-keeper
Dec 5, 2023
840d6a9
refactor clean
Dec 5, 2023
76229f7
format
Dec 5, 2023
55e22f0
use sample
Dec 5, 2023
1442278
encoding
Dec 5, 2023
7886bb1
remove network
Dec 5, 2023
76331f1
refactor keeper
Dec 6, 2023
9c384e7
Merge branch 'main' into test/integration-keeper
Dec 6, 2023
52add38
fix
Dec 6, 2023
161d2d5
Merge branch 'main' into refactor/chaintestutil
Dec 6, 2023
dbdcc3f
clean
Dec 6, 2023
baf3a3d
Merge branch 'test/integration-keeper' into refactor/chaintestutil
Dec 6, 2023
c0586a4
use repo
Dec 7, 2023
d20c200
ok
Dec 7, 2023
4ccdce9
remove
Dec 7, 2023
29a87fb
clean
Dec 7, 2023
33a4561
Merge branch 'main' into refactor/chaintestutil
Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
init integration pkg
aljo242 committed Dec 4, 2023

Verified

This commit was signed with the committer’s verified signature.
arvindh123 Arvindh
commit 3d5ac574beee6e44c0f84542eb007f1c54ef3a64
96 changes: 86 additions & 10 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -3,21 +3,97 @@ package integration_test
import (
"testing"

"cosmossdk.io/math"
"github.com/stretchr/testify/suite"

"github.com/skip-mev/feemarket/testutils"
"github.com/skip-mev/feemarket/x/feemarket/types"

sdk "github.com/cosmos/cosmos-sdk/types"

testkeeper "github.com/skip-mev/feemarket/testutils/keeper"
)

func TestKeepers(t *testing.T) {
var (
ctx, tk, _ = testkeeper.NewTestSetup(t)
wCtx = sdk.WrapSDKContext(ctx)
)
type IntegrationTestSuite struct {
suite.Suite

testKeepers testkeeper.TestKeepers
testMsgServers testkeeper.TestMsgServers
encCfg testutils.EncodingConfig
ctx sdk.Context
authorityAccount sdk.AccAddress
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}

func (s *IntegrationTestSuite) SetupTest() {
s.encCfg = testutils.CreateTestEncodingConfig()

s.ctx, s.testKeepers, s.testMsgServers = testkeeper.NewTestSetup(s.T())
}

func (s *IntegrationTestSuite) TestState() {
s.Run("set and get default eip1559 state", func() {
state := types.DefaultState()

err := s.testKeepers.FeeMarketKeeper.SetState(s.ctx, state)
s.Require().NoError(err)

gotState, err := s.testKeepers.FeeMarketKeeper.GetState(s.ctx)
s.Require().NoError(err)

s.Require().EqualValues(state, gotState)
})

s.Run("set and get aimd eip1559 state", func() {
state := types.DefaultAIMDState()

err := s.testKeepers.FeeMarketKeeper.SetState(s.ctx, state)
s.Require().NoError(err)

gotState, err := s.testKeepers.FeeMarketKeeper.GetState(s.ctx)
s.Require().NoError(err)

s.Require().Equal(state, gotState)
})
}

func (s *IntegrationTestSuite) TestParams() {
s.Run("set and get default params", func() {
params := types.DefaultParams()

err := s.testKeepers.FeeMarketKeeper.SetParams(s.ctx, params)
s.Require().NoError(err)

gotParams, err := s.testKeepers.FeeMarketKeeper.GetParams(s.ctx)
s.Require().NoError(err)

s.Require().EqualValues(params, gotParams)
})

s.Run("set and get custom params", func() {
params := types.Params{
Alpha: math.LegacyMustNewDecFromStr("0.1"),
Beta: math.LegacyMustNewDecFromStr("0.1"),
Theta: math.LegacyMustNewDecFromStr("0.1"),
Delta: math.LegacyMustNewDecFromStr("0.1"),
MinBaseFee: math.NewInt(10),
MinLearningRate: math.LegacyMustNewDecFromStr("0.1"),
MaxLearningRate: math.LegacyMustNewDecFromStr("0.1"),
TargetBlockUtilization: 5,
MaxBlockUtilization: 10,
Window: 1,
Enabled: true,
}

err := s.testKeepers.FeeMarketKeeper.SetParams(s.ctx, params)
s.Require().NoError(err)

numIterations := 100
gotParams, err := s.testKeepers.FeeMarketKeeper.GetParams(s.ctx)
s.Require().NoError(err)

for i := 0; i < numIterations; i++ {
_ = tk
_ = wCtx
}
s.Require().EqualValues(params, gotParams)
})
}
44 changes: 30 additions & 14 deletions testutils/keeper/initializer.go
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
@@ -21,18 +23,19 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/skip-mev/feemarket/testutils/sample"
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"

"github.com/skip-mev/feemarket/testutils/sample"
)

var moduleAccountPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
feemarkettypes.ModuleName: nil,
feemarkettypes.FeeCollectorName: {authtypes.Burner},
}

// initializer allows to initialize each module keeper
@@ -62,7 +65,7 @@ func ModuleAccountAddrs(maccPerms map[string][]string) map[string]bool {
return modAccAddrs
}

func (i initializer) Param() paramskeeper.Keeper {
func (i *initializer) Param() paramskeeper.Keeper {
storeKey := sdk.NewKVStoreKey(paramstypes.StoreKey)
tkeys := sdk.NewTransientStoreKey(paramstypes.TStoreKey)

@@ -77,7 +80,7 @@ func (i initializer) Param() paramskeeper.Keeper {
)
}

func (i initializer) Auth(paramKeeper paramskeeper.Keeper) authkeeper.AccountKeeper {
func (i *initializer) Auth(paramKeeper paramskeeper.Keeper) authkeeper.AccountKeeper {
storeKey := sdk.NewKVStoreKey(authtypes.StoreKey)
i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB)
paramKeeper.Subspace(authtypes.ModuleName)
@@ -92,7 +95,7 @@ func (i initializer) Auth(paramKeeper paramskeeper.Keeper) authkeeper.AccountKee
)
}

func (i initializer) Bank(paramKeeper paramskeeper.Keeper, authKeeper authkeeper.AccountKeeper) bankkeeper.Keeper {
func (i *initializer) Bank(paramKeeper paramskeeper.Keeper, authKeeper authkeeper.AccountKeeper) bankkeeper.Keeper {
storeKey := sdk.NewKVStoreKey(banktypes.StoreKey)
i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB)
paramKeeper.Subspace(banktypes.ModuleName)
@@ -113,7 +116,7 @@ type ProtocolVersionSetter struct{}

func (vs ProtocolVersionSetter) SetProtocolVersion(uint64) {}

func (i initializer) Upgrade() *upgradekeeper.Keeper {
func (i *initializer) Upgrade() *upgradekeeper.Keeper {
storeKey := sdk.NewKVStoreKey(upgradetypes.StoreKey)
i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB)

@@ -130,7 +133,7 @@ func (i initializer) Upgrade() *upgradekeeper.Keeper {
)
}

func (i initializer) Staking(
func (i *initializer) Staking(
authKeeper authkeeper.AccountKeeper,
bankKeeper bankkeeper.Keeper,
paramKeeper paramskeeper.Keeper,
@@ -148,7 +151,7 @@ func (i initializer) Staking(
)
}

func (i initializer) Distribution(
func (i *initializer) Distribution(
authKeeper authkeeper.AccountKeeper,
bankKeeper bankkeeper.Keeper,
stakingKeeper *stakingkeeper.Keeper,
@@ -167,7 +170,7 @@ func (i initializer) Distribution(
)
}

func (i initializer) FeeMarket(
func (i *initializer) FeeMarket(
authKeeper authkeeper.AccountKeeper,
) *feemarketkeeper.Keeper {
storeKey := sdk.NewKVStoreKey(feemarkettypes.StoreKey)
@@ -180,3 +183,16 @@ func (i initializer) FeeMarket(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
}

func (i *initializer) FeeGrant(
authKeeper authkeeper.AccountKeeper,
) feegrantkeeper.Keeper {
storeKey := sdk.NewKVStoreKey(feegrant.StoreKey)
i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB)

return feegrantkeeper.NewKeeper(
i.Codec,
storeKey,
authKeeper,
)
}
10 changes: 7 additions & 3 deletions testutils/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -5,19 +5,20 @@ import (
"testing"
"time"

feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"

"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"

feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)

var (
@@ -36,6 +37,7 @@ type TestKeepers struct {
DistrKeeper distrkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
FeeMarketKeeper *feemarketkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
}

// TestMsgServers holds all message servers used during keeper tests for all modules
@@ -66,6 +68,7 @@ func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeeper
stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper)
distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper)
feeMarketKeeper := initializer.FeeMarket(authKeeper)
feeGrantKeeper := initializer.FeeGrant(authKeeper)

require.NoError(t, initializer.StateStore.LoadLatestVersion())

@@ -104,6 +107,7 @@ func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeeper
DistrKeeper: distrKeeper,
StakingKeeper: stakingKeeper,
FeeMarketKeeper: feeMarketKeeper,
FeeGrantKeeper: feeGrantKeeper,
},
TestMsgServers{
T: t,
40 changes: 40 additions & 0 deletions x/feemarket/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ package keeper_test
import (
"testing"

"cosmossdk.io/math"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -88,3 +90,41 @@ func (s *KeeperTestSuite) TestState() {
s.Require().Equal(state, gotState)
})
}

func (s *KeeperTestSuite) TestParams() {
s.Run("set and get default params", func() {
params := types.DefaultParams()

err := s.feemarketKeeper.SetParams(s.ctx, params)
s.Require().NoError(err)

gotParams, err := s.feemarketKeeper.GetParams(s.ctx)
s.Require().NoError(err)

s.Require().EqualValues(params, gotParams)
})

s.Run("set and get custom params", func() {
params := types.Params{
Alpha: math.LegacyMustNewDecFromStr("0.1"),
Beta: math.LegacyMustNewDecFromStr("0.1"),
Theta: math.LegacyMustNewDecFromStr("0.1"),
Delta: math.LegacyMustNewDecFromStr("0.1"),
MinBaseFee: math.NewInt(10),
MinLearningRate: math.LegacyMustNewDecFromStr("0.1"),
MaxLearningRate: math.LegacyMustNewDecFromStr("0.1"),
TargetBlockUtilization: 5,
MaxBlockUtilization: 10,
Window: 1,
Enabled: true,
}

err := s.feemarketKeeper.SetParams(s.ctx, params)
s.Require().NoError(err)

gotParams, err := s.feemarketKeeper.GetParams(s.ctx)
s.Require().NoError(err)

s.Require().EqualValues(params, gotParams)
})
}