Skip to content

Commit

Permalink
feat: add icq module & add fee-abs docker tests (#787)
Browse files Browse the repository at this point in the history
* add fee abs module

* fix tests

* fix tests

* fix tests

* fix tests

* feat: integrated feemarket

* add fee abs keeper in HandlerOptions

* fix tests

* add logs

* chore: updated anteHandler and postHandler

* chore: use replace for feemarket in go.mod

* chore: changed go version in docker file

* fix : fix testing in antehandler

* fix: fix lint issues

* chore: updated antehandler

* fix: fix lint issues

* fix: fix lint issues

* fix: lint issus

* chore: updated ante and fix test cases

* fix: gofumt errors

* fix: golint issues

* chore: updated postHandler

* testing

* chore: added test cases

* fix

* fix

* fix: golint issues

* fix : fix testcase

* fix: fix lint issues

* disable update tests

* disable report test

* fix: added response check in tests

* fix

* chore: added param subsace for feemarket

* add unit tests

* fix test

* fix lint

* remove comment

* addressed review comments

* fix

* fix

* fix

* TODO in app.go

* fix: golint error

* add go mod

* cheqd changes

* go.mod

* go mod

* add tests

* integrate ICQ module

* fix lint

* fix go mod

* add extra case

* fix failing test case

* add tests for fee-abs

* go mod changes

* change build name

* fix test

* fix tests

* fix lint

* fix tests

* update gitignore

* Apply suggestions from code review

* fix lint

* Update tests/fee-abs/cheqd/proposal.json

* Update tests/fee-abs/osmosis/pool.json

* Update .gitignore

* remove icq, fee-abs is not depending on it.

* Removed redundant

---------

Co-authored-by: vishal <[email protected]>
Co-authored-by: Tasos Derisiotis <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent 4930576 commit 26d77d1
Show file tree
Hide file tree
Showing 26 changed files with 888 additions and 4,917 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,7 @@ cython_debug/

# ignore mnemonics
tests/ibc-defi/cheqd_relayer_mnemonic.txt
tests/ibc-defi/osmo_relayer_mnemonic.txt
tests/ibc-defi/osmo_relayer_mnemonic.txt

tests/fee-abs/cheqd_relayer_mnemonic.txt
tests/fee-abs/osmo_relayer_mnemonic.txt
79 changes: 71 additions & 8 deletions ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,10 +1192,6 @@ var _ = Describe("Fee abstraction along with fee market", func() {
})

It("Ensure native tx fee txns are working", func() {
err := s.app.FeeabsKeeper.SetHostZoneConfig(s.ctx, mockHostZoneConfig)
Expect(err).ToNot(HaveOccurred())
s.app.FeeabsKeeper.SetTwapRate(s.ctx, "ibcfee", sdk.NewDec(1))

anteHandler := sdk.ChainAnteDecorators(decorators...)

priv1, _, addr1 := testdata.KeyTestPubAddr()
Expand Down Expand Up @@ -1324,11 +1320,78 @@ var _ = Describe("Fee abstraction along with fee market", func() {
Expect(feeCollectorBalance.Amount).To(Equal(reward.AmountOf(didtypes.BaseMinimalDenom)), "Reward was not sent to the fee collector")
})

It("Ensure taxable txn working fine after integrating the fee-abs", func() {
// err := s.app.FeeabsKeeper.SetHostZoneConfig(s.ctx, mockHostZoneConfig)
// Expect(err).ToNot(HaveOccurred())
// s.app.FeeabsKeeper.SetTwapRate(s.ctx, "ibcfee", sdk.NewDec(1))
It("Ensure to convert the IBC Denom to native fee for non taxable txn", func() {
err := s.app.FeeabsKeeper.SetHostZoneConfig(s.ctx, mockHostZoneConfig)
Expect(err).ToNot(HaveOccurred())
ibcDenom := "ibcfee"
s.app.FeeabsKeeper.SetTwapRate(s.ctx, ibcDenom, sdk.NewDec(1))

anteHandler := sdk.ChainAnteDecorators(decorators...)

priv1, _, addr1 := testdata.KeyTestPubAddr()

// msg and signatures
msg := testdata.NewTestMsg(addr1)
feeAmount := sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(50_000_000_000)))
gasLimit := testdata.NewTestGasLimit()
Expect(s.txBuilder.SetMsgs(msg)).To(BeNil())
s.txBuilder.SetFeeAmount(feeAmount)
s.txBuilder.SetGasLimit(gasLimit)
s.txBuilder.SetFeePayer(addr1)

privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tx, err := s.CreateTestTx(privs, accNums, accSeqs, s.ctx.ChainID())
Expect(err).To(BeNil())

// set account with sufficient funds
acc := s.app.AccountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.app.AccountKeeper.SetAccount(s.ctx, acc)
amount := sdk.NewInt(50_000_000_000)
err = testutil.FundAccount(s.app.BankKeeper, s.ctx, addr1, sdk.NewCoins(sdk.NewCoin(ibcDenom, amount)))
Expect(err).To(BeNil())

err = testutil.FundModuleAccount(s.app.BankKeeper, s.ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin("ncheq", amount)))
Expect(err).To(BeNil())

taxDecorator := cheqdpost.NewTaxDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.DidKeeper, s.app.ResourceKeeper, s.app.FeeMarketKeeper)
posthandler := sdk.ChainPostDecorators(taxDecorator)

// get supply before tx
supplyBefore, _, err := s.app.BankKeeper.GetPaginatedTotalSupply(s.ctx, &query.PageRequest{})
Expect(err).To(BeNil())

newCtx, err := anteHandler(s.ctx, tx, true)
Expect(err).To(BeNil())

_, _, proposer := testdata.KeyTestPubAddr()
s.ctx = newCtx
a := s.ctx.BlockHeader()
a.ProposerAddress = proposer
newCtx = s.ctx.WithBlockHeader(a)
s.ctx = newCtx

_, err = posthandler(s.ctx, tx, false, true)
Expect(err).To(BeNil(), "Tx errored when fee payer had sufficient funds and provided sufficient fee while subtracting tax on deliverTx")

// check balance of fee payer
balance := s.app.BankKeeper.GetBalance(s.ctx, addr1, ibcDenom)
Expect(amount.Sub(sdk.NewInt(feeAmount.AmountOf(ibcDenom).Int64())).Equal(balance.Amount)).To(BeTrue(), "Fee amount subtracted was not equal to fee amount required for non-taxable tx")

// get supply after tx
supplyAfter, _, err := s.app.BankKeeper.GetPaginatedTotalSupply(s.ctx, &query.PageRequest{})
Expect(err).To(BeNil())

// check that supply was not deflated
Expect(supplyBefore).To(Equal(supplyAfter), "Supply was deflated")

// check that reward has been sent to the fee collector
feeCollector := s.app.AccountKeeper.GetModuleAddress(feemarkettypes.FeeCollectorName)
feeCollectorBalance := s.app.BankKeeper.GetBalance(s.ctx, feeCollector, didtypes.BaseMinimalDenom)

Expect((feeCollectorBalance.Amount).GT(math.NewInt(0)))
})

It("Ensure taxable txn working fine after integrating the fee-abs", func() {
anteHandler := sdk.ChainAnteDecorators(decorators...)

priv1, _, addr1 := testdata.KeyTestPubAddr()
Expand Down
22 changes: 10 additions & 12 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ module github.com/cheqd/cheqd-node/api/v2
go 1.21

require (
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk/api v0.1.0
github.com/cosmos/gogoproto v1.4.10
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
github.com/cosmos/gogoproto v1.5.0
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
)

require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
)
9 changes: 8 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ type App struct {
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedResourceKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper
ScopedFeeAbsKeeper capabilitykeeper.ScopedKeeper
FeeabsKeeper feeabskeeper.Keeper

DidKeeper didkeeper.Keeper
Expand Down Expand Up @@ -550,6 +552,8 @@ func New(
scopedFeeabsKeeper,
)

feeabsModule := feeabsmodule.NewAppModule(appCodec, app.FeeabsKeeper)
feeabsIBCModule := feeabsmodule.NewIBCModule(appCodec, app.FeeabsKeeper)
app.FeeMarketKeeper.SetDenomResolver(&cheqdante.DenomResolverImpl{
StakingKeeper: app.StakingKeeper,
FeeabsKeeper: app.FeeabsKeeper,
Expand Down Expand Up @@ -607,7 +611,8 @@ func New(
// Add host, controller & ica auth modules to IBC router
ibcRouter.
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack)
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(feeabstypes.ModuleName, feeabsIBCModule)

// x/resource
app.ResourceKeeper = *resourcekeeper.NewKeeper(
Expand Down Expand Up @@ -686,6 +691,7 @@ func New(
// cheqd modules
did.NewAppModule(appCodec, app.DidKeeper),
resource.NewAppModule(appCodec, app.ResourceKeeper, app.DidKeeper),
feeabsModule,
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -866,6 +872,7 @@ func New(
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedResourceKeeper = scopedResourceKeeper
app.ScopedFeeAbsKeeper = scopedFeeabsKeeper

return app
}
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ replace (
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0

// github.com/osmosis-labs/fee-abstraction/v7 => /home/vitwit/go/src/github.com/cheqd/fee-abstraction
github.com/osmosis-labs/fee-abstraction/v7 => github.com/cheqd/fee-abstraction/v7 v7.0.3-0.20240919093501-645e58a8252d

github.com/skip-mev/feemarket => github.com/cheqd/feemarket v1.0.4-sdk47.0.20240919093317-104ec7d7b634
// github.com/skip-mev/feemarket => /home/vitwit/go/src/github.com/cheqd/feemarket

// replace broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
Loading

0 comments on commit 26d77d1

Please sign in to comment.