Skip to content

Commit

Permalink
Merge pull request #36 from alice-si/ensure-more-than-one-outcome-slot
Browse files Browse the repository at this point in the history
Add validation requiring more than one outcome
  • Loading branch information
cag committed Jul 9, 2019
2 parents a982033 + a149d87 commit 75369ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/PredictionMarketSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract PredictionMarketSystem is OracleConsumer, ERC1155 {
/// @param outcomeSlotCount The number of outcome slots which should be used for this condition. Must not exceed 256.
function prepareCondition(address oracle, bytes32 questionId, uint outcomeSlotCount) external {
require(outcomeSlotCount <= 256, "too many outcome slots");
require(outcomeSlotCount > 0, "no outcome slots provided");
require(outcomeSlotCount > 1, "there should be more than one outcome slot");
bytes32 conditionId = keccak256(abi.encodePacked(oracle, questionId, outcomeSlotCount));
require(payoutNumerators[conditionId].length == 0, "condition already prepared");
payoutNumerators[conditionId] = new uint[](outcomeSlotCount);
Expand Down
9 changes: 8 additions & 1 deletion test/test_pm_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ contract("PredictionMarketSystem", function(accounts) {
);
});

it("should not be able to prepare a condition with no outomes slots", async () => {
it("should not be able to prepare a condition with no outcome slots", async () => {
await assertRejects(
predictionMarketSystem.prepareCondition(oracle, questionId, 0),
"Transaction should have reverted."
);
});

it("should not be able to prepare a condition with just one outcome slots", async () => {
await assertRejects(
predictionMarketSystem.prepareCondition(oracle, questionId, 1),
"Transaction should have reverted."
);
});

it("should have obtainable conditionIds if in possession of oracle, questionId, and outcomeSlotCount", async () => {
assert.equal(
(await predictionMarketSystem.getOutcomeSlotCount(conditionId)).valueOf(),
Expand Down

0 comments on commit 75369ea

Please sign in to comment.