Skip to content

Commit 2180ed9

Browse files
catconcathoank101
andauthored
fix(feeabs): fix BeginBlocker disabled (#200)
* update params * fix and add custom fee test * fix BeginBlock not work on x/feeabs * remove log * fix ante * fix begin block panic * add ante test * Refactor * fix: miss init module acc * fix lint --------- Co-authored-by: Khanh Hoa <[email protected]>
1 parent 11340fb commit 2180ed9

26 files changed

+1254
-425
lines changed

.github/workflows/interchaintest.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- run: make ictest-basic
4343
env:
44-
BRANCH_CI: 'latest'
44+
BRANCH_CI: "latest"
4545

4646
test-ibc:
4747
runs-on: ubuntu-latest
@@ -57,9 +57,9 @@ jobs:
5757

5858
- run: make ictest-ibc
5959
env:
60-
BRANCH_CI: 'latest'
60+
BRANCH_CI: "latest"
6161

62-
test-packet-forward:
62+
test-ibc-ibcfee:
6363
runs-on: ubuntu-latest
6464
needs: build-and-push-image
6565
steps:
@@ -71,11 +71,11 @@ jobs:
7171
- name: checkout code
7272
uses: actions/checkout@v3
7373

74-
- run: make ictest-packet-forward
74+
- run: make ictest-ibc-custom
7575
env:
76-
BRANCH_CI: 'latest'
76+
BRANCH_CI: "latest"
7777

78-
test-host-zone-proposal:
78+
test-packet-forward:
7979
runs-on: ubuntu-latest
8080
needs: build-and-push-image
8181
steps:
@@ -87,11 +87,11 @@ jobs:
8787
- name: checkout code
8888
uses: actions/checkout@v3
8989

90-
- run: make ictest-host-zone-proposal
90+
- run: make ictest-packet-forward
9191
env:
92-
BRANCH_CI: 'latest'
92+
BRANCH_CI: "latest"
9393

94-
test-feeabs:
94+
test-host-zone-proposal:
9595
runs-on: ubuntu-latest
9696
needs: build-and-push-image
9797
steps:
@@ -103,9 +103,9 @@ jobs:
103103
- name: checkout code
104104
uses: actions/checkout@v3
105105

106-
- run: make ictest-feeabs
106+
- run: make ictest-host-zone-proposal
107107
env:
108-
BRANCH_CI: 'latest'
108+
BRANCH_CI: "latest"
109109

110110
test-query-osmosis-twap:
111111
runs-on: ubuntu-latest
@@ -121,4 +121,4 @@ jobs:
121121

122122
- run: make ictest-query-osmosis-twap
123123
env:
124-
BRANCH_CI: 'latest'
124+
BRANCH_CI: "latest"

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ ictest-basic:
119119

120120
# Executes IBC tests via interchaintest
121121
ictest-ibc:
122-
cd tests/interchaintest && go test -timeout=25m -race -v -run TestFeeabsGaiaIBCTransfer .
122+
cd tests/interchaintest && go test -timeout=25m -race -v -run '^TestFeeabsGaiaIBCTransfer$$' .
123123

124124
# Executes IBC tests via interchaintest
125125
ictest-packet-forward:
@@ -128,12 +128,12 @@ ictest-packet-forward:
128128
ictest-host-zone-proposal:
129129
cd tests/interchaintest && go test -timeout=25m -race -v -run TestHostZoneProposal .
130130

131-
ictest-feeabs:
132-
cd tests/interchaintest && go test -timeout=25m -race -v -run '^TestFeeAbs$$' .
133-
134131
ictest-query-osmosis-twap:
135132
cd tests/interchaintest && go test -timeout=25m -race -v -run TestQueryOsmosisTwap .
136133

134+
ictest-ibc-custom:
135+
cd tests/interchaintest && go test -timeout=25m -race -v -run TestFeeabsGaiaIBCTransferWithIBCFee .
136+
137137
# ictest-feeabs-ibc-transfer:
138138
# cd tests/interchaintest && go test -timeout=25m -race -v -run TestIBCTransferWithFeeAbs .
139139

app/app.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import (
3838
"github.com/rakyll/statik/fs"
3939
"github.com/spf13/cast"
4040

41+
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
42+
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
4143
"cosmossdk.io/client/v2/autocli"
4244
"cosmossdk.io/core/appmodule"
4345
"cosmossdk.io/log"
@@ -127,6 +129,11 @@ import (
127129

128130
const appName = "FeeApp"
129131

132+
var (
133+
_ runtime.AppI = (*FeeApp)(nil)
134+
_ servertypes.Application = (*FeeApp)(nil)
135+
)
136+
130137
// We pull these out so we can set them with LDFLAGS in the Makefile
131138
var (
132139
NodeDir = ".feeapp"
@@ -627,8 +634,11 @@ func NewFeeApp(
627634
// CanWithdrawInvariant invariant.
628635
// NOTE: staking module is required if HistoricalEntries param > 0
629636
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
630-
app.mm.SetOrderBeginBlockers(
637+
// NOTE: upgrade module is required to be prioritized
638+
app.mm.SetOrderPreBlockers(
631639
upgradetypes.ModuleName,
640+
)
641+
app.mm.SetOrderBeginBlockers(
632642
capabilitytypes.ModuleName,
633643
minttypes.ModuleName,
634644
distrtypes.ModuleName,
@@ -713,7 +723,13 @@ func NewFeeApp(
713723
if err := app.mm.RegisterServices(app.configurator); err != nil {
714724
panic(err)
715725
}
726+
autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules))
716727

728+
reflectionSvc, err := runtimeservices.NewReflectionService()
729+
if err != nil {
730+
panic(err)
731+
}
732+
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)
717733
// create the simulation manager and define the order of the modules for deterministic simulations
718734
//
719735
// NOTE: this is not required apps that don't use the simulator for fuzz testing
@@ -728,6 +744,7 @@ func NewFeeApp(
728744
app.MountKVStores(keys)
729745
app.MountTransientStores(tkeys)
730746
app.MountMemoryStores(memKeys)
747+
app.SetPreBlocker(app.PreBlocker)
731748

732749
app.SetInitChainer(app.InitChainer)
733750
app.SetBeginBlocker(app.BeginBlocker)
@@ -780,6 +797,11 @@ func (app *FeeApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
780797
return app.mm.EndBlock(ctx)
781798
}
782799

800+
// PreBlocker application updates every pre block
801+
func (app *FeeApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
802+
return app.mm.PreBlock(ctx)
803+
}
804+
783805
// InitChainer application update at chain initialization
784806
func (app *FeeApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
785807
var genesisState GenesisState

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/spf13/cast v1.6.0
2929
github.com/spf13/cobra v1.8.0
3030
github.com/stretchr/testify v1.9.0
31+
go.uber.org/mock v0.4.0
3132
golang.org/x/tools v0.20.0
3233
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
3334
google.golang.org/grpc v1.63.2
@@ -220,7 +221,7 @@ require (
220221
cloud.google.com/go/compute/metadata v0.2.3 // indirect
221222
cloud.google.com/go/iam v1.1.6 // indirect
222223
cloud.google.com/go/storage v1.36.0 // indirect
223-
cosmossdk.io/api v0.7.4 // indirect
224+
cosmossdk.io/api v0.7.4
224225
cosmossdk.io/core v0.11.0
225226
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
226227
cosmossdk.io/math v1.3.0
@@ -262,7 +263,7 @@ require (
262263
github.com/gogo/googleapis v1.4.1 // indirect
263264
github.com/golang/glog v1.2.0 // indirect
264265
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
265-
github.com/golang/mock v1.6.0 // indirect
266+
github.com/golang/mock v1.6.0
266267
github.com/golang/snappy v0.0.4 // indirect
267268
github.com/google/btree v1.1.2 // indirect
268269
github.com/google/go-cmp v0.6.0 // indirect

tests/interchaintest/chain_start_test.go

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package interchaintest
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

7-
"github.com/strangelove-ventures/interchaintest/v8"
88
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
9-
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
109
"github.com/stretchr/testify/require"
11-
"go.uber.org/zap/zaptest"
1210
)
1311

1412
// TestStartFeeabs is a basic test to assert that spinning up a Feeabs network with 1 validator works properly.
@@ -17,50 +15,11 @@ func TestStartFeeabs(t *testing.T) {
1715
t.Skip()
1816
}
1917

20-
t.Parallel()
21-
18+
// Set up chains, users and channels
2219
ctx := context.Background()
23-
24-
// Create chain factory with Feeabs
25-
numVals := 1
26-
numFullNodes := 1
27-
28-
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
29-
{
30-
Name: "feeabs",
31-
ChainConfig: feeabsConfig,
32-
NumValidators: &numVals,
33-
NumFullNodes: &numFullNodes,
34-
},
35-
})
36-
37-
// Get chains from the chain factory
38-
chains, err := cf.Chains(t.Name())
39-
require.NoError(t, err)
40-
41-
feeabs := chains[0].(*cosmos.CosmosChain)
42-
43-
// Relayer Factory
44-
client, network := interchaintest.DockerSetup(t)
45-
46-
// Create a new Interchain object which describes the chains, relayers, and IBC connections we want to use
47-
ic := interchaintest.NewInterchain().AddChain(feeabs)
48-
49-
rep := testreporter.NewNopReporter()
50-
eRep := rep.RelayerExecReporter(t)
51-
52-
err = ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
53-
TestName: t.Name(),
54-
Client: client,
55-
NetworkID: network,
56-
SkipPathCreation: true,
57-
58-
// This can be used to write to the block database which will index all block data e.g. txs, msgs, events, etc.
59-
// BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(),
60-
})
20+
chains, _, _ := SetupChain(t, ctx)
21+
feeabs, _, _ := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain), chains[2].(*cosmos.CosmosChain)
22+
a, err := feeabs.AuthQueryModuleAccounts(ctx)
6123
require.NoError(t, err)
62-
63-
t.Cleanup(func() {
64-
_ = ic.Close()
65-
})
24+
fmt.Println("module accounts", a)
6625
}

tests/interchaintest/feeabs/osmosis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func CreatePool(c *cosmos.CosmosChain, ctx context.Context, keyName string, params cosmos.OsmosisPoolParams) (string, error) {
14-
tn := getFullNode(c)
14+
tn := c.GetNode()
1515
poolbz, err := json.Marshal(params)
1616
if err != nil {
1717
return "", err
@@ -50,7 +50,7 @@ func CreatePool(c *cosmos.CosmosChain, ctx context.Context, keyName string, para
5050
func SetupProposePFM(c *cosmos.CosmosChain, ctx context.Context, keyName string, contractAddress string, message string, ibcdenom string) (txHash string, err error) {
5151
oneCoin := strconv.FormatInt(1, 10)
5252
amount := oneCoin + ibcdenom
53-
tn := getFullNode(c)
53+
tn := c.GetNode()
5454
return tn.ExecTx(ctx, keyName,
5555
"wasm", "execute", contractAddress, message, "--amount", amount, "--gas", "1000000",
5656
)

tests/interchaintest/feeabs/proposal.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ func getTransaction(ctx client.Context, txHash string) (*types.TxResponse, error
4343
}
4444

4545
func CrossChainSwap(c *cosmos.CosmosChain, ctx context.Context, keyName string, ibcDenom string) (tx ibc.Tx, _ error) {
46-
tn := getFullNode(c)
46+
tn := c.GetNode()
4747

4848
txHash, err := tn.ExecTx(ctx, keyName,
4949
"feeabs", "swap", ibcDenom,
5050
"--gas", "auto",
5151
)
52-
5352
if err != nil {
5453
return tx, fmt.Errorf("executing transaction failed: %w", err)
5554
}
@@ -103,7 +102,7 @@ func CrossChainSwap(c *cosmos.CosmosChain, ctx context.Context, keyName string,
103102
}
104103

105104
func AddHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
106-
tn := getFullNode(c)
105+
tn := c.GetNode()
107106
dat, err := os.ReadFile(fileLocation)
108107
if err != nil {
109108
return "", fmt.Errorf("failed to read file: %w", err)
@@ -127,7 +126,7 @@ func AddHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName str
127126
}
128127

129128
func DeleteHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
130-
tn := getFullNode(c)
129+
tn := c.GetNode()
131130
dat, err := os.ReadFile(fileLocation)
132131
if err != nil {
133132
return "", fmt.Errorf("failed to read file: %w", err)
@@ -151,7 +150,7 @@ func DeleteHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName
151150
}
152151

153152
func SetHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
154-
tn := getFullNode(c)
153+
tn := c.GetNode()
155154
dat, err := os.ReadFile(fileLocation)
156155
if err != nil {
157156
return "", fmt.Errorf("failed to read file: %w", err)
@@ -175,7 +174,7 @@ func SetHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName str
175174
}
176175

177176
func ParamChangeProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, prop *paramsutils.ParamChangeProposalJSON) (tx cosmos.TxProposal, _ error) {
178-
tn := getFullNode(c)
177+
tn := c.GetNode()
179178
content, err := json.Marshal(prop)
180179
if err != nil {
181180
return tx, err
@@ -206,7 +205,8 @@ func ParamChangeProposal(c *cosmos.CosmosChain, ctx context.Context, keyName str
206205
}
207206

208207
func txProposal(c *cosmos.CosmosChain, txHash string) (tx cosmos.TxProposal, _ error) {
209-
fn := getFullNode(c)
208+
fn := c.GetNode()
209+
210210
txResp, err := getTransaction(fn.CliContext(), txHash)
211211
if err != nil {
212212
return tx, fmt.Errorf("failed to get transaction %s: %w", txHash, err)

tests/interchaintest/feeabs/query.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func QueryHostZoneConfigWithDenom(c *cosmos.CosmosChain, ctx context.Context, denom string) (*HostChainFeeAbsConfigResponse, error) {
15-
tn := getFullNode(c)
15+
tn := c.GetNode()
1616
cmd := []string{"feeabs", "host-chain-config", denom}
1717
stdout, _, err := tn.ExecQuery(ctx, cmd...)
1818
if err != nil {
@@ -29,7 +29,7 @@ func QueryHostZoneConfigWithDenom(c *cosmos.CosmosChain, ctx context.Context, de
2929
}
3030

3131
func QueryAllHostZoneConfig(c *cosmos.CosmosChain, ctx context.Context) (*AllQueryHostChainConfigResponse, error) {
32-
tn := getFullNode(c)
32+
tn := c.GetNode()
3333
cmd := []string{"feeabs", "all-host-chain-config"}
3434
stdout, _, err := tn.ExecQuery(ctx, cmd...)
3535
if err != nil {
@@ -46,7 +46,7 @@ func QueryAllHostZoneConfig(c *cosmos.CosmosChain, ctx context.Context) (*AllQue
4646
}
4747

4848
func QueryModuleAccountBalances(c *cosmos.CosmosChain, ctx context.Context) (*feeabstypes.QueryFeeabsModuleBalacesResponse, error) {
49-
tn := getFullNode(c)
49+
tn := c.GetNode()
5050
cmd := []string{"feeabs", "module-balances"}
5151
stdout, _, err := tn.ExecQuery(ctx, cmd...)
5252
if err != nil {
@@ -63,7 +63,7 @@ func QueryModuleAccountBalances(c *cosmos.CosmosChain, ctx context.Context) (*fe
6363

6464
// QueryOsmosisArithmeticTwap queries the arithmetic twap of ibc denom stored in fee abstraction module
6565
func QueryOsmosisArithmeticTwap(c *cosmos.CosmosChain, ctx context.Context, ibcDenom string) (*feeabstypes.QueryOsmosisArithmeticTwapResponse, error) {
66-
node := getFullNode(c)
66+
node := c.GetNode()
6767
cmd := []string{"feeabs", "osmo-arithmetic-twap", ibcDenom}
6868
stdout, _, err := node.ExecQuery(ctx, cmd...)
6969
if err != nil {
@@ -79,7 +79,7 @@ func QueryOsmosisArithmeticTwap(c *cosmos.CosmosChain, ctx context.Context, ibcD
7979

8080
// QueryOsmosisArithmeticTwapOsmosis queries the arithmetic twap of a pool on osmosis chain
8181
func QueryOsmosisArithmeticTwapOsmosis(c *cosmos.CosmosChain, ctx context.Context, poolID, ibcDenom string) (*feeabstypes.QueryOsmosisArithmeticTwapResponse, error) {
82-
node := getFullNode(c)
82+
node := c.GetNode()
8383
currentEpoch := time.Now().Unix()
8484

8585
cmd := []string{"twap", "arithmetic", poolID, ibcDenom, fmt.Sprintf("%d", currentEpoch-20), fmt.Sprintf("%d", currentEpoch-10)}

0 commit comments

Comments
 (0)