-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnew_tx_test.go
52 lines (41 loc) · 1.13 KB
/
new_tx_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
47
48
49
50
51
52
package bloxroute_sdk_go
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestOnNewTx(t *testing.T) {
t.Run("ws_cloud_api", testOnNewTx(wsCloudApiUrl))
t.Run("ws_gateway", testOnNewTx(wsGatewayUrl))
t.Run("grpc_gateway", testOnNewTx(grpcGatewayUrl))
}
func testOnNewTx(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.OnNewTx(context.Background(), &NewTxParams{Include: []string{"raw_tx"}}, func(ctx context.Context, err error, result *NewTxNotification) {
select {
case <-receive:
return
default:
}
require.NoError(t, err)
require.NotNilf(t, result, "result is nil")
require.NotEmptyf(t, result.RawTx, "raw tx is empty")
close(receive)
})
require.NoError(t, err)
// wait for the first new tx
select {
case <-receive:
case <-time.After(10 * time.Second):
require.Fail(t, "timeout waiting for new tx")
}
err = c.UnsubscribeFromNewTxs()
require.NoError(t, err)
require.NoError(t, c.Close())
}
}