Skip to content

Commit

Permalink
feat: implement simapp and e2e tests (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey authored May 22, 2024
1 parent ba89b76 commit 0ef1a33
Show file tree
Hide file tree
Showing 30 changed files with 7,716 additions and 6 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: End to End Tests

on:
pull_request:

env:
TAR_PATH: docker-image.tar
ARTIFACT_NAME: tar-docker-image

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Build Docker Image
uses: strangelove-ventures/[email protected]
with:
registry: "" # empty registry, image only shared for e2e testing
tag: local # emulate local environment for consistency in interchaintest cases
tar-export-path: ${{ env.TAR_PATH }} # export a tarball that can be uploaded as an artifact for the e2e jobs
platform: linux/amd64 # test runner architecture only
git-ref: ${{ github.head_ref }} # source code ref

# Heighliner chains.yaml config
chain: noble-authority-simd
dockerfile: cosmos
build-target: make build
build-dir: simapp
binaries: |
- simapp/build/simd
- name: Publish Tarball as Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.TAR_PATH }}

prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '>=1.22'

- name: Generate Matrix
id: set-matrix
run: |
# Run the command and convert its output to a JSON array
TESTS=$(cd e2e && go test -list . | grep -v "^ok " | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=${TESTS}" >> $GITHUB_OUTPUT
test:
needs:
- build
- prepare
runs-on: ubuntu-latest
strategy:
matrix:
# names of `make` commands to run tests
test: ${{fromJson(needs.prepare.outputs.matrix)}}
fail-fast: false

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '>=1.22'

- name: Download Tarball Artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}

- name: Load Docker Image
run: docker image load -i ${{ env.TAR_PATH }}

- name: Run Tests
run: cd e2e && go test -race -v -timeout 15m -run ^${{ matrix.test }}$ .
5 changes: 4 additions & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Unit Tests

on:
push:
branches:
- main
- v*
pull_request:

jobs:
Expand All @@ -14,7 +17,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: '>=1.22'

- name: Run Tests
run: make test-unit
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.authority
.idea
build
coverage.out
27 changes: 24 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
.PHONY: proto-format proto-lint proto-gen format lint test-unit
all: proto-all format lint test
.PHONY: proto-format proto-lint proto-gen format lint test-unit build local-image test-e2e
all: proto-all format lint test-unit build local-image test-e2e

###############################################################################
### Build ###
###############################################################################

build:
@echo "🤖 Building simd..."
@cd simapp && make build 1> /dev/null
@echo "✅ Completed build!"

###############################################################################
### Formatting & Linting ###
Expand Down Expand Up @@ -49,9 +58,21 @@ proto-lint:
### Testing ###
###############################################################################

test: test-unit
local-image:
ifeq (,$(shell which heighliner))
@echo heighliner not found. https://github.com/strangelove-ventures/heighliner
else
@echo "🤖 Building image..."
@heighliner build --chain noble-authority-simd --local 1> /dev/null
@echo "✅ Completed build!"
endif

test-unit:
@echo "🤖 Running unit tests..."
@go test -cover -coverprofile=coverage.out -race -v ./x/authority/keeper/...
@echo "✅ Completed unit tests!"

test-e2e:
@echo "🤖 Running e2e tests..."
@cd e2e && go test -timeout 15m -race -v ./...
@echo "✅ Completed e2e tests!"
Binary file added audits/Authority Module Audit.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions chains.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: noble-authority-simd
dockerfile: cosmos
build-dir: simapp
build-target: make build
binaries:
- simapp/build/simd
26 changes: 26 additions & 0 deletions e2e/clients.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"body": {
"messages": [
{
"@type": "/ibc.core.client.v1.MsgRecoverClient",
"signer": "noble13am065qmk680w86wya4u9refhnssqwcvgs0sfk",
"subject_client_id": "07-tendermint-0",
"substitute_client_id": "07-tendermint-1"
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
74 changes: 74 additions & 0 deletions e2e/clients_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package e2e

import (
_ "embed"
"path"
"testing"

"cosmossdk.io/math"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"github.com/stretchr/testify/require"
)

//go:embed clients.json
var Clients []byte

// TestClientSubstitution tests the module's ability to substitute IBC clients.
func TestClientSubstitution(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx, reporter, rly := Suite(t, &wrapper, true)
validator := wrapper.chain.Validators[0]

nobleChainID, gaiaChainID := wrapper.chain.Config().ChainID, wrapper.gaia.Config().ChainID
pathName := "transfer"

err := rly.GeneratePath(ctx, reporter, nobleChainID, gaiaChainID, pathName)
require.NoError(t, err)

err = rly.CreateClient(ctx, reporter, nobleChainID, gaiaChainID, pathName, ibc.CreateClientOptions{
TrustingPeriod: "30s",
})
require.NoError(t, err)
err = rly.CreateClient(ctx, reporter, gaiaChainID, nobleChainID, pathName, ibc.CreateClientOptions{})
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 1, wrapper.chain, wrapper.gaia))

err = rly.CreateConnections(ctx, reporter, pathName)
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 1, wrapper.chain, wrapper.gaia))

err = rly.CreateChannel(ctx, reporter, pathName, ibc.DefaultChannelOpts())
require.NoError(t, err)

users := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(5_000_000), wrapper.chain, wrapper.gaia)
require.NoError(t, testutil.WaitForBlocks(ctx, 10, wrapper.chain, wrapper.gaia))

_, err = validator.SendIBCTransfer(ctx, "channel-0", users[0].KeyName(), ibc.WalletAmount{
Address: users[1].FormattedAddress(),
Denom: "uusdc",
Amount: math.NewInt(1_000_000),
}, ibc.TransferOptions{})
require.ErrorContains(t, err, "client state is not active")

res := rly.Exec(ctx, reporter, []string{"rly", "tx", "client", nobleChainID, gaiaChainID, pathName, "--override", "--home", rly.HomeDir()}, nil)
require.NoError(t, res.Err)

require.NoError(t, validator.WriteFile(ctx, Clients, "clients.json"))
_, err = validator.ExecTx(
ctx, wrapper.owner.KeyName(),
"authority", "execute", path.Join(validator.HomeDir(), "clients.json"),
)
require.NoError(t, err)

_, err = validator.SendIBCTransfer(ctx, "channel-0", users[0].KeyName(), ibc.WalletAmount{
Address: users[1].FormattedAddress(),
Denom: "uusdc",
Amount: math.NewInt(1_000_000),
}, ibc.TransferOptions{})
require.NoError(t, err)
}
Loading

0 comments on commit 0ef1a33

Please sign in to comment.