pragma solidity ^0.8.0;
import "forge-std/Test.sol";
import "../src/ThePredicter.sol";
import "../src/ScoreBoard.sol";
contract ThePredicterTest is Test {
ThePredicter public thePredicter;
ScoreBoard public scoreBoard;
address public owner = address(1);
address public player = address(2);
uint256 public predictionFee = 0.01 ether;
uint256 public entranceFee = 0.04 ether;
uint256 public START_TIME = 1723752000;
function setUp() public {
vm.deal(owner, 1 ether);
vm.deal(player, 1 ether);
vm.startPrank(owner);
scoreBoard = new ScoreBoard();
thePredicter = new ThePredicter(address(scoreBoard), entranceFee, predictionFee);
thePredicter.register{value: entranceFee}();
vm.stopPrank();
}
function testUnapprovedPlayerCannotPredict() public {
vm.startPrank(player);
vm.expectRevert(ThePredicter__UnauthorizedAccess.selector);
thePredicter.makePrediction{value: predictionFee}(0, ScoreBoard.Result.Win);
vm.stopPrank();
}
}
Unauthorized users can make predictions, potentially compromising the integrity of the prediction system.
Add a check to verify that the player is authorized to make a prediction before confirming payment and setting the prediction.
function makePrediction(
uint256 matchNumber,
ScoreBoard.Result prediction
) public payable {
if (msg.value != predictionFee) {
revert ThePredicter__IncorrectPredictionFee();
}
if (block.timestamp > START_TIME + matchNumber * 86400 - 3600) {
revert ThePredicter__PredictionsAreClosed();
}
if (playersStatus[msg.sender] != Status.Approved) {
revert ThePredicter__UnauthorizedAccess();
}
scoreBoard.confirmPredictionPayment(msg.sender, matchNumber);
scoreBoard.setPrediction(msg.sender, matchNumber, prediction);
emit PredictionMade(msg.sender, matchNumber, prediction);
}
event PredictionMade(address indexed player, uint256 matchNumber, ScoreBoard.Result prediction);