-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timestamping phase 2 e2e tests (#419)
* Update babylon-contract * Update README * Fix localnet nodes 3 & 4 * Fix babylon contract instantiation * Fix / adapt contract execution test * Contract download script (#155) Add download contract from release script * Fix typos * Reduce network / IB relayer start wait time * Move IBC config to chain config * Add BTC Timestamping Phase 2 test * Improve syntax Co-authored-by: Runchao Han <me@runchao.rocks> * Revert "Fix localnet nodes 3 & 4" This reverts commit aaf3707b28985d5f03261107d0fad518fc478527. * Now fix localnet nodes 3 & 4 * Simplify phase-2 vs phase-1 test setup * Simplify phase 2 test * Make chain-B the CZ chain * Use regtest const for network * Use default checkpoint tag const for babylon tag Update contract to custom * Fix comment Co-authored-by: Runchao Han <me@runchao.rocks> * Update contract to custom * Fix original test as well * Increase delay to wait for chain ready * Add (failing) next IBC packet sequence check * Fix: contains wasm check * Storage contract e2e (#171) * Revert "Update babylon-contract" This reverts commit 7c656b183818098f2662ac9996cde80b8f4009ba. * Update storage-contract to custom * Revert "Update README" This reverts commit 3669c88d16b2ea1c8185ed53a74be0a0ae3b11ea. * Revert "Fix babylon contract instantiation" This reverts commit 1fb44d7fcfac3d79a4c8b9323a56eb8b0a837d83. * Revert "Fix / adapt contract execution test" This reverts commit 124099dd64dd519aba0774d3e5a7e43d7a44162a. * Fix imports * fix phase-2 e2e test (#163) * Upgrade keyring / go-keychain dependency (#170) * Add cosmos relayer docker image build * Reduce cosmos-relayer image * Set / use relayer tag * Improve hermes bootstrap script * Set ABCI packet persistence * Add Cosmos relayer setup * Enable debug logs * Reduce relayer setup wait time * Simplify seup / remove commented lines * fix * Fix: packet acknowledgements check * Rename for consistency * Same acknowledgements logic for Hermes relayer * More test renaming for consistency * Skip BTC timestamping phase 2 test (Hermes) * Fix: BTC timestamping phase 1 tests * Improve flaky BTC timestamping tests * Return network to RegTest * Update contracts code to latest * Remove docker Platform directive / commented code * Increase wait for blocks delay * Add cosmos relayer docker build target to e2e target deps * Fix rebase errors * Remove unused helper * Add TODOs * Remove commented code * Comment BTC timestamping hermes test out * Restore original BTC timestamping test * Report target arch / Go lang version * Hardcode target arch for CI * Hardcode next expected sequence --------- Co-authored-by: Runchao Han <me@runchao.rocks> Co-authored-by: Mauro Lacy <mauro@babylonchain.io>
- Loading branch information
1 parent
fa904d3
commit fac4830
Showing
32 changed files
with
1,037 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
FROM debian:bullseye-slim AS build-env | ||
|
||
RUN apt-get update && apt-get install -y git make jq gcc make wget | ||
|
||
WORKDIR /work | ||
|
||
ARG TARGETARCH="amd64" | ||
|
||
# Download and install Go | ||
ENV GOLANG_VERSION 1.21.4 | ||
RUN wget -q https://golang.org/dl/go${GOLANG_VERSION}.linux-${TARGETARCH}.tar.gz && \ | ||
tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-${TARGETARCH}.tar.gz && \ | ||
rm go${GOLANG_VERSION}.linux-${TARGETARCH}.tar.gz | ||
# Set Go environment variables | ||
ENV PATH /usr/local/go/bin:$PATH | ||
ENV GOPATH /go | ||
ENV PATH $GOPATH/bin:$PATH | ||
|
||
WORKDIR /work | ||
|
||
ENV GO111MODULE on | ||
ENV RELAYER_TAG main | ||
# ENV RELAYER_TAG v2.4.2 | ||
|
||
# Install the relayer | ||
RUN git clone https://github.com/cosmos/relayer.git | ||
RUN cd relayer && git fetch origin && git checkout ${RELAYER_TAG} && make install && cd - | ||
|
||
FROM debian:bullseye-slim AS run | ||
# Create a user | ||
RUN addgroup --system rly && adduser --system --gid 101 rly | ||
|
||
COPY --from=build-env /go/bin/rly /usr/bin/rly | ||
|
||
# Set home directory and user | ||
WORKDIR /home/rly | ||
RUN chown -R rly /home/rly | ||
USER rly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package e2e | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/babylonchain/babylon/test/e2e/configurer" | ||
"github.com/babylonchain/babylon/test/e2e/initialization" | ||
ct "github.com/babylonchain/babylon/x/checkpointing/types" | ||
zctypes "github.com/babylonchain/babylon/x/zoneconcierge/types" | ||
"github.com/cosmos/cosmos-sdk/types/query" | ||
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type BTCTimestampingPhase2HermesTestSuite struct { | ||
suite.Suite | ||
|
||
configurer configurer.Configurer | ||
} | ||
|
||
func (s *BTCTimestampingPhase2HermesTestSuite) SetupSuite() { | ||
s.T().Log("setting up phase 2 integration test suite...") | ||
var ( | ||
err error | ||
) | ||
|
||
// The e2e test flow is as follows: | ||
// | ||
// 1. Configure two chains - chain A and chain B. | ||
// * For each chain, set up several validator nodes | ||
// * Initialize configs and genesis for all them. | ||
// 2. Start both networks. | ||
// 3. Store and instantiate babylon contract on chain B. | ||
// 3. Execute various e2e tests, excluding IBC | ||
s.configurer, err = configurer.NewBTCTimestampingPhase2Configurer(s.T(), true) | ||
|
||
s.Require().NoError(err) | ||
|
||
err = s.configurer.ConfigureChains() | ||
s.Require().NoError(err) | ||
|
||
err = s.configurer.RunSetup() | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *BTCTimestampingPhase2HermesTestSuite) TearDownSuite() { | ||
err := s.configurer.ClearResources() | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *BTCTimestampingPhase2HermesTestSuite) Test1IbcCheckpointingPhase2Hermes() { | ||
chainA := s.configurer.GetChainConfig(0) | ||
|
||
babylonNode, err := chainA.GetNodeAtIndex(2) | ||
s.NoError(err) | ||
czNode, err := s.configurer.GetChainConfig(1).GetNodeAtIndex(2) | ||
s.NoError(err) | ||
|
||
// Validate channel state and kind (Babylon side) | ||
babylonChannelsResp, err := babylonNode.QueryIBCChannels() | ||
s.NoError(err) | ||
s.Len(babylonChannelsResp.Channels, 1) | ||
babylonChannel := babylonChannelsResp.Channels[0] | ||
// channel has to be open and ordered | ||
s.Equal(channeltypes.OPEN, babylonChannel.State) | ||
s.Equal(channeltypes.ORDERED, babylonChannel.Ordering) | ||
// the counterparty has to be the Babylon smart contract | ||
s.Contains(babylonChannel.Counterparty.PortId, "wasm.") | ||
|
||
// Validate channel state (CZ side) | ||
czChannelsResp, err := czNode.QueryIBCChannels() | ||
s.NoError(err) | ||
s.Len(czChannelsResp.Channels, 2) // TODO: why 2 channels? | ||
czChannel := czChannelsResp.Channels[0] | ||
s.Equal(channeltypes.OPEN, czChannel.State) | ||
s.Equal(channeltypes.ORDERED, czChannel.Ordering) | ||
s.Equal(zctypes.PortID, czChannel.Counterparty.PortId) | ||
|
||
// Query checkpoint chain info for the consumer chain | ||
listHeaderResp, err := babylonNode.QueryListHeaders(initialization.ChainBID, &query.PageRequest{Limit: 1}) | ||
s.NoError(err) | ||
startEpochNum := listHeaderResp.Headers[0].BabylonEpoch | ||
endEpochNum := startEpochNum + 2 | ||
|
||
// wait until epoch endEpochNum | ||
// so that there will be endEpochNum - startEpochNum + 1 = 3 | ||
// BTC timestamps in Babylon contract | ||
chainA.WaitUntilHeight(int64(endEpochNum*10 + 5)) | ||
babylonNode.FinalizeSealedEpochs(1, endEpochNum) | ||
|
||
// ensure endEpochNum has been finalised | ||
endEpoch, err := babylonNode.QueryRawCheckpoint(endEpochNum) | ||
s.NoError(err) | ||
s.Equal(endEpoch.Status, ct.Finalized) | ||
|
||
// there should be 3 IBC packets sent (with sequence number 1, 2, 3). | ||
// Thus, the next sequence number will eventually be 4 | ||
s.Eventually(func() bool { | ||
nextSequenceSendResp, err := babylonNode.QueryNextSequenceSend(babylonChannel.ChannelId, babylonChannel.PortId) | ||
if err != nil { | ||
return false | ||
} | ||
s.T().Logf("next sequence send at ZoneConcierge is %d", nextSequenceSendResp.NextSequenceSend) | ||
return nextSequenceSendResp.NextSequenceSend >= endEpochNum-startEpochNum+1+1 | ||
}, time.Minute, time.Second*2) | ||
|
||
// ensure the next receive sequence number of Babylon contract is also 3 | ||
s.Eventually(func() bool { | ||
nextSequenceRecv, err := czNode.QueryNextSequenceReceive(babylonChannel.Counterparty.ChannelId, babylonChannel.Counterparty.PortId) | ||
if err != nil { | ||
return false | ||
} | ||
s.T().Logf("next sequence receive at Babylon contract is %d", nextSequenceRecv.NextSequenceReceive) | ||
return nextSequenceRecv.NextSequenceReceive >= endEpochNum-startEpochNum+1+1 | ||
}, time.Minute, time.Second*2) | ||
|
||
// Ensure the IBC packet acknowledgements (on chain B) are there | ||
lastSequence := endEpochNum | ||
for seq := uint64(1); seq < lastSequence; seq++ { | ||
var seqResp *channeltypes.QueryPacketAcknowledgementResponse | ||
s.Eventually(func() bool { | ||
seqResp, err = czNode.QueryPacketAcknowledgement(czChannel.ChannelId, czChannel.PortId, seq) | ||
s.T().Logf("acknowledgement resp of IBC packet #%d: %v, err: %v", seq, seqResp, err) | ||
return err == nil | ||
}, time.Minute, time.Second*2) | ||
} | ||
} |
Oops, something went wrong.