Skip to content

Commit

Permalink
Improved comments and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfior committed Sep 18, 2024
1 parent e1bfb0d commit 04a8177
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
20 changes: 8 additions & 12 deletions src/OmenAgentResultMapping.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,33 @@ pragma solidity ^0.8.24;

import {Prediction} from "./structs.sol";

/// This contract allows for mapping market addresses to IPFS hashes containing agent results.
contract OmenAgentResultMapping {
event AgentResultAdded(
event PredictionAdded(
address indexed marketAddress,
uint16 estimatedProbabilityBps,
address indexed publisherAddress,
bytes32 txHash,
bytes32 ipfsHash
);

// Mapping of a market address to an array of IPFS hashes (bytes32).
mapping(address => Prediction[]) private marketToPredictions;
mapping(address => Prediction[]) private marketPredictions;

// We set the deployer as the default admin.
constructor() {}

function getPredictions(address marketAddress) public view returns (Prediction[] memory) {
return marketToPredictions[marketAddress];
return marketPredictions[marketAddress];
}

// ToDo - Check ConditionalTokens for a >0 address of the sender.
function addPrediction(address marketAddress, Prediction memory prediction) public {
require(address(msg.sender) == address(prediction.publisherAddress), "Only publisher can add an IPFS hash");
marketToPredictions[marketAddress].push(prediction);
emit AgentResultAdded(
require(address(msg.sender) == address(prediction.publisherAddress), "Only publisher can add a prediction");
marketPredictions[marketAddress].push(prediction);
emit PredictionAdded(
marketAddress, prediction.estimatedProbabilityBps, msg.sender, prediction.txHash, prediction.ipfsHash
);
}

function getPredictionByIndex(address marketAddress, uint256 index) public view returns (Prediction memory) {
require(index < marketToPredictions[marketAddress].length, "Index out of bounds");
return marketToPredictions[marketAddress][index];
require(index < marketPredictions[marketAddress].length, "Index out of bounds");
return marketPredictions[marketAddress][index];
}
}
10 changes: 3 additions & 7 deletions test/OmenAgentResultMapping.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {OmenAgentResultMapping} from "../src/OmenAgentResultMapping.sol";
import {Prediction} from "../src/structs.sol";

contract OmenAgentResultMappingTest is Test {
event AgentResultAdded(
event PredictionAdded(
address indexed marketAddress,
uint16 estimatedProbabilityBps,
address indexed publisherAddress,
Expand All @@ -18,11 +18,10 @@ contract OmenAgentResultMappingTest is Test {
address publisher;
address marketAddress;

/// @notice Deploys a new instance of the OmenAgentResultMapping contract before each test.
function setUp() public {
omenAgentResultMapping = new OmenAgentResultMapping();
publisher = vm.addr(1);

// We mock the market address value as being the address of this test contract.
marketAddress = address(this);
}

Expand All @@ -35,7 +34,6 @@ contract OmenAgentResultMappingTest is Test {
return prediction;
}

/// @notice Helper function to add a mock IPFS hash based on a given input string.
function addMockPrediction(string memory input) internal returns (bytes32) {
Prediction memory prediction = buildPrediction(input);
vm.prank(publisher);
Expand All @@ -48,7 +46,6 @@ contract OmenAgentResultMappingTest is Test {
bytes32 expectedHash1 = addMockPrediction("test-input1");
bytes32 expectedHash2 = addMockPrediction("test-input2");

// Retrieve the list of IPFS hashes for the sender's address
Prediction[] memory predictions = omenAgentResultMapping.getPredictions(address(this));
assertEq(predictions[0].ipfsHash, expectedHash1);
assertEq(predictions[1].ipfsHash, expectedHash2);
Expand All @@ -64,12 +61,11 @@ contract OmenAgentResultMappingTest is Test {
}

function testAddPredictionEmitsEvent() public {
// ToDo - Add Use for Prediction
Prediction memory prediction = buildPrediction("test-input1");

vm.expectEmit(true, true, false, true);
vm.startPrank(publisher);
emit AgentResultAdded(
emit PredictionAdded(
marketAddress,
prediction.estimatedProbabilityBps,
prediction.publisherAddress,
Expand Down

0 comments on commit 04a8177

Please sign in to comment.