Skip to content

Commit

Permalink
Make templates work with string concat, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundedgar committed Nov 2, 2023
1 parent 6a50872 commit f65a501
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
5 changes: 3 additions & 2 deletions contracts/AdjudicationFramework.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ contract AdjudicationFramework is BalanceHolder {
string memory templatePrefixRemove = '{"title": "Should we remove arbitrator %s from the framework ';
string memory templateSuffix = '?", "type": "bool", "category": "adjudication", "lang": "en"}';

string memory addTemplate = _toString(abi.encodePacked(templatePrefixAdd, address(this), templateSuffix));
string memory removeTemplate = _toString(abi.encodePacked(templatePrefixRemove, address(this), templateSuffix));
string memory thisContractStr = _toString(abi.encodePacked(address(this)));
string memory addTemplate = string.concat(templatePrefixAdd, thisContractStr, templateSuffix);
string memory removeTemplate = string.concat(templatePrefixRemove, thisContractStr, templateSuffix);

templateIdAddArbitrator = realityETH.createTemplate(addTemplate);
templateIdRemoveArbitrator = realityETH.createTemplate(removeTemplate);
Expand Down
39 changes: 34 additions & 5 deletions test/AdjudicationIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ pragma solidity ^0.8.20;

/* solhint-disable not-rely-on-time */
/* solhint-disable reentrancy */
/* solhint-disable quotes */

import { Vm } from 'forge-std/Vm.sol';

import {Test} from "forge-std/Test.sol";
import {Arbitrator} from "../contracts/lib/reality-eth/Arbitrator.sol";
Expand All @@ -22,6 +25,13 @@ import {L2ChainInfo} from "../contracts/L2ChainInfo.sol";
import {MockPolygonZkEVMBridge} from "./testcontract/MockPolygonZkEVMBridge.sol";

contract AdjudicationIntegrationTest is Test {

struct Log {
bytes32[] topics;
bytes data;
address emitter;
}

Arbitrator public govArb;

IERC20 internal tokenMock = IERC20(0x1234567890123456789012345678901234567890);
Expand Down Expand Up @@ -171,16 +181,15 @@ contract AdjudicationIntegrationTest is Test {

}

function testInitialArbitrators() internal {
function testInitialArbitrators() public {
// Initial arbitrators from the contructor should be added
assertTrue(adjudicationFramework1.arbitrators(initialArbitrator1));
assertTrue(adjudicationFramework1.arbitrators(initialArbitrator2));
// Arbitrators we use in adding tests with won't be added until we pass propositions for them
assertFalse(adjudicationFramework1.arbitrators(address(l2Arbitrator1)));
// This arbitrator may be added in other tests by creating a proposition
assertFalse(adjudicationFramework1.arbitrators(address(l2Arbitrator2)));
}

function testContestedAddArbitrator()
internal {
function testContestedAddArbitrator() public {

addArbitratorQID2 = adjudicationFramework1.beginAddArbitratorToAllowList(address(l2Arbitrator2));
l2realityEth.submitAnswer{value: 10000}(addArbitratorQID2, bytes32(uint256(1)), 0);
Expand Down Expand Up @@ -411,6 +420,25 @@ contract AdjudicationIntegrationTest is Test {

}

function testAdjudicationFrameworkTemplateCreation() public {
address[] memory initialArbs;
vm.recordLogs();

// Creates 2 templates, each with a log entry from reality.eth
new AdjudicationFramework(address(l2realityEth), 123, address(l2forkArbitrator), initialArbs);

// NB The length and indexes of this may change if we add unrelated log entries to the AdjudicationFramework constructor
Vm.Log[] memory entries = vm.getRecordedLogs();
assertEq(entries.length, 2);

// TODO: Not sure if this contract address will change when we do other stuff

string memory addLog = '{"title": "Should we add arbitrator %s to the framework 0xd6bbde9174b1cdaa358d2cf4d57d1a9f7178fbff?", "type": "bool", "category": "adjudication", "lang": "en"}';
string memory removeLog = '{"title": "Should we remove arbitrator %s from the framework 0xd6bbde9174b1cdaa358d2cf4d57d1a9f7178fbff?", "type": "bool", "category": "adjudication", "lang": "en"}';
assertEq(abi.decode(entries[0].data, (string)), string(addLog));
assertEq(abi.decode(entries[1].data, (string)), string(removeLog));

}

/*
// TODO:
Expand All @@ -435,4 +463,5 @@ contract AdjudicationIntegrationTest is Test {
*/



}

0 comments on commit f65a501

Please sign in to comment.