-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnew_blocks_test.go
46 lines (36 loc) · 1.11 KB
/
new_blocks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package bloxroute_sdk_go
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestOnNewBlock(t *testing.T) {
t.Run("ws_cloud_api", testOnNewBlock(wsCloudApiUrl))
t.Run("ws_gateway", testOnNewBlock(wsGatewayUrl))
t.Run("grpc_gateway", testOnNewBlock(grpcGatewayUrl))
}
func testOnNewBlock(url testURL) func(t *testing.T) {
return func(t *testing.T) {
config := testConfig(t, url)
c, err := NewClient(context.Background(), config)
require.NoError(t, err)
receive := make(chan struct{})
err = c.OnNewBlock(context.Background(), &NewBlockParams{Include: []string{}}, func(ctx context.Context, err error, result *OnBdnBlockNotification) {
require.NoError(t, err)
require.NotNilf(t, result, "result is nil")
require.NotEmptyf(t, result.Hash, "hash is empty")
require.NotEmptyf(t, result.Header, "header is empty")
close(receive)
})
require.NoError(t, err)
select {
case <-receive:
case <-time.After(time.Minute):
require.Fail(t, "timeout waiting for block")
}
err = c.UnsubscribeFromOnNewBlock()
require.NoError(t, err)
require.NoError(t, c.Close())
}
}