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

chore: e2e upgrade #3

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ build-docs: diagrams ## Builds a docs site
done < versions ;
.PHONY: build-docs

###############################################################################
### E2E build ###
###############################################################################

# Executed to build the binary for chain initialization, one of
## chain => test/e2e/initialization/chain/main.go
## node => test/e2e/initialization/node/main.go
e2e-build-script:
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./test/e2e/initialization/$(E2E_SCRIPT_NAME)

###############################################################################
### Tests & Simulation ###
###############################################################################
Expand Down Expand Up @@ -243,7 +254,7 @@ endif

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

test-e2e: build-docker
test-e2e: build-docker-e2e
go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e

test-sim-nondeterminism:
Expand Down Expand Up @@ -411,14 +422,23 @@ proto-lint: ## Lint protobuf files
###############################################################################
### Docker ###
###############################################################################
dockerNetworkList=$($(DOCKER) network ls --filter name=bbn-testnet --format {{.ID}})

build-docker: ## Build babylond Docker image
$(MAKE) -C contrib/images babylond

build-docker-e2e:
$(MAKE) -C contrib/images babylond-e2e
$(MAKE) -C contrib/images babylond-before-upgrade
$(MAKE) -C contrib/images e2e-init-chain

build-cosmos-relayer-docker: ## Build Docker image for the Cosmos relayer
$(MAKE) -C contrib/images cosmos-relayer

.PHONY: build-docker build-cosmos-relayer-docker
clean-docker-network:
$(DOCKER) network rm ${dockerNetworkList}

.PHONY: build-docker build-docker-e2e build-cosmos-relayer-docker clean-docker-network

###############################################################################
### Localnet ###
Expand Down
9 changes: 9 additions & 0 deletions app/e2e_include_upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build e2e

package app

import "github.com/babylonlabs-io/babylon/app/upgrades/vanilla"

func init() {
Upgrades = append(Upgrades, vanilla.Upgrade)
}
41 changes: 35 additions & 6 deletions app/upgrades/vanilla/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,47 @@ func propVanilla(
accountKeeper *authkeeper.AccountKeeper,
bsKeeper *btcstakingkeeper.Keeper,
) {
// remove an account
// remove the account with higher number and the lowest is the new fp addr
allAccounts := accountKeeper.GetAllAccounts(ctx)
accountKeeper.RemoveAccount(ctx, allAccounts[len(allAccounts)-1])
var (
accToRemove sdk.AccountI
accFp sdk.AccountI
)
heighestAccNumber, lowestAccNumber := uint64(0), uint64(len(allAccounts))

// insert a FP
sk, err := btcec.NewPrivateKey()
for _, acc := range allAccounts {
accNumber := acc.GetAccountNumber()
if accNumber > heighestAccNumber {
heighestAccNumber = accNumber
accToRemove = acc
}
if accNumber < lowestAccNumber {
lowestAccNumber = accNumber
accFp = acc
}
}

accountKeeper.RemoveAccount(ctx, accToRemove)

// insert a FP from predefined public key
pk, err := btcec.ParsePubKey(
[]byte{0x06, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb,
0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07,
0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59,
0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb,
0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48,
0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb,
0x10, 0xd4, 0xb8,
},
)
if err != nil {
panic(err)
}
btcPK := bbn.NewBIP340PubKeyFromBTCPK(sk.PubKey())

btcPK := bbn.NewBIP340PubKeyFromBTCPK(pk)
fp := &bstypes.FinalityProvider{
Addr: allAccounts[0].GetAddress().String(),
Addr: accFp.GetAddress().String(),
BtcPk: btcPK,
}
bsKeeper.SetFinalityProvider(ctx, fp)
Expand Down
22 changes: 18 additions & 4 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
RELAYER_TAG := $(shell grep '^ENV RELAYER_TAG' cosmos-relayer/Dockerfile | cut -f3 -d\ )
BABYLON_FULL_PATH := $(shell git rev-parse --show-toplevel)
BABYLON_VERSION_BEFORE_UPGRADE ?= 5f8af8ced17d24f3f0c6172293cd37fb3d055807
RafilxTenfen marked this conversation as resolved.
Show resolved Hide resolved

all: babylond cosmos-relayer

babylond: babylond-rmi
docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile \
$(shell git rev-parse --show-toplevel)
docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH}

