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 1 commit
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
Next Next commit
chore: add e2e software upgrade
  • Loading branch information
RafilxTenfen committed Jul 29, 2024
commit 61654901e525d37d42da2c2c455aa9e2d8830ede
23 changes: 21 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,22 @@ 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: build-docker
$(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
7 changes: 5 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import (
"github.com/spf13/cast"

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

appkeepers "github.com/babylonlabs-io/babylon/app/keepers"
Expand Down Expand Up @@ -158,8 +159,10 @@ var (
}

// software upgrades and forks
Upgrades = []upgrades.Upgrade{}
Forks = []upgrades.Fork{}
Upgrades = []upgrades.Upgrade{
vanilla.Upgrade,
}
Forks = []upgrades.Fork{}
)

func init() {
Expand Down
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
18 changes: 14 additions & 4 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
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-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
5 changes: 1 addition & 4 deletions contrib/images/babylond/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
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

Expand All @@ -23,6 +19,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"]
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...)
}
}
59 changes: 59 additions & 0 deletions test/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

govv1 "cosmossdk.io/api/cosmos/gov/v1"
txformat "github.com/babylonlabs-io/babylon/btctxformatter"
"github.com/babylonlabs-io/babylon/test/e2e/containers"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"
Expand Down Expand Up @@ -94,6 +95,10 @@ func (n *NodeConfig) BankSendFromNode(receiveAddress, amount string) {
n.BankSend(n.WalletName, receiveAddress, amount)
}

func (n *NodeConfig) BankMultiSendFromNode(addresses []string, amount string) {
n.BankMultiSend(n.WalletName, addresses, amount)
}

func (n *NodeConfig) BankSend(fromWallet, to, amount string, overallFlags ...string) {
fromAddr := n.GetWallet(fromWallet)
n.LogActionF("bank sending %s from wallet %s to %s", amount, fromWallet, to)
Expand All @@ -103,6 +108,23 @@ func (n *NodeConfig) BankSend(fromWallet, to, amount string, overallFlags ...str
n.LogActionF("successfully sent bank sent %s from address %s to %s", amount, fromWallet, to)
}

func (n *NodeConfig) BankMultiSend(fromWallet string, receivers []string, amount string, overallFlags ...string) {
if len(receivers) == 0 {
require.Error(n.t, fmt.Errorf("no address to send to"))
}

fromAddr := n.GetWallet(fromWallet)
n.LogActionF("bank multi-send sending %s from wallet %s to %+v", amount, fromWallet, receivers)

cmd := []string{"babylond", "tx", "bank", "multi-send", fromAddr} // starts the initial flags
cmd = append(cmd, receivers...) // appends all the receivers
cmd = append(cmd, amount, fmt.Sprintf("--from=%s", fromWallet)) // set amounts and overall

_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...))
require.NoError(n.t, err)
n.LogActionF("successfully sent bank multi-send %s from address %s to %+v", amount, fromWallet, receivers)
}

func (n *NodeConfig) BankSendOutput(fromWallet, to, amount string, overallFlags ...string) (out bytes.Buffer, errBuff bytes.Buffer, err error) {
fromAddr := n.GetWallet(fromWallet)
n.LogActionF("bank sending %s from wallet %s to %s", amount, fromWallet, to)
Expand Down Expand Up @@ -385,3 +407,40 @@ func ParseBTCHeaderInfoResponseToInfo(r *blc.BTCHeaderInfoResponse) (*blc.BTCHea
Work: &r.Work,
}, nil
}

// Proposal submits a governance proposal from the file inside the container,
// if the file is local, remind to add it to the mounting point in container.
func (n *NodeConfig) TxGovPropSubmitProposal(proposalJsonFilePath, from string, overallFlags ...string) int {
n.LogActionF("submitting new v1 proposal type %s", proposalJsonFilePath)

cmd := []string{
"babylond", "tx", "gov", "submit-proposal", proposalJsonFilePath,
fmt.Sprintf("--from=%s", from),
}

_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...))
require.NoError(n.t, err)

n.WaitForNextBlock()

props := n.QueryProposals()
require.GreaterOrEqual(n.t, len(props.Proposals), 1)

n.LogActionF("successfully submitted new v1 proposal type")
return int(props.Proposals[len(props.Proposals)-1].ProposalId)
}

// TxGovVote votes in a governance proposal
func (n *NodeConfig) TxGovVote(from string, propID int, option govv1.VoteOption, overallFlags ...string) {
n.LogActionF("submitting vote %s to prop %d", option, propID)

cmd := []string{
"babylond", "tx", "gov", "vote", fmt.Sprintf("%d", propID), option.String(),
fmt.Sprintf("--from=%s", from),
}

_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...))
require.NoError(n.t, err)

n.LogActionF("successfully submitted vote %s to prop %d", option, propID)
}
Loading