-
Notifications
You must be signed in to change notification settings - Fork 15
/
protocol_test.go
52 lines (43 loc) · 1.36 KB
/
protocol_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 protocol_test
/*
The test-file should at the very least run the protocol for a varying number
of nodes. It is even better practice to test the different methods of the
protocol, as in Test Driven Development.
*/
import (
"testing"
"time"
"github.com/dedis/cothority_template/protocol"
"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v3/suites"
"go.dedis.ch/onet/v3"
"go.dedis.ch/onet/v3/log"
"go.dedis.ch/onet/v3/network"
)
var tSuite = suites.MustFind("Ed25519")
func TestMain(m *testing.M) {
log.MainTest(m)
}
// Tests a 2, 5 and 13-node system. It is good practice to test different
// sizes of trees to make sure your protocol is stable.
func TestNode(t *testing.T) {
nodes := []int{2, 5, 13}
for _, nbrNodes := range nodes {
local := onet.NewLocalTest(tSuite)
_, _, tree := local.GenTree(nbrNodes, true)
log.Lvl3(tree.Dump())
pi, err := local.CreateProtocol("Template", tree)
require.Nil(t, err)
protocol := pi.(*protocol.TemplateProtocol)
require.NoError(t, protocol.Start())
timeout := network.WaitRetry * time.Duration(network.MaxRetryConnect*nbrNodes*2) * time.Millisecond
select {
case children := <-protocol.ChildCount:
log.Lvl2("Instance 1 is done")
require.Equal(t, children, nbrNodes, "Didn't get a child-cound of", nbrNodes)
case <-time.After(timeout):
t.Fatal("Didn't finish in time")
}
local.CloseAll()
}
}