babylond-e2e: babylond-rmi
docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} \
--build-arg BUILD_TAGS="e2e"

babylond-before-upgrade:
docker rmi babylonlabs-io/babylond-before-upgrade 2>/dev/null; true && \
docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \
--build-arg VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}" ${BABYLON_FULL_PATH}

babylond-rmi:
docker rmi babylonlabs-io/babylond 2>/dev/null; true

e2e-init-chain:
@DOCKER_BUILDKIT=1 docker build -t babylonlabs-io/babylond-e2e-init-chain --build-arg E2E_SCRIPT_NAME=chain --platform=linux/x86_64 \
-f e2e-initialization/init.Dockerfile ${BABYLON_FULL_PATH}

cosmos-relayer: cosmos-relayer-rmi
docker build --tag babylonlabs-io/cosmos-relayer:${RELAYER_TAG} -f cosmos-relayer/Dockerfile \
$(shell git rev-parse --show-toplevel)/contrib/images/cosmos-relayer
${BABYLON_FULL_PATH}/contrib/images/cosmos-relayer
docker tag babylonlabs-io/cosmos-relayer:${RELAYER_TAG} babylonlabs-io/cosmos-relayer:latest

cosmos-relayer-rmi:
docker rmi babylonlabs-io/cosmos-relayer 2>/dev/null; true

.PHONY: all babylond cosmos-relayer babylond-rmi cosmos-relayer-rmi
.PHONY: all babylond babylond-before-upgrade cosmos-relayer e2e-init-chain babylond-rmi cosmos-relayer-rmi
6 changes: 2 additions & 4 deletions contrib/images/babylond/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
FROM golang:1.21 AS build-env

# Customize to your build env

# TARGETPLATFORM should be one of linux/amd64 or linux/arm64.
ARG TARGETPLATFORM="linux/amd64"
# Version to build. Default is empty
ARG VERSION

ARG BUILD_TAGS=""
ARG LEDGER_ENABLED="false"
# Cosmos build options
ARG COSMOS_BUILD_OPTIONS=""
Expand All @@ -23,6 +20,7 @@ RUN go mod download
COPY ./ /go/src/github.com/babylonlabs-io/babylon/
# If version is set, then checkout this version
RUN if [ -n "${VERSION}" ]; then \
git fetch origin ${VERSION}; \
git checkout -f ${VERSION}; \
fi

Expand Down
43 changes: 43 additions & 0 deletions contrib/images/e2e-initialization/init.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM golang:1.21 as build-env

ARG E2E_SCRIPT_NAME

# Install cli tools for building and final image
RUN apt-get update && apt-get install -y make git bash gcc curl jq

WORKDIR /go/src/github.com/babylonlabs-io/babylon

# First cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/babylon/
RUN go mod download

# Copy everything else
COPY ./ /go/src/github.com/babylonlabs-io/babylon/

RUN LEDGER_ENABLED=false LINK_STATICALLY=false E2E_SCRIPT_NAME=${E2E_SCRIPT_NAME} make e2e-build-script

FROM debian:bookworm-slim AS run

# Create a user
RUN addgroup --gid 1137 --system babylon && adduser --uid 1137 --gid 1137 --system --home /home/babylon babylon
RUN apt-get update && apt-get install -y bash curl jq wget

COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/go.mod /tmp
RUN WASMVM_VERSION=$(grep github.com/CosmWasm/wasmvm /tmp/go.mod | cut -d' ' -f2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$(uname -m).so \
-O /lib/libwasmvm.$(uname -m).so && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm.$(uname -m).so | grep $(cat /tmp/checksums.txt | grep libwasmvm.$(uname -m) | cut -d ' ' -f 1)

# Args only last for a single build stage - renew
ARG E2E_SCRIPT_NAME

COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/build/${E2E_SCRIPT_NAME} /bin/${E2E_SCRIPT_NAME}

# Docker ARGs are not expanded in ENTRYPOINT in the exec mode. At the same time,
# it is impossible to add CMD arguments when running a container in the shell mode.
# As a workaround, we create the entrypoint.sh script to bypass these issues.
RUN echo "#!/bin/bash\n${E2E_SCRIPT_NAME} \"\$@\"" >> entrypoint.sh && chmod +x entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ require (
github.com/vulpine-io/io-test v1.0.0
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0
golang.org/x/sync v0.7.0
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
)

Expand Down Expand Up @@ -247,7 +248,6 @@ require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/api v0.162.0 // indirect
Expand Down
16 changes: 9 additions & 7 deletions test/e2e/btc_staking_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat
s.Equal(prCommitMap[activatedHeight].Commitment, msgCommitPubRandList.Commitment)

// no reward gauge for finality provider and delegation yet
fpBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes())
fpBabylonAddr, err := sdk.AccAddressFromBech32(cacheFP.Addr)
s.NoError(err)

_, err = nonValidatorNode.QueryRewardGauge(fpBabylonAddr)
s.Error(err)
delBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes())
_, err = nonValidatorNode.QueryRewardGauge(delBabylonAddr)
s.Error(err)
s.ErrorContains(err, itypes.ErrRewardGaugeNotFound.Error())
delBabylonAddr := fpBabylonAddr

/*
submit finality signature
Expand Down Expand Up @@ -358,8 +358,10 @@ func (s *BTCStakingTestSuite) Test4WithdrawReward() {
s.NoError(err)

// finality provider balance before withdraw
fpBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes())
delBabylonAddr := sdk.AccAddress(nonValidatorNode.SecretKey.PubKey().Address().Bytes())
fpBabylonAddr, err := sdk.AccAddressFromBech32(cacheFP.Addr)
s.NoError(err)
delBabylonAddr := fpBabylonAddr

fpBalance, err := nonValidatorNode.QueryBalances(fpBabylonAddr.String())
s.NoError(err)
// finality provider reward gauge should not be fully withdrawn
Expand Down
17 changes: 10 additions & 7 deletions test/e2e/configurer/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/babylonlabs-io/babylon/types"
types2 "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)

// baseConfigurer is the base implementation for the
Expand All @@ -39,16 +40,18 @@ const defaultSyncUntilHeight = 3
func (bc *baseConfigurer) ClearResources() error {
bc.t.Log("tearing down e2e integration test suite...")

if err := bc.containerManager.ClearResources(); err != nil {
return err
}
g := new(errgroup.Group)
g.Go(func() error {
return bc.containerManager.ClearResources()
})

for _, chainConfig := range bc.chainConfigs {
if err := os.RemoveAll(chainConfig.DataDir); err != nil {
return err
}
chainConfig := chainConfig
g.Go(func() error {
return os.RemoveAll(chainConfig.DataDir)
})
}
return nil
return g.Wait()
}

func (bc *baseConfigurer) GetChainConfig(chainIndex int) *chain.Config {
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/configurer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package chain

import (
"fmt"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
"testing"
"time"

govv1 "cosmossdk.io/api/cosmos/gov/v1"
ibctesting "github.com/cosmos/ibc-go/v8/testing"

coretypes "github.com/cometbft/cometbft/rpc/core/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -173,3 +175,10 @@ func (c *Config) GetNodeAtIndex(nodeIndex int) (*NodeConfig, error) {
}
return c.NodeConfigs[nodeIndex], nil
}

// TxGovVoteFromAllNodes votes in a gov prop from all nodes wallet.
func (c *Config) TxGovVoteFromAllNodes(propID int, option govv1.VoteOption, overallFlags ...string) {
for _, n := range c.NodeConfigs {
n.TxGovVote(n.WalletName, propID, option, overallFlags...)
}
}
Loading