-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: standardized timestamp comparison #72
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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 |
---|---|---|
|
@@ -43,7 +43,7 @@ | |
} | ||
} | ||
|
||
contract BaseTest is Test, Helpers { | ||
// The target contract | ||
ForTest_PrivateERC20ResolutionModule public module; | ||
// A mock oracle | ||
|
@@ -51,6 +51,10 @@ | |
// A mock token | ||
IERC20 public token; | ||
|
||
uint256 public constant REVEALING_TIME_WINDOW = 40_000; | ||
uint256 public constant START_TIME = 100_000; | ||
uint256 public constant END_TIME = START_TIME + REVEALING_TIME_WINDOW; | ||
|
||
// Events | ||
event CommittingPhaseStarted(uint256 _startTime, bytes32 _disputeId); | ||
event VoteCommitted(address _voter, bytes32 _disputeId, bytes32 _commitment); | ||
|
@@ -95,7 +99,7 @@ | |
); | ||
module.commitVote(_request, _dispute, _commitment); | ||
|
||
vm.warp(140_001); | ||
vm.warp(END_TIME + 1); | ||
|
||
vm.mockCall( | ||
address(token), | ||
|
@@ -173,7 +177,7 @@ | |
votingToken: token, | ||
minVotesForQuorum: 1, | ||
committingTimeWindow: 40_000, | ||
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. would it make sense to use a constant for the committing window as well? 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. Added |
||
revealingTimeWindow: 40_000 | ||
revealingTimeWindow: REVEALING_TIME_WINDOW | ||
}) | ||
); | ||
|
||
|
@@ -183,7 +187,7 @@ | |
bytes32 _disputeId = _getId(mockDispute); | ||
|
||
// Store mock escalation data with startTime 100_000 | ||
module.forTest_setStartTime(_disputeId, 100_000); | ||
module.forTest_setStartTime(_disputeId, START_TIME); | ||
|
||
// Set timestamp for valid committingTimeWindow | ||
vm.warp(123_456); | ||
|
@@ -365,7 +369,7 @@ | |
* @notice Test that `commitVote` reverts if called outside of the committing time window. | ||
*/ | ||
function test_revertIfCommittingPhaseOver(uint256 _timestamp, bytes32 _commitment) public { | ||
_timestamp = bound(_timestamp, 140_000, type(uint96).max); | ||
_timestamp = bound(_timestamp, END_TIME, type(uint96).max); | ||
|
||
// Set mock request data | ||
mockRequest.resolutionModuleData = abi.encode( | ||
|
@@ -374,7 +378,7 @@ | |
votingToken: token, | ||
minVotesForQuorum: 1, | ||
committingTimeWindow: 40_000, | ||
revealingTimeWindow: 40_000 | ||
revealingTimeWindow: REVEALING_TIME_WINDOW | ||
}) | ||
); | ||
|
||
|
@@ -384,7 +388,7 @@ | |
bytes32 _disputeId = _getId(mockDispute); | ||
|
||
// Store mock escalation data with startTime 100_000 | ||
module.forTest_setStartTime(_disputeId, 100_000); | ||
module.forTest_setStartTime(_disputeId, START_TIME); | ||
|
||
// Warp to invalid timestamp for commitment | ||
vm.warp(_timestamp); | ||
|
@@ -414,7 +418,7 @@ | |
votingToken: token, | ||
minVotesForQuorum: 1, | ||
committingTimeWindow: 40_000, | ||
revealingTimeWindow: 40_000 | ||
revealingTimeWindow: REVEALING_TIME_WINDOW | ||
}) | ||
); | ||
|
||
|
@@ -427,7 +431,7 @@ | |
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.disputeCreatedAt, (_disputeId)), abi.encode(1)); | ||
|
||
// Store mock escalation data with startTime 100_000 | ||
module.forTest_setStartTime(_disputeId, 100_000); | ||
module.forTest_setStartTime(_disputeId, START_TIME); | ||
|
||
// Store commitment | ||
vm.prank(_voter); | ||
|
@@ -491,7 +495,7 @@ | |
* @notice Test that `revealVote` reverts if called outside the revealing time window. | ||
*/ | ||
function test_revertIfInvalidPhase(uint256 _numberOfVotes, bytes32 _salt, uint256 _timestamp) public { | ||
vm.assume(_timestamp >= 100_000 && (_timestamp <= 140_000 || _timestamp > 180_000)); | ||
vm.assume(_timestamp >= 100_000 && (_timestamp < END_TIME || _timestamp > 180_000)); | ||
|
||
// Set mock request data | ||
mockRequest.resolutionModuleData = abi.encode( | ||
|
@@ -500,7 +504,7 @@ | |
votingToken: token, | ||
minVotesForQuorum: 1, | ||
committingTimeWindow: 40_000, | ||
revealingTimeWindow: 40_000 | ||
revealingTimeWindow: REVEALING_TIME_WINDOW | ||
}) | ||
); | ||
|
||
|
@@ -511,12 +515,12 @@ | |
|
||
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.disputeCreatedAt, _disputeId), abi.encode(1)); | ||
|
||
module.forTest_setStartTime(_disputeId, 100_000); | ||
module.forTest_setStartTime(_disputeId, START_TIME); | ||
|
||
// Jump to timestamp | ||
vm.warp(_timestamp); | ||
|
||
if (_timestamp <= 140_000) { | ||
if (_timestamp < END_TIME) { | ||
// Check: does it revert if trying to reveal during the committing phase? | ||
vm.expectRevert(IPrivateERC20ResolutionModule.PrivateERC20ResolutionModule_OnGoingCommittingPhase.selector); | ||
module.revealVote(mockRequest, _dispute, _numberOfVotes, _salt); | ||
|
@@ -550,7 +554,7 @@ | |
votingToken: token, | ||
minVotesForQuorum: 1, | ||
committingTimeWindow: 40_000, | ||
revealingTimeWindow: 40_000 | ||
revealingTimeWindow: REVEALING_TIME_WINDOW | ||
}) | ||
); | ||
|
||
|
@@ -562,7 +566,7 @@ | |
// Mock and expect IOracle.disputeCreatedAt to be called | ||
_mockAndExpect(address(oracle), abi.encodeCall(IOracle.disputeCreatedAt, (_disputeId)), abi.encode(1)); | ||
|
||
module.forTest_setStartTime(_disputeId, 100_000); | ||
module.forTest_setStartTime(_disputeId, START_TIME); | ||
|
||
vm.warp(150_000); | ||
|
||
|
@@ -601,7 +605,7 @@ | |
votingToken: token, | ||
minVotesForQuorum: _minVotesForQuorum, | ||
committingTimeWindow: 40_000, | ||
revealingTimeWindow: 40_000 | ||
revealingTimeWindow: REVEALING_TIME_WINDOW | ||
}) | ||
); | ||
|
||
|
@@ -613,7 +617,7 @@ | |
mockDispute.responseId = _responseId; | ||
bytes32 _disputeId = _getId(mockDispute); | ||
|
||
module.forTest_setStartTime(_disputeId, 100_000); | ||
module.forTest_setStartTime(_disputeId, START_TIME); | ||
|
||
// Store escalation data with startTime 100_000 and votes 0 | ||
uint256 _votersAmount = 5; | ||
|
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.
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.
What do you think about forcing the use of
<
and inverting this comparison?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.
I decided to leave it like this to always have the timestamp in the left side of the comparison. I think it's easier to read like that
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.
Understandable.
I agree it's easier to read, but it also forces me to think properly.