Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add chain upgrade test as gh action #430

Merged
merged 25 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/interchaintest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Run InterchainTest

on:
pull_request:
branches:
- main

jobs:
build_images:
name: Build archway images 🛠️
runs-on: ubuntu-latest

steps:
- name: Checkout archway-network/archway
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get last release tag
id: lastrelease
uses: revam/gh-action-get-tag-and-version@v1

- name: Checkout heighliner
uses: actions/checkout@v3
with:
repository: strangelove-ventures/heighliner
path: heighliner

- name: Setup up Golang
uses: actions/setup-go@v4
with:
go-version-file: 'heighliner/go.mod'

- name: Install heighliner
run: cd heighliner && go install

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build current image
run: |
heighliner build --org archway-network --repo archway --dockerfile cosmos --build-target "make build" --build-env "BUILD_TAGS=muslc" --binaries "build/archwayd" --git-ref ${{ github.head_ref }} --tag local
docker image tag acrechain:local archway:local
docker rmi acrechain:local

- name: Upload current image
uses: ishworkh/container-image-artifact-upload@v1.0.0
with:
image: archway:local
retention_days: 3

- name: Build ${{ steps.lastrelease.outputs.tag }} image
run: |
heighliner build --org archway-network --repo archway --dockerfile cosmos --build-target "make build" --build-env "BUILD_TAGS=muslc" --binaries "build/archwayd" --git-ref ${{ steps.lastrelease.outputs.tag }} --tag ${{ steps.lastrelease.outputs.tag }}
docker image tag acrechain:${{ steps.lastrelease.outputs.tag }} archway:${{ steps.lastrelease.outputs.tag }}
docker rmi acrechain:${{ steps.lastrelease.outputs.tag }}

- name: Upload ${{ steps.lastrelease.outputs.tag }} image
uses: ishworkh/container-image-artifact-upload@v1.0.0
with:
image: archway:${{ steps.lastrelease.outputs.tag }}
retention_days: 3

run_chain_upgrade_test:
name: Chain upgrade test 🏆
needs: [build_images]
runs-on: ubuntu-latest

steps:
- name: Checkout archway-network/archway/interchaintest
uses: actions/checkout@v3
with:
fetch-depth: 0
sparse-checkout: interchaintest

- name: Setup up Golang
uses: actions/setup-go@v4
with:
go-version-file: 'interchaintest/go.mod'

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Download current image
uses: actions/download-artifact@v3
with:
name: action_image_artifact_archway_local

- name: Load current image
run: docker load --input archway_local

- name: Get last release tag
id: lastrelease
uses: revam/gh-action-get-tag-and-version@v1

- name: Download ${{ steps.lastrelease.outputs.tag }} image
uses: actions/download-artifact@v3
with:
name: action_image_artifact_archway_${{ steps.lastrelease.outputs.tag }}

- name: Load ${{ steps.lastrelease.outputs.tag }} image
run: docker load --input archway_${{ steps.lastrelease.outputs.tag }}

- name: Run chain upgrade test
run: |
cd interchaintest
go test -v -race -run TestChainUpgrade
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Contains all the PRs that improved the code without changing the behaviours.
### Added

