-
Notifications
You must be signed in to change notification settings - Fork 214
Add nil-element validation to flow data models #8668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhangchiqing
wants to merge
3
commits into
leo/fix-new-payload-nil-element-validation
from
leo/fix-nil-element-validation
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,18 +118,45 @@ func TestBlock_Status(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // blockWithLastViewTC returns a FullBlockFixture that is guaranteed to have a non-nil LastViewTC. | ||
| // HeaderBodyWithParentFixture omits LastViewTC when view == parent.View+1 (1-in-10 chance). | ||
| // NewHeaderBody now validates LastViewTC via NewTimeoutCertificate, so mutating a nil TC to a | ||
| // zero-value struct would cause hashModel() to panic in the malleability checker. | ||
| func blockWithLastViewTC() *flow.Block { | ||
| const maxAttempts = 1000 | ||
| for i := 0; i < maxAttempts; i++ { | ||
| if b := unittest.FullBlockFixture(); b.LastViewTC != nil { | ||
| return b | ||
| } | ||
| } | ||
| panic("failed to generate FullBlockFixture with non-nil LastViewTC") | ||
| } | ||
|
|
||
| // TestBlockMalleability checks that flow.Block is not malleable: any change in its data | ||
| // should result in a different ID. | ||
| // Because our NewHeaderBody constructor enforces ParentView < View we use | ||
| // WithFieldGenerator to safely pass it. | ||
| // NewHeaderBody enforces ParentView < View and validates LastViewTC via NewTimeoutCertificate, | ||
| // so WithFieldGenerator is used for both to keep those constraints intact. | ||
| func TestBlockMalleability(t *testing.T) { | ||
| block := unittest.FullBlockFixture() | ||
| block := blockWithLastViewTC() | ||
| unittest.RequireEntityNonMalleable( | ||
| t, | ||
| unittest.FullBlockFixture(), | ||
| block, | ||
| unittest.WithFieldGenerator("HeaderBody.ParentView", func() uint64 { | ||
| return block.View - 1 // ParentView must stay below View, so set it to View-1 | ||
|
Comment on lines
141
to
145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in commit |
||
| }), | ||
| // The field generator for LastViewTC must return the struct value (not a pointer): | ||
| // isModelMalleable dereferences *TimeoutCertificate before invoking the generator, | ||
| // so modelOrField is flow.TimeoutCertificate at that point. | ||
| unittest.WithFieldGenerator("HeaderBody.LastViewTC", func() flow.TimeoutCertificate { | ||
| qc := unittest.QuorumCertificateFixture() | ||
| return flow.TimeoutCertificate{ | ||
| View: qc.View + 1, | ||
| NewestQCViews: []uint64{qc.View}, | ||
| NewestQC: qc, | ||
| SignerIndices: unittest.SignerIndicesFixture(4), | ||
| SigData: unittest.SignatureFixture(), | ||
| } | ||
| }), | ||
| unittest.WithFieldGenerator("Payload.Results", func() flow.ExecutionResultList { | ||
| return flow.ExecutionResultList{unittest.ExecutionResultFixture()} | ||
| }), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.