-
Notifications
You must be signed in to change notification settings - Fork 183
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: Add mainnet forking test case #4306
Changes from 7 commits
5a30c84
e57e1de
550452b
3bc4ba4
04d50db
93df314
2436447
10aed71
7eb6a36
c821b07
e5616ab
b6e51ec
9fcb870
4e3eac0
1e05945
29f9fef
1b02ab4
c6ba478
fe911cd
be2cade
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import "../../fixtures/common/CommonTestBase.sol"; | ||
|
||
import "../../../../contracts/data-verification-mechanism/implementation/VotingV2.sol"; | ||
import "../../../../contracts/data-verification-mechanism/interfaces/VotingAncillaryInterface.sol"; | ||
import "../../../../contracts/common/interfaces/ExpandedIERC20.sol"; | ||
|
||
contract CommonDataVerificationMechanismTest is CommonTestBase { | ||
VotingV2 voting; | ||
ExpandedIERC20 votingToken; | ||
|
||
bool shouldRunTest; | ||
|
||
address registeredRequester; | ||
address governor; | ||
|
||
bytes32 identifier = bytes32("YES_OR_NO_QUERY"); | ||
bytes ancillaryData = bytes("Some data"); | ||
uint256 gatMeetingAmountOfTokens = 6e24; | ||
uint256 requestTime = 420; | ||
|
||
function _commonSetup() public { | ||
uint256 chainId = block.chainid; | ||
shouldRunTest = (chainId == 1 || chainId == 5); | ||
if (!shouldRunTest) return; // Exit early if we are not executing forked tests. | ||
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. nit: Is this meant to house any DVM tests? Or just specifically forked ones? I noticed that shouldRunTest is based on whether we're on a fork, but everything else in here seems general. Thoughts on renaming this variable to shouldRunForkTests? 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. nope, this is meant to house only |
||
|
||
// TODO: look into a way to not have to hard code these addresses. Ok for now as we wont be changing them. | ||
address votingAddress = chainId == 1 ? address(0) : 0xF71cdF8A34c56933A8871354A2570a301364e95F; | ||
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. Assuming there's also a TODO here for replacing this address(0) with the real deployment address? |
||
|
||
voting = VotingV2(votingAddress); | ||
|
||
registeredRequester = chainId == 1 | ||
? 0xA0Ae6609447e57a42c51B50EAe921D701823FFAe | ||
: 0xA5B9d8a0B0Fa04Ba71BDD68069661ED5C0848884; | ||
|
||
governor = chainId == 1 | ||
? 0x592349F7DeDB2b75f9d4F194d4b7C16D82E507Dc | ||
: 0xFf0E348389400d7D7510a230361Fc00904429e48; | ||
|
||
votingToken = voting.votingToken(); | ||
} | ||
|
||
function moveToNextPhase() public { | ||
(uint256 phaseLength, ) = voting.voteTiming(); | ||
vm.warp(voting.getRoundEndTime(voting.getCurrentRoundId()) - phaseLength); | ||
} | ||
|
||
function moveToNextRound() public { | ||
vm.warp(voting.getRoundEndTime(voting.getCurrentRoundId())); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import "./CommonDataVerificationMechanismTest.sol"; | ||
|
||
contract FakeLifeCycle is CommonDataVerificationMechanismTest { | ||
function setUp() public { | ||
_commonSetup(); | ||
} | ||
|
||
function test_CanEnqueueRequestAndVoteWithNewlyStakedTokens() public { | ||
if (!shouldRunTest) return; // Exit early if we are not executing forked tests. | ||
|
||
// Submit a new request and show it increments. | ||
// Ensure we are at the start of a voting round so we can stake and vote without the stake being disabled. | ||
if (voting.getVotePhase() == VotingV2Interface.Phase.Reveal) moveToNextRound(); | ||
|
||
uint256 numberRequestsPreRequest = voting.getNumberOfPriceRequests(); | ||
vm.prank(registeredRequester); | ||
voting.requestPrice(identifier, requestTime, ancillaryData); | ||
assert(voting.getNumberOfPriceRequests() == numberRequestsPreRequest + 1); | ||
|
||
// Mint fresh UMA and stake them. | ||
vm.prank(address(voting)); | ||
votingToken.mint(TestAddress.account1, gatMeetingAmountOfTokens); | ||
|
||
vm.startPrank(TestAddress.account1); | ||
votingToken.approve(address(voting), gatMeetingAmountOfTokens); | ||
voting.stake(gatMeetingAmountOfTokens); | ||
assert(voting.getVoterStakePostUpdate(TestAddress.account1) == gatMeetingAmountOfTokens); | ||
|
||
// Move to next round and vote from the newly staked account. | ||
moveToNextRound(); | ||
int256 price = 1e18; | ||
int256 salt = 42069; | ||
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. Can't believe this number popped out of your local rng +1 |
||
uint256 roundId = voting.getCurrentRoundId(); | ||
address account = TestAddress.account1; | ||
bytes32 hash = | ||
keccak256(abi.encodePacked(price, salt, account, requestTime, ancillaryData, roundId, identifier)); | ||
voting.commitVote(identifier, requestTime, ancillaryData, hash); | ||
moveToNextPhase(); | ||
voting.revealVote(identifier, requestTime, price, ancillaryData, salt); | ||
|
||
// Check the price has resolved correctly. | ||
moveToNextRound(); | ||
vm.stopPrank(); | ||
vm.prank(registeredRequester); | ||
assertEq(voting.getPrice(identifier, requestTime, ancillaryData), price); | ||
|
||
// Can unstake and has more than started with due to rewards and positive slashing. | ||
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 depends on having other accounts having staked on fork time. If its 0 (e.g. shortly after deployment) then this test might fail as there are no positive slashing if 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. Also note that the test does not withdraw rewards, so any balance increase is only due to positive slashing. 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. Just for the sake of robustness could add a 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. we'll only ever run this against a deployment that has been setup and is actually being used I'd say. so worrying about there being no other stakers is less of an issue. I do agree, though, that the test should separately validate that you can: 1) get rewards (calling the claim reward function) and 2) withdraw from unstake. |
||
vm.startPrank(TestAddress.account1); | ||
voting.requestUnstake(voting.getVoterStakePostUpdate(TestAddress.account1)); | ||
vm.warp(voting.getCurrentTime() + voting.unstakeCoolDown()); | ||
voting.executeUnstake(); | ||
assert(votingToken.balanceOf(TestAddress.account1) > gatMeetingAmountOfTokens); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import "./TestAddress.sol"; | ||
|
||
contract CommonTestBase is Test {} |
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.
tiny nit: doesn't this disagree with our repo license?