Skip to content

Commit 8e4ab70

Browse files
committed
Fix key message handling tests
1 parent f7a7a3e commit 8e4ab70

File tree

2 files changed

+64
-27
lines changed

2 files changed

+64
-27
lines changed

rolling-shutter/keyper/epochkghandler/key_test.go

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ func TestHandleDecryptionKeyIntegration(t *testing.T) {
2828

2929
queries := database.New(dbpool)
3030

31-
eon := config.GetEon()
3231
identityPreimages := []identitypreimage.IdentityPreimage{}
3332
for i := 0; i < 3; i++ {
3433
identityPreimage := identitypreimage.Uint64ToIdentityPreimage(uint64(i))
3534
identityPreimages = append(identityPreimages, identityPreimage)
3635
}
3736
keyperIndex := uint64(1)
37+
keyperConfigIndex := uint64(1)
3838

3939
tkg := testsetup.InitializeEon(ctx, t, dbpool, config, keyperIndex)
4040

@@ -56,13 +56,13 @@ func TestHandleDecryptionKeyIntegration(t *testing.T) {
5656
}
5757
msgs := p2ptest.MustHandleMessage(t, handler, ctx, &p2pmsg.DecryptionKeys{
5858
InstanceID: config.GetInstanceID(),
59-
Eon: eon,
59+
Eon: keyperConfigIndex,
6060
Keys: keys,
6161
})
6262
assert.Check(t, len(msgs) == 0)
6363
for i, identityPreimage := range identityPreimages {
6464
key, err := queries.GetDecryptionKey(ctx, database.GetDecryptionKeyParams{
65-
Eon: int64(eon),
65+
Eon: int64(keyperConfigIndex),
6666
EpochID: identityPreimage.Bytes(),
6767
})
6868
assert.NilError(t, err)
@@ -80,7 +80,7 @@ func TestDecryptionKeyValidatorIntegration(t *testing.T) {
8080
t.Cleanup(dbclose)
8181

8282
keyperIndex := uint64(1)
83-
eon := config.GetEon()
83+
keyperConfigIndex := uint64(1)
8484
identityPreimage := identitypreimage.BigToIdentityPreimage(common.Big0)
8585
secondIdentityPreimage := identitypreimage.BigToIdentityPreimage(common.Big1)
8686
wrongIdentityPreimage := identitypreimage.BigToIdentityPreimage(common.Big2)
@@ -99,7 +99,7 @@ func TestDecryptionKeyValidatorIntegration(t *testing.T) {
9999
validationResult: pubsub.ValidationAccept,
100100
msg: &p2pmsg.DecryptionKeys{
101101
InstanceID: config.GetInstanceID(),
102-
Eon: eon,
102+
Eon: keyperConfigIndex,
103103
Keys: []*p2pmsg.Key{
104104
{
105105
Identity: identityPreimage.Bytes(),
@@ -113,7 +113,7 @@ func TestDecryptionKeyValidatorIntegration(t *testing.T) {
113113
validationResult: pubsub.ValidationReject,
114114
msg: &p2pmsg.DecryptionKeys{
115115
InstanceID: config.GetInstanceID(),
116-
Eon: eon,
116+
Eon: keyperConfigIndex,
117117
Keys: []*p2pmsg.Key{
118118
{
119119
Identity: wrongIdentityPreimage.Bytes(),
@@ -127,7 +127,7 @@ func TestDecryptionKeyValidatorIntegration(t *testing.T) {
127127
validationResult: pubsub.ValidationReject,
128128
msg: &p2pmsg.DecryptionKeys{
129129
InstanceID: config.GetInstanceID() + 1,
130-
Eon: eon,
130+
Eon: keyperConfigIndex,
131131
Keys: []*p2pmsg.Key{
132132
{
133133
Identity: identityPreimage.Bytes(),
@@ -141,34 +141,16 @@ func TestDecryptionKeyValidatorIntegration(t *testing.T) {
141141
validationResult: pubsub.ValidationReject,
142142
msg: &p2pmsg.DecryptionKeys{
143143
InstanceID: config.GetInstanceID(),
144-
Eon: eon,
144+
Eon: keyperConfigIndex,
145145
Keys: []*p2pmsg.Key{},
146146
},
147147
},
148-
{
149-
name: "invalid decryption key duplicate",
150-
validationResult: pubsub.ValidationReject,
151-
msg: &p2pmsg.DecryptionKeys{
152-
InstanceID: config.GetInstanceID(),
153-
Eon: eon,
154-
Keys: []*p2pmsg.Key{
155-
{
156-
Identity: identityPreimage.Bytes(),
157-
Key: secretKey,
158-
},
159-
{
160-
Identity: identityPreimage.Bytes(),
161-
Key: secretKey,
162-
},
163-
},
164-
},
165-
},
166148
{
167149
name: "invalid decryption key unordered",
168150
validationResult: pubsub.ValidationReject,
169151
msg: &p2pmsg.DecryptionKeys{
170152
InstanceID: config.GetInstanceID(),
171-
Eon: eon,
153+
Eon: keyperConfigIndex,
172154
Keys: []*p2pmsg.Key{
173155
{
174156
Identity: secondIdentityPreimage.Bytes(),
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package epochkghandler
2+
3+
// import (
4+
// "context"
5+
// "testing"
6+
7+
// pubsub "github.com/libp2p/go-libp2p-pubsub"
8+
// "gotest.tools/assert"
9+
10+
// "github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database"
11+
// "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/identitypreimage"
12+
// "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/testsetup"
13+
// "github.com/shutter-network/rolling-shutter/rolling-shutter/p2pmsg"
14+
// )
15+
16+
// func BenchmarkDecryptionKeySharesValidationIntegration(b *testing.B) {
17+
// ctx := context.Background()
18+
19+
// dbpool, dbclose := testsetup.NewTestDBPool(ctx, b, database.Definition)
20+
// b.Cleanup(dbclose)
21+
22+
// identityPreimages := []identitypreimage.IdentityPreimage{}
23+
// for i := 0; i < 3; i++ {
24+
// identityPreimage := identitypreimage.Uint64ToIdentityPreimage(uint64(i))
25+
// identityPreimages = append(identityPreimages, identityPreimage)
26+
// }
27+
// keyperIndex := uint64(1)
28+
// keyperConfigIndex := uint64(1)
29+
30+
// tkg := testsetup.InitializeEon(ctx, b, dbpool, config, keyperIndex)
31+
// handler := &DecryptionKeyShareHandler{config: config, dbpool: dbpool}
32+
33+
// shares := []*p2pmsg.KeyShare{}
34+
// for _, identityPreimage := range identityPreimages {
35+
// share := &p2pmsg.KeyShare{
36+
// EpochID: identityPreimage.Bytes(),
37+
// Share: tkg.EpochSecretKeyShare(identityPreimage, 0).Marshal(),
38+
// }
39+
// shares = append(shares, share)
40+
// }
41+
42+
// msg := &p2pmsg.DecryptionKeyShares{
43+
// InstanceID: config.GetInstanceID(),
44+
// Eon: keyperConfigIndex,
45+
// KeyperIndex: keyperIndex,
46+
// Shares: shares,
47+
// }
48+
49+
// b.ResetTimer()
50+
// validationResult, err := handler.ValidateMessage(ctx, msg)
51+
// b.StopTimer()
52+
53+
// assert.NilError(b, err)
54+
// assert.Equal(b, pubsub.ValidationAccept, validationResult)
55+
// }

0 commit comments

Comments
 (0)