- [#429](https://github.com/archway-network/archway/pull/429) - Adding `cosmwasm_1_3` capabilities by bumping wasmd to v0.33.0
- [#430](https://github.com/archway-network/archway/pull/430) - Added gh workflow to run chain upgarde test on PRs

### Changed

Expand Down
37 changes: 37 additions & 0 deletions interchaintest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Interchain Test

## Chain upgrade test

To run the chain upgrade test locally:


1. Install Heighliner

```sh
git clone https://github.com/strangelove-ventures/heighliner.git
cd heighliner
go install
```

2. Build the current branch docker image

```sh
heighliner build --org archway-network --repo archway --dockerfile cosmos --build-target "make build" --build-env "BUILD_TAGS=muslc" --binaries "build/archwayd" --git-ref <local_branch_name> --tag local
docker image tag acrechain:local archway:local # There is an issue with heighliner where it wrongly names the docker image
docker rmi acrechain:local
```

3. Build the last release docker image

```sh
heighliner build --org archway-network --repo archway --dockerfile cosmos --build-target "make build" --build-env "BUILD_TAGS=muslc" --binaries "build/archwayd" --git-ref v3.0.0 --tag local
docker image tag acrechain:3.0.0archway:3.0.0
docker rmi acrechain:3.0.0
```

4. Now go to Archway repo root and

```sh
cd interchaintest
go test -v -race -run TestChainUpgrade
```
125 changes: 125 additions & 0 deletions interchaintest/chain_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package interchaintest

import (
"context"
"testing"
"time"

"github.com/docker/docker/client"
interchaintest "github.com/strangelove-ventures/interchaintest/v4"
"github.com/strangelove-ventures/interchaintest/v4/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v4/ibc"
"github.com/strangelove-ventures/interchaintest/v4/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

const (
haltHeightDelta = uint64(10) // The number of blocks after which to apply upgrade after creation of proposal.
blocksAfterUpgrade = uint64(10) // The number of blocks to wait for after the upgrade has been applied.
)

func TestChainUpgrade(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
}

archwayChain, client, ctx := startChain(t)
chainUser := fundChainUser(t, ctx, archwayChain)
haltHeight := submitUpgradeProposalAndVote(t, ctx, archwayChain, chainUser)

height, err := archwayChain.Height(ctx)
require.NoError(t, err, "cound not fetch height before upgrade")

timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Second*45)
defer timeoutCtxCancel()

// This should timeout due to chain halt at upgrade height.
_ = testutil.WaitForBlocks(timeoutCtx, int(haltHeight-height)+1, archwayChain)

height, err = archwayChain.Height(ctx)
require.NoError(t, err, "could not fetch height after chain should have halted")

// Make sure that chain is halted
require.Equal(t, haltHeight, height, "height is not equal to halt height")

// Bring down nodes to prepare for upgrade
err = archwayChain.StopAllNodes(ctx)
require.NoError(t, err, "could not stop node(s)")

// Upgrade version on all nodes - We are passing in the local image for the upgrade build
archwayChain.UpgradeVersion(ctx, client, chainName, "local")

// Start all nodes back up.
// Validators reach consensus on first block after upgrade height
// And chain block production resumes 🎉
err = archwayChain.StartAllNodes(ctx)
require.NoError(t, err, "could not start upgraded node(s)")

timeoutCtx, timeoutCtxCancel = context.WithTimeout(ctx, time.Second*45)
defer timeoutCtxCancel()

err = testutil.WaitForBlocks(timeoutCtx, int(blocksAfterUpgrade), archwayChain)
require.NoError(t, err, "chain did not produce blocks after upgrade")
}

func submitUpgradeProposalAndVote(t *testing.T, ctx context.Context, archwayChain *cosmos.CosmosChain, chainUser ibc.Wallet) uint64 {
height, err := archwayChain.Height(ctx) // The current chain height
require.NoError(t, err, "error fetching height before submit upgrade proposal")

haltHeight := height + haltHeightDelta // The height at which upgrade should be applied

proposal := cosmos.SoftwareUpgradeProposal{
Deposit: "10000000000" + archwayChain.Config().Denom,
Title: "Test upgrade",
Name: upgradeName,
Description: "Every PR we perform a upgrade check to ensure nothing breaks",
Height: haltHeight,
}

upgradeTx, err := archwayChain.UpgradeProposal(ctx, chainUser.KeyName(), proposal) // Submitting the software upgrade proposal
require.NoError(t, err, "error submitting software upgrade proposal tx")

err = archwayChain.VoteOnProposalAllValidators(ctx, upgradeTx.ProposalID, cosmos.ProposalVoteYes)
require.NoError(t, err, "failed to submit votes")

_, err = cosmos.PollForProposalStatus(ctx, archwayChain, height, height+haltHeightDelta, upgradeTx.ProposalID, cosmos.ProposalStatusPassed)
require.NoError(t, err, "proposal status did not change to passed in expected number of blocks")
return haltHeight
}

func fundChainUser(t *testing.T, ctx context.Context, archwayChain *cosmos.CosmosChain) ibc.Wallet {
const userFunds = int64(10_000_000_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, archwayChain)
return users[0]
}

func startChain(t *testing.T) (*cosmos.CosmosChain, *client.Client, context.Context) {
numOfVals := 1
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: chainName,
ChainName: "archway-1",
Version: initialVersion,
ChainConfig: archwayConfig,
NumValidators: &numOfVals,
},
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
archwayChain := chains[0].(*cosmos.CosmosChain)

ic := interchaintest.NewInterchain().AddChain(archwayChain)
client, network := interchaintest.DockerSetup(t)
ctx := context.Background()
require.NoError(t, ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
}))
t.Cleanup(func() {
_ = ic.Close()
})
return archwayChain, client, ctx
}
Loading
Loading