-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add mainnet forking test case (#4306)
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
- Loading branch information
1 parent
d22ac68
commit 7f551a3
Showing
25 changed files
with
172 additions
and
42 deletions.
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
53 changes: 53 additions & 0 deletions
53
...oundry/data-verification-mechanism/fork-tests/CommonDataVerificationMechanismForkTest.sol
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
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 CommonDataVerificationMechanismForkTest is CommonTestBase { | ||
VotingV2 voting; | ||
ExpandedIERC20 votingToken; | ||
|
||
bool shouldRunForkedTest; | ||
|
||
address registeredRequester; | ||
address governor; | ||
|
||
bytes32 identifier = bytes32("YES_OR_NO_QUERY"); | ||
bytes ancillaryData = bytes("Some data"); | ||
uint256 gatMeetingNumOfTokens = 6e24; | ||
uint256 requestTime = 420; | ||
|
||
function _commonSetup() public { | ||
uint256 chainId = block.chainid; | ||
shouldRunForkedTest = (chainId == 1 || chainId == 5); | ||
if (!shouldRunForkedTest) return; // Exit early if we are not executing forked tests. | ||
|
||
// 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; | ||
|
||
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())); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
packages/core/test/foundry/data-verification-mechanism/fork-tests/FakeLifeCycle.ft.sol
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import "./CommonDataVerificationMechanismForkTest.sol"; | ||
|
||
contract FakeLifeCycle is CommonDataVerificationMechanismForkTest { | ||
function setUp() public { | ||
_commonSetup(); | ||
} | ||
|
||
function test_CanEnqueueRequestAndVoteWithNewlyStakedTokens() public { | ||
if (!shouldRunForkedTest) 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)); | ||
uint256 stakedNumOfTokens = gatMeetingNumOfTokens; | ||
votingToken.mint(TestAddress.account1, stakedNumOfTokens); | ||
vm.startPrank(TestAddress.account1); | ||
votingToken.approve(address(voting), stakedNumOfTokens); | ||
uint256 stakeTime = voting.getCurrentTime(); | ||
voting.stake(stakedNumOfTokens); | ||
assert(voting.getVoterStakePostUpdate(TestAddress.account1) == stakedNumOfTokens); | ||
|
||
// Advance some time to ensure reward accrual works as expected. | ||
moveToNextRound(); | ||
voting.withdrawRewards(); // Check if the Staker claims rewards now they get the expected amount. | ||
uint256 stakerBalanceAfterRewardWithdrawal = votingToken.balanceOf(TestAddress.account1); | ||
assert(voting.getVoterStakePostUpdate(TestAddress.account1) == stakedNumOfTokens); | ||
|
||
uint256 rewardsPerToken = | ||
((voting.getCurrentTime() - stakeTime) * voting.emissionRate() * 1e18) / voting.cumulativeStake(); | ||
uint256 expectedRewards = (rewardsPerToken * voting.getVoterStakePostUpdate(TestAddress.account1)) / 1e18; | ||
assertEq(stakerBalanceAfterRewardWithdrawal, expectedRewards); | ||
|
||
// Move to next round, request a price and vote on it from the newly staked account. | ||
moveToNextRound(); | ||
int256 price = 1e18; | ||
int256 salt = 42069; | ||
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); | ||
|
||
// Finally, considering we were the only voter, we should be able to work out the slashing amount precisely. | ||
uint256 totalStakedAtVote = voting.cumulativeStake(); // Has not changed from when we staked. | ||
uint256 slashPerTokenPerNoVote = | ||
voting.slashingLibrary().calcNoVoteSlashPerToken(totalStakedAtVote, stakedNumOfTokens, stakedNumOfTokens); | ||
uint256 totalSlashedTokens = ((totalStakedAtVote - stakedNumOfTokens) * slashPerTokenPerNoVote) / 1e18; | ||
uint256 expectedStakerBalanceAfterSlashing = stakedNumOfTokens + totalSlashedTokens; | ||
assertEq(voting.getVoterStakePostUpdate(TestAddress.account1), expectedStakerBalanceAfterSlashing); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/core/test/foundry/fixtures/common/CommonTestBase.sol
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 |
---|---|---|
@@ -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 {} |
5 changes: 2 additions & 3 deletions
5
...st/foundry/optimistic-asserter/Common.sol → ...asserter/CommonOptimisticAsserterTest.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/OptimisticAsserter.Callbacks.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/OptimisticAsserter.EdgeCases.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/OptimisticAsserter.Events.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/OptimisticAsserter.Lifecycle.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/OptimisticAsserter.Maintenance.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/OptimisticAsserter.SsPolicy.t.sol
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
4 changes: 2 additions & 2 deletions
4
...lationManager/BaseEscalationManager.t.sol → ...ation-manager/BaseEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
...er/DisputeLimitingEscalationManager.t.sol → ...er/DisputeLimitingEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
...Manager/FullPolicyEscalationManager.t.sol → ...manager/FullPolicyEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
...OwnerDiscardOracleEscalationManager.t.sol → ...OwnerDiscardOracleEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
.../OwnerSelectOracleEscalationManager.t.sol → .../OwnerSelectOracleEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
...nManager/SuperbondEscalationManager.t.sol → ...-manager/SuperbondEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
.../WhitelistAsserterEscalationManager.t.sol → .../WhitelistAsserterEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
...er/WhitelistCallerEscalationManager.t.sol → ...er/WhitelistCallerEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
.../WhitelistDisputerEscalationManager.t.sol → .../WhitelistDisputerEscalationManager.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/examples/DataAsserter.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/examples/Insurance.t.sol
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
4 changes: 2 additions & 2 deletions
4
packages/core/test/foundry/optimistic-asserter/examples/PredictionMarket.Common.sol
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
Oops, something went wrong.