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

fix: discontinue the use of depinject #160

Merged
merged 38 commits into from
Oct 2, 2024
Merged
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ea824f3
discontinue the use of dependency injection
mantrachain-support Oct 1, 2024
d4a881d
continue cleanup of app.go
mantrachain-support Oct 1, 2024
6dd4cd6
restore genesis config
mantrachain-support Oct 1, 2024
b8d96ff
restore 1:1 original antehandler
mantrachain-support Oct 1, 2024
8ed8c5b
fix test helper code
mantrachain-support Oct 1, 2024
0038bba
further cleanup of app.go
mantrachain-support Oct 1, 2024
1a301f5
cleanup: antehandler and app.go
mantrachain-support Oct 1, 2024
da5db45
fix tokenfactory
freeelancer Oct 1, 2024
a5e01ae
update additional items
mantrachain-support Oct 1, 2024
9440343
ensure that we don't incorrectly add connect to genesis
mantrachain-support Oct 1, 2024
ff1e27a
remove ante folder
mantrachain-support Oct 1, 2024
d75fe18
add old antehandler
mantrachain-support Oct 1, 2024
eb7f5a6
use xfeemarket post handler
freeelancer Oct 1, 2024
9316f7e
remove FinalizeBlock
freeelancer Oct 1, 2024
c8701b8
added connect
freeelancer Oct 1, 2024
7417f59
add swagger
freeelancer Oct 1, 2024
8f4a719
added tax
freeelancer Oct 1, 2024
42f0359
fix lint
freeelancer Oct 1, 2024
36f3207
correct all pointers
freeelancer Oct 1, 2024
4b6b897
add ratelimit
freeelancer Oct 1, 2024
95ad216
add subspace
freeelancer Oct 1, 2024
e3479c7
remove paramskeeper where not needed
freeelancer Oct 2, 2024
fd781f0
remove ica entirely
freeelancer Oct 2, 2024
fea26ac
Merge branch 'main' into discontinue-depinject
mantrachain-support Oct 2, 2024
99ff0f2
Merge branch 'main' into discontinue-depinject
mantrachain-support Oct 2, 2024
659a7a7
fix lint
mantrachain-support Oct 2, 2024
94d7aec
Merge branch 'discontinue-depinject' of https://github.com/mantra-cha…
mantrachain-support Oct 2, 2024
bbfced1
fix test helpers
mantrachain-support Oct 2, 2024
ffcd7d4
refactor golangci
mantrachain-support Oct 2, 2024
6b009a6
re-add init() functions to tests
mantrachain-support Oct 2, 2024
70d63b4
Merge branch 'main' into discontinue-depinject
mantrachain-support Oct 2, 2024
1894afc
refactor config.set code
freeelancer Oct 2, 2024
0b1be0f
added address verifier
freeelancer Oct 2, 2024
a093055
restore the precise former configuration of genesis.go
mantrachain-support Oct 2, 2024
458e169
Merge branch 'discontinue-depinject' of https://github.com/mantra-cha…
mantrachain-support Oct 2, 2024
de75654
remove references to wasmd
mantrachain-support Oct 2, 2024
11c808f
naming references
mantrachain-support Oct 2, 2024
24205c1
update commands
mantrachain-support Oct 2, 2024
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
11 changes: 7 additions & 4 deletions app/ante.go → app/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package ante

