Skip to content

Commit

Permalink
ssz: implement non-implemented tests (#165)
Browse files Browse the repository at this point in the history
* Fix decided.InvalidFullData and proposal.InvalidValueCheck

* Implement messages.MarshalJustifications, messages.MarshalJustificationsWithFullData, messages.UnmarshalJustifications

* Fix MarshalJustifications and MarshalJustificationsWithFullData

* Fix code review requests

* resolve merge conflicts

* make generate-jsons

---------

Co-authored-by: olegshmuelov <45327364+olegshmuelov@users.noreply.github.com>
Co-authored-by: Gal Rogozinski <galrogogit@gmail.com>
  • Loading branch information
3 people committed May 1, 2023
1 parent 8f827ea commit 2023d3c
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 48 deletions.
10 changes: 5 additions & 5 deletions qbft/spectest/all_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var AllTests = []tests.TestF{
decided.DuplicateMsg,
decided.DuplicateSigners,
decided.Invalid,
//decided.InvalidFullData, // TODO: implement
decided.InvalidFullData,
decided.InvalidValCheckData,
decided.PastInstance,
decided.UnknownSigner,
Expand Down Expand Up @@ -110,9 +110,9 @@ var AllTests = []tests.TestF{
messages.CreateRoundChangePreviouslyPrepared,
messages.RoundChangeDataEncoding,
messages.SignedMessageSigner0,
//messages.MarshaJustifications, // TODO: implement
//messages.MarshaJustificationsWithFullData, // TODO: implement
//messages.UnMarshaJustifications, // TODO: implement
messages.MarshalJustificationsWithoutFullData,
messages.MarshalJustificationsWithFullData,
messages.UnmarshalJustifications,

tests.HappyFlow,
tests.SevenOperators,
Expand Down Expand Up @@ -142,7 +142,7 @@ var AllTests = []tests.TestF{
proposal.DuplicateRCMsg,
proposal.InvalidPrepareJustificationValue,
proposal.InvalidPrepareJustificationRound,
//proposal.InvalidValueCheck, // TODO: implement
proposal.InvalidValueCheck,
proposal.MultiSigner,
proposal.PostDecided,
proposal.PostPrepared,
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/generate/tests.json

Large diffs are not rendered by default.

31 changes: 29 additions & 2 deletions qbft/spectest/tests/controller/decided/invalid_full_data.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
package decided

import "github.com/bloxapp/ssv-spec/qbft/spectest/tests"
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"
"github.com/herumi/bls-eth-go-binary/bls"
)

// InvalidFullData tests signed decided with an invalid full data field
func InvalidFullData() tests.SpecTest {
panic("implement")
ks := testingutils.Testing4SharesSet()

msg := testingutils.TestingCommitMultiSignerMessageWithHeight(
[]*bls.SecretKey{ks.Shares[1], ks.Shares[2], ks.Shares[3]},
[]types.OperatorID{1, 2, 3},
10,
)
msg.FullData = []byte("invalid")

return &tests.ControllerSpecTest{
Name: "decide invalid full data",
RunInstanceData: []*tests.RunInstanceData{
{
InputValue: []byte{1, 2, 3, 4},
InputMessages: []*qbft.SignedMessage{
msg,
},
ControllerPostRoot: "47713c38fe74ce55959980781287886c603c2117a14dc8abce24dcb9be0093af",
},
},
ExpectedError: "invalid decided msg: H(data) != root",
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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"
)

// MarshalJustificationsWithFullData tests marshalling justifications with full data (should omit it)
func MarshalJustificationsWithFullData() tests.SpecTest {
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, err := hex.DecodeString("fddc24432bfcc56695474576b1c70aed011f18bfa1ad2c10c85772f8c588e412")
if err != nil {
panic(err)
}

b, err := hex.DecodeString("901603cd1e6e9c2a4fd690039a3f0731e17a64d1a68ab883dbff61688822054870e300fa9f21b30ff315f0851376758100ff0919db5d6dc674ce71577426c724d8935adba2c624ad2323fac3510c2dd117eb49f6a3a6b4171fb749a67aa0772e6c000000740000005402000001000000000000000000000000000000000000000000000002000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b4000000000000000050000000180100000102030404000000b77c035c1d1d9c6c7cc22810c50a85c9e560ad791509055061dfe07d403edaa1304161466d49f64844b6e5cf4b09709f069debfd91438f97d414a4f64cdcb4f8cf1e9703f8da141be9f74509087e2f84492314b0341966c4b8fc16d931f6ba086c00000074000000c400000001000000000000000300000000000000000000000000000002000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b40000000000000000500000005000000001020304040000008129e6862a5120bd085e1936b4efb5a55fc7d19c0d0fda0e9ec576d18abd4a17ab3a033f5296b74c5fdaf85cb7b3da3201b63feca76b883613e3b1ca137e763a342e3b1dddbce016f8ca3cbce32c8b125dd8c25a7639819c20b539e9e7c6c5796c00000074000000c400000001000000000000000100000000000000000000000000000001000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b40000000000000000500000005000000001020304010203040506070809010203040506070809010203040506070809")
if err != nil {
panic(err)
}

return &tests.MsgSpecTest{
Name: "marshal justifications with full data",
Messages: []*qbft.SignedMessage{
msg,
},
EncodedMessages: [][]byte{
b,
},
ExpectedRoots: [][32]byte{
*(*[32]byte)(r),
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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"
)

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

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

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

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

r, err := hex.DecodeString("38977ca5244c072549564f2fd90a88fd7e3cf5124ebd3c77154c042ea3ed8aa0")
if err != nil {
panic(err)
}

b, err := hex.DecodeString("97b88bdd65b68dc9f35bcaa236a41c2e279e0d60d1f3b88f43b5184ce29b2bcde2ff79f4e9877e2655eb269f103a7ed7070469f2fc0f53db4676f85f7602d42ae8715f2a9e8fc08e75ee09ecb213e0e94d01d95a5214d165569ada5f8f9434a96c000000740000005402000001000000000000000000000000000000000000000000000002000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b4000000000000000050000000180100000102030404000000b0a85408a6085a2dc0d571f37a6d687f1b76bb152f8764fb6111048d91642a656e66bb0e260981b752980cfff4d2c0ff0a79e5b1877d8f5cd62f4d5c59c13695d672f2b4b83c5596b9ec3838d5eea245bb6086676989fefcd65fbb6bf93678806c00000074000000c400000001000000000000000300000000000000000000000000000002000000000000004c000000e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500000000000000005000000050000000010203040400000094f75ab09524ef2d4fff17e641437abcc9aef029962b4298c13ee7914f88e10463f27edb5d12f19c211df499a10f3852126184cc2acd150f087f298bd4ff42d917f94910e82fd8a6974400626c99ea2dacac83ead8cafd1b913359b23c5734a36c00000074000000c400000001000000000000000100000000000000000000000000000001000000000000004c000000e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000000000000500000005000000001020304010203040506070809010203040506070809010203040506070809")
if err != nil {
panic(err)
}

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

This file was deleted.

45 changes: 45 additions & 0 deletions qbft/spectest/tests/messages/unmarshal_justification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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.SpecTest {
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, err := hex.DecodeString("fddc24432bfcc56695474576b1c70aed011f18bfa1ad2c10c85772f8c588e412")
if err != nil {
panic(err)
}

b, err := hex.DecodeString("901603cd1e6e9c2a4fd690039a3f0731e17a64d1a68ab883dbff61688822054870e300fa9f21b30ff315f0851376758100ff0919db5d6dc674ce71577426c724d8935adba2c624ad2323fac3510c2dd117eb49f6a3a6b4171fb749a67aa0772e6c000000740000005402000001000000000000000000000000000000000000000000000002000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b4000000000000000050000000180100000102030404000000b77c035c1d1d9c6c7cc22810c50a85c9e560ad791509055061dfe07d403edaa1304161466d49f64844b6e5cf4b09709f069debfd91438f97d414a4f64cdcb4f8cf1e9703f8da141be9f74509087e2f84492314b0341966c4b8fc16d931f6ba086c00000074000000c400000001000000000000000300000000000000000000000000000002000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b40000000000000000500000005000000001020304040000008129e6862a5120bd085e1936b4efb5a55fc7d19c0d0fda0e9ec576d18abd4a17ab3a033f5296b74c5fdaf85cb7b3da3201b63feca76b883613e3b1ca137e763a342e3b1dddbce016f8ca3cbce32c8b125dd8c25a7639819c20b539e9e7c6c5796c00000074000000c400000001000000000000000100000000000000000000000000000001000000000000004c000000be956fb7df4ef37531682d588320084fc914c3f0fed335263e5b44062e6c29b40000000000000000500000005000000001020304010203040506070809010203040506070809010203040506070809")
if err != nil {
panic(err)
}

return &tests.MsgSpecTest{
Name: "unmarshal justifications",
Messages: []*qbft.SignedMessage{
msg,
},
EncodedMessages: [][]byte{
b,
},
ExpectedRoots: [][32]byte{
*(*[32]byte)(r),
},
}
}
39 changes: 17 additions & 22 deletions qbft/spectest/tests/proposal/invalid_value_check.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
package proposal

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"
)

// InvalidValueCheck tests a proposal that doesn't pass value check
func InvalidValueCheck() tests.SpecTest {
panic("implement")
pre := testingutils.BaseInstance()
ks := testingutils.Testing4SharesSet()
msgs := []*qbft.SignedMessage{
testingutils.TestingProposalMessageWithIdentifierAndFullData(
ks.Shares[1], types.OperatorID(1), []byte{1, 2, 3, 4}, testingutils.TestingInvalidValueCheck),
}

// TODO: implement passing invalid value

//pre := testingutils.BaseInstance()
//ks := testingutils.Testing4SharesSet()
//msgs := []*qbft.SignedMessage{
// testingutils.SignQBFTMsg(ks.Shares[1], types.OperatorID(1), &qbft.Message{
// MsgType: qbft.ProposalMsgType,
// Height: qbft.FirstHeight,
// Round: qbft.FirstRound,
// Identifier: []byte{1, 2, 3, 4},
// Root: testingutils.ProposalDataBytes(testingutils.TestingInvalidValueCheck, nil, nil),
// }),
//}
//return &tests.MsgProcessingSpecTest{
// Name: "invalid proposal value check",
// Pre: pre,
// PostRoot: "5b18ca0b470208d8d247543306850618f02bddcbaa7c37eb6d5b36eb3accb5fb",
// InputMessages: msgs,
// OutputMessages: []*qbft.SignedMessage{},
// ExpectedError: "invalid signed message: proposal not justified: proposal value invalid: invalid value",
//}
return &tests.MsgProcessingSpecTest{
Name: "invalid proposal value check",
Pre: pre,
PostRoot: "5b18ca0b470208d8d247543306850618f02bddcbaa7c37eb6d5b36eb3accb5fb",
InputMessages: msgs,
OutputMessages: []*qbft.SignedMessage{},
ExpectedError: "invalid signed message: proposal not justified: proposal fullData invalid: invalid value",
}
}
2 changes: 1 addition & 1 deletion ssv/spectest/generate/tests.json

Large diffs are not rendered by default.

Loading

0 comments on commit 2023d3c

Please sign in to comment.