-
Notifications
You must be signed in to change notification settings - Fork 8
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
Improve FlexVotingClient test structure #71
base: master
Are you sure you want to change the base?
Conversation
@@ -196,8 +440,12 @@ contract Deposit is FlexVotingClientTest { | |||
} | |||
} | |||
|
|||
contract Vote is FlexVotingClientTest { | |||
function testFuzz_UserCanCastVotes(address _user, uint208 _voteWeight, uint8 _supportType) public { | |||
contract ExpressVote is FlexVotingClientTest { |
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.
Probably worth adding a test that tries to express votes on a bogus proposalId
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.
Looking really great @davidlaprade, huge improvement! Left some thoughts, but it's mostly marginal stuff.
test/FlexVotingClient.t.sol
Outdated
|
||
// Contract name has a leading underscore for scopelint spec support. | ||
contract _RawBalanceOf is FlexVotingClientTest { | ||
function _commonUserAssumptions(address _user) internal view { |
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: in other projects we tend to use a naming convention that states this actively, i.e. like _assumeSafeUser
in this case.
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 like that better, thanks. Done in 4fb9abc
uint208 _amount | ||
) public { | ||
vm.assume(_depositor != address(flexClient)); | ||
vm.assume(_nonDepositor != address(flexClient)); |
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'm surprised we're not getting test failures here, because I think we would need an assumption that _depositor != _nonDepositor
. That makes me wonder if something is not right with the test, and it's passing for the wrong reason?
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.
Great catch. You were right. Fixed in 34e4c2c
test/FlexVotingClient.t.sol
Outdated
uint48 _blockNum | ||
) public { | ||
vm.assume(_user != address(flexClient)); | ||
vm.assume(_blockNum > 2); |
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.
For numeric values, we should use bound rather than assume, for performance reasons. Also, it might be better to use block.number
here instead of assuming the current block number is less than 2. We could end up changing setUp
to roll the block number, for some reason, or the tests could end up running in a different context in the future (such as a fork test from a network).
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.
Doh 🤦. Done 4d6d8b2
flexClient.exposed_setDeposits(_user, _amount); | ||
assertEq(flexClient.getPastRawBalance(_user, _blockNum), 0); | ||
|
||
vm.roll(_blockNum); |
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.
It would be best to do vm.roll(block.number + _blockNum)
here, or alternatively, we can bound the _blockNum
value to something above block.number
in the first place, as suggested above.
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.
Taken care of in 4d6d8b2
test/FlexVotingClient.t.sol
Outdated
function testFuzz_SubmitsVotesToGovernor(address _user, uint208 _voteWeight, uint8 _supportType) | ||
public | ||
{ | ||
_voteWeight = _commonFuzzerAssumptions(_user, _voteWeight, _supportType); |
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.
We should refactor this test helper for a couple reasons, but I will pull that into its own issue since it's not part of what this PR is changing.
Coverage after merging improve-flex-client-test-structure-#69 into master will be
|
Fixes #69
This PR restructures the FlexClient tests to accord with
scopelint spec
. Some tests were renamed. Other tests were added. The resulting spec is: