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

feat: add fee abs module #780

Merged
merged 63 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cf56c42
add fee abs module
atheeshp Aug 19, 2024
5a90925
fix tests
atheeshp Aug 27, 2024
e355a38
fix tests
atheeshp Aug 27, 2024
dcf202d
fix tests
atheeshp Aug 27, 2024
291ad7f
fix tests
atheeshp Aug 27, 2024
89c3505
feat: integrated feemarket
vishal-kanna Aug 27, 2024
321ae23
add fee abs keeper in HandlerOptions
atheeshp Aug 27, 2024
5d403ad
fix tests
atheeshp Aug 28, 2024
2c0ae04
add logs
atheeshp Aug 28, 2024
defe327
chore: updated anteHandler and postHandler
vishal-kanna Aug 28, 2024
5e33e65
chore: use replace for feemarket in go.mod
vishal-kanna Aug 28, 2024
d5667f0
chore: changed go version in docker file
vishal-kanna Aug 29, 2024
8684ce9
fix : fix testing in antehandler
vishal-kanna Aug 29, 2024
ea06beb
fix: fix lint issues
vishal-kanna Aug 29, 2024
d09e816
chore: updated antehandler
vishal-kanna Aug 29, 2024
adcd9f3
fix: fix lint issues
vishal-kanna Aug 29, 2024
e2f6a74
fix: fix lint issues
vishal-kanna Aug 29, 2024
f016460
fix: lint issus
vishal-kanna Aug 29, 2024
36202e4
chore: updated ante and fix test cases
vishal-kanna Aug 30, 2024
945b3cc
fix: gofumt errors
vishal-kanna Aug 30, 2024
74089c2
fix: golint issues
vishal-kanna Aug 30, 2024
4256d7f
chore: updated postHandler
vishal-kanna Aug 30, 2024
acd8d74
testing
vishal-kanna Sep 3, 2024
4779b6a
chore: added test cases
vishal-kanna Sep 4, 2024
9557978
fix
vishal-kanna Sep 4, 2024
044bc3d
fix
vishal-kanna Sep 4, 2024
b2b8502
fix: golint issues
vishal-kanna Sep 4, 2024
e2866fb
fix : fix testcase
vishal-kanna Sep 5, 2024
9bcd0cb
fix: fix lint issues
vishal-kanna Sep 5, 2024
64c505d
disable update tests
vishal-kanna Sep 5, 2024
b05f6ee
disable report test
vishal-kanna Sep 5, 2024
9af6f82
fix: added response check in tests
vishal-kanna Sep 5, 2024
6181458
fix
vishal-kanna Sep 5, 2024
33403e1
chore: added param subsace for feemarket
vishal-kanna Sep 6, 2024
9a5c9d8
add unit tests
atheeshp Sep 6, 2024
98d86ea
fix test
atheeshp Sep 9, 2024
358cdb0
fix lint
atheeshp Sep 9, 2024
3827e97
remove comment
atheeshp Sep 9, 2024
05fa0ec
addressed review comments
vishal-kanna Sep 10, 2024
281af5e
chore: merged feemarket integration PR
vishal-kanna Sep 10, 2024
0c5a67b
fix
vishal-kanna Sep 10, 2024
1fd19a2
fix
vishal-kanna Sep 10, 2024
cb727e6
fix
vishal-kanna Sep 10, 2024
611e181
TODO in app.go
vishal-kanna Sep 10, 2024
af939e1
fix: golint error
vishal-kanna Sep 10, 2024
3bb51c1
add go mod
atheeshp Sep 11, 2024
b4c7afe
Merge branch 'vishal/integrate-antehandler' of github.com:cheqd/cheqd…
atheeshp Sep 11, 2024
999d9bb
cheqd changes
atheeshp Sep 17, 2024
2a1528a
go.mod
atheeshp Sep 17, 2024
98e903b
go mod
atheeshp Sep 17, 2024
15b751a
Temporarily disabled upgrade test runs + references
Eengineer1 Sep 18, 2024
9a64ed4
chore: added upgradeHandler and upgraded the store loader
vishal-kanna Sep 19, 2024
bd49157
Merge branch 'vishal/integrate-antehandler' of https://github.com/che…
vishal-kanna Sep 19, 2024
6ea0b87
add tests
atheeshp Sep 19, 2024
985acee
Merge branch 'vishal/integrate-antehandler' into ap/add-feeabs-mod
Eengineer1 Sep 19, 2024
1971cc2
chore: added denom resolver logic for feemarket
vishal-kanna Sep 20, 2024
5b7e733
Merge branch 'develop' into ap/add-feeabs-mod
vishal-kanna Sep 20, 2024
cf4689e
Merge branch 'develop' of https://github.com/cheqd/cheqd-node into ap…
vishal-kanna Sep 20, 2024
9d928b9
Revert "Merge branch 'develop' of https://github.com/cheqd/cheqd-node…
Eengineer1 Sep 24, 2024
4684112
Merge branch 'develop' into ap/add-feeabs-mod
Eengineer1 Sep 24, 2024
80e6c46
Temporarily disabled upgrade test suite
Eengineer1 Sep 24, 2024
1a50b17
gofumpt'ed
Eengineer1 Sep 24, 2024
23fdff8
Bump gas adjustment
Eengineer1 Sep 24, 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
282 changes: 282 additions & 0 deletions ante/fee_test.go
Eengineer1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package ante_test

import (
"strings"

cheqdante "github.com/cheqd/cheqd-node/ante"
cheqdpost "github.com/cheqd/cheqd-node/post"
didtypes "github.com/cheqd/cheqd-node/x/did/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/ante"
"github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -385,3 +391,279 @@ var _ = Describe("Fee tests on DeliverTx", func() {
Expect(feeCollectorBalance.Amount).To(Equal(sdk.NewInt(0)), "Reward was sent to the fee collector when taxable tx simulation mode")
})
})

var _ = Describe("Fee abstraction", func() {
var gasLimit uint64
var mockHostZoneConfig types.HostChainFeeAbsConfig

// mockHostZoneConfig is used to mock the host zone config, with ibcfee as the ibc fee denom to be used as alternative fee
BeforeEach(func() {
gasLimit = 200000
mockHostZoneConfig = types.HostChainFeeAbsConfig{
IbcDenom: "ibcfee",
OsmosisPoolTokenDenomIn: "osmosis",
PoolId: 1,
Status: types.HostChainFeeAbsStatus_UPDATED,
MinSwapAmount: 0,
}
})

// Define test cases inside a context
Context("Testing MempoolDecorator with different fee amounts", func() {
var suite *AnteTestSuite

BeforeEach(func() {
// Set up the test suite for each test case
suite = new(AnteTestSuite)
err := suite.SetupTest(true) // setup
Expect(err).To(BeNil(), "Error on creating test app")
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
})

It("should fail with empty fee", func() {
feeAmount := sdk.Coins{}
minGasPrice := sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("ncheq", 100))...)
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetFeeAmount(feeAmount)
suite.ctx = suite.ctx.WithMinGasPrices(minGasPrice)

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
mempoolDecorator := ante.NewFeeAbstrationMempoolFeeDecorator(suite.app.FeeabsKeeper)
anteHandler := sdk.ChainAnteDecorators(mempoolDecorator)

_, err := anteHandler(suite.ctx, tx, false)

// Expect error due to insufficient fee
Expect(err).To(HaveOccurred())
Expect(strings.Contains(err.Error(), errors.ErrInsufficientFee.Error())).To(BeTrue())
})

It("should fail with insufficient native fee", func() {
feeAmount := sdk.NewCoins(sdk.NewInt64Coin("ncheq", 100))
minGasPrice := sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("ncheq", 1000))...)
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetFeeAmount(feeAmount)
suite.ctx = suite.ctx.WithMinGasPrices(minGasPrice)

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
mempoolDecorator := ante.NewFeeAbstrationMempoolFeeDecorator(suite.app.FeeabsKeeper)
anteHandler := sdk.ChainAnteDecorators(mempoolDecorator)

_, err := anteHandler(suite.ctx, tx, false)

// Expect error due to insufficient fee
Expect(err).To(HaveOccurred())
Expect(strings.Contains(err.Error(), errors.ErrInsufficientFee.Error())).To(BeTrue())
})

It("should pass with sufficient native fee", func() {
feeAmount := sdk.NewCoins(sdk.NewInt64Coin("ncheq", 1000*int64(gasLimit)))
minGasPrice := sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("ncheq", 1000))...)
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetFeeAmount(feeAmount)
suite.ctx = suite.ctx.WithMinGasPrices(minGasPrice)

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
mempoolDecorator := ante.NewFeeAbstrationMempoolFeeDecorator(suite.app.FeeabsKeeper)
anteHandler := sdk.ChainAnteDecorators(mempoolDecorator)

_, err := anteHandler(suite.ctx, tx, false)

// No error is expected
Expect(err).ToNot(HaveOccurred())
})

It("should fail with unknown ibc fee denom", func() {
feeAmount := sdk.NewCoins(sdk.NewInt64Coin("ibcfee", 1000*int64(gasLimit)))
minGasPrice := sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("ncheq", 1000))...)
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetFeeAmount(feeAmount)
suite.ctx = suite.ctx.WithMinGasPrices(minGasPrice)

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
mempoolDecorator := ante.NewFeeAbstrationMempoolFeeDecorator(suite.app.FeeabsKeeper)
anteHandler := sdk.ChainAnteDecorators(mempoolDecorator)

_, err := anteHandler(suite.ctx, tx, false)

// Expect error due to unknown ibc fee denom
Expect(err).To(HaveOccurred())
Expect(strings.Contains(err.Error(), errors.ErrInvalidCoins.Error())).To(BeTrue())
})

It("should pass with sufficient ibc fee", func() {
feeAmount := sdk.NewCoins(sdk.NewInt64Coin("ibcfee", 1000*int64(gasLimit)))
minGasPrice := sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))...)
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetFeeAmount(feeAmount)
suite.ctx = suite.ctx.WithMinGasPrices(minGasPrice)

// Configure the HostZoneConfig
err := suite.app.FeeabsKeeper.SetHostZoneConfig(suite.ctx, mockHostZoneConfig)
Expect(err).ToNot(HaveOccurred())
suite.app.FeeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", sdk.NewDec(1))

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
mempoolDecorator := ante.NewFeeAbstrationMempoolFeeDecorator(suite.app.FeeabsKeeper)
anteHandler := sdk.ChainAnteDecorators(mempoolDecorator)

_, err = anteHandler(suite.ctx, tx, false)

// No error is expected
Expect(err).ToNot(HaveOccurred())
})
})
})

var _ = Describe("DeductFeeDecorator", func() {
var gasLimit uint64
var minGasPrice sdk.DecCoins
var feeAmount sdk.Coins
var ibcFeeAmount sdk.Coins
var mockHostZoneConfig types.HostChainFeeAbsConfig
var suite *AnteTestSuite
var testAcc TestAccount

// Setup the common test data
BeforeEach(func() {
gasLimit = 200000
minGasPrice = sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("ncheq", 1000))...)
feeAmount = sdk.NewCoins(sdk.NewInt64Coin("ncheq", 1000*int64(gasLimit)))
ibcFeeAmount = sdk.NewCoins(sdk.NewInt64Coin("ibcfee", 1000*int64(gasLimit)))

mockHostZoneConfig = types.HostChainFeeAbsConfig{
IbcDenom: "ibcfee",
OsmosisPoolTokenDenomIn: "osmosis",
PoolId: 1,
Status: types.HostChainFeeAbsStatus_UPDATED,
MinSwapAmount: 0,
}

// Initialize suite for each test case
suite = new(AnteTestSuite)
err := suite.SetupTest(true) // setup
Expect(err).To(BeNil(), "Error on creating test app")
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
acc, err := suite.CreateTestAccounts(1)
testAcc = acc[0]
Expect(err).To(BeNil())
Expect(len(acc)).To(Equal(1))
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetFeePayer(acc[0].acc.GetAddress())
suite.ctx = suite.ctx.WithMinGasPrices(minGasPrice)

params := suite.app.StakingKeeper.GetParams(suite.ctx)
params.BondDenom = "ncheq"
err = suite.app.StakingKeeper.SetParams(suite.ctx, params)
Expect(err).To(BeNil(), "Error setting the params")

// this line will create the module account
_ = suite.app.AccountKeeper.GetModuleAccount(suite.ctx, types.ModuleName)
})

