Skip to content

Commit

Permalink
fix some e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Aug 19, 2024
1 parent 48a8e23 commit e2aa1ac
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 111 deletions.
21 changes: 15 additions & 6 deletions test/e2e/btc_timestamping_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,19 @@ func (s *BTCTimestampingTestSuite) Test4IbcCheckpointing() {
nonValidatorNode, err := chainA.GetNodeAtIndex(2)
s.NoError(err)

// Query open IBC channels and assert there is only one
channels, err := nonValidatorNode.QueryIBCChannels()
s.NoError(err)
s.Equal(1, len(channels.Channels), "Expected only one open IBC channel")
// Get the client ID under this IBC channel
channelClientState, err := nonValidatorNode.QueryChannelClientState(channels.Channels[0].ChannelId, channels.Channels[0].PortId)
s.NoError(err)
clientID := channelClientState.IdentifiedClientState.ClientId

// Query checkpoint chain info for opposing chain
chainsInfo, err := nonValidatorNode.QueryChainsInfo([]string{initialization.ChainBID})
chainsInfo, err := nonValidatorNode.QueryChainsInfo([]string{clientID})
s.NoError(err)
s.Equal(chainsInfo[0].ConsumerId, initialization.ChainBID)
s.Equal(chainsInfo[0].ConsumerId, clientID)

// Finalize epoch 1, 2, 3, as first headers of opposing chain are in epoch 3
var (
Expand All @@ -140,17 +149,17 @@ func (s *BTCTimestampingTestSuite) Test4IbcCheckpointing() {
nonValidatorNode.WaitForNextBlock()

// Check we have epoch info for opposing chain and some basic assertions
epochChainsInfo, err := nonValidatorNode.QueryEpochChainsInfo(endEpochNum, []string{initialization.ChainBID})
epochChainsInfo, err := nonValidatorNode.QueryEpochChainsInfo(endEpochNum, []string{clientID})
s.NoError(err)
s.Equal(epochChainsInfo[0].ConsumerId, initialization.ChainBID)
s.Equal(epochChainsInfo[0].ConsumerId, clientID)
s.Equal(epochChainsInfo[0].LatestHeader.BabylonEpoch, endEpochNum)

// Check we have finalized epoch info for opposing chain and some basic assertions
finalizedChainsInfo, err := nonValidatorNode.QueryFinalizedChainsInfo([]string{initialization.ChainBID})
finalizedChainsInfo, err := nonValidatorNode.QueryFinalizedChainsInfo([]string{clientID})
s.NoError(err)

// TODO Add more assertion here. Maybe check proofs ?
s.Equal(finalizedChainsInfo[0].FinalizedChainInfo.ConsumerId, initialization.ChainBID)
s.Equal(finalizedChainsInfo[0].FinalizedChainInfo.ConsumerId, clientID)
s.Equal(finalizedChainsInfo[0].EpochInfo.EpochNumber, endEpochNum)

currEpoch, err := nonValidatorNode.QueryCurrentEpoch()
Expand Down
11 changes: 9 additions & 2 deletions test/e2e/btc_timestamping_phase2_hermes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/babylonlabs-io/babylon/test/e2e/configurer"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"
ct "github.com/babylonlabs-io/babylon/x/checkpointing/types"
"github.com/cosmos/cosmos-sdk/types/query"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand Down Expand Up @@ -51,6 +50,8 @@ func (s *BTCTimestampingPhase2HermesTestSuite) TearDownSuite() {

func (s *BTCTimestampingPhase2HermesTestSuite) Test1IbcCheckpointingPhase2Hermes() {
chainA := s.configurer.GetChainConfig(0)
nonValidatorNode, err := chainA.GetNodeAtIndex(2)
s.NoError(err)

babylonNode, err := chainA.GetNodeAtIndex(2)
s.NoError(err)
Expand Down Expand Up @@ -98,9 +99,15 @@ func (s *BTCTimestampingPhase2HermesTestSuite) Test1IbcCheckpointingPhase2Hermes
return true
}, time.Minute, time.Second*2)

// Get the client ID under this IBC channel
channelClientState, err := nonValidatorNode.QueryChannelClientState(babylonChannel.ChannelId, babylonChannel.PortId)
s.NoError(err)
clientID := channelClientState.IdentifiedClientState.ClientId

// Query checkpoint chain info for the consumer chain
listHeaderResp, err := babylonNode.QueryListHeaders(initialization.ChainBID, &query.PageRequest{Limit: 1})
listHeaderResp, err := babylonNode.QueryListHeaders(clientID, &query.PageRequest{Limit: 1})
s.NoError(err)
s.GreaterOrEqual(len(listHeaderResp.Headers), 1)
startEpochNum := listHeaderResp.Headers[0].BabylonEpoch
endEpochNum := startEpochNum + 2

Expand Down
11 changes: 9 additions & 2 deletions test/e2e/btc_timestamping_phase2_rly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/babylonlabs-io/babylon/test/e2e/configurer"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"
ct "github.com/babylonlabs-io/babylon/x/checkpointing/types"
"github.com/cosmos/cosmos-sdk/types/query"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand Down Expand Up @@ -51,6 +50,8 @@ func (s *BTCTimestampingPhase2RlyTestSuite) TearDownSuite() {

func (s *BTCTimestampingPhase2RlyTestSuite) Test1IbcCheckpointingPhase2Rly() {
chainA := s.configurer.GetChainConfig(0)
nonValidatorNode, err := chainA.GetNodeAtIndex(2)
s.NoError(err)

babylonNode, err := chainA.GetNodeAtIndex(2)
s.NoError(err)
Expand Down Expand Up @@ -98,9 +99,15 @@ func (s *BTCTimestampingPhase2RlyTestSuite) Test1IbcCheckpointingPhase2Rly() {
return true
}, time.Minute, time.Second*2)

// Get the client ID under this IBC channel
channelClientState, err := nonValidatorNode.QueryChannelClientState(babylonChannel.ChannelId, babylonChannel.PortId)
s.NoError(err)
clientID := channelClientState.IdentifiedClientState.ClientId

// Query checkpoint chain info for the consumer chain
listHeaderResp, err := babylonNode.QueryListHeaders(initialization.ChainBID, &query.PageRequest{Limit: 1})
listHeaderResp, err := babylonNode.QueryListHeaders(clientID, &query.PageRequest{Limit: 1})
s.NoError(err)
s.GreaterOrEqual(len(listHeaderResp.Headers), 1)
startEpochNum := listHeaderResp.Headers[0].BabylonEpoch
endEpochNum := startEpochNum + 2

Expand Down
16 changes: 8 additions & 8 deletions test/e2e/configurer/chain/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ func (n *NodeConfig) QueryHeaderDepth(hash string) (uint64, error) {
return blcResponse.Depth, nil
}

func (n *NodeConfig) QueryListHeaders(chainID string, pagination *query.PageRequest) (*zctypes.QueryListHeadersResponse, error) {
func (n *NodeConfig) QueryListHeaders(consumerID string, pagination *query.PageRequest) (*zctypes.QueryListHeadersResponse, error) {
queryParams := url.Values{}
if pagination != nil {
queryParams.Set("pagination.key", base64.URLEncoding.EncodeToString(pagination.Key))
queryParams.Set("pagination.limit", strconv.Itoa(int(pagination.Limit)))
}

path := fmt.Sprintf("babylon/zoneconcierge/v1/headers/%s", chainID)
path := fmt.Sprintf("babylon/zoneconcierge/v1/headers/%s", consumerID)
bz, err := n.QueryGRPCGateway(path, queryParams)
require.NoError(n.t, err)

Expand All @@ -264,10 +264,10 @@ func (n *NodeConfig) QueryListHeaders(chainID string, pagination *query.PageRequ
return &resp, nil
}

func (n *NodeConfig) QueryFinalizedChainsInfo(chainIDs []string) ([]*zctypes.FinalizedChainInfo, error) {
func (n *NodeConfig) QueryFinalizedChainsInfo(consumerIDs []string) ([]*zctypes.FinalizedChainInfo, error) {
queryParams := url.Values{}
for _, chainId := range chainIDs {
queryParams.Add("chain_ids", chainId)
for _, consumerID := range consumerIDs {
queryParams.Add("consumer_ids", consumerID)
}

bz, err := n.QueryGRPCGateway("babylon/zoneconcierge/v1/finalized_chains_info", queryParams)
Expand All @@ -281,11 +281,11 @@ func (n *NodeConfig) QueryFinalizedChainsInfo(chainIDs []string) ([]*zctypes.Fin
return resp.FinalizedChainsInfo, nil
}

func (n *NodeConfig) QueryEpochChainsInfo(epochNum uint64, chainIDs []string) ([]*zctypes.ChainInfo, error) {
func (n *NodeConfig) QueryEpochChainsInfo(epochNum uint64, consumerIDs []string) ([]*zctypes.ChainInfo, error) {
queryParams := url.Values{}
for _, chainId := range chainIDs {
for _, consumerID := range consumerIDs {
queryParams.Add("epoch_num", fmt.Sprintf("%d", epochNum))
queryParams.Add("chain_ids", chainId)
queryParams.Add("consumer_ids", consumerID)
}

bz, err := n.QueryGRPCGateway("babylon/zoneconcierge/v1/epoch_chains_info", queryParams)
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/configurer/chain/queries_ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ func (n *NodeConfig) QueryIBCChannels() (*channeltypes.QueryChannelsResponse, er
return &resp, nil
}

func (n *NodeConfig) QueryChannelClientState(channelID, portID string) (*channeltypes.QueryChannelClientStateResponse, error) {
path := fmt.Sprintf("/ibc/core/channel/v1/channels/%s/ports/%s/client_state", channelID, portID)
bz, err := n.QueryGRPCGateway(path, url.Values{})
if err != nil {
return nil, err
}

var resp channeltypes.QueryChannelClientStateResponse
if err := util.Cdc.UnmarshalJSON(bz, &resp); err != nil {
return nil, err
}

return &resp, nil
}

func (n *NodeConfig) QueryNextSequenceReceive(channelID, portID string) (*channeltypes.QueryNextSequenceReceiveResponse, error) {
path := fmt.Sprintf("/ibc/core/channel/v1/channels/%s/ports/%s/next_sequence", channelID, portID)
bz, err := n.QueryGRPCGateway(path, url.Values{})
Expand Down
13 changes: 5 additions & 8 deletions testutil/datagen/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func GenRandomTMHeader(r *rand.Rand, chainID string, height uint64) *cmtproto.He
}
}

func GenRandomIBCTMHeader(r *rand.Rand, chainID string, height uint64) *ibctmtypes.Header {
func GenRandomIBCTMHeader(r *rand.Rand, height uint64) *ibctmtypes.Header {
return &ibctmtypes.Header{
SignedHeader: &cmtproto.SignedHeader{
Header: &cmtproto.Header{
ChainID: chainID,
ChainID: GenRandomHexStr(r, 10),
Height: int64(height),
AppHash: GenRandomByteArray(r, 32),
},
Expand All @@ -34,13 +34,10 @@ func GenRandomIBCTMHeader(r *rand.Rand, chainID string, height uint64) *ibctmtyp
}

func GenRandomTMHeaderInfo(r *rand.Rand, chainID string, height uint64) *header.Info {
tmHeader := GenRandomIBCTMHeader(r, chainID, height)
return &header.Info{
Height: tmHeader.Header.Height,
Hash: tmHeader.Header.DataHash,
Time: tmHeader.Header.Time,
ChainID: tmHeader.Header.ChainID,
AppHash: tmHeader.Header.AppHash,
Height: int64(height),
ChainID: chainID,
AppHash: GenRandomByteArray(r, 32),
}
}

Expand Down
16 changes: 8 additions & 8 deletions x/zoneconcierge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ message Params {
### ChainInfo

The [chain info storage](./keeper/chain_info_indexer.go) maintains `ChainInfo`
for each PoS blockchain. The key is the PoS blockchain's `ChainID`, and the
value is a `ChainInfo` object. The `ChainInfo` is a structure storing the
information of a PoS blockchain that checkpoints to Babylon.
for each PoS blockchain. The key is the PoS blockchain's `ConsumerID`, which is the
ID of the IBC light client. The value is a `ChainInfo` object. The `ChainInfo` is
a structure storing the information of a PoS blockchain that checkpoints to Babylon.

```protobuf
// ChainInfo is the information of a CZ
Expand All @@ -235,14 +235,14 @@ message ChainInfo {

The [epoch chain info storage](./keeper/epoch_chain_info_indexer.go) maintains
`ChainInfo` at the end of each Babylon epoch for each PoS blockchain. The key is
the PoS blockchain's `ChainID` plus the epoch number, and the value is a
the PoS blockchain's `ConsumerID` plus the epoch number, and the value is a
`ChainInfo` object.

### CanonicalChain

The [canonical chain storage](./keeper/canonical_chain_indexer.go) maintains the
metadata of canonical IBC headers of a PoS blockchain. The key is the consumer
chain's `ChainID` plus the height, and the value is a `IndexedHeader` object.
chain's `ConsumerID` plus the height, and the value is a `IndexedHeader` object.
`IndexedHeader` is a structure storing IBC header's metadata.

```protobuf
Expand Down Expand Up @@ -277,7 +277,7 @@ message IndexedHeader {
### Fork

The [fork storage](./keeper/fork_indexer.go) maintains the metadata of canonical
IBC headers of a PoS blockchain. The key is the PoS blockchain's `ChainID` plus
IBC headers of a PoS blockchain. The key is the PoS blockchain's `ConsumerID` plus
the height, and the value is a list of `IndexedHeader` objects, which represent
fork headers at that height.

Expand Down Expand Up @@ -421,9 +421,9 @@ Babylon. The logic is defined at
is still canonical in the segment to the current tip of the BTC light
client.
3. For each of these IBC channels:
1. Find the `ChainID` of the counterparty chain (i.e., the PoS blockchain) in
1. Find the `ConsumerID` of the counterparty chain (i.e., the PoS blockchain) in
the IBC channel.
2. Get the `ChainInfo` of the `ChainID` at the last finalized epoch.
2. Get the `ChainInfo` of the `ConsumerID` at the last finalized epoch.
3. Get the metadata of the last finalized epoch and its corresponding raw
checkpoint.
4. Generate the proof that the last PoS blockchain's canonical header is
Expand Down
12 changes: 6 additions & 6 deletions x/zoneconcierge/keeper/epoch_chain_info_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func FuzzEpochChainInfoIndexer(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
czChainID := "test-chainid"
consumerID := "test-consumerid"

hooks := zcKeeper.Hooks()

Expand All @@ -33,13 +33,13 @@ func FuzzEpochChainInfoIndexer(f *testing.F) {
// invoke the hook a random number of times to simulate a random number of blocks
numHeaders := datagen.RandomInt(r, 100) + 1
numForkHeaders := datagen.RandomInt(r, 10) + 1
SimulateNewHeadersAndForks(ctx, r, &zcKeeper, czChainID, 0, numHeaders, numForkHeaders)
SimulateNewHeadersAndForks(ctx, r, &zcKeeper, consumerID, 0, numHeaders, numForkHeaders)

// end this epoch
hooks.AfterEpochEnds(ctx, epochNum)

// check if the chain info of this epoch is recorded or not
chainInfoWithProof, err := zcKeeper.GetEpochChainInfo(ctx, czChainID, epochNum)
chainInfoWithProof, err := zcKeeper.GetEpochChainInfo(ctx, consumerID, epochNum)
chainInfo := chainInfoWithProof.ChainInfo
require.NoError(t, err)
require.Equal(t, numHeaders-1, chainInfo.LatestHeader.Height)
Expand All @@ -57,7 +57,7 @@ func FuzzGetEpochHeaders(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
czChainID := "test-chainid"
consumerID := "test-consumerid"

hooks := zcKeeper.Hooks()

Expand Down Expand Up @@ -87,7 +87,7 @@ func FuzzGetEpochHeaders(f *testing.F) {
numHeadersList = append(numHeadersList, datagen.RandomInt(r, 100)+1)
numForkHeadersList = append(numForkHeadersList, datagen.RandomInt(r, 10)+1)
// trigger hooks to append these headers and fork headers
expectedHeaders, _ := SimulateNewHeadersAndForks(ctx, r, &zcKeeper, czChainID, nextHeightList[i], numHeadersList[i], numForkHeadersList[i])
expectedHeaders, _ := SimulateNewHeadersAndForks(ctx, r, &zcKeeper, consumerID, nextHeightList[i], numHeadersList[i], numForkHeadersList[i])
expectedHeadersMap[epochNum] = expectedHeaders
// prepare nextHeight for the next request
nextHeightList = append(nextHeightList, nextHeightList[i]+numHeadersList[i])
Expand All @@ -102,7 +102,7 @@ func FuzzGetEpochHeaders(f *testing.F) {
for i := uint64(0); i < numReqs; i++ {
epochNum := epochNumList[i]
// check if the headers are same as expected
headers, err := zcKeeper.GetEpochHeaders(ctx, czChainID, epochNum)
headers, err := zcKeeper.GetEpochHeaders(ctx, consumerID, epochNum)
require.NoError(t, err)
require.Equal(t, len(expectedHeadersMap[epochNum]), len(headers))
for j := 0; j < len(expectedHeadersMap[epochNum]); j++ {
Expand Down
11 changes: 5 additions & 6 deletions x/zoneconcierge/keeper/fork_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ func FuzzForkIndexer(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
czChainID := "test-chainid"
consumerID := "test-consumerid"

// invoke the hook a random number of times to simulate a random number of blocks
numHeaders := datagen.RandomInt(r, 100) + 1
numForkHeaders := datagen.RandomInt(r, 10) + 1
_, forkHeaders := SimulateNewHeadersAndForks(ctx, r, &zcKeeper, czChainID, 0, numHeaders, numForkHeaders)
_, forkHeaders := SimulateNewHeadersAndForks(ctx, r, &zcKeeper, consumerID, 0, numHeaders, numForkHeaders)

// check if the fork is updated or not
forks := zcKeeper.GetForks(ctx, czChainID, numHeaders-1)
forks := zcKeeper.GetForks(ctx, consumerID, numHeaders-1)
require.Equal(t, numForkHeaders, uint64(len(forks.Headers)))
for i := range forks.Headers {
require.Equal(t, czChainID, forks.Headers[i].ConsumerId)
require.Equal(t, numHeaders-1, forks.Headers[i].Height)
require.Equal(t, forkHeaders[i].Header.AppHash, forks.Headers[i].Hash)
}

// check if the chain info is updated or not
chainInfo, err := zcKeeper.GetChainInfo(ctx, czChainID)
chainInfo, err := zcKeeper.GetChainInfo(ctx, consumerID)
require.NoError(t, err)
require.Equal(t, numForkHeaders, uint64(len(chainInfo.LatestForks.Headers)))
for i := range forks.Headers {
require.Equal(t, czChainID, chainInfo.LatestForks.Headers[i].ConsumerId)
require.Equal(t, consumerID, chainInfo.LatestForks.Headers[i].ConsumerId)
require.Equal(t, numHeaders-1, chainInfo.LatestForks.Headers[i].Height)
require.Equal(t, forkHeaders[i].Header.AppHash, chainInfo.LatestForks.Headers[i].Hash)
}
Expand Down
4 changes: 2 additions & 2 deletions x/zoneconcierge/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (k Keeper) ChainsInfo(c context.Context, req *types.QueryChainsInfoRequest)

// return if no chain IDs are provided
if len(req.ConsumerIds) == 0 {
return nil, status.Error(codes.InvalidArgument, "chain IDs cannot be empty")
return nil, status.Error(codes.InvalidArgument, "consumer IDs cannot be empty")
}

// return if chain IDs exceed the limit
Expand Down Expand Up @@ -118,7 +118,7 @@ func (k Keeper) EpochChainsInfo(c context.Context, req *types.QueryEpochChainsIn

// return if no chain IDs are provided
if len(req.ConsumerIds) == 0 {
return nil, status.Error(codes.InvalidArgument, "chain IDs cannot be empty")
return nil, status.Error(codes.InvalidArgument, "consumer IDs cannot be empty")
}

// return if chain IDs exceed the limit
Expand Down
Loading

0 comments on commit e2aa1ac

Please sign in to comment.