-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathct_node_test.go
115 lines (86 loc) · 2.87 KB
/
ct_node_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package DCP
import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/ivpusic/grpool"
"testing"
"time"
)
func TestCtPrint(t *testing.T) {
node := CtNode{
Id: uuid.New(),
Co: &CalculationObjectPaillier{},
Ids: nil,
}
_ = node.Co.KeyGen()
node.Print()
}
func TestCtNode_HandleCalculationObjectCtChannel(t *testing.T) {
config := NewCtNodeConfig()
config.NodeVisitDecryptThreshold = 2
pool := grpool.NewPool(100, 10)
defer pool.Release()
node1 := NewCtNode([]string{uuid.New().String()}, config, pool)
node2 := NewCtNode([]string{uuid.New().String()}, config, pool)
_ = node1.Co.KeyGen()
_ = node2.Co.KeyGen()
node1.TransportLayer.ReachableNodes[node2.TransportLayer.DataCh] = struct{}{}
node2.TransportLayer.ReachableNodes[node1.TransportLayer.DataCh] = struct{}{}
_ = InitRoutine(PrepareIdLenCalculation, node1)
node1.Listen()
node2.Listen()
node1.Broadcast(nil)
time.Sleep(1 * time.Millisecond)
}
func TestCtNode_HandleCalculationObjectAbortAlreadyHandled(t *testing.T) {
pool := grpool.NewPool(100, 10)
defer pool.Release()
node1 := NewCtNode([]string{uuid.New().String(), uuid.New().String()}, NewCtNodeConfig(), pool)
node2 := NewCtNode([]string{uuid.New().String(), uuid.New().String()}, NewCtNodeConfig(), pool)
node3 := NewCtNode([]string{uuid.New().String(), uuid.New().String()}, NewCtNodeConfig(), pool)
_ = node1.Co.KeyGen()
_ = node2.Co.KeyGen()
_ = node3.Co.KeyGen()
node1.TransportLayer.ReachableNodes[node2.TransportLayer.DataCh] = struct{}{}
node2.TransportLayer.ReachableNodes[node3.TransportLayer.DataCh] = struct{}{}
node3.TransportLayer.ReachableNodes[node2.TransportLayer.DataCh] = struct{}{}
_ = InitRoutine(PrepareIdLenCalculation, node1)
node1.Listen()
node2.Listen()
node3.Listen()
node1.Broadcast(nil)
time.Sleep(1 * time.Millisecond)
fmt.Println(NrOfBranches)
}
func TestCtNode_HandleCalculationObjectUpdateSelfNodeCo(t *testing.T) {
pool := grpool.NewPool(100, 10)
defer pool.Release()
node1 := NewCtNode([]string{uuid.New().String(), uuid.New().String()}, NewCtNodeConfig(), pool)
node2 := NewCtNode([]string{uuid.New().String(), uuid.New().String()}, NewCtNodeConfig(), pool)
node1.Co.Counter = defaultNodeVisitDecryptThreshold - 1
_ = node1.Co.KeyGen()
_ = node2.Co.KeyGen()
node1.TransportLayer.ReachableNodes[node2.TransportLayer.DataCh] = struct{}{}
node2.TransportLayer.ReachableNodes[node1.TransportLayer.DataCh] = struct{}{}
_ = InitRoutine(PrepareIdLenCalculation, node1)
node1.Listen()
node2.Listen()
node1.Broadcast(nil)
time.Sleep(1 * time.Millisecond)
msg := node1.Co.Decrypt(node1.Co.Cipher)
if msg.String() != "4" {
t.Fail()
}
}
func Test_CtNodeMarshal(t *testing.T) {
pool := grpool.NewPool(100, 10)
defer pool.Release()
c := NewCtNodeConfig()
node := NewCtNode([]string{uuid.New().String()}, c, pool)
_, e := json.Marshal(node)
if e != nil {
fmt.Println(e.Error())
t.Fail()
}
}