MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestBlockEvents

Function TestBlockEvents

rpc/client/event_test.go:56–99  ·  view source on GitHub ↗

subscribe to new blocks and make sure height increments by 1

(t *testing.T)

Source from the content-addressed store, hash-verified

54
55// subscribe to new blocks and make sure height increments by 1
56func TestBlockEvents(t *testing.T) {
57 for _, c := range GetClients() {
58 c := c
59 t.Run(reflect.TypeOf(c).String(), func(t *testing.T) {
60
61 // start for this test it if it wasn't already running
62 if !c.IsRunning() {
63 // if so, then we start it, listen, and stop it.
64 err := c.Start()
65 require.Nil(t, err)
66 t.Cleanup(func() {
67 if err := c.Stop(); err != nil {
68 t.Error(err)
69 }
70 })
71 }
72
73 const subscriber = "TestBlockEvents"
74
75 eventCh, err := c.Subscribe(context.Background(), subscriber, types.QueryForEvent(types.EventNewBlock).String())
76 require.NoError(t, err)
77 t.Cleanup(func() {
78 if err := c.UnsubscribeAll(context.Background(), subscriber); err != nil {
79 t.Error(err)
80 }
81 })
82
83 var firstBlockHeight int64
84 for i := int64(0); i < 3; i++ {
85 event := <-eventCh
86 blockEvent, ok := event.Data.(types.EventDataNewBlock)
87 require.True(t, ok)
88
89 block := blockEvent.Block
90
91 if firstBlockHeight == 0 {
92 firstBlockHeight = block.Header.Height
93 }
94
95 require.Equal(t, firstBlockHeight+i, block.Header.Height)
96 }
97 })
98 }
99}
100
101func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) { testTxEventsSent(t, "async") }
102func TestTxEventsSentWithBroadcastTxSync(t *testing.T) { testTxEventsSent(t, "sync") }

Callers

nothing calls this directly

Calls 12

QueryForEventFunction · 0.92
GetClientsFunction · 0.85
RunMethod · 0.65
StringMethod · 0.65
IsRunningMethod · 0.65
StartMethod · 0.65
CleanupMethod · 0.65
StopMethod · 0.65
ErrorMethod · 0.65
SubscribeMethod · 0.65
UnsubscribeAllMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected