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

feat: add e2e-init-chain #46

Merged
merged 11 commits into from
Sep 3, 2024
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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 @@ -408,17 +408,32 @@ proto-lint: ## Lint protobuf files

.PHONY: proto-gen proto-swagger-gen proto-format prot-lint

###############################################################################
### 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)

###############################################################################
### Docker ###
###############################################################################

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

build-docker-e2e:
$(MAKE) -C contrib/images babylond-e2e
$(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
.PHONY: build-docker build-docker-e2e build-cosmos-relayer-docker

###############################################################################
### Localnet ###
Expand Down
19 changes: 15 additions & 4 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
RELAYER_TAG := $(shell grep '^ENV RELAYER_TAG' cosmos-relayer/Dockerfile | cut -f3 -d\ )
BABYLON_FULL_PATH := $(shell git rev-parse --show-toplevel)

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:
docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} \
--build-arg BUILD_TAGS="e2e"

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

e2e-init-chain-rmi:
docker rmi babylonlabs-io/babylond-e2e-init-chain --force 2>/dev/null; true

e2e-init-chain:
docker build -t babylonlabs-io/babylond-e2e-init-chain --build-arg E2E_SCRIPT_NAME=chain --platform=linux/x86_64 \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether --platform shouldn't be configurable by some env variable, as when I run test locally on arm mac those fail due to native binding to bls libraries and changing platform fixes that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know that, I will add --platform tag to docker builds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if this 997de7c
solved?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I have checked it locally and got:

> make build-docker
/Library/Developer/CommandLineTools/usr/bin/make -C contrib/images babylond
docker rmi babylonlabs-io/babylond 2>/dev/null; true
Untagged: babylonlabs-io/babylond:latest
Deleted: sha256:7cd3d4a92eff50f5490ea0636532b3fbbcea3f5585d98fb886b1e96423614339
docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile /Users/konradstaniec/Work/babylon/babylon --platform=local
[+] Building 2.0s (3/3) FINISHED                                                                                                                                    docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                0.0s
 => => transferring dockerfile: 2.22kB                                                                                                                                              0.0s
 => ERROR [internal] load metadata for docker.io/library/debian:bookworm-slim                                                                                                       2.0s
 => ERROR [internal] load metadata for docker.io/library/golang:1.21                                                                                                                2.0s
------
 > [internal] load metadata for docker.io/library/debian:bookworm-slim:
------
------
 > [internal] load metadata for docker.io/library/golang:1.21:
------
Dockerfile:1
--------------------
   1 | >>> FROM golang:1.21 AS build-env
   2 |
   3 |     # Customize to your build env
--------------------
ERROR: failed to solve: golang:1.21: no match for platform in manifest: not found
make[1]: *** [babylond] Error 1
make: *** [build-docker] Error 2

so it seems --platform=local does not really work on m1 macs 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking out loud, why do we even need this --platform=linux/x86_64 in this particular target ? Other docker building commands do not specify this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the --platform tag at 07b4094

-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 cosmos-relayer babylond-e2e e2e-init-chain e2e-init-chain-rmi babylond-rmi cosmos-relayer-rmi
39 changes: 39 additions & 0 deletions contrib/images/e2e-initialization/init.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM golang:1.21 as build-env

ARG E2E_SCRIPT_NAME

# Copy All
WORKDIR /go/src/github.com/babylonlabs-io/babylon
COPY ./ /go/src/github.com/babylonlabs-io/babylon/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't it need to be:

# Version to build. Default is empty
ARG VERSION

# Copy All
WORKDIR /go/src/github.com/babylonlabs-io/babylon
COPY ./ /go/src/github.com/babylonlabs-io/babylon/

# Handle if version is set
RUN if [ -n "${VERSION}" ]; then \
        git fetch origin ${VERSION}; \
        git checkout -f ${VERSION}; \
    fi

i.e we should be able to configure binary version here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we want this fixed version for testing, we don't need to have the version argument

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm correct me if I am wrong, but I have had imagined that this is needed similiary to babylond-before-upgrade step.

i.e for babylon before upgrade we call :

	docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \
    --build-arg VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}" ${BABYLON_FULL_PATH}

