Skip to content

Commit

Permalink
Merge branch 'main' into test-share
Browse files Browse the repository at this point in the history
  • Loading branch information
GalRogozinski committed Jan 15, 2024
2 parents f39a4ae + 1b367a0 commit 0cf502c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
2 changes: 2 additions & 0 deletions types/spectest/all_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type SpecTest interface {

var AllTests = []SpecTest{
ssvmsg.Encoding(),
ssvmsg.MsgIDBelongs(),
ssvmsg.MsgIDDoesntBelongs(),

partialsigmessage.Encoding(),

Expand Down
2 changes: 1 addition & 1 deletion types/spectest/generate/tests.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions types/spectest/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ func TestJson(t *testing.T) {
typedTest := &share.ShareTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))
typedTest.Run(t)
case reflect.TypeOf(&ssvmsg.SSVMessageTest{}).String():
byts, err := json.Marshal(test)
require.NoError(t, err)
typedTest := &ssvmsg.SSVMessageTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))
typedTest.Run(t)
default:
t.Fatalf("unknown test")
}
Expand Down
18 changes: 16 additions & 2 deletions types/spectest/tests/ssvmsg/msg_id_belongs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package ssvmsg

import (
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// MsgIDBelongs tests msg id belonging to validator id
func MsgIDBelongs() SpecTest {
panic("implement")
func MsgIDBelongs() *SSVMessageTest {
return &SSVMessageTest{
Name: "belongs",
MessageIDs: []types.MessageID{
types.NewMsgID(testingutils.TestingSSVDomainType, testingutils.TestingValidatorPubKey[:], types.BNRoleAttester),
types.NewMsgID(testingutils.TestingSSVDomainType, testingutils.TestingValidatorPubKey[:], types.BeaconRole(100)),
types.NewMsgID(types.DomainType{0x99, 0x99, 0x99, 0x99}, testingutils.TestingValidatorPubKey[:], types.BNRoleAttester),
types.NewMsgID(types.DomainType{0x99, 0x99, 0x99, 0x99}, testingutils.TestingValidatorPubKey[:], types.BeaconRole(100)),
},
BelongsToValidator: true,
}
}
18 changes: 16 additions & 2 deletions types/spectest/tests/ssvmsg/msg_id_doesnt_belong.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package ssvmsg

import (
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// MsgIDDoesntBelongs tests msg id doesn't belonging to validator id
func MsgIDDoesntBelongs() SpecTest {
panic("implement")
func MsgIDDoesntBelongs() *SSVMessageTest {
return &SSVMessageTest{
Name: "does not belong",
MessageIDs: []types.MessageID{
types.NewMsgID(testingutils.TestingSSVDomainType, testingutils.TestingWrongValidatorPubKey[:], types.BNRoleAttester),
types.NewMsgID(testingutils.TestingSSVDomainType, testingutils.TestingWrongValidatorPubKey[:], types.BeaconRole(100)),
types.NewMsgID(types.DomainType{0x99, 0x99, 0x99, 0x99}, testingutils.TestingWrongValidatorPubKey[:], types.BNRoleAttester),
types.NewMsgID(types.DomainType{0x99, 0x99, 0x99, 0x99}, testingutils.TestingWrongValidatorPubKey[:], types.BeaconRole(100)),
},
BelongsToValidator: false,
}
}
26 changes: 19 additions & 7 deletions types/spectest/tests/ssvmsg/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ package ssvmsg

import (
"testing"

"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
"github.com/stretchr/testify/require"
)

type SpecTest struct {
Name string
Data []byte
type SSVMessageTest struct {
Name string
MessageIDs []types.MessageID
BelongsToValidator bool
}

func (test *SpecTest) TestName() string {
return test.Name
func (test *SSVMessageTest) TestName() string {
return "ssvmessage " + test.Name
}

func (test *SpecTest) Run(t *testing.T) {
panic("implement")
func (test *SSVMessageTest) Run(t *testing.T) {

ks := testingutils.Testing4SharesSet()

// For each message ID, test if MessageIDBelongs returns the expected value
for _, msgID := range test.MessageIDs {
belongs := testingutils.TestingShare(ks).ValidatorPubKey.MessageIDBelongs(msgID)
require.Equal(t, test.BelongsToValidator, belongs)
}
}

0 comments on commit 0cf502c

Please sign in to comment.