@@ -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"
@@ -52,6 +54,7 @@ func TestActor_MarshalJSON(t *testing.T) {
52
54
actor1 , err := p .NewActor ([]byte ("deadbeef" ), & fake.Pool {},
53
55
fake.Manager {}, NewHandlerData ())
54
56
require .NoError (t , err )
57
+ require .Equal (t , float64 (dkg .Initialized ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
55
58
56
59
// Serialize its persistent data
57
60
actor1Buf , err := actor1 .MarshalJSON ()
@@ -62,8 +65,11 @@ func TestActor_MarshalJSON(t *testing.T) {
62
65
err = handlerData .UnmarshalJSON (actor1Buf )
63
66
require .NoError (t , err )
64
67
68
+ initMetrics ()
69
+
65
70
actor2 , err := p .NewActor ([]byte ("beefdead" ), & fake.Pool {}, fake.Manager {}, handlerData )
66
71
require .NoError (t , err )
72
+ require .Equal (t , float64 (dkg .Initialized ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
67
73
68
74
// Check that the persistent data is the same for both actors
69
75
requireActorsEqual (t , actor1 , actor2 )
@@ -72,6 +78,8 @@ func TestActor_MarshalJSON(t *testing.T) {
72
78
// After initializing a Pedersen when dkgMap is not empty, the actors map should
73
79
// contain the same information as dkgMap
74
80
func TestPedersen_InitNonEmptyMap (t * testing.T ) {
81
+ initMetrics ()
82
+
75
83
// Create a new DKG map and fill it with data
76
84
dkgMap := fake .NewInMemoryDB ()
77
85
@@ -141,9 +149,14 @@ func TestPedersen_InitNonEmptyMap(t *testing.T) {
141
149
142
150
_ , err = p .NewActor (electionIDBuf , & fake.Pool {}, fake.Manager {}, handlerData )
143
151
if err != nil {
152
+ require .Equal (t , float64 (dkg .Failed ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
144
153
return err
154
+ } else {
155
+ require .Equal (t , float64 (dkg .Initialized ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
145
156
}
146
157
158
+ initMetrics ()
159
+
147
160
return nil
148
161
})
149
162
})
@@ -301,6 +314,8 @@ func TestPedersen_TwoListens(t *testing.T) {
301
314
}
302
315
303
316
func TestPedersen_Setup (t * testing.T ) {
317
+ initMetrics ()
318
+
304
319
electionID := "d3adbeef"
305
320
306
321
service := fake .NewService (electionID , etypes.Election {
@@ -325,6 +340,9 @@ func TestPedersen_Setup(t *testing.T) {
325
340
326
341
_ , err := actor .Setup ()
327
342
require .EqualError (t , err , "failed to get election: election does not exist: <nil>" )
343
+ require .Equal (t , float64 (dkg .Failed ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
344
+
345
+ initMetrics ()
328
346
329
347
actor .electionID = electionID
330
348
@@ -333,6 +351,7 @@ func TestPedersen_Setup(t *testing.T) {
333
351
334
352
_ , err = actor .Setup ()
335
353
require .EqualError (t , err , fake .Err ("failed to stream" ))
354
+ require .Equal (t , float64 (dkg .Failed ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
336
355
337
356
// RPC is bogus 2
338
357
actor .rpc = fake .NewRPC ()
@@ -396,6 +415,7 @@ func TestPedersen_Setup(t *testing.T) {
396
415
// We test that particular behaviour later.
397
416
_ , err = actor .Setup ()
398
417
require .NoError (t , err )
418
+ require .Equal (t , float64 (dkg .Setup ), testutil .ToFloat64 (evoting .PromElectionDkgStatus ))
399
419
}
400
420
401
421
func TestPedersen_GetPublicKey (t * testing.T ) {
@@ -623,6 +643,10 @@ func TestPedersen_ComputePubshares_OK(t *testing.T) {
623
643
// -----------------------------------------------------------------------------
624
644
// Utility functions
625
645
646
+ func initMetrics () {
647
+ evoting .PromElectionDkgStatus .Reset ()
648
+ }
649
+
626
650
// actorsEqual checks that two actors hold the same data
627
651
func requireActorsEqual (t require.TestingT , actor1 , actor2 dkg.Actor ) {
628
652
actor1Data , err := actor1 .MarshalJSON ()
0 commit comments