Skip to content

Commit

Permalink
feat: package-forwarding-middleware and ibc-hooks (#416)
Browse files Browse the repository at this point in the history
Co-authored-by: Pham Anh Minh <[email protected]>
Co-authored-by: Dong Lieu <[email protected]>
Co-authored-by: Lặc <[email protected]>
Co-authored-by: Pham Anh Minh <[email protected]>
Co-authored-by: expertdicer <[email protected]>
  • Loading branch information
6 people authored Feb 23, 2024
1 parent 9b972d2 commit 0aa8152
Show file tree
Hide file tree
Showing 66 changed files with 7,594 additions and 105 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Run End-To-End Tests

on:
workflow_dispatch:
pull_request:
push:
branches:
- frag/foundation
permissions:
contents: read
packages: write

jobs:
e2e:
name: Tests
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
-
name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.4'
-
name: Check out repository code
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build e2e image
uses: docker/build-push-action@v3
with:
file: ./tests/e2e/e2e.Dockerfile
context: .
platforms: linux/amd64
tags: terra:debug
build-args: |
BASE_IMG_TAG=debug
-
name: Testing
run: make test-e2e
108 changes: 108 additions & 0 deletions .github/workflows/interchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Interchain Tests

on:
workflow_dispatch:
pull_request:
push:
branches:
- frag/foundation
permissions:
contents: read
packages: write

jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Check out repository code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build interchain image
id: build_image
uses: docker/build-push-action@v3
with:
file: ./ictest.Dockerfile
context: .
platforms: linux/amd64
tags: |
core:local
test-terra-start:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

- name: checkout code
uses: actions/checkout@v4

- run: make ictest-start

test-ibc-transfer:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

- name: checkout code
uses: actions/checkout@v4

- run: make ictest-ibc

test-ibc-hooks:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

- name: checkout code
uses: actions/checkout@v4

- run: make ictest-ibc-hooks

test-ibc-pfm:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

- name: checkout code
uses: actions/checkout@v4

- run: make ictest-ibc-pfm

test-validator:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

- name: checkout code
uses: actions/checkout@v4

- run: make ictest-validator
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/make -f

include tests/e2e/e2e.mk

PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
Expand Down Expand Up @@ -248,6 +250,31 @@ benchmark:

.PHONY: test test-all test-cover test-unit test-race

###############################################################################
### Interchain test ###
###############################################################################
# Executes basic chain tests via interchaintest
ictest-start: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraStart .

ictest-validator: ictest-build
@cd tests/interchaintest && go test -timeout=25m -race -v -run TestValidator .

ictest-ibc: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraGaiaIBCTranfer .

ictest-ibc-hooks: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraIBCHooks .

ictest-ibc-pfm: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraGaiaOsmoPFM .

ictest-ibc-pfm-terra: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraPFM .

ictest-build:
@DOCKER_BUILDKIT=1 docker build -t core:local -f ictest.Dockerfile .

###############################################################################
### Linting ###
###############################################################################
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
v5 "github.com/classic-terra/core/v2/app/upgrades/v5"
v6 "github.com/classic-terra/core/v2/app/upgrades/v6"
v6_1 "github.com/classic-terra/core/v2/app/upgrades/v6_1"
v7 "github.com/classic-terra/core/v2/app/upgrades/v7"

customante "github.com/classic-terra/core/v2/custom/auth/ante"
custompost "github.com/classic-terra/core/v2/custom/auth/post"
Expand All @@ -67,7 +68,7 @@ var (
DefaultNodeHome string

// Upgrades defines upgrades to be applied to the network
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade, v6.Upgrade, v6_1.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade, v6.Upgrade, v6_1.Upgrade, v7.Upgrade}

// Forks defines forks to be applied to the network
Forks = []upgrades.Fork{}
Expand Down
91 changes: 74 additions & 17 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package keepers
import (
"path/filepath"

forward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router"
forwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/keeper"
forwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types"
icacontrollerkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types"
icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types"
ibcfeekeeper "github.com/cosmos/ibc-go/v6/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types"
ibctransfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host"
Expand Down Expand Up @@ -62,6 +66,10 @@ import (
oracletypes "github.com/classic-terra/core/v2/x/oracle/types"
treasurykeeper "github.com/classic-terra/core/v2/x/treasury/keeper"
treasurytypes "github.com/classic-terra/core/v2/x/treasury/types"

ibchooks "github.com/terra-money/core/v2/x/ibc-hooks"
ibchookskeeper "github.com/terra-money/core/v2/x/ibc-hooks/keeper"
ibchooktypes "github.com/terra-money/core/v2/x/ibc-hooks/types"
)

type AppKeepers struct {
Expand Down Expand Up @@ -95,6 +103,13 @@ type AppKeepers struct {
TreasuryKeeper treasurykeeper.Keeper
WasmKeeper wasmkeeper.Keeper
DyncommKeeper dyncommkeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ForwardKeeper forwardkeeper.Keeper

Ics20WasmHooks *ibchooks.WasmHooks
IBCHooksWrapper *ibchooks.ICS4Middleware
TransferStack ibctransfer.IBCModule
ForwardModule forward.AppModule

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -136,6 +151,8 @@ func NewAppKeepers(
ibcfeetypes.StoreKey,
icacontrollertypes.StoreKey,
icahosttypes.StoreKey,
ibchooktypes.StoreKey,
forwardtypes.StoreKey,
oracletypes.StoreKey,
markettypes.StoreKey,
treasurytypes.StoreKey,
Expand Down Expand Up @@ -275,19 +292,6 @@ func NewAppKeepers(
&appKeepers.IBCKeeper.PortKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper,
)

// Create Transfer Keepers
appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
appKeepers.IBCFeeKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
scopedTransferKeeper,
)

appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
appKeepers.keys[icahosttypes.StoreKey],
Expand All @@ -311,10 +315,6 @@ func NewAppKeepers(
bApp.MsgServiceRouter(),
)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := appKeepers.newIBCRouter()
appKeepers.IBCKeeper.SetRouter(ibcRouter)

// create evidence keeper with router
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, appKeepers.keys[evidencetypes.StoreKey], &appKeepers.StakingKeeper, appKeepers.SlashingKeeper,
Expand All @@ -341,6 +341,51 @@ func NewAppKeepers(
&appKeepers.WasmKeeper, distrtypes.ModuleName,
)

hooksKeeper := ibchookskeeper.NewKeeper(
appKeepers.keys[ibchooktypes.StoreKey],
)
appKeepers.IBCHooksKeeper = &hooksKeeper

appKeepers.ForwardKeeper = *forwardkeeper.NewKeeper(
appCodec,
appKeepers.keys[forwardtypes.StoreKey],
appKeepers.GetSubspace(forwardtypes.ModuleName),
appKeepers.TransferKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
appKeepers.IBCFeeKeeper, // ICS4 Wrapper
)

// - contract keeper needs to be initialized after wasm
// - transfer needs to be initialized before wasm
// - hooks needs to be initialized before transfer
wasmHooks := ibchooks.NewWasmHooks(
appKeepers.IBCHooksKeeper, nil,
sdk.GetConfig().GetBech32AccountAddrPrefix(),
)
appKeepers.Ics20WasmHooks = &wasmHooks

hooksMiddleware := ibchooks.NewICS4Middleware(
appKeepers.IBCFeeKeeper,
appKeepers.Ics20WasmHooks,
)
appKeepers.IBCHooksWrapper = &hooksMiddleware

// Create Transfer Keepers AFTER Hooks keeper but BEFORE wasm
appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
&appKeepers.ForwardKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
scopedTransferKeeper,
)
appKeepers.ForwardKeeper.SetTransferKeeper(appKeepers.TransferKeeper)

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic("error while reading wasm config: " + err.Error())
Expand Down Expand Up @@ -396,6 +441,10 @@ func NewAppKeepers(
wasmOpts...,
)

// AFTER wasm set contractKeeper for ics20 wasm hook
contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(appKeepers.WasmKeeper)
appKeepers.Ics20WasmHooks.ContractKeeper = contractKeeper

// register the proposal types
govRouter := appKeepers.newGovRouter()
govConfig := govtypes.DefaultConfig()
Expand Down Expand Up @@ -425,6 +474,12 @@ func NewAppKeepers(
appKeepers.ScopedIBCFeeKeeper = scopedIBCFeeKeeper
appKeepers.ScopedWasmKeeper = scopedWasmKeeper

appKeepers.ForwardModule = forward.NewAppModule(&appKeepers.ForwardKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := appKeepers.newIBCRouter()
appKeepers.IBCKeeper.SetRouter(ibcRouter)

return appKeepers
}

Expand Down Expand Up @@ -454,6 +509,8 @@ func initParamsKeeper(
paramsKeeper.Subspace(treasurytypes.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(dyncommtypes.ModuleName)
paramsKeeper.Subspace(ibchooktypes.ModuleName)
paramsKeeper.Subspace(forwardtypes.ModuleName).WithKeyTable(forwardtypes.ParamKeyTable())

return paramsKeeper
}
Expand Down
Loading

0 comments on commit 0aa8152

Please sign in to comment.