Skip to content

Commit

Permalink
Fix MarshalJustifications and MarshalJustificationsWithFullData
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Apr 11, 2023
1 parent ea35d68 commit a9c3322
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion qbft/spectest/all_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var AllTests = []SpecTest{
messages.CreateRoundChangePreviouslyPrepared(),
messages.RoundChangeDataEncoding(),
messages.SignedMessageSigner0(),
messages.MarshalJustifications(),
messages.MarshalJustificationsWithoutFullData(),
messages.MarshalJustificationsWithFullData(),
messages.UnmarshalJustifications(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import (
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()
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,
[][]byte{encodedRCMsg}, [][]byte{encodedPrepareMsg})
testingutils.MarshalJustifications(rcMsgs), testingutils.MarshalJustifications(prepareMsgs))

r, _ := msg.GetRoot()
b, _ := msg.Encode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"github.com/bloxapp/ssv-spec/types/testingutils"
)

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

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

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

msg := testingutils.TestingProposalMessageWithParams(
Expand Down
34 changes: 34 additions & 0 deletions types/testingutils/qbft_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ var TestingPrepareMessageWithFullData = func(sk *bls.SecretKey, id types.Operato
ret.FullData = fullData
return ret
}
var TestingPrepareMessageWithRoundAndFullData = func(
sk *bls.SecretKey,
id types.OperatorID,
round qbft.Round,
fullData []byte,
) *qbft.SignedMessage {
msg := &qbft.Message{
MsgType: qbft.PrepareMsgType,
Height: qbft.FirstHeight,
Round: round,
Identifier: TestingIdentifier,
Root: sha256.Sum256(fullData),
}
ret := SignQBFTMsg(sk, id, msg)
ret.FullData = fullData
return ret
}
var TestingPrepareMessageWithParams = func(
sk *bls.SecretKey,
id types.OperatorID,
Expand Down Expand Up @@ -348,6 +365,23 @@ var TestingRoundChangeMessageWithHeightAndIdentifier = func(sk *bls.SecretKey, i
ret.FullData = TestingQBFTFullData
return ret
}
var TestingRoundChangeMessageWithRoundAndFullData = func(
sk *bls.SecretKey,
id types.OperatorID,
round qbft.Round,
fullData []byte,
) *qbft.SignedMessage {
msg := &qbft.Message{
MsgType: qbft.RoundChangeMsgType,
Height: qbft.FirstHeight,
Round: round,
Identifier: TestingIdentifier,
Root: sha256.Sum256(fullData),
}
ret := SignQBFTMsg(sk, id, msg)
ret.FullData = fullData
return ret
}
var TestingRoundChangeMessageWithParams = func(
sk *bls.SecretKey,
id types.OperatorID,
Expand Down

0 comments on commit a9c3322

Please sign in to comment.