Skip to content

Commit

Permalink
fix some e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Nov 27, 2024
1 parent d0b97f1 commit 8180c5c
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 167 deletions.
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ func (ak *AppKeepers) InitKeepers(
runtime.NewKVStoreService(keys[zctypes.StoreKey]),
ak.IBCFeeKeeper,
ak.IBCKeeper.ClientKeeper,
ak.IBCKeeper.ConnectionKeeper,
ak.IBCKeeper.ChannelKeeper,
ak.IBCKeeper.PortKeeper,
ak.AccountKeeper,
Expand Down
7 changes: 2 additions & 5 deletions proto/babylon/btcstkconsumer/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ message MsgRegisterConsumer {
string consumer_name = 3;
// consumer_description is a description for the consumer (can be empty)
string consumer_description = 4;
// cosmos_ibc_client_id is the IBC client ID for the consumer consumer chain
// (required for Cosmos integration)
string cosmos_ibc_client_id = 5;
// eth_l2_finality_contract_address is the address of the finality contract
// (required for ETH L2 integration)
string eth_l2_finality_contract_address = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// (if set, then this means this is an ETH L2 integration)
string eth_l2_finality_contract_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgRegisterConsumerResponse is the response to the MsgRegisterConsumer message.
Expand Down
28 changes: 15 additions & 13 deletions test/e2e/bcd_consumer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,20 @@ func (s *BCDConsumerIntegrationTestSuite) Test1ChainStartup() {
}, time.Minute, time.Second, "Failed to query Consumer node status", err)
s.T().Logf("Consumer node status: %v", consumerStatus.SyncInfo.LatestBlockHeight)

// register the consumer after the

// Wait till IBC connection/channel b/w babylon<->bcd is established
s.waitForIBCConnection()
}

// Test2RegisterAndVerifyNewConsumer registers a new consumer and
// Test2RegisterAndIntegrateConsumer registers a new consumer and
// 1. Verifies that an IBC connection is established between the consumer chain and Babylon
// 2. Checks that the consumer is registered in Babylon's consumer registry
// 3. Validates the consumer registration details in Babylon
func (s *BCDConsumerIntegrationTestSuite) Test2RegisterAndVerifyNewConsumer() {
// Then, it waits until the IBC channel between babylon<->bcd is established
func (s *BCDConsumerIntegrationTestSuite) Test2RegisterAndIntegrateConsumer() {
// register and verify consumer
s.registerVerifyConsumer()

// after the consumer is registered, wait till IBC connection/channel
// between babylon<->bcd is established
s.waitForIBCConnection()
}

// Test3CreateConsumerFinalityProvider
Expand Down Expand Up @@ -242,7 +244,7 @@ func (s *BCDConsumerIntegrationTestSuite) Test5ActivateDelegation() {
s.Eventually(func() bool {
dataFromContract, err = s.cosmwasmController.QueryDelegations()
return err == nil && dataFromContract != nil && len(dataFromContract.Delegations) == 1
}, time.Second*20, time.Second)
}, time.Second*30, time.Second)

// Assert delegation details
s.Empty(dataFromContract.Delegations[0].UndelegationInfo.DelegatorUnbondingSig)
Expand Down Expand Up @@ -1051,11 +1053,11 @@ func (s *BCDConsumerIntegrationTestSuite) registerVerifyConsumer() *bsctypes.Con
// wait until the consumer is registered
s.Eventually(func() bool {
// Register a random consumer on Babylon
registeredConsumer = &bsctypes.ConsumerRegister{
ConsumerId: consumerID,
ConsumerName: datagen.GenRandomHexStr(r, 5),
ConsumerDescription: "Chain description: " + datagen.GenRandomHexStr(r, 15),
}
registeredConsumer = bsctypes.NewCosmosConsumerRegister(
consumerID,
datagen.GenRandomHexStr(r, 5),
"Chain description: "+datagen.GenRandomHexStr(r, 15),
)
_, err = s.babylonController.RegisterConsumerChain(registeredConsumer.ConsumerId, registeredConsumer.ConsumerName, registeredConsumer.ConsumerDescription)
if err != nil {
return false
Expand All @@ -1072,7 +1074,7 @@ func (s *BCDConsumerIntegrationTestSuite) registerVerifyConsumer() *bsctypes.Con
s.Require().Equal(registeredConsumer.ConsumerDescription, consumerRegistryResp.GetConsumersRegister()[0].ConsumerDescription)

return true
}, time.Minute, 5*time.Second, "Consumer was not registered within the expected time")
}, 2*time.Minute, 5*time.Second, "Consumer was not registered within the expected time")

