diff --git a/qbft/spectest/all_tests.go b/qbft/spectest/all_tests.go index 484593f9e..3ec27c295 100644 --- a/qbft/spectest/all_tests.go +++ b/qbft/spectest/all_tests.go @@ -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" @@ -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 { @@ -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(), diff --git a/qbft/spectest/tests/messages/marsha_justification.go b/qbft/spectest/tests/messages/marsha_justification.go deleted file mode 100644 index 8b96613e5..000000000 --- a/qbft/spectest/tests/messages/marsha_justification.go +++ /dev/null @@ -1,8 +0,0 @@ -package messages - -import "github.com/bloxapp/ssv-spec/qbft/spectest/tests" - -// MarshaJustifications tests marshalling justifications -func MarshaJustifications() *tests.MsgSpecTest { - panic("implement") -} diff --git a/qbft/spectest/tests/messages/marsha_justification_with_full_data.go b/qbft/spectest/tests/messages/marsha_justification_with_full_data.go deleted file mode 100644 index 36bb1c10f..000000000 --- a/qbft/spectest/tests/messages/marsha_justification_with_full_data.go +++ /dev/null @@ -1,8 +0,0 @@ -package messages - -import "github.com/bloxapp/ssv-spec/qbft/spectest/tests" - -// MarshaJustificationsWithFullData tests marshalling justifications with full data (should omit it) -func MarshaJustificationsWithFullData() *tests.MsgSpecTest { - panic("implement") -} diff --git a/qbft/spectest/tests/messages/marshal_justification.go b/qbft/spectest/tests/messages/marshal_justification.go new file mode 100644 index 000000000..77c869ae4 --- /dev/null +++ b/qbft/spectest/tests/messages/marshal_justification.go @@ -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, + }, + } +} diff --git a/qbft/spectest/tests/messages/marshal_justification_with_full_data.go b/qbft/spectest/tests/messages/marshal_justification_with_full_data.go new file mode 100644 index 000000000..e6e0b3d1e --- /dev/null +++ b/qbft/spectest/tests/messages/marshal_justification_with_full_data.go @@ -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, + }, + } +} diff --git a/qbft/spectest/tests/messages/unmarsha_justification.go b/qbft/spectest/tests/messages/unmarsha_justification.go deleted file mode 100644 index b20ee0ce7..000000000 --- a/qbft/spectest/tests/messages/unmarsha_justification.go +++ /dev/null @@ -1,8 +0,0 @@ -package messages - -import "github.com/bloxapp/ssv-spec/qbft/spectest/tests" - -// UnMarshaJustifications tests unmarshalling justifications -func UnMarshaJustifications() *tests.MsgSpecTest { - panic("implement") -} diff --git a/qbft/spectest/tests/messages/unmarshal_justification.go b/qbft/spectest/tests/messages/unmarshal_justification.go new file mode 100644 index 000000000..cc3ac062e --- /dev/null +++ b/qbft/spectest/tests/messages/unmarshal_justification.go @@ -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, + }, + } +}