Skip to content
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

Merged
merged 20 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: UNLICENSED
Copy link
Member

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?

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.
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, this is meant to house only fork-tests, as it is located in this directory. agreed though that the variable name is not as explicit as it should be. I'll update it.


// 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;
Copy link
Member

Choose a reason for hiding this comment

The 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;
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 TestAddress.account1 is the sole staker.

Copy link
Contributor

@Reinis-FRP Reinis-FRP Dec 14, 2022

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the sake of robustness could add a TestAddress.account2 as staker not participating in vote so that there always is positive slashing for TestAddress.account1

Copy link
Member Author

Choose a reason for hiding this comment

The 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 {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "../fixtures/common/CommonTestBase.sol";
import "../fixtures/optimistic-asserter/OptimisticAsserterFixture.sol";
import "../fixtures/common/TestAddress.sol";
import "../../../contracts/data-verification-mechanism/test/MockOracleAncillary.sol";

contract Common is Test {
contract CommonOptimisticAsserterTest is CommonTestBase {
// Data structures, that might be used in tests.
struct OracleRequest {
bytes32 identifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./Common.sol";
import "./CommonOptimisticAsserterTest.sol";

contract OptimisticAsserterCallbacks is Common {
contract OptimisticAsserterCallbacks is CommonOptimisticAsserterTest {
function setUp() public {
_commonSetup();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./Common.sol";
import "./CommonOptimisticAsserterTest.sol";

contract InvalidParameters is Common {
contract InvalidParameters is CommonOptimisticAsserterTest {
function setUp() public {
_commonSetup();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./Common.sol";
import "./CommonOptimisticAsserterTest.sol";

contract OptimisticAsserterEvents is Common {
contract OptimisticAsserterEvents is CommonOptimisticAsserterTest {
event AdminPropertiesSet(IERC20 defaultCurrency, uint64 defaultLiveness, uint256 burnedBondPercentage);

function setUp() public {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./Common.sol";
import "./CommonOptimisticAsserterTest.sol";

contract SimpleAssertionsWithClaimOnly is Common {
contract SimpleAssertionsWithClaimOnly is CommonOptimisticAsserterTest {
function setUp() public {
_commonSetup();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./Common.sol";
import "./CommonOptimisticAsserterTest.sol";
import "../../../contracts/data-verification-mechanism/implementation/Store.sol";

contract MaintenanceTest is Common {
contract MaintenanceTest is CommonOptimisticAsserterTest {
function setUp() public {
_commonSetup();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./Common.sol";
import "./CommonOptimisticAsserterTest.sol";

contract EscalationManagerPolicyEnforced is Common {
contract EscalationManagerPolicyEnforced is CommonOptimisticAsserterTest {
function setUp() public {
_commonSetup();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/BaseEscalationManager.sol";

contract BaseEscalationManagerTest is Common {
contract BaseEscalationManagerTest is CommonOptimisticAsserterTest {
BaseEscalationManager escalationManager;

bytes32 identifier = "test";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/DisputeLimitingEscalationManager.sol";

contract DisputeLimitingEscalationManagerTest is Common {
contract DisputeLimitingEscalationManagerTest is CommonOptimisticAsserterTest {
DisputeLimitingEscalationManager escalationManager;

bytes32 assertionId = "test";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/FullPolicyEscalationManager.sol";

contract FullPolicyEscalationManagerTest is Common {
contract FullPolicyEscalationManagerTest is CommonOptimisticAsserterTest {
FullPolicyEscalationManager escalationManager;
bytes32 assertionId = bytes32(0);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/OwnerDiscardOracleEscalationManager.sol";

contract OwnerDiscardOracleEscalationManagerTest is Common {
contract OwnerDiscardOracleEscalationManagerTest is CommonOptimisticAsserterTest {
OwnerDiscardOracleEscalationManager escalationManager;

function setUp() public {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/OwnerSelectOracleEscalationManager.sol";

contract OwnerSelectOracleEscalationManagerTest is Common {
contract OwnerSelectOracleEscalationManagerTest is CommonOptimisticAsserterTest {
OwnerSelectOracleEscalationManager escalationManager;

function setUp() public {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/SuperbondEscalationManager.sol";

contract SuperbondEscalationManagerTest is Common {
contract SuperbondEscalationManagerTest is CommonOptimisticAsserterTest {
SuperbondEscalationManager escalationManager;
uint256 superbond = 100e18;
uint256 bond = 50e18;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/WhitelistAsserterEscalationManager.sol";

contract WhitelistAsserterEscalationManagerTest is Common {
contract WhitelistAsserterEscalationManagerTest is CommonOptimisticAsserterTest {
WhitelistAsserterEscalationManager escalationManager;

bytes32 assertionId = "test";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/WhitelistCallerEscalationManager.sol";

contract WhitelistCallerEscalationManagerTest is Common {
contract WhitelistCallerEscalationManagerTest is CommonOptimisticAsserterTest {
WhitelistCallerEscalationManager escalationManager;

function setUp() public {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/escalation-manager/WhitelistDisputerEscalationManager.sol";

contract WhitelistDisputerEscalationManagerTest is Common {
contract WhitelistDisputerEscalationManagerTest is CommonOptimisticAsserterTest {
WhitelistDisputerEscalationManager escalationManager;

function setUp() public {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/examples/DataAsserter.sol";

contract DataAsserterTest is Common {
contract DataAsserterTest is CommonOptimisticAsserterTest {
DataAsserter public dataAsserter;
bytes32 dataId = bytes32("dataId");
bytes32 correctData = bytes32("correctData");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/examples/Insurance.sol";

contract InsuranceTest is Common {
contract InsuranceTest is CommonOptimisticAsserterTest {
Insurance public insurance;
bytes insuredEvent = bytes("insuredEvent");
uint256 insuranceAmount = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../Common.sol";
import "../CommonOptimisticAsserterTest.sol";
import "../../../../contracts/optimistic-asserter/implementation/examples/PredictionMarket.sol";

contract PredictionMarketTestCommon is Common {
contract PredictionMarketTestCommon is CommonOptimisticAsserterTest {
PredictionMarket public predictionMarket;
string outcome1 = "Red";
string outcome2 = "Blue";
Expand Down