s.T().Logf("Consumer registered: ID=%s, Name=%s, Description=%s",
registeredConsumer.ConsumerId,
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/btc_staking_integration_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ func (s *BTCStakingIntegrationTestSuite) Test6ContractQueries() {
// helper function: register a random consumer on Babylon and verify it
func (s *BTCStakingIntegrationTestSuite) registerVerifyConsumer(babylonNode *chain.NodeConfig, consumerID string) *bsctypes.ConsumerRegister {
// Register a random consumer on Babylon
randomConsumer := &bsctypes.ConsumerRegister{
ConsumerId: consumerID,
ConsumerName: datagen.GenRandomHexStr(r, 5),
ConsumerDescription: "Chain description: " + datagen.GenRandomHexStr(r, 15),
}
randomConsumer := bsctypes.NewCosmosConsumerRegister(
consumerID,
datagen.GenRandomHexStr(r, 5),
"Chain description: "+datagen.GenRandomHexStr(r, 15),
)
babylonNode.RegisterConsumer(randomConsumer.ConsumerId, randomConsumer.ConsumerName, randomConsumer.ConsumerDescription)
babylonNode.WaitForNextBlock()

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/bytecode/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.11.0-rc.1
5fcde96d5e065fffd94146a98d69ba4a9ad158b8
1 change: 1 addition & 0 deletions testutil/keeper/zoneconcierge.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func ZoneConciergeKeeper(
runtime.NewKVStoreService(storeKey),
nil, // TODO: mock this keeper
nil, // TODO: mock this keeper
nil, // TODO: mock this keeper
channelKeeper,
portKeeper,
nil, // TODO: mock this keeper
Expand Down
41 changes: 19 additions & 22 deletions x/btcstkconsumer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ func (ms msgServer) RegisterConsumer(ctx context.Context, req *types.MsgRegister
return nil, err
}

if len(req.CosmosIbcClientId) > 0 {
// this is a Cosmos consumer

// ensure the IBC light client exists
sdkCtx := sdk.UnwrapSDKContext(ctx)
_, exist := ms.clientKeeper.GetClientState(sdkCtx, req.CosmosIbcClientId)
if !exist {
return nil, types.ErrInvalidCosmosConsumerRequest.Wrapf("IBC light client does not exist")
}

// all good, register this Cosmos consumer
consumerRegister := types.NewCosmosConsumerRegister(
req.ConsumerId,
req.ConsumerName,
req.ConsumerDescription,
req.CosmosIbcClientId,
)
if err := ms.Keeper.RegisterConsumer(ctx, consumerRegister); err != nil {
return nil, err
}
}

if len(req.EthL2FinalityContractAddress) > 0 {
// this is a ETH L2 consumer

Expand All @@ -78,6 +56,25 @@ func (ms msgServer) RegisterConsumer(ctx context.Context, req *types.MsgRegister
if err := ms.Keeper.RegisterConsumer(ctx, consumerRegister); err != nil {
return nil, err
}
} else {
// this is a Cosmos consumer

// ensure the IBC light client exists
sdkCtx := sdk.UnwrapSDKContext(ctx)
_, exist := ms.clientKeeper.GetClientState(sdkCtx, req.ConsumerId)
if !exist {
return nil, types.ErrInvalidCosmosConsumerRequest.Wrapf("IBC light client does not exist")
}

// all good, register this Cosmos consumer
consumerRegister := types.NewCosmosConsumerRegister(
req.ConsumerId,
req.ConsumerName,
req.ConsumerDescription,
)
if err := ms.Keeper.RegisterConsumer(ctx, consumerRegister); err != nil {
return nil, err
}
}

return &types.MsgRegisterConsumerResponse{}, nil
Expand Down
2 changes: 0 additions & 2 deletions x/btcstkconsumer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func FuzzRegisterConsumer(f *testing.F) {
ConsumerId: consumerRegister.ConsumerId,
ConsumerName: consumerRegister.ConsumerName,
ConsumerDescription: consumerRegister.ConsumerDescription,
CosmosIbcClientId: consumerRegister.ConsumerId,
})
require.Error(t, err)
require.ErrorIs(t, err, govtypes.ErrInvalidSigner)
Expand All @@ -77,7 +76,6 @@ func FuzzRegisterConsumer(f *testing.F) {
ConsumerId: consumerRegister.ConsumerId,
ConsumerName: consumerRegister.ConsumerName,
ConsumerDescription: consumerRegister.ConsumerDescription,
CosmosIbcClientId: consumerRegister.ConsumerId,
})
require.NoError(t, err)
// check that the consumer is registered
Expand Down
10 changes: 2 additions & 8 deletions x/btcstkconsumer/types/chain_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@ func (m *MsgRegisterConsumer) ValidateBasic() error {
if len(m.ConsumerDescription) == 0 {
return fmt.Errorf("ConsumerDescription must be non-empty")
}
if len(m.CosmosIbcClientId) == 0 && len(m.EthL2FinalityContractAddress) == 0 {
return fmt.Errorf("either CosmosIbcClientId or EthL2FinalityContractAddress must be non-empty")
}
if len(m.CosmosIbcClientId) != 0 && len(m.EthL2FinalityContractAddress) != 0 {
return fmt.Errorf("both CosmosIbcClientId and EthL2FinalityContractAddress cannot be set simultaneously")
}
return nil
}

func NewCosmosConsumerRegister(consumerId, consumerName, consumerDescription string, cosmosIbcClientId string) *ConsumerRegister {
func NewCosmosConsumerRegister(consumerId, consumerName, consumerDescription string) *ConsumerRegister {
return &ConsumerRegister{
ConsumerId: consumerId,
ConsumerName: consumerName,
ConsumerDescription: consumerDescription,
ConsumerMetadata: &ConsumerRegister_CosmosConsumerMetadata{
CosmosConsumerMetadata: &CosmosConsumerMetadata{
ClientId: cosmosIbcClientId,
ClientId: consumerId,
},
},
}
Expand Down
128 changes: 37 additions & 91 deletions x/btcstkconsumer/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8180c5c

Please sign in to comment.