Skip to content

Commit

Permalink
fix(feeabs): fix BeginBlocker disabled (#200)
Browse files Browse the repository at this point in the history
* 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 <hoa@notional.ventures>
  • Loading branch information
tuantran1702 and hoank101 authored May 31, 2024
1 parent 11340fb commit 2180ed9
Show file tree
Hide file tree
Showing 26 changed files with 1,254 additions and 425 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/interchaintest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- run: make ictest-basic
env:
BRANCH_CI: 'latest'
BRANCH_CI: "latest"

test-ibc:
runs-on: ubuntu-latest
Expand All @@ -57,9 +57,9 @@ jobs:

- run: make ictest-ibc
env:
BRANCH_CI: 'latest'
BRANCH_CI: "latest"

test-packet-forward:
test-ibc-ibcfee:
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
Expand All @@ -71,11 +71,11 @@ jobs:
- name: checkout code
uses: actions/checkout@v3

- run: make ictest-packet-forward
- run: make ictest-ibc-custom
env:
BRANCH_CI: 'latest'
BRANCH_CI: "latest"

test-host-zone-proposal:
test-packet-forward:
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
Expand All @@ -87,11 +87,11 @@ jobs:
- name: checkout code
uses: actions/checkout@v3

- run: make ictest-host-zone-proposal
- run: make ictest-packet-forward
env:
BRANCH_CI: 'latest'
BRANCH_CI: "latest"

test-feeabs:
test-host-zone-proposal:
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
Expand All @@ -103,9 +103,9 @@ jobs:
- name: checkout code
uses: actions/checkout@v3

- run: make ictest-feeabs
- run: make ictest-host-zone-proposal
env:
BRANCH_CI: 'latest'
BRANCH_CI: "latest"

test-query-osmosis-twap:
runs-on: ubuntu-latest
Expand All @@ -121,4 +121,4 @@ jobs:

- run: make ictest-query-osmosis-twap
env:
BRANCH_CI: 'latest'
BRANCH_CI: "latest"
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ictest-basic:

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

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

ictest-feeabs:
cd tests/interchaintest && go test -timeout=25m -race -v -run '^TestFeeAbs$$' .

ictest-query-osmosis-twap:
cd tests/interchaintest && go test -timeout=25m -race -v -run TestQueryOsmosisTwap .

ictest-ibc-custom:
cd tests/interchaintest && go test -timeout=25m -race -v -run TestFeeabsGaiaIBCTransferWithIBCFee .

# ictest-feeabs-ibc-transfer:
# cd tests/interchaintest && go test -timeout=25m -race -v -run TestIBCTransferWithFeeAbs .

Expand Down
24 changes: 23 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
Expand Down Expand Up @@ -127,6 +129,11 @@ import (

const appName = "FeeApp"

var (
_ runtime.AppI = (*FeeApp)(nil)
_ servertypes.Application = (*FeeApp)(nil)
)

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".feeapp"
Expand Down Expand Up @@ -627,8 +634,11 @@ func NewFeeApp(
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
app.mm.SetOrderBeginBlockers(
// NOTE: upgrade module is required to be prioritized
app.mm.SetOrderPreBlockers(
upgradetypes.ModuleName,
)
app.mm.SetOrderBeginBlockers(
capabilitytypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
Expand Down Expand Up @@ -713,7 +723,13 @@ func NewFeeApp(
if err := app.mm.RegisterServices(app.configurator); err != nil {
panic(err)
}
autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules))

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

app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
Expand Down Expand Up @@ -780,6 +797,11 @@ func (app *FeeApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
return app.mm.EndBlock(ctx)
}

// PreBlocker application updates every pre block
func (app *FeeApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
return app.mm.PreBlock(ctx)
}

// InitChainer application update at chain initialization
func (app *FeeApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
var genesisState GenesisState
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
go.uber.org/mock v0.4.0
golang.org/x/tools v0.20.0
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/grpc v1.63.2
Expand Down Expand Up @@ -220,7 +221,7 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
cosmossdk.io/api v0.7.4 // indirect
cosmossdk.io/api v0.7.4
cosmossdk.io/core v0.11.0
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/math v1.3.0
Expand Down Expand Up @@ -262,7 +263,7 @@ require (
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/mock v1.6.0
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down
53 changes: 6 additions & 47 deletions tests/interchaintest/chain_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package interchaintest

import (
"context"
"fmt"
"testing"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

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

t.Parallel()

// Set up chains, users and channels
ctx := context.Background()

// Create chain factory with Feeabs
numVals := 1
numFullNodes := 1

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: "feeabs",
ChainConfig: feeabsConfig,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
})

// Get chains from the chain factory
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

feeabs := chains[0].(*cosmos.CosmosChain)

// Relayer Factory
client, network := interchaintest.DockerSetup(t)

// Create a new Interchain object which describes the chains, relayers, and IBC connections we want to use
ic := interchaintest.NewInterchain().AddChain(feeabs)

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

err = ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,

// This can be used to write to the block database which will index all block data e.g. txs, msgs, events, etc.
// BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(),
})
chains, _, _ := SetupChain(t, ctx)
feeabs, _, _ := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain), chains[2].(*cosmos.CosmosChain)
a, err := feeabs.AuthQueryModuleAccounts(ctx)
require.NoError(t, err)

t.Cleanup(func() {
_ = ic.Close()
})
fmt.Println("module accounts", a)
}
4 changes: 2 additions & 2 deletions tests/interchaintest/feeabs/osmosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func CreatePool(c *cosmos.CosmosChain, ctx context.Context, keyName string, params cosmos.OsmosisPoolParams) (string, error) {
tn := getFullNode(c)
tn := c.GetNode()
poolbz, err := json.Marshal(params)
if err != nil {
return "", err
Expand Down Expand Up @@ -50,7 +50,7 @@ func CreatePool(c *cosmos.CosmosChain, ctx context.Context, keyName string, para
func SetupProposePFM(c *cosmos.CosmosChain, ctx context.Context, keyName string, contractAddress string, message string, ibcdenom string) (txHash string, err error) {
oneCoin := strconv.FormatInt(1, 10)
amount := oneCoin + ibcdenom
tn := getFullNode(c)
tn := c.GetNode()
return tn.ExecTx(ctx, keyName,
"wasm", "execute", contractAddress, message, "--amount", amount, "--gas", "1000000",
)
Expand Down
14 changes: 7 additions & 7 deletions tests/interchaintest/feeabs/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ func getTransaction(ctx client.Context, txHash string) (*types.TxResponse, error
}

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

txHash, err := tn.ExecTx(ctx, keyName,
"feeabs", "swap", ibcDenom,
"--gas", "auto",
)

if err != nil {
return tx, fmt.Errorf("executing transaction failed: %w", err)
}
Expand Down Expand Up @@ -103,7 +102,7 @@ func CrossChainSwap(c *cosmos.CosmosChain, ctx context.Context, keyName string,
}

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

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

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

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

func txProposal(c *cosmos.CosmosChain, txHash string) (tx cosmos.TxProposal, _ error) {
fn := getFullNode(c)
fn := c.GetNode()

txResp, err := getTransaction(fn.CliContext(), txHash)
if err != nil {
return tx, fmt.Errorf("failed to get transaction %s: %w", txHash, err)
Expand Down
10 changes: 5 additions & 5 deletions tests/interchaintest/feeabs/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

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

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

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

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

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

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

0 comments on commit 2180ed9

Please sign in to comment.