import (
"errors"
@@ -15,18 +15,21 @@ import (
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
BaseOptions ante.HandlerOptions
BaseOptions ante.HandlerOptions

IBCKeeper *keeper.Keeper
WasmConfig *wasmTypes.WasmConfig
WasmKeeper *wasmkeeper.Keeper
TXCounterStoreService corestoretypes.KVStoreService
CircuitKeeper *circuitkeeper.Keeper
BankKeeper feemarketante.BankKeeper
AccountKeeper feemarketante.AccountKeeper
FeeMarketKeeper feemarketante.FeeMarketKeeper
AccountKeeper feemarketante.AccountKeeper
BankKeeper feemarketante.BankKeeper
}

// NewAnteHandler constructor
129 changes: 129 additions & 0 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package ante

import (
"testing"

"github.com/osmosis-labs/fee-abstraction/v8/x/feeabs/types"
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"cosmossdk.io/errors"
math "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

func TestMempoolDecorator(t *testing.T) {
gasLimit := uint64(200000)
minGasPrice := sdk.NewDecCoinsFromCoins(sdk.NewInt64Coin("ueve", feemarkettypes.DefaultMinBaseGasPrice.TruncateInt64()))
validFeeAmount := feemarkettypes.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit))
validFee := sdk.NewCoins(sdk.NewCoin("ueve", validFeeAmount.TruncateInt()))
validIbcFee := sdk.NewCoins(sdk.NewCoin("ibcfee", validFeeAmount.TruncateInt()))
// mockHostZoneConfig is used to mock the host zone config, with ibcfee as the ibc fee denom to be used as alternative fee
mockHostZoneConfig := types.HostChainFeeAbsConfig{
IbcDenom: "ibcfee",
OsmosisPoolTokenDenomIn: "osmosis",
PoolId: 1,
Status: types.HostChainFeeAbsStatus_UPDATED,
}
testCases := []struct {
name string
feeAmount sdk.Coins
malleate func(*AnteTestSuite)
expErr error
}{
{
"empty fee, should fail",
sdk.Coins{},
func(suite *AnteTestSuite) {
},
errors.Wrapf(feemarkettypes.ErrNoFeeCoins, "%s", "got length 0"),
},
{
"valid native fee, should pass",
validFee,
func(suite *AnteTestSuite) {
suite.bankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, mock.Anything,
feemarkettypes.FeeCollectorName, mock.Anything).Return(nil).Once()
},
nil,
},
{
"valid ibc fee, should pass",
validIbcFee,
func(suite *AnteTestSuite) {
err := suite.feeabsKeeper.SetHostZoneConfig(suite.ctx, mockHostZoneConfig)
require.NoError(t, err)
suite.feeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", math.LegacyNewDec(1))
suite.stakingKeeper.EXPECT().BondDenom(gomock.Any()).Return("ueve", nil).AnyTimes()
suite.bankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, mock.Anything,
feemarkettypes.FeeCollectorName, mock.Anything).Return(nil).Once()
},
nil,
},
{
"not enough ibc fee, should fail",
validIbcFee.Sub(sdk.NewCoin("ibcfee", math.NewInt(1))),
func(suite *AnteTestSuite) {
err := suite.feeabsKeeper.SetHostZoneConfig(suite.ctx, mockHostZoneConfig)
require.NoError(t, err)
suite.feeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", math.LegacyNewDec(1))
suite.stakingKeeper.EXPECT().BondDenom(gomock.Any()).Return("ueve", nil).AnyTimes()
},
sdkerrors.ErrInsufficientFee,
},
{
"fee in unsupported denom, should fail",
sdk.NewCoins(sdk.NewCoin("unsupported", validFeeAmount.TruncateInt())),
func(suite *AnteTestSuite) {
suite.stakingKeeper.EXPECT().BondDenom(gomock.Any()).Return("ueve", nil).AnyTimes()
},
ErrDenomNotRegistered("unsupported"),
},
{
"multiple fee denoms, only one supported, should pass",
sdk.NewCoins(validFee[0], sdk.NewCoin("unsupported", math.NewInt(100))),
func(suite *AnteTestSuite) {},
feemarkettypes.ErrTooManyFeeCoins,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
suite := SetupTestSuite(t, true)

tc.malleate(suite)
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetFeeAmount(tc.feeAmount)
accs := suite.CreateTestAccounts(1)
require.NoError(t, suite.txBuilder.SetMsgs([]sdk.Msg{testdata.NewTestMsg(accs[0].acc.GetAddress())}...))

suite.ctx = suite.ctx.WithMinGasPrices(minGasPrice)

// Construct tx and run through mempool decorator
tx := suite.txBuilder.GetTx()
feemarketDecorator := feemarketante.NewFeeMarketCheckDecorator(
suite.accountKeeper,
suite.bankKeeper,
suite.feeGrantKeeper,
suite.feemarketKeeper,
nil)
antehandler := sdk.ChainAnteDecorators(feemarketDecorator)

// Run the ante handler
_, err := antehandler(suite.ctx, tx, false)

if tc.expErr != nil {
require.Error(t, err)
require.ErrorContains(t, err, tc.expErr.Error())
} else {
require.NoError(t, err)
}
})
}
}
27 changes: 27 additions & 0 deletions app/ante/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ante

