-
Notifications
You must be signed in to change notification settings - Fork 0
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
Audit #10
Open
dbrajovic
wants to merge
22
commits into
main
Choose a base branch
from
fix/audit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Audit #10
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3946687
fix issues A & B
dbrajovic c0850c6
fix issue D
dbrajovic b234c92
fix issue E
dbrajovic 3b098d3
fix issue H
dbrajovic 526d27c
fix issue C
dbrajovic d12d663
fix issue F
dbrajovic 0c13e5c
fix tests/linter
dbrajovic 7cc28e2
simplify makefile
dbrajovic 024d328
inline test handlers
dbrajovic fa90319
fix test to trigger appropriate check
dbrajovic 54b47ba
add type check in test handler
dbrajovic 5f6e542
change proto field to camel case
dbrajovic 310e6ad
use *proto.ProposedBlock as proposal
dbrajovic 5d46bbd
rename proto: ProposedBlock -> Proposal
dbrajovic 5c95b5b
remove redundant check
dbrajovic 1e0b261
log error from validateRoundChangeCertificate
dbrajovic be8c7bd
new line for linter
dbrajovic 9854b9a
linter
dbrajovic b0a09fa
bump Go version and linter
dbrajovic 23c964a
fix linter again
dbrajovic 078043a
lint me one more time
dbrajovic a03cc81
fix issue N
dbrajovic 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 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 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 |
---|---|---|
|
@@ -829,6 +829,124 @@ func TestRunNewRound_Validator_NonZero(t *testing.T) { | |
} | ||
} | ||
|
||
func TestRunNewRound_Round1_Accepts_Round0_Proposal(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ( | ||
log mockLogger | ||
backend mockBackend | ||
transport mockTransport | ||
msgs mockMessages | ||
|
||
notifyCh = make(chan uint64, 1) | ||
|
||
ctx context.Context | ||
|
||
round1ProposalMsg *proto.Message | ||
|
||
round0Proposer = []byte("round 0 proposer") | ||
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. This is the only value that is shared in the test (checked against the proposal), the rest (below) are only used to initialize fields. Please inline them where they are used |
||
round1Proposer = []byte("round 1 proposer") | ||
round0Proposal = []byte("round 0 proposal") | ||
round0ProposalHash = []byte("round 0 proposal hash") | ||
) | ||
|
||
ctx, cancelFn := context.WithCancel(context.Background()) | ||
|
||
// backend | ||
backend.isProposerFn = func(from []byte, _ uint64, round uint64) bool { | ||
switch round { | ||
case 0: | ||
return bytes.Equal(from, round0Proposer) | ||
case 1: | ||
return bytes.Equal(from, round1Proposer) | ||
} | ||
|
||
return false | ||
} | ||
|
||
// messages | ||
msgs.subscribeFn = func(_ messages.SubscriptionDetails) *messages.Subscription { | ||
return &messages.Subscription{ | ||
SubCh: notifyCh, | ||
} | ||
} | ||
|
||
msgs.getValidMessagesFn = func(_ *proto.View, _ proto.MessageType, isValid func(message *proto.Message) bool) []*proto.Message { | ||
if !isValid(round1ProposalMsg) { | ||
return nil | ||
} | ||
|
||
return []*proto.Message{round1ProposalMsg} | ||
} | ||
|
||
msgs.unsubscribeFn = func(_ messages.SubscriptionID) { cancelFn() } | ||
|
||
round1ProposalMsg = &proto.Message{ | ||
View: &proto.View{Round: 1}, | ||
From: round1Proposer, | ||
Type: proto.MessageType_PREPREPARE, | ||
Payload: &proto.Message_PreprepareData{ | ||
PreprepareData: &proto.PrePrepareMessage{ | ||
Proposal: round0Proposal, | ||
ProposalHash: round0ProposalHash, | ||
Certificate: &proto.RoundChangeCertificate{ | ||
RoundChangeMessages: []*proto.Message{ | ||
{ | ||
View: &proto.View{Round: 0}, | ||
Type: proto.MessageType_ROUND_CHANGE, | ||
Payload: &proto.Message_RoundChangeData{ | ||
RoundChangeData: &proto.RoundChangeMessage{ | ||
LastPreparedProposedBlock: round0Proposal, | ||
LatestPreparedCertificate: &proto.PreparedCertificate{ | ||
ProposalMessage: &proto.Message{ | ||
View: &proto.View{Round: 0}, | ||
From: round0Proposer, | ||
Type: proto.MessageType_PREPREPARE, | ||
Payload: &proto.Message_PreprepareData{ | ||
PreprepareData: &proto.PrePrepareMessage{ | ||
Proposal: round0Proposal, | ||
ProposalHash: round0ProposalHash, | ||
}, | ||
}, | ||
}, | ||
PrepareMessages: []*proto.Message{ | ||
{ | ||
View: &proto.View{Round: 0}, | ||
From: []byte("some validator"), | ||
Type: proto.MessageType_PREPARE, | ||
Payload: &proto.Message_PrepareData{ | ||
PrepareData: &proto.PrepareMessage{ | ||
ProposalHash: round0ProposalHash, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}}, | ||
}}, | ||
} | ||
|
||
i := NewIBFT(log, backend, transport) | ||
i.messages = msgs | ||
i.state.setView(&proto.View{Round: 1}) | ||
|
||
// Make sure the notification is sent out | ||
notifyCh <- 1 | ||
|
||
i.wg.Add(1) | ||
i.startRound(ctx) | ||
i.wg.Wait() | ||
|
||
// Make sure the node moves to prepare state | ||
assert.Equal(t, prepare, i.state.name) | ||
|
||
// Make sure the accepted proposal is the one that was sent out | ||
assert.Equal(t, round0Proposal, i.state.getProposal()) | ||
} | ||
|
||
// TestRunPrepare checks that the node behaves correctly | ||
// in prepare state | ||
func TestRunPrepare(t *testing.T) { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not define the handlers here in-line?
It's much cleaner, and more in line with our other tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined
024d328