From debb501352ecc7fa3e689409cad9ea1d3ecec9f6 Mon Sep 17 00:00:00 2001 From: josojo Date: Tue, 6 Feb 2024 08:23:09 +0100 Subject: [PATCH] better interface for delay information (#209) --- .../MinimalAdjudicationFramework.sol | 41 +------ .../IMinimalAdjudicationFramework.sol | 49 ++++++++ .../IMinimalAdjudicationFrameworkErrors.sol | 24 ++++ contracts/L2ForkArbitrator.sol | 44 ++----- contracts/interfaces/IL2ForkArbitrator.sol | 27 ++--- .../AdjudicationFrameworkMinimal.t.sol | 14 +-- .../AdjudicationFrameworkRequests.t.sol | 104 ++++++++++++++-- test/L2ForkArbitrator.t.sol | 114 ++++++++---------- 8 files changed, 253 insertions(+), 164 deletions(-) create mode 100644 contracts/AdjudicationFramework/interface/IMinimalAdjudicationFramework.sol create mode 100644 contracts/AdjudicationFramework/interface/IMinimalAdjudicationFrameworkErrors.sol diff --git a/contracts/AdjudicationFramework/MinimalAdjudicationFramework.sol b/contracts/AdjudicationFramework/MinimalAdjudicationFramework.sol index 49098896..831acc52 100644 --- a/contracts/AdjudicationFramework/MinimalAdjudicationFramework.sol +++ b/contracts/AdjudicationFramework/MinimalAdjudicationFramework.sol @@ -8,7 +8,7 @@ pragma solidity ^0.8.20; import {IRealityETH} from "./../lib/reality-eth/interfaces/IRealityETH.sol"; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; -import {IL2ForkArbitrator} from "../interfaces/IL2ForkArbitrator.sol"; +import {IMinimalAdjudicationFramework} from "./interface/IMinimalAdjudicationFramework.sol"; /* Minimal Adjudication framework every framework should implement. Contains an enumerableSet of Arbitrators. @@ -16,26 +16,8 @@ Arbitrators can be removed or added by providing a realityETH question with fork Also, arbitrators who are challenged by a removal question, can be temporarily frozen, if a sufficient bond is provided. */ -contract MinimalAdjudicationFramework { +contract MinimalAdjudicationFramework is IMinimalAdjudicationFramework { using EnumerableSet for EnumerableSet.AddressSet; - /// @dev Error thrown with illegal modification of arbitrators - error NoArbitratorsToModify(); - /// @dev Error thrown when a proposition already exists - error PropositionAlreadyExists(); - /// @dev Error thrown when a proposition is not found - error PropositionNotFound(); - /// @dev Error thrown when a proposition is not found - error ArbitratorNotInAllowList(); - /// @dev Error thrown when an arbitrator is already frozen - error ArbitratorAlreadyFrozen(); - /// @dev Error thrown when received messages from realityEth is not yes - error AnswerNotYes(); - /// @dev Error thrown when received messages from realityEth is yes, but expected to be no - error PropositionNotFailed(); - /// @dev Error thrown when bond is too low to freeze an arbitrator - error BondTooLowToFreeze(); - /// @dev Error thrown when proposition is not accepted - error PropositionNotAccepted(); // Question delimiter for arbitrator modification questions for reality.eth string internal constant _QUESTION_DELIM = "\u241f"; @@ -64,12 +46,6 @@ contract MinimalAdjudicationFramework { // Contract used for requesting a fork in the L1 chain in remove propositions address public forkArbitrator; - // Reality.eth questions for propositions we may be asked to rule on - struct ArbitratorProposition { - address arbitratorToRemove; - address arbitratorToAdd; - bool isFrozen; - } mapping(bytes32 => ArbitratorProposition) public propositions; // Keep a count of active propositions that freeze an arbitrator. @@ -176,15 +152,6 @@ contract MinimalAdjudicationFramework { 0, REALITY_ETH_BOND_ARBITRATOR_REMOVE ); - IL2ForkArbitrator(forkArbitrator).storeInformation( - templateId, - uint32(block.timestamp), - question, - REALITY_ETH_TIMEOUT, - REALITY_ETH_BOND_ARBITRATOR_REMOVE, - 0, - forkActivationDelay - ); if ( propositions[questionId].arbitratorToAdd != address(0) || propositions[questionId].arbitratorToRemove != address(0) @@ -314,4 +281,8 @@ contract MinimalAdjudicationFramework { ) external view returns (bool) { return propositions[questionId].isFrozen; } + + function getInvestigationDelay() external view returns (uint256) { + return forkActivationDelay; + } } diff --git a/contracts/AdjudicationFramework/interface/IMinimalAdjudicationFramework.sol b/contracts/AdjudicationFramework/interface/IMinimalAdjudicationFramework.sol new file mode 100644 index 00000000..f727ad7e --- /dev/null +++ b/contracts/AdjudicationFramework/interface/IMinimalAdjudicationFramework.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-3.0-only + +pragma solidity ^0.8.20; + +/* solhint-disable quotes */ +/* solhint-disable not-rely-on-time */ + +import {IMinimalAdjudicationFrameworkErrors} from "./IMinimalAdjudicationFrameworkErrors.sol"; + +interface IMinimalAdjudicationFramework is IMinimalAdjudicationFrameworkErrors { + // Reality.eth questions for propositions we may be asked to rule on + struct ArbitratorProposition { + address arbitratorToRemove; + address arbitratorToAdd; + bool isFrozen; + } + + function requestModificationOfArbitrators( + address arbitratorToRemove, + address arbitratorToAdd + ) external returns (bytes32); + + function executeModificationArbitratorFromAllowList( + bytes32 questionId + ) external; + + // When an arbitrator is listed for removal, they can be frozen given a sufficient bond + function freezeArbitrator( + bytes32 questionId, + bytes32[] memory historyHashes, + address[] memory addrs, + uint256[] memory bonds, + bytes32[] memory answers + ) external; + + function clearFailedProposition(bytes32 questionId) external; + + // Getter functions only below here + + function realitio() external view returns (address); + + function isArbitrator(address arbitrator) external view returns (bool); + + function isArbitratorPropositionFrozen( + bytes32 questionId + ) external view returns (bool); + + function getInvestigationDelay() external view returns (uint256); +} diff --git a/contracts/AdjudicationFramework/interface/IMinimalAdjudicationFrameworkErrors.sol b/contracts/AdjudicationFramework/interface/IMinimalAdjudicationFrameworkErrors.sol new file mode 100644 index 00000000..1d6c2910 --- /dev/null +++ b/contracts/AdjudicationFramework/interface/IMinimalAdjudicationFrameworkErrors.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-3.0-only + +pragma solidity ^0.8.20; + +interface IMinimalAdjudicationFrameworkErrors { + /// @dev Error thrown with illegal modification of arbitrators + error NoArbitratorsToModify(); + /// @dev Error thrown when a proposition already exists + error PropositionAlreadyExists(); + /// @dev Error thrown when a proposition is not found + error PropositionNotFound(); + /// @dev Error thrown when a proposition is not found + error ArbitratorNotInAllowList(); + /// @dev Error thrown when an arbitrator is already frozen + error ArbitratorAlreadyFrozen(); + /// @dev Error thrown when received messages from realityEth is not yes + error AnswerNotYes(); + /// @dev Error thrown when received messages from realityEth is yes, but expected to be no + error PropositionNotFailed(); + /// @dev Error thrown when bond is too low to freeze an arbitrator + error BondTooLowToFreeze(); + /// @dev Error thrown when proposition is not accepted + error PropositionNotAccepted(); +} diff --git a/contracts/L2ForkArbitrator.sol b/contracts/L2ForkArbitrator.sol index ee182019..7a1f90a7 100644 --- a/contracts/L2ForkArbitrator.sol +++ b/contracts/L2ForkArbitrator.sol @@ -11,6 +11,7 @@ import {CalculateMoneyBoxAddress} from "./lib/CalculateMoneyBoxAddress.sol"; import {IPolygonZkEVMBridge} from "@RealityETH/zkevm-contracts/contracts/interfaces/IPolygonZkEVMBridge.sol"; import {IL2ForkArbitrator} from "./interfaces/IL2ForkArbitrator.sol"; +import {IMinimalAdjudicationFramework} from "./AdjudicationFramework/interface/IMinimalAdjudicationFramework.sol"; /* This contract is the arbitrator used by governance propositions for AdjudicationFramework contracts. It charges a dispute fee of 5% of total supply [TODO], which it forwards to L1 when requesting a fork. @@ -39,15 +40,6 @@ contract L2ForkArbitrator is IL2ForkArbitrator { uint256 timeOfRequest; } - enum ArbitrationStatus { - NONE, - SOME - } - struct ArbitrationData { - ArbitrationStatus status; - uint256 delay; // Delay in seconds before the fork is activated - } - event LogRequestArbitration( bytes32 indexed question_id, uint256 fee_paid, @@ -58,9 +50,6 @@ contract L2ForkArbitrator is IL2ForkArbitrator { // stores data on the arbitration process // questionId => ArbitrationRequest mapping(bytes32 => ArbitrationRequest) public arbitrationRequests; - // stores data on the arbitration itself - // questionId => ArbitrationData - mapping(bytes32 => ArbitrationData) public arbitrationData; mapping(address => uint256) public refundsDue; @@ -117,25 +106,21 @@ contract L2ForkArbitrator is IL2ForkArbitrator { maxPrevious ); emit LogRequestArbitration(questionId, msg.value, msg.sender, 0); - if ( - !isForkInProgress && - arbitrationData[questionId].delay == 0 && - arbitrationData[questionId].status == ArbitrationStatus.SOME - ) { - requestActivateFork(questionId); - } return true; } /// @inheritdoc IL2ForkArbitrator - function storeInformation( + // @note This function requires all the information from the original question, + // to verify the address of the adjudication framework that initially asked the question + // With the address of the adjudication framework, we can get the investigation delay + function requestActivateFork( uint256 templateId, uint32 openingTs, string calldata question, uint32 timeout, uint256 minBond, uint256 nonce, - uint256 delay + address adjudicationFramework ) public { bytes32 contentHash = keccak256( abi.encodePacked(templateId, openingTs, question) @@ -147,25 +132,18 @@ contract L2ForkArbitrator is IL2ForkArbitrator { timeout, minBond, address(realitio), - msg.sender, + adjudicationFramework, nonce ) ); - arbitrationData[question_id] = ArbitrationData( - ArbitrationStatus.SOME, - delay - ); - } + uint256 delay = IMinimalAdjudicationFramework(adjudicationFramework) + .getInvestigationDelay(); - /// @inheritdoc IL2ForkArbitrator - function requestActivateFork(bytes32 question_id) public { - if (arbitrationData[question_id].status == ArbitrationStatus.NONE) - revert ArbitrationDataNotSet(); if ( - arbitrationRequests[question_id].timeOfRequest + - arbitrationData[question_id].delay > + arbitrationRequests[question_id].timeOfRequest + delay > block.timestamp ) revert RequestStillInWaitingPeriod(); + if (isForkInProgress) { revert ForkInProgress(); // Forking over something else } diff --git a/contracts/interfaces/IL2ForkArbitrator.sol b/contracts/interfaces/IL2ForkArbitrator.sol index d072c26b..3ab303a0 100644 --- a/contracts/interfaces/IL2ForkArbitrator.sol +++ b/contracts/interfaces/IL2ForkArbitrator.sol @@ -62,30 +62,25 @@ interface IL2ForkArbitrator is IBridgeMessageReceiver { uint256 maxPrevious ) external payable returns (bool); - /// @notice If the fork request fails, we will get a message back through the bridge telling us about it - /// We will set FORK_REQUEST_FAILED which will allow anyone to request cancellation - /// @param templateId The templateId of the question - /// @param openingTs The opening timestamp of the question - /// @param question The question - /// @param timeout The timeout of the question - /// @param minBond The minimum bond of the question - /// @param nonce The nonce of the question - /// @param delay The delay for the L2 ForkArbitrator - function storeInformation( + /// @notice Request a fork via the bridge + /// @dev Talks to the L1 ForkingManager asynchronously, and may fail. + /// @param templateId The template id of the question during requestArbitration call + /// @param openingTs The opening timestamp of the question during requestArbitration call + /// @param question The question during requestArbitration call + /// @param timeout The timeout of the question during requestArbitration call + /// @param minBond The min bond of the question during requestArbitration call + /// @param nonce The nonce of the question during requestArbitration call + /// @param adjudicationFramework The address of the adjudication framework + function requestActivateFork( uint256 templateId, uint32 openingTs, string calldata question, uint32 timeout, uint256 minBond, uint256 nonce, - uint256 delay + address adjudicationFramework ) external; - /// @notice Request a fork via the bridge - /// @dev Talks to the L1 ForkingManager asynchronously, and may fail. - /// @param questionId The questionId in the question - function requestActivateFork(bytes32 questionId) external; - // If the fork request fails, we will get a message back through the bridge telling us about it // We will set FORK_REQUEST_FAILED which will allow anyone to request cancellation function onMessageReceived( diff --git a/test/AdjudicationFramework/AdjudicationFrameworkMinimal.t.sol b/test/AdjudicationFramework/AdjudicationFrameworkMinimal.t.sol index 9b6836e4..0aa19771 100644 --- a/test/AdjudicationFramework/AdjudicationFrameworkMinimal.t.sol +++ b/test/AdjudicationFramework/AdjudicationFrameworkMinimal.t.sol @@ -18,6 +18,7 @@ import {MinimalAdjudicationFramework} from "../../contracts/AdjudicationFramewor import {L2ForkArbitrator} from "../../contracts/L2ForkArbitrator.sol"; import {L1GlobalForkRequester} from "../../contracts/L1GlobalForkRequester.sol"; import {L2ChainInfo} from "../../contracts/L2ChainInfo.sol"; +import {IMinimalAdjudicationFrameworkErrors} from "../../contracts/AdjudicationFramework/interface/IMinimalAdjudicationFrameworkErrors.sol"; import {MockPolygonZkEVMBridge} from "../testcontract/MockPolygonZkEVMBridge.sol"; @@ -301,12 +302,9 @@ contract AdjudicationIntegrationTest is Test { true, delay ); - bytes32 questionIdAddMultiple = adjudicationFrameworkWithDelay - .requestModificationOfArbitrators(address(0), address(0x1000)); - (, uint256 storedDelay) = l2ForkArbitrator.arbitrationData( - questionIdAddMultiple - ); - assertEq(delay, storedDelay, "delay not stored correctly"); + uint256 receivedDelay = adjudicationFrameworkWithDelay + .getInvestigationDelay(); + assertEq(delay, receivedDelay, "delay not stored correctly"); } function testrequestModificationOfArbitrators() public { @@ -339,7 +337,7 @@ contract AdjudicationIntegrationTest is Test { // Scenario 4: Invalid case - No arbitrators to modify vm.expectRevert( - MinimalAdjudicationFramework.NoArbitratorsToModify.selector + IMinimalAdjudicationFrameworkErrors.NoArbitratorsToModify.selector ); adjudicationFramework1.requestModificationOfArbitrators( address(0), @@ -421,7 +419,7 @@ contract AdjudicationIntegrationTest is Test { // Clear failed proposition vm.expectRevert( - MinimalAdjudicationFramework.PropositionNotFailed.selector + IMinimalAdjudicationFrameworkErrors.PropositionNotFailed.selector ); adjudicationFramework1.clearFailedProposition(questionId); } diff --git a/test/AdjudicationFramework/AdjudicationFrameworkRequests.t.sol b/test/AdjudicationFramework/AdjudicationFrameworkRequests.t.sol index 0ba6cb6d..c661c09c 100644 --- a/test/AdjudicationFramework/AdjudicationFrameworkRequests.t.sol +++ b/test/AdjudicationFramework/AdjudicationFrameworkRequests.t.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.20; /* solhint-disable quotes */ import {Test} from "forge-std/Test.sol"; +import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {ForkableRealityETH_ERC20} from "../../contracts/ForkableRealityETH_ERC20.sol"; import {AdjudicationFrameworkRequests} from "../../contracts/AdjudicationFramework/Pull/AdjudicationFrameworkRequests.sol"; @@ -17,6 +18,7 @@ import {L2ChainInfo} from "../../contracts/L2ChainInfo.sol"; import {MockPolygonZkEVMBridge} from "../testcontract/MockPolygonZkEVMBridge.sol"; import {MinimalAdjudicationFramework} from "../../contracts/AdjudicationFramework/MinimalAdjudicationFramework.sol"; import {AdjudicationFrameworkRequests} from "../../contracts/AdjudicationFramework/Pull/AdjudicationFrameworkRequests.sol"; +import {IMinimalAdjudicationFrameworkErrors} from "../../contracts/AdjudicationFramework/interface/IMinimalAdjudicationFrameworkErrors.sol"; contract AdjudicationIntegrationTest is Test { Arbitrator public govArb; @@ -295,7 +297,8 @@ contract AdjudicationIntegrationTest is Test { bytes32 removalQuestionId, bytes32 lastHistoryHash, bytes32 lastAnswer, - address lastAnswerer + address lastAnswerer, + uint32 questionTimestamp ) { bytes32 qid = _setupContestableQuestion(); @@ -316,6 +319,8 @@ contract AdjudicationIntegrationTest is Test { ); // now before we can complete this somebody challenges it + uint256 questionTimestamp2 = block.timestamp + 1; + vm.warp(questionTimestamp2); removalQuestionId = adjudicationFramework1 .requestModificationOfArbitrators( address(l2Arbitrator1), @@ -333,7 +338,7 @@ contract AdjudicationIntegrationTest is Test { bytes32[] memory answers; vm.expectRevert( - MinimalAdjudicationFramework.BondTooLowToFreeze.selector + IMinimalAdjudicationFrameworkErrors.BondTooLowToFreeze.selector ); adjudicationFramework1.freezeArbitrator( removalQuestionId, @@ -379,13 +384,14 @@ contract AdjudicationIntegrationTest is Test { removalQuestionId, lastHistoryHash, bytes32(uint256(1)), - user2 + user2, + uint32(questionTimestamp2) ); } function testArbitrationContestPassedWithoutFork() public { // (bytes32 qid, bytes32 removalQuestionId, bytes32 lastHistoryHash, bytes32 lastAnswer, address lastAnswerer) = _setupContestedArbitration(); - (, bytes32 removalQuestionId, , , ) = _setupContestedArbitration(); + (, bytes32 removalQuestionId, , , , ) = _setupContestedArbitration(); // Currently in the "yes" state, so once it times out we can complete the removal @@ -407,7 +413,7 @@ contract AdjudicationIntegrationTest is Test { function testArbitrationContestRejectedWithoutFork() public { //(bytes32 qid, bytes32 removalQuestionId, bytes32 lastHistoryHash, bytes32 lastAnswer, address lastAnswerer) = _setupContestedArbitration(); - (, bytes32 removalQuestionId, , , ) = _setupContestedArbitration(); + (, bytes32 removalQuestionId, , , , ) = _setupContestedArbitration(); // Put the proposition to remove the arbitrator into the "no" state l2RealityEth.submitAnswer{value: 40000}( @@ -429,7 +435,7 @@ contract AdjudicationIntegrationTest is Test { skip(86401); vm.expectRevert( - MinimalAdjudicationFramework.PropositionNotAccepted.selector + IMinimalAdjudicationFrameworkErrors.PropositionNotAccepted.selector ); adjudicationFramework1.executeModificationArbitratorFromAllowList( removalQuestionId @@ -457,7 +463,8 @@ contract AdjudicationIntegrationTest is Test { bytes32 removalQuestionId, bytes32 lastHistoryHash, bytes32 lastAnswer, - address lastAnswerer + address lastAnswerer, + uint32 removalQuestionOpeningTimestamp ) = _setupContestedArbitration(); // Currently in the "yes" state, so once it times out we can complete the removal @@ -488,6 +495,29 @@ contract AdjudicationIntegrationTest is Test { 0 ); + vm.mockCall( + address(adjudicationFramework1), + abi.encodeWithSelector( + bytes4(keccak256("getInvestigationDelay()")) + ), + abi.encode(0) + ); + string memory question = Strings.toHexString(address(l2Arbitrator1)); + assertEq( + address(l2ForkArbitrator), + adjudicationFramework1.forkArbitrator(), + "ForkArbitrator is set" + ); + l2ForkArbitrator.requestActivateFork( + adjudicationFramework1.templateIdRemoveArbitrator(), + removalQuestionOpeningTimestamp, + question, + adjudicationFramework1.REALITY_ETH_TIMEOUT(), + adjudicationFramework1.REALITY_ETH_BOND_ARBITRATOR_REMOVE(), + 0, + address(adjudicationFramework1) + ); + // IMAGINE THE FORK HAPPENED HERE // There are now two L2s, each with a different chain ID uint256 newChainId1 = 123; @@ -552,7 +582,8 @@ contract AdjudicationIntegrationTest is Test { bytes32 removalQuestionId, bytes32 lastHistoryHash, bytes32 lastAnswer, - address lastAnswerer + address lastAnswerer, + uint32 removalQuestionOpeningTimestamp ) = _setupContestedArbitration(); // Currently in the "yes" state, so once it times out we can complete the removal @@ -583,6 +614,28 @@ contract AdjudicationIntegrationTest is Test { removalQuestionId, 0 ); + vm.mockCall( + address(adjudicationFramework1), + abi.encodeWithSelector( + bytes4(keccak256("getInvestigationDelay()")) + ), + abi.encode(0) + ); + string memory question = Strings.toHexString(address(l2Arbitrator1)); + assertEq( + address(l2ForkArbitrator), + adjudicationFramework1.forkArbitrator(), + "ForkArbitrator is set" + ); + l2ForkArbitrator.requestActivateFork( + adjudicationFramework1.templateIdRemoveArbitrator(), + removalQuestionOpeningTimestamp, + question, + adjudicationFramework1.REALITY_ETH_TIMEOUT(), + adjudicationFramework1.REALITY_ETH_BOND_ARBITRATOR_REMOVE(), + 0, + address(adjudicationFramework1) + ); // IMAGINE THE FORK HAPPENED HERE // There are now two L2s, each with a different chain ID @@ -626,7 +679,7 @@ contract AdjudicationIntegrationTest is Test { assertTrue(adjudicationFramework1.isArbitrator(address(l2Arbitrator1))); vm.expectRevert( - MinimalAdjudicationFramework.PropositionNotAccepted.selector + IMinimalAdjudicationFrameworkErrors.PropositionNotAccepted.selector ); adjudicationFramework1.executeModificationArbitratorFromAllowList( removalQuestionId @@ -644,7 +697,14 @@ contract AdjudicationIntegrationTest is Test { } function testArbitrationContestForkFailed() public { - (, bytes32 removalQuestionId, , , ) = _setupContestedArbitration(); + ( + , + bytes32 removalQuestionId, + , + , + , + uint32 removalQuestionOpeningTimestamp + ) = _setupContestedArbitration(); // Currently in the "yes" state, so once it times out we can complete the removal @@ -675,6 +735,28 @@ contract AdjudicationIntegrationTest is Test { removalQuestionId, 0 ); + vm.mockCall( + address(adjudicationFramework1), + abi.encodeWithSelector( + bytes4(keccak256("getInvestigationDelay()")) + ), + abi.encode(0) + ); + string memory question = Strings.toHexString(address(l2Arbitrator1)); + assertEq( + address(l2ForkArbitrator), + adjudicationFramework1.forkArbitrator(), + "ForkArbitrator is set" + ); + l2ForkArbitrator.requestActivateFork( + adjudicationFramework1.templateIdRemoveArbitrator(), + removalQuestionOpeningTimestamp, + question, + adjudicationFramework1.REALITY_ETH_TIMEOUT(), + adjudicationFramework1.REALITY_ETH_BOND_ARBITRATOR_REMOVE(), + 0, + address(adjudicationFramework1) + ); assertTrue(l2ForkArbitrator.isForkInProgress(), "In forking state"); @@ -701,7 +783,7 @@ contract AdjudicationIntegrationTest is Test { "Not in forking state" ); - assertEq(forkFee, l2ForkArbitrator.refundsDue(user2)); + assertEq(forkFee, l2ForkArbitrator.refundsDue(user2), "forkfee wrong"); uint256 user2Bal = user2.balance; vm.prank(user2); diff --git a/test/L2ForkArbitrator.t.sol b/test/L2ForkArbitrator.t.sol index e68cd1ce..a3adfde1 100644 --- a/test/L2ForkArbitrator.t.sol +++ b/test/L2ForkArbitrator.t.sol @@ -67,43 +67,6 @@ contract L2ForkArbitratorTest is Test { ); } - function testStoreInformation() public { - uint256 delay = 60 * 60; // 1 hour - uint256 templateId = 1; - string memory question = "TestQuestion"; - uint32 timeout = 300; - uint256 minBond = 1 ether; - uint32 openingTs = uint32(block.timestamp); - uint256 nonce = 1; - arbitrator.storeInformation( - templateId, - openingTs, - question, - timeout, - minBond, - nonce, - delay - ); - - bytes32 contentHash = keccak256( - abi.encodePacked(templateId, openingTs, question) - ); - bytes32 questionId = keccak256( - abi.encodePacked( - contentHash, - address(arbitrator), - timeout, - minBond, - address(realitio), - address(this), - nonce - ) - ); - - (, uint256 storedDelay) = arbitrator.arbitrationData(questionId); - assertEq(storedDelay, delay, "Stored delay is incorrect"); - } - function testRequestActivateFork() public { uint256 maxPrevious = 0; uint256 delay = 60 * 60; // 1 hour @@ -142,24 +105,24 @@ contract L2ForkArbitratorTest is Test { arbitrator.requestArbitration{value: 1 ether}(questionId, maxPrevious); // Attempt to activate fork - vm.expectRevert(IL2ForkArbitrator.ArbitrationDataNotSet.selector); - arbitrator.requestActivateFork(questionId); - - // setup the necessary conditions - arbitrator.storeInformation( + vm.mockCall( + address(this), + abi.encodeWithSelector( + bytes4(keccak256("getInvestigationDelay()")) + ), + abi.encode(delay) + ); + vm.expectRevert(IL2ForkArbitrator.RequestStillInWaitingPeriod.selector); + arbitrator.requestActivateFork( templateId, openingTs, question, 300, // timeout, minBond, nonce, - delay + address(this) ); - // Attempt to activate fork - vm.expectRevert(IL2ForkArbitrator.RequestStillInWaitingPeriod.selector); - arbitrator.requestActivateFork(questionId); - // Simulate passage of time vm.warp(block.timestamp + delay + 1); vm.mockCall( @@ -183,7 +146,15 @@ contract L2ForkArbitratorTest is Test { abi.encode(address(0x16542)) ); vm.deal(address(arbitrator), 1 ether); - arbitrator.requestActivateFork(questionId); + arbitrator.requestActivateFork( + templateId, + openingTs, + question, + 300, // timeout, + minBond, + nonce, + address(this) + ); } function testANewRequestDoesNotHaveToWaitAgain() public { @@ -223,17 +194,6 @@ contract L2ForkArbitratorTest is Test { vm.deal(address(this), 1 ether); arbitrator.requestArbitration{value: 1 ether}(questionId, maxPrevious); - // setup the necessary conditions - arbitrator.storeInformation( - templateId, - openingTs, - question, - 300, // timeout, - minBond, - nonce, - delay - ); - // Simulate passage of time vm.warp(block.timestamp + delay + 1); vm.mockCall( @@ -256,8 +216,23 @@ contract L2ForkArbitratorTest is Test { abi.encodeWithSelector(bytes4(keccak256("getForkonomicToken()"))), abi.encode(address(0x16542)) ); + vm.mockCall( + address(this), + abi.encodeWithSelector( + bytes4(keccak256("getInvestigationDelay()")) + ), + abi.encode(delay) + ); vm.deal(address(arbitrator), 1 ether); - arbitrator.requestActivateFork(questionId); + arbitrator.requestActivateFork( + templateId, + openingTs, + question, + 300, // timeout, + minBond, + nonce, + address(this) + ); // Simulate a cancellation vm.mockCall( @@ -273,6 +248,8 @@ contract L2ForkArbitratorTest is Test { ); vm.deal(address(this), 1 ether); + uint256 nextTimestamp = block.timestamp + 1; + vm.warp(nextTimestamp); arbitrator.requestArbitration{value: 1 ether}(questionId, maxPrevious); // now the requestArbitationFork can be called immediately, without waiting for the delay vm.mockCall( @@ -295,7 +272,22 @@ contract L2ForkArbitratorTest is Test { abi.encodeWithSelector(bytes4(keccak256("getForkonomicToken()"))), abi.encode(address(0x16542)) ); + vm.mockCall( + address(this), + abi.encodeWithSelector( + bytes4(keccak256("getInvestigationDelay()")) + ), + abi.encode(delay) + ); vm.deal(address(arbitrator), 1 ether); - arbitrator.requestActivateFork(questionId); + arbitrator.requestActivateFork( + templateId, + openingTs, + question, + 300, // timeout, + minBond, + nonce, + address(this) + ); } }