-
Notifications
You must be signed in to change notification settings - Fork 15
/
api_test.go
69 lines (58 loc) · 1.57 KB
/
api_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
package template_test
import (
"testing"
"github.com/stretchr/testify/require"
// We need to include the service so it is started.
"github.com/dedis/cothority_template"
_ "github.com/dedis/cothority_template/service"
"go.dedis.ch/kyber/v3/suites"
"go.dedis.ch/onet/v3"
"go.dedis.ch/onet/v3/log"
)
var tSuite = suites.MustFind("Ed25519")
func TestMain(m *testing.M) {
log.MainTest(m)
}
func TestClient_Clock(t *testing.T) {
nbr := 5
local := onet.NewTCPTest(tSuite)
// generate 5 hosts, they don't connect, they process messages, and they
// don't register the tree or entitylist
_, roster, _ := local.GenTree(nbr, true)
defer local.CloseAll()
c := template.NewClient()
cl1, err := c.Clock(roster)
require.Nil(t, err)
require.Equal(t, nbr, cl1.Children)
cl2, err := c.Clock(roster)
require.Nil(t, err)
require.Equal(t, nbr, cl2.Children)
}
func TestClient_Count(t *testing.T) {
nbr := 5
local := onet.NewTCPTest(tSuite)
// generate 5 hosts, they don't connect, they process messages, and they
// don't register the tree or entitylist
_, roster, _ := local.GenTree(nbr, true)
defer local.CloseAll()
c := template.NewClient()
// Verify it's all 0s before
for _, s := range roster.List {
count, err := c.Count(s)
require.Nil(t, err)
require.Equal(t, 0, count)
}
// Make some clock-requests
for range roster.List {
_, err := c.Clock(roster)
require.Nil(t, err)
}
// Verify we have the correct total of requests
total := 0
for _, s := range roster.List {
count, err := c.Count(s)
require.Nil(t, err)
total += count
}
require.Equal(t, nbr, total)
}