Skip to content

Commit

Permalink
base pfm simapp
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Oct 5, 2023
1 parent e0bfde7 commit c84377a
Show file tree
Hide file tree
Showing 16 changed files with 2,609 additions and 30 deletions.
65 changes: 64 additions & 1 deletion .github/workflows/packet-forward-middleware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ env:
LINT_VERSION: v1.52
GO_VERSION: 1.21.0
WORKING_DIRECTORY: middleware/packet-forward-middleware/

DOCKER_TAG: pfm:local
TAR_PATH: /tmp/pfm-docker-image.tar
IMAGE_NAME: pfm-docker-image

jobs:
golangci:
Expand Down Expand Up @@ -39,4 +43,63 @@ jobs:
run: go test ./...
working-directory: ${{ env.WORKING_DIRECTORY }}

# TODO: e2e
# TODO: build in the correct repo
build-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and export
uses: docker/build-push-action@v5
with:
context: ${{ env.WORKING_DIRECTORY }}
tags: ${{ env.DOCKER_TAG }}
outputs: type=docker,dest=${{ env.TAR_PATH }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}
path: ${{ env.TAR_PATH }}

e2e-tests:
needs: build-docker
runs-on: ubuntu-latest
strategy:
matrix:
test:
- "ictest-forward"
- "ictest-timeout"
fail-fast: false

steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

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

- name: Download Tarball Artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}
path: /tmp

- name: Load Docker Image
run: |
docker image load -i ${{ env.TAR_PATH }}
docker image ls -a
- name: Run Test
run: make ${{ matrix.test }}
30 changes: 30 additions & 0 deletions middleware/packet-forward-middleware/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# docker build . -t pfm:local
# docker run --rm -it pfm:local q ibc-router

FROM golang:1.21-alpine3.18 as builder

RUN set -eux; apk add --no-cache git libusb-dev linux-headers gcc musl-dev make;

ENV GOPATH=""

ADD testing testing
ADD LICENSE LICENSE

COPY testing/contrib/devtools/Makefile contrib/devtools/Makefile
COPY Makefile .

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN make build

FROM alpine:3.18

COPY --from=builder /go/build/simd /bin/simd

ENTRYPOINT ["simd"]

12 changes: 11 additions & 1 deletion middleware/packet-forward-middleware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ BUILD_TARGETS := build install

build: BUILD_ARGS=-o $(BUILDDIR)/
build-linux:
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build -o bin/simd ./cmd/simd

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
Expand Down Expand Up @@ -211,6 +211,16 @@ endif

.PHONY: run-tests test test-all $(TEST_TARGETS)

###############################################################################
### e2e interchain test ###
###############################################################################

ictest-forward:
cd middleware/packet-forward-middleware/e2e && go test -race -v -run TestPacketForwardMiddleware .

ictest-timeout:
cd middleware/packet-forward-middleware/e2e && go test -race -v -run TestTimeoutOnForward .

###############################################################################
### Linting ###
###############################################################################
Expand Down
24 changes: 19 additions & 5 deletions middleware/packet-forward-middleware/e2e/packet_forward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,28 @@ func TestPacketForwardMiddleware(t *testing.T) {

chainIdA, chainIdB, chainIdC, chainIdD := "chain-a", "chain-b", "chain-c", "chain-d"

fullNodes := 1
vals := 1
fullNodes := 0

baseCfg := DefaultConfig

baseCfg.ChainID = chainIdA
configA := baseCfg

baseCfg.ChainID = chainIdB
configB := baseCfg

baseCfg.ChainID = chainIdC
configC := baseCfg

baseCfg.ChainID = chainIdD
configD := baseCfg

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{Name: "gaia", Version: "v9.0.1", ChainConfig: ibc.ChainConfig{ChainID: chainIdA, GasPrices: "0.0uatom"}, NumFullNodes: &fullNodes, NumValidators: &vals},
{Name: "gaia", Version: "v9.0.1", ChainConfig: ibc.ChainConfig{ChainID: chainIdB, GasPrices: "0.0uatom"}, NumFullNodes: &fullNodes, NumValidators: &vals},
{Name: "gaia", Version: "v9.0.1", ChainConfig: ibc.ChainConfig{ChainID: chainIdC, GasPrices: "0.0uatom"}, NumFullNodes: &fullNodes, NumValidators: &vals},
{Name: "gaia", Version: "v9.0.1", ChainConfig: ibc.ChainConfig{ChainID: chainIdD, GasPrices: "0.0uatom"}, NumFullNodes: &fullNodes, NumValidators: &vals},
{Name: "pfm", ChainConfig: configA, NumFullNodes: &fullNodes, NumValidators: &vals},
{Name: "pfm", ChainConfig: configB, NumFullNodes: &fullNodes, NumValidators: &vals},
{Name: "pfm", ChainConfig: configC, NumFullNodes: &fullNodes, NumValidators: &vals},
{Name: "pfm", ChainConfig: configD, NumFullNodes: &fullNodes, NumValidators: &vals},
})

chains, err := cf.Chains(t.Name())
Expand Down
80 changes: 80 additions & 0 deletions middleware/packet-forward-middleware/e2e/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package e2e

import (
"fmt"
"os"
"strings"

testutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibclocalhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
)

var (
pfmRepo, pfmVersion = GetDockerImageInfo()
PFMImage = ibc.DockerImage{
Repository: pfmRepo,
Version: pfmVersion,
UidGid: "1025:1025",
}

Denom = "token"
GenesisWalletAmount = int64(10_000_000)

DefaultConfig = ibc.ChainConfig{
Type: "cosmos",
Name: "pfm",
ChainID: "pfm-1",
Images: []ibc.DockerImage{PFMImage},
Bin: "simd",
Bech32Prefix: "cosmos",
Denom: Denom,
CoinType: "118",
GasPrices: fmt.Sprintf("0%s", Denom),
GasAdjustment: 2.0,
TrustingPeriod: "112h",
NoHostMount: false,
ConfigFileOverrides: nil,
EncodingConfig: encoding(),
UsingNewGenesisCommand: true,
}
)

func encoding() *testutil.TestEncodingConfig {
cfg := cosmos.DefaultEncoding()

// TODO: Getting this error
// Error: error creating clients: failed to create client on src chain{chain-c}: failed to find a matching client for the new client state: no concrete type registered for type URL /ibc.lightclients.localhost.v2.ClientState against interface *exported.ClientState

// register custom types
ibclocalhost.RegisterInterfaces(cfg.InterfaceRegistry)
transfertypes.RegisterInterfaces(cfg.InterfaceRegistry)
clienttypes.RegisterInterfaces(cfg.InterfaceRegistry)
connectiontypes.RegisterInterfaces(cfg.InterfaceRegistry)
channeltypes.RegisterInterfaces(cfg.InterfaceRegistry)

return &cfg
}

// GetDockerImageInfo returns the appropriate repo and branch version string for integration with the CI pipeline.
// The remote runner sets the BRANCH_CI env var. If present, interchaintest will use the docker image pushed up to the repo.
// If testing locally, user should run `make local-image` and interchaintest will use the local image.
func GetDockerImageInfo() (repo, version string) {
branchVersion, found := os.LookupEnv("BRANCH_CI")
repo = "strangelove-ventures/pfm"

// github action
if !found {
repo = "pfm"
branchVersion = "local"
}

// github converts / to - for pushed docker images
branchVersion = strings.ReplaceAll(branchVersion, "/", "-")
return repo, branchVersion
}
Loading

0 comments on commit c84377a

Please sign in to comment.