import (
"errors"
"fmt"
)

var (
ErrMissingAccountKeeper = errors.New("account keeper is required for ante builder")
ErrMissingBankKeeper = errors.New("bank keeper is required for ante builder")
ErrMissingSignModeHandler = errors.New("sign mode handler is required for ante builder")
ErrMissingWasmConfig = errors.New("wasm config is required for ante builder")
ErrMissingWasmStoreService = errors.New("wasm store service is required for ante builder")
ErrMissingCircuitKeeper = errors.New("circuit keeper is required for ante builder")
)

func ErrNeitherNativeDenom(coinDenom, denom string) error {
return fmt.Errorf("neither of coin.Denom %s and denom %s is the native denom of the chain", coinDenom, denom)
}

func ErrDenomNotRegistered(denom string) error {
return fmt.Errorf("denom %s not registered in host zone", denom)
}

func ErrExpectedOneCoin(count int) error {
return fmt.Errorf("expected exactly one native coin, got %d", count)
}
144 changes: 144 additions & 0 deletions app/ante/suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package ante

import (
"testing"

capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
transferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"
portkeeper "github.com/cosmos/ibc-go/v8/modules/core/05-port/keeper"
feeabskeeper "github.com/osmosis-labs/fee-abstraction/v8/x/feeabs/keeper"
feeabstestutil "github.com/osmosis-labs/fee-abstraction/v8/x/feeabs/testutil"
feeabstypes "github.com/osmosis-labs/fee-abstraction/v8/x/feeabs/types"
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"
feemarketmocks "github.com/skip-mev/feemarket/x/feemarket/ante/mocks"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
"github.com/stretchr/testify/require"
ubermock "go.uber.org/mock/gomock"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// TestAccount represents an account used in the tests in x/auth/ante.
type TestAccount struct {
acc sdk.AccountI
priv cryptotypes.PrivKey
}

// AnteTestSuite is a test suite to be used with ante handler tests.
type AnteTestSuite struct {
ctx sdk.Context
clientCtx client.Context
txBuilder client.TxBuilder
accountKeeper authkeeper.AccountKeeper
bankKeeper *feemarketmocks.BankKeeper
feeGrantKeeper *feeabstestutil.MockFeegrantKeeper
stakingKeeper *feeabstestutil.MockStakingKeeper
feeabsKeeper feeabskeeper.Keeper
feemarketKeeper feemarketante.FeeMarketKeeper
channelKeeper *feeabstestutil.MockChannelKeeper
portKeeper *feeabstestutil.MockPortKeeper
scopedKeeper *feeabstestutil.MockScopedKeeper
encCfg moduletestutil.TestEncodingConfig
}

// SetupTest setups a new test, with new app, context, and anteHandler.
func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
t.Helper()
suite := &AnteTestSuite{}
ctrl := ubermock.NewController(t)

govAuthority := authtypes.NewModuleAddress("gov").String()

// Setup mock keepers
suite.bankKeeper = feemarketmocks.NewBankKeeper(t)
suite.stakingKeeper = feeabstestutil.NewMockStakingKeeper(ctrl)
suite.feeGrantKeeper = feeabstestutil.NewMockFeegrantKeeper(ctrl)
suite.channelKeeper = feeabstestutil.NewMockChannelKeeper(ctrl)
suite.portKeeper = feeabstestutil.NewMockPortKeeper(ctrl)
suite.scopedKeeper = feeabstestutil.NewMockScopedKeeper(ctrl)

// setup necessary params for Account Keeper
key := storetypes.NewKVStoreKey(feeabstypes.StoreKey)
authKey := storetypes.NewKVStoreKey(authtypes.StoreKey)
subspace := paramtypes.NewSubspace(nil, nil, nil, nil, "feeabs")
subspace = subspace.WithKeyTable(feeabstypes.ParamKeyTable())
maccPerms := map[string][]string{
"fee_collector": nil,
"mint": {"minter"},
"bonded_tokens_pool": {"burner", "staking"},
"not_bonded_tokens_pool": {"burner", "staking"},
"multiPerm": {"burner", "minter", "staking"},
"random": {"random"},
"feeabs": nil,
}

// setup context for Account Keeper
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
testCtx.CMS.MountStoreWithDB(authKey, storetypes.StoreTypeIAVL, testCtx.DB)
testCtx.CMS.MountStoreWithDB(storetypes.NewTransientStoreKey("transient_test2"), storetypes.StoreTypeTransient, testCtx.DB)
err := testCtx.CMS.LoadLatestVersion()
require.NoError(t, err)
suite.ctx = testCtx.Ctx.WithIsCheckTx(isCheckTx).WithBlockHeight(1) // app.BaseApp.NewContext(isCheckTx, tmproto.Header{}).WithBlockHeight(1)

suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
suite.encCfg.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(suite.encCfg.InterfaceRegistry)
suite.accountKeeper = authkeeper.NewAccountKeeper(
suite.encCfg.Codec, runtime.NewKVStoreService(authKey), authtypes.ProtoBaseAccount, maccPerms,
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.Bech32MainPrefix, govAuthority,
)
suite.accountKeeper.SetModuleAccount(suite.ctx, authtypes.NewEmptyModuleAccount(feeabstypes.ModuleName))
// Setup feeabs keeper
suite.feeabsKeeper = feeabskeeper.NewKeeper(suite.encCfg.Codec, key, subspace, suite.stakingKeeper, suite.accountKeeper, keeper.BaseKeeper{}, transferkeeper.Keeper{}, channelkeeper.Keeper{}, &portkeeper.Keeper{}, capabilitykeeper.ScopedKeeper{}, govAuthority)
suite.clientCtx = client.Context{}.
WithTxConfig(suite.encCfg.TxConfig)
require.NoError(t, err)

// setup txBuilder
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

// setup feemarket
feemarketParams := feemarkettypes.DefaultParams()
feemarketParams.FeeDenom = "uom"
Fixed Show fixed Hide fixed
// suite.feemarketKeeper = feemarketkeeper.NewKeeper(suite.encCfg.Codec, key, suite.accountKeeper, &DenomResolverImpl{
// FeeabsKeeper: suite.feeabsKeeper,
// StakingKeeper: suite.stakingKeeper,
// }, govAuthority)
//err = suite.feemarketKeeper.SetParams(suite.ctx, feemarketParams)
//require.NoError(t, err)
//err = suite.feemarketKeeper.SetState(suite.ctx, feemarkettypes.DefaultState())
//require.NoError(t, err)
return suite
}

func (suite *AnteTestSuite) CreateTestAccounts(numAccs int) []TestAccount {
var accounts []TestAccount

for i := 0; i < numAccs; i++ {
priv, _, addr := testdata.KeyTestPubAddr()
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr)
err := acc.SetAccountNumber(uint64(i + 100))
if err != nil {
panic(err)
}
suite.accountKeeper.SetAccount(suite.ctx, acc)
accounts = append(accounts, TestAccount{acc, priv})
}

return accounts
}
Loading