forked from bitfinexcom/bfxfixgw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisconnect_test.go
73 lines (65 loc) · 2.19 KB
/
disconnect_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"testing"
"time"
)
func TestDisconnect(t *testing.T) {
set := mockFixSettings{
ApiKey: "apiKey1",
ApiSecret: "apiSecret2",
BfxUserID: "user123",
FixVersion: Fix42,
}
fixMd, fixOrd, srvWs, gw := setup(t, 6001, set)
defer func() {
fixMd.Stop()
fixOrd.Stop()
gw.Stop()
srvWs.Stop()
}()
// assert FIX MD logon
fix, err := fixMd.WaitForMessage(MarketDataSessionID, 1)
if err != nil {
t.Fatal(err)
}
err = checkFixTags(fix, "35=A", "49=BFXFIX", "56=EXORG_MD")
if err != nil {
t.Fatal(err)
}
// assert FIX order logon
fix, err = fixOrd.WaitForMessage(OrderSessionID, 1)
if err != nil {
t.Fatal(err)
}
err = checkFixTags(fix, "35=A", "49=BFXFIX", "56=EXORG_ORD")
if err != nil {
t.Fatal(err)
}
// assume both ws clients connected in setup()
srvWs.Broadcast(`{"event":"info","version":2}`)
// assert MD ws auth request
msg, err := srvWs.WaitForMessage(MarketDataClient, 0)
if err != nil {
t.Fatal(err)
}
if `{"subId":"nonce1","event":"auth","apiKey":"apiKey1","authSig":"2744ec1afc974eadbda7e09efa03da80578628ba90e2aa5fcba8c2c61014b811f3a8be5a041c3ee35c464a59856b3869","authPayload":"AUTHnonce1","authNonce":"nonce1"}` != msg {
t.Fatalf("unexpectedly got: %s", msg)
}
// assert order ws auth request
msg, err = srvWs.WaitForMessage(OrdersClient, 0)
if err != nil {
t.Fatal(err)
}
if `{"subId":"nonce1","event":"auth","apiKey":"apiKey1","authSig":"2744ec1afc974eadbda7e09efa03da80578628ba90e2aa5fcba8c2c61014b811f3a8be5a041c3ee35c464a59856b3869","authPayload":"AUTHnonce1","authNonce":"nonce1"}` != msg {
t.Fatalf("unexpectedly got: %s", msg)
}
// broadcast auth ack to both clients
srvWs.Broadcast(`{"event":"auth","status":"OK","chanId":0,"userId":1,"subId":"nonce1","auth_id":"valid-auth-guid","caps":{"orders":{"read":1,"write":0},"account":{"read":1,"write":0},"funding":{"read":1,"write":0},"history":{"read":1,"write":0},"wallets":{"read":1,"write":0},"withdraw":{"read":0,"write":0},"positions":{"read":1,"write":0}}}`)
// disconnect ws
srvWs.Stop()
// wait for ws disconnect & reconnect period, assert FIX logoff msgs
fix, err = fixMd.WaitForMessageWithWait(MarketDataSessionID, 2, time.Second*20)
if err != nil {
t.Fatal(err)
}
}