@@ -14,10 +14,12 @@ import (
14
14
"go.dedis.ch/dela/core/validation"
15
15
"golang.org/x/xerrors"
16
16
17
+ "github.com/dedis/d-voting/contracts/evoting"
17
18
etypes "github.com/dedis/d-voting/contracts/evoting/types"
18
19
"github.com/dedis/d-voting/internal/testing/fake"
19
20
"github.com/dedis/d-voting/services/dkg"
20
21
"github.com/dedis/d-voting/services/dkg/pedersen/types"
22
+ "github.com/prometheus/client_golang/prometheus/testutil"
21
23
"github.com/stretchr/testify/require"
22
24
"go.dedis.ch/dela/core/ordering/cosipbft/authority"
23
25
"go.dedis.ch/dela/core/store/kv"
@@ -46,12 +48,15 @@ func init() {
46
48
// If you get the persistent data from an actor and then recreate an actor
47
49
// from that data, the persistent data should be the same in both actors.
48
50
func TestActor_MarshalJSON (t * testing.T ) {
51
+ initMetrics ()
52
+
49
53
p := NewPedersen (fake.Mino {}, & fake.Service {}, & fake.Pool {}, fake.Factory {}, fake.Signer {})
50
54
51
55
// Create new actor
52
56
actor1 , err := p .NewActor ([]byte ("deadbeef" ), & fake.Pool {},
53
57
fake.Manager {}, NewHandlerData ())
54
58
require .NoError (t , err )
59
+ require .Equal (t , float64 (dkg .Initialized ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
55
60
56
61
// Serialize its persistent data
57
62
actor1Buf , err := actor1 .MarshalJSON ()
@@ -62,8 +67,11 @@ func TestActor_MarshalJSON(t *testing.T) {
62
67
err = handlerData .UnmarshalJSON (actor1Buf )
63
68
require .NoError (t , err )
64
69
70
+ initMetrics ()
71
+
65
72
actor2 , err := p .NewActor ([]byte ("beefdead" ), & fake.Pool {}, fake.Manager {}, handlerData )
66
73
require .NoError (t , err )
74
+ require .Equal (t , float64 (dkg .Initialized ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
67
75
68
76
// Check that the persistent data is the same for both actors
69
77
requireActorsEqual (t , actor1 , actor2 )
@@ -72,6 +80,8 @@ func TestActor_MarshalJSON(t *testing.T) {
72
80
// After initializing a Pedersen when dkgMap is not empty, the actors map should
73
81
// contain the same information as dkgMap
74
82
func TestPedersen_InitNonEmptyMap (t * testing.T ) {
83
+ initMetrics ()
84
+
75
85
// Create a new DKG map and fill it with data
76
86
dkgMap := fake .NewInMemoryDB ()
77
87
@@ -141,9 +151,14 @@ func TestPedersen_InitNonEmptyMap(t *testing.T) {
141
151
142
152
_ , err = p .NewActor (electionIDBuf , & fake.Pool {}, fake.Manager {}, handlerData )
143
153
if err != nil {
154
+ require .Equal (t , float64 (dkg .Failed ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
144
155
return err
156
+ } else {
157
+ require .Equal (t , float64 (dkg .Initialized ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
145
158
}
146
159
160
+ initMetrics ()
161
+
147
162
return nil
148
163
})
149
164
})
@@ -301,6 +316,8 @@ func TestPedersen_TwoListens(t *testing.T) {
301
316
}
302
317
303
318
func TestPedersen_Setup (t * testing.T ) {
319
+ initMetrics ()
320
+
304
321
electionID := "d3adbeef"
305
322
306
323
service := fake .NewService (electionID , etypes.Election {
@@ -325,6 +342,9 @@ func TestPedersen_Setup(t *testing.T) {
325
342
326
343
_ , err := actor .Setup ()
327
344
require .EqualError (t , err , "failed to get election: election does not exist: <nil>" )
345
+ require .Equal (t , float64 (dkg .Failed ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
346
+
347
+ initMetrics ()
328
348
329
349
actor .electionID = electionID
330
350
@@ -333,6 +353,7 @@ func TestPedersen_Setup(t *testing.T) {
333
353
334
354
_ , err = actor .Setup ()
335
355
require .EqualError (t , err , fake .Err ("failed to stream" ))
356
+ require .Equal (t , float64 (dkg .Failed ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
336
357
337
358
// RPC is bogus 2
338
359
actor .rpc = fake .NewRPC ()
@@ -396,6 +417,7 @@ func TestPedersen_Setup(t *testing.T) {
396
417
// We test that particular behaviour later.
397
418
_ , err = actor .Setup ()
398
419
require .NoError (t , err )
420
+ require .Equal (t , float64 (dkg .Setup ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
399
421
}
400
422
401
423
func TestPedersen_GetPublicKey (t * testing.T ) {
@@ -623,6 +645,10 @@ func TestPedersen_ComputePubshares_OK(t *testing.T) {
623
645
// -----------------------------------------------------------------------------
624
646
// Utility functions
625
647
648
+ func initMetrics () {
649
+ evoting .PromElectionDkgStatus .Reset ()
650
+ }
651
+
626
652
// actorsEqual checks that two actors hold the same data
627
653
func requireActorsEqual (t require.TestingT , actor1 , actor2 dkg.Actor ) {
628
654
actor1Data , err := actor1 .MarshalJSON ()
0 commit comments