Describe("Handling Deduct Fee Decorator", func() {
When("native fee is insufficient", func() {
It("should fail due to insufficient native fee", func() {
suite.app.FeeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", sdk.NewDec(1))
_, _, addr := testdata.KeyTestPubAddr()
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr)
err := acc.SetAccountNumber(1)
Expect(err).ToNot(HaveOccurred())

suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

suite.txBuilder.SetFeePayer(acc.GetAddress())
// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
deductFeeDecorator := ante.NewFeeAbstractionDeductFeeDecorate(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.FeeabsKeeper, suite.app.FeeGrantKeeper)
anteHandler := sdk.ChainAnteDecorators(deductFeeDecorator)

_, err = anteHandler(suite.ctx, tx, false)

Expect(err).To(HaveOccurred())
Expect(strings.Contains(err.Error(), errors.ErrInsufficientFunds.Error())).To(BeTrue())
})
})
})

When("native fee is sufficient", func() {
It("should pass with sufficient native fee", func() {
suite.app.FeeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", sdk.NewDec(1))

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
deductFeeDecorator := ante.NewFeeAbstractionDeductFeeDecorate(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.FeeabsKeeper, suite.app.FeeGrantKeeper)
anteHandler := sdk.ChainAnteDecorators(deductFeeDecorator)

_, err := anteHandler(suite.ctx, tx, false)

Expect(err).ToNot(HaveOccurred())
})
})

When("ibc fee is insufficient", func() {
It("should fail due to insufficient ibc fee", func() {
err := suite.app.FeeabsKeeper.SetHostZoneConfig(suite.ctx, mockHostZoneConfig)
Expect(err).ToNot(HaveOccurred())
suite.app.FeeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", sdk.NewDec(1))

suite.txBuilder.SetFeeAmount(ibcFeeAmount)

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
deductFeeDecorator := ante.NewFeeAbstractionDeductFeeDecorate(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.FeeabsKeeper, suite.app.FeeGrantKeeper)
anteHandler := sdk.ChainAnteDecorators(deductFeeDecorator)

_, err = anteHandler(suite.ctx, tx, false)

Expect(err).To(HaveOccurred())
Expect(strings.Contains(err.Error(), errors.ErrInsufficientFunds.Error())).To(BeTrue())
})
})

When("ibc fee is sufficient", func() {
It("should pass with sufficient ibc fee", func() {
err := suite.app.FeeabsKeeper.SetHostZoneConfig(suite.ctx, mockHostZoneConfig)
Expect(err).ToNot(HaveOccurred())
suite.app.FeeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", sdk.NewDec(1))
suite.txBuilder.SetFeeAmount(ibcFeeAmount)

feeabsAddr := suite.app.FeeabsKeeper.GetFeeAbsModuleAddress()

err = suite.mintCoins(feeabsAddr, sdk.NewCoins(feeAmount...))
Expect(err).ToNot(HaveOccurred())

err = suite.mintCoins(testAcc.acc.GetAddress(), sdk.NewCoins(ibcFeeAmount...))
Expect(err).ToNot(HaveOccurred())

// Construct and run the ante handler
tx := suite.txBuilder.GetTx()
deductFeeDecorator := ante.NewFeeAbstractionDeductFeeDecorate(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.FeeabsKeeper, suite.app.FeeGrantKeeper)
anteHandler := sdk.ChainAnteDecorators(deductFeeDecorator)

_, err = anteHandler(suite.ctx, tx, false)

Expect(err).ToNot(HaveOccurred())
})
})
})

func (s *AnteTestSuite) mintCoins(addr sdk.AccAddress, someCoins sdk.Coins) error {
err := s.app.BankKeeper.MintCoins(s.ctx, minttypes.ModuleName, someCoins)
if err != nil {
return err
}

err = s.app.BankKeeper.SendCoinsFromModuleToAccount(s.ctx, minttypes.ModuleName, addr, someCoins)
if err != nil {
return err
}

return nil
}
6 changes: 5 additions & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
feeabsante "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/ante"
feeabskeeper "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/keeper"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
Expand All @@ -26,6 +28,7 @@ type HandlerOptions struct {
IBCKeeper *ibckeeper.Keeper
DidKeeper cheqdante.DidKeeper
ResourceKeeper cheqdante.ResourceKeeper
FeeAbskeeper feeabskeeper.Keeper
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand All @@ -51,11 +54,12 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
feeabsante.NewFeeAbstrationMempoolFeeDecorator(options.FeeAbskeeper),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
cheqdante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
feeabsante.NewFeeAbstractionDeductFeeDecorate(options.AccountKeeper, options.BankKeeper, options.FeeAbskeeper, options.FeegrantKeeper),
Eengineer1 marked this conversation as resolved.
Show resolved Hide resolved
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
Expand Down
Loading
Loading