to actually build the image with some old version.

I thought this will happen here too i.e

  1. First init chain with the VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}"
  2. then build image before upgrade also with VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}"
    what am I missing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have VERSION argument on main branch, that is to go to another version, here it will not be used to move to another version because this is already the fixed version we need to test

But if you feel more comfortable I could add it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add it for the sake of completeness, the worst case scenario it will be unused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added version argument to dockerfile
26a3fc9

At the makefile to build the docker I did not set any argument


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

FROM debian:bookworm-slim AS wasm-link

RUN apt-get update && apt-get install -y wget bash

# Label should match your github repo
LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/babylond:${VERSION}"

# Install libraries
# Cosmwasm - Download correct libwasmvm version
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)
RUN rm -f /tmp/go.mod

# 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
5 changes: 3 additions & 2 deletions test/e2e/btc_timestamping_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (s *BTCTimestampingTestSuite) SetupSuite() {
// 3. Run IBC relayer between the two chains.
// 4. Execute various e2e tests, including IBC
s.configurer, err = configurer.NewBTCTimestampingConfigurer(s.T(), true)

s.Require().NoError(err)

err = s.configurer.ConfigureChains()
Expand All @@ -50,7 +49,9 @@ func (s *BTCTimestampingTestSuite) SetupSuite() {

func (s *BTCTimestampingTestSuite) TearDownSuite() {
err := s.configurer.ClearResources()
s.Require().NoError(err)
if err != nil {
s.T().Logf("error to clear resources %s", err.Error())
}
}

// Most simple test, just checking that two chains are up and connected through
Expand Down
33 changes: 32 additions & 1 deletion test/e2e/configurer/chain/chain.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package chain

import (
"encoding/hex"
"fmt"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
"strings"
"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"

"github.com/babylonlabs-io/babylon/test/e2e/configurer/config"
"github.com/babylonlabs-io/babylon/test/e2e/containers"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
)

type Config struct {
Expand All @@ -27,6 +32,7 @@ type Config struct {
LatestProposalNumber int
LatestLockNumber int
NodeConfigs []*NodeConfig
BTCHeaders []*btclighttypes.BTCHeaderInfo
IBCConfig *ibctesting.ChannelConfig

LatestCodeId int
Expand Down Expand Up @@ -57,6 +63,7 @@ func New(t *testing.T, containerManager *containers.Manager, id string, initVali
ExpeditedVotingPeriod: config.PropDepositBlocks + numVal*config.PropVoteBlocks + config.PropBufferBlocks - 2,
t: t,
containerManager: containerManager,
BTCHeaders: []*btclighttypes.BTCHeaderInfo{},
}
}

Expand Down Expand Up @@ -173,3 +180,27 @@ 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...)
}
}

// BTCHeaderBytesHexJoined join all the btc headers as byte string hex
func (c *Config) BTCHeaderBytesHexJoined() string {
if c.BTCHeaders == nil || len(c.BTCHeaders) == 0 {
return ""
}

strBtcHeaders := make([]string, len(c.BTCHeaders))
for i, btcHeader := range c.BTCHeaders {
bz, err := btcHeader.Marshal()
if err != nil {
panic(err)
}
strBtcHeaders[i] = hex.EncodeToString(bz)
}
return strings.Join(strBtcHeaders, ",")
}
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)
}
17 changes: 17 additions & 0 deletions test/e2e/configurer/chain/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

cmtjson "github.com/cometbft/cometbft/libs/json"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -185,3 +186,19 @@ func (n *NodeConfig) LogActionF(msg string, args ...interface{}) {
s := fmt.Sprintf(msg, args...)
n.t.Logf("[%s] %s. From container %s", timeSinceStart, s, n.Name)
}

func (n *NodeConfig) Status() (*coretypes.ResultStatus, error) {
cmd := []string{"babylond", "status", "--output=json"}
outBuf, _, err := n.containerManager.ExecCmd(n.t, n.Name, cmd, "")
if err != nil {
return nil, err
}

var r coretypes.ResultStatus
err = cmtjson.Unmarshal(outBuf.Bytes(), &r)
if err != nil {
return nil, err
}

return &r, nil
}
Loading
Loading