Skip to content

Commit

Permalink
Implement messages.MarshalJustifications, messages.MarshalJustificati…
Browse files Browse the repository at this point in the history
…onsWithFullData, messages.UnmarshalJustifications
  • Loading branch information
nkryuchkov committed Apr 11, 2023
1 parent f9adf29 commit ea35d68
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 28 deletions.
9 changes: 5 additions & 4 deletions qbft/spectest/all_tests.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package spectest

import (
"testing"

"github.com/bloxapp/ssv-spec/qbft/spectest/tests"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/commit"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/controller/decided"
Expand All @@ -14,7 +16,6 @@ import (
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/roundchange"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/startinstance"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/timeout"
"testing"
)

type SpecTest interface {
Expand Down Expand Up @@ -116,9 +117,9 @@ var AllTests = []SpecTest{
messages.CreateRoundChangePreviouslyPrepared(),
messages.RoundChangeDataEncoding(),
messages.SignedMessageSigner0(),
//messages.MarshaJustifications(), // TODO: implement
//messages.MarshaJustificationsWithFullData(), // TODO: implement
//messages.UnMarshaJustifications(), // TODO: implement
messages.MarshalJustifications(),
messages.MarshalJustificationsWithFullData(),
messages.UnmarshalJustifications(),

tests.HappyFlow(),
tests.SevenOperators(),
Expand Down
8 changes: 0 additions & 8 deletions qbft/spectest/tests/messages/marsha_justification.go

This file was deleted.

This file was deleted.

41 changes: 41 additions & 0 deletions qbft/spectest/tests/messages/marshal_justification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package messages

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

// MarshalJustifications tests marshalling justifications
func MarshalJustifications() *tests.MsgSpecTest {
ks := testingutils.Testing4SharesSet()

rcMsgs := []*qbft.SignedMessage{
testingutils.TestingRoundChangeMessageWithRound(ks.Shares[1], 1, 2),
}

prepareMsgs := []*qbft.SignedMessage{
testingutils.TestingPrepareMessage(ks.Shares[1], types.OperatorID(1)),
}

msg := testingutils.TestingProposalMessageWithParams(
ks.Shares[1], types.OperatorID(1), 2, qbft.FirstHeight, testingutils.TestingQBFTRootData,
testingutils.MarshalJustifications(rcMsgs), testingutils.MarshalJustifications(prepareMsgs))

r, _ := msg.GetRoot()
b, _ := msg.Encode()

return &tests.MsgSpecTest{
Name: "marshal justifications",
Messages: []*qbft.SignedMessage{
msg,
},
EncodedMessages: [][]byte{
b,
},
ExpectedRoots: [][32]byte{
r,
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package messages

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

// MarshalJustificationsWithFullData tests marshalling justifications with full data (should omit it)
func MarshalJustificationsWithFullData() *tests.MsgSpecTest {
ks := testingutils.Testing4SharesSet()

encodedRCMsg, _ := testingutils.TestingRoundChangeMessageWithRound(ks.Shares[1], 1, 2).MarshalSSZ()
encodedPrepareMsg, _ := testingutils.TestingPrepareMessage(ks.Shares[1], types.OperatorID(1)).MarshalSSZ()

msg := testingutils.TestingProposalMessageWithParams(
ks.Shares[1], types.OperatorID(1), 2, qbft.FirstHeight, testingutils.TestingQBFTRootData,
[][]byte{encodedRCMsg}, [][]byte{encodedPrepareMsg})

r, _ := msg.GetRoot()
b, _ := msg.Encode()

return &tests.MsgSpecTest{
Name: "marshal justifications with full data",
Messages: []*qbft.SignedMessage{
msg,
},
EncodedMessages: [][]byte{
b,
},
ExpectedRoots: [][32]byte{
r,
},
}
}
8 changes: 0 additions & 8 deletions qbft/spectest/tests/messages/unmarsha_justification.go

This file was deleted.

38 changes: 38 additions & 0 deletions qbft/spectest/tests/messages/unmarshal_justification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package messages

import (
"encoding/hex"

"github.com/bloxapp/ssv-spec/qbft"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests"
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// UnmarshalJustifications tests unmarshalling justifications
func UnmarshalJustifications() *tests.MsgSpecTest {
ks := testingutils.Testing4SharesSet()

encodedRCMsg, _ := hex.DecodeString("b77c035c1d1d9c6c7cc22810c50a85c9e560ad791509055061dfe07d403edaa1304161466d49f64844b6e5cf4b09709f069debfd91438f97d414a4f64cdcb4f8cf1e9703f8da141be9f74509087e2f84492314b0341966c4b8fc16d931f6ba086c00000074000000c400000001000000000000000300000000000000000000000000000002000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b40000000000000000500000005000000001020304")
encodedPrepareMsg, _ := hex.DecodeString("8129e6862a5120bd085e1936b4efb5a55fc7d19c0d0fda0e9ec576d18abd4a17ab3a033f5296b74c5fdaf85cb7b3da3201b63feca76b883613e3b1ca137e763a342e3b1dddbce016f8ca3cbce32c8b125dd8c25a7639819c20b539e9e7c6c5796c00000074000000c400000001000000000000000100000000000000000000000000000001000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b40000000000000000500000005000000001020304")

msg := testingutils.TestingProposalMessageWithParams(
ks.Shares[1], types.OperatorID(1), 2, qbft.FirstHeight, testingutils.TestingQBFTRootData,
[][]byte{encodedRCMsg}, [][]byte{encodedPrepareMsg})

r, _ := msg.GetRoot()
b, _ := msg.Encode()

return &tests.MsgSpecTest{
Name: "unmarshal justifications",
Messages: []*qbft.SignedMessage{
msg,
},
EncodedMessages: [][]byte{
b,
},
ExpectedRoots: [][32]byte{
r,
},
}
}

0 comments on commit ea35d68

Please sign in to comment.