From b77146f184345226a276097f111aaa59da9524cf Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Wed, 17 Jul 2024 14:11:00 -0400 Subject: [PATCH 1/2] test: query for events --- app/test/testnode_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/test/testnode_test.go b/app/test/testnode_test.go index fd7a78aafb..1273c25aa2 100644 --- a/app/test/testnode_test.go +++ b/app/test/testnode_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "testing" + "time" "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/test/util/testnode" @@ -11,6 +12,7 @@ import ( sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/types" "google.golang.org/grpc" ) @@ -29,6 +31,35 @@ func Test_testnode(t *testing.T) { require.NoError(t, err) assert.Equal(t, wantMinGasPrice, got) }) + t.Run("testnode can query CometBFT events", func(t *testing.T) { + cctx, _, _ := testnode.NewNetwork(t, testnode.DefaultConfig()) + client := cctx.Client + + newBlockSubscriber := "NewBlock/Events" + newDataSignedBlockQuery := types.QueryForEvent(types.EventSignedBlock).String() + + ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) + t.Cleanup(cancel) + + eventChan, err := client.Subscribe(ctx, newBlockSubscriber, newDataSignedBlockQuery) + require.NoError(t, err) + + for i := 1; i <= 3; i++ { + select { + case evt := <-eventChan: + h := evt.Data.(types.EventDataSignedBlock).Header.Height + fmt.Printf("Block height: %d\n", h) + block, err := client.Block(ctx, &h) + require.NoError(t, err) + require.GreaterOrEqual(t, block.Block.Height, int64(i)) + case <-ctx.Done(): + require.NoError(t, ctx.Err()) + } + } + + // unsubscribe to event channel + require.NoError(t, client.Unsubscribe(ctx, newBlockSubscriber, newDataSignedBlockQuery)) + }) } func queryMinimumGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float64, error) { From ddc1c06899bbefbffa7292c17174a45c4fdfb56d Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Wed, 17 Jul 2024 14:12:21 -0400 Subject: [PATCH 2/2] refactor: remove debug line --- app/test/testnode_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/app/test/testnode_test.go b/app/test/testnode_test.go index 1273c25aa2..cc4591095d 100644 --- a/app/test/testnode_test.go +++ b/app/test/testnode_test.go @@ -48,7 +48,6 @@ func Test_testnode(t *testing.T) { select { case evt := <-eventChan: h := evt.Data.(types.EventDataSignedBlock).Header.Height - fmt.Printf("Block height: %d\n", h) block, err := client.Block(ctx, &h) require.NoError(t, err) require.GreaterOrEqual(t, block.Block.Height, int64(i))