-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket_proxy_test.go
More file actions
76 lines (65 loc) · 1.75 KB
/
socket_proxy_test.go
File metadata and controls
76 lines (65 loc) · 1.75 KB
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
74
75
76
package proxy
import (
"reflect"
"testing"
"time"
"github.com/newdag/common"
"github.com/newdag/hashgraph"
"github.com/newdag/proxy"
)
func TestSokcetProxyServer(t *testing.T) {
clientAddr := "127.0.0.1:9990"
proxyAddr := "127.0.0.1:9991"
proxy := proxy.NewSocketAppProxy(clientAddr, proxyAddr, 1*time.Second, common.NewTestLogger(t))
submitCh := proxy.SubmitCh()
tx := []byte("the test transaction")
// Listen for a request
go func() {
select {
case st := <-submitCh:
// Verify the command
if !reflect.DeepEqual(st, tx) {
t.Fatalf("tx mismatch: %#v %#v", tx, st)
}
case <-time.After(200 * time.Millisecond):
t.Fatalf("timeout")
}
}()
// now client part connecting to RPC service
// and calling methods
dummyClient, err := NewDummySocketClient(clientAddr, proxyAddr, common.NewTestLogger(t))
if err != nil {
t.Fatal(err)
}
err = dummyClient.SubmitTx(tx)
if err != nil {
t.Fatal(err)
}
}
func TestSocketProxyClient(t *testing.T) {
clientAddr := "127.0.0.1:9992"
proxyAddr := "127.0.0.1:9993"
proxy := proxy.NewSocketAppProxy(clientAddr, proxyAddr, 1*time.Second, common.NewTestLogger(t))
dummyClient, err := NewDummySocketClient(clientAddr, proxyAddr, common.NewTestLogger(t))
if err != nil {
t.Fatal(err)
}
clientCh := dummyClient.babbleProxy.CommitCh()
block := hashgraph.NewBlock(0, 1, [][]byte{[]byte("the test transaction")})
// Listen for a request
go func() {
select {
case commit := <-clientCh:
if !reflect.DeepEqual(commit.Block, block) {
t.Fatalf("block mismatch: %#v %#v", block, commit.Block)
}
case <-time.After(200 * time.Millisecond):
t.Fatalf("timeout")
}
}()
stateHash, err := proxy.CommitBlock(block)
if err != nil {
t.Fatal(err)
}
t.Logf("stateHash: %v", stateHash)
}