Skip to content

Commit

Permalink
Merge pull request #9 from rpenn/test-suite
Browse files Browse the repository at this point in the history
Test suite
  • Loading branch information
mcgrathcoutinho authored Sep 15, 2023
2 parents 7af33ff + d146a3b commit 11d180a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
12 changes: 12 additions & 0 deletions contracts/EventManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,16 @@ contract EventManager {
eventToUpdate.price
);
}

function getCurrentEventId() external view returns(uint256){
return currentEventId;
}

function getOwner() external view returns(address) {
return owner;
}

function getEvent(uint256 _currentEventId) external view returns(Event memory) {
return events[_currentEventId];
}
}
35 changes: 32 additions & 3 deletions test/testEventManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,49 @@
pragma solidity 0.8.19;

import {Test, console} from "forge-std/Test.sol";
import {EventManager} from "../src/EventManager.sol";
import {EventManager} from "contracts/EventManager.sol";

contract testEventManager is Test {

//Stores the event manager instance
EventManager eventManager;

//Sample event struct copy since structs ain't imported, explicit convesion required wherever used

//Deploys an EventManager contract
function setUp() external {
eventManager = new EventManager();
}

function testOwnerIsMsgSender() public {
address owner = eventManager.owner();
address owner = eventManager.getOwner();
assertEq(owner, address(this));
}
}

function testCreateEvent() public {
eventManager.createEvent({
name: "F1",
location: "Japan Suzuka",
date: 100,
startTime: 200,
endTime: 1000,
description: "Max wins the championship",
eventType: 1,
price: 1e17, //corresponds to 0.1 ether
ticketQuantity: 50000
});

uint256 currentEventId = eventManager.getCurrentEventId();
EventManager.Event memory currentEvent = eventManager.getEvent(currentEventId);
assertEq(currentEvent.creator, address(this));
assertEq(currentEvent.name, "F1");
assertEq(currentEvent.location, "Japan Suzuka");
assertEq(currentEvent.date, 100);
assertEq(currentEvent.startTime, 200);
assertEq(currentEvent.endTime, 1000);
assertEq(currentEvent.description, "Max wins the championship");
assertEq(currentEvent.eventType, 1);
assertEq(currentEvent.price, 10 ** 17);
assertEq(currentEvent.ticketQuantity, 50000);
}
}

0 comments on commit 11d180a

Please sign in to comment.