-
Notifications
You must be signed in to change notification settings - Fork 130
Ibft Int Testing - Local Node is proposer #527
Conversation
import org.junit.Test; | ||
|
||
public class LocalNodeIsProposerTest { | ||
// These tests assume the basic function of the Ibft Round State Machine has been proven |
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.
Is there a reason this comment cannot be a class comment? (as it seems an appropriate level)
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.
Done.
|
||
@Before | ||
public void setup() { | ||
when(mockBlockCreationTime.millis()).thenReturn(blockTimeStamp * 1000); |
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.
blockTimeStamp * 1000
would be the 100 seconds ...what's the significance of that number?
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.
So - as the local node is the proposer, it will create a block, with the timestamp as reported by the Clock (which is mocked in these tests).
In order to validate packets, the timestamp in the created (and transmitted) block must known - thus the expectedBlock has 'blockTimestamp' in it - and the clock which will provide a timestamp to the UUT is set to the same time.
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.
Could use Clock.fixed to created a clock for testing
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.
Right, so it's just about covering the blocTimeStamp
to seconds ...because in that case you could useTimeUnit.MILLISECONDS.toSeconds(blocTimeStamp)
and loose the magic number :)
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.
Changed to clock.fixed, nicer than using Mocks if we don't need to.
assertPeersReceivedExactly(roles.getAllPeers(), expectedTxProposal); | ||
|
||
// NOTE: In these test roles.getProposer() will return NULL. | ||
roles.getNonProposingPeers().get(0).injectPrepare(roundId, expectedProposedBlock.getHash()); |
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.
nit; for a readability gain, if you changed the signature of getNonProposingPeers()
to accept an integer then getNonProposingPeers().get(0)
could become getNonProposingPeer(0)
.
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.
yup - much nicer solution.
|
||
@Before | ||
public void setup() { | ||
when(mockBlockCreationTime.millis()).thenReturn(blockTimeStamp * 1000); |
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.
Could use Clock.fixed to created a clock for testing
expectedTxProposal = | ||
localNodeMessageFactory.createSignedProposalPayload(roundId, expectedProposedBlock); | ||
|
||
final IbftExtraData extraData = |
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.
perhaps this could be moved into a common test util somewhere we are probably going to do this in many of the nodes. or perhaps just inside the createSignedCommitPayload using the proposedBlock as an arg to it?
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.
LGTM
PR description
Fixed Issue(s)