Skip to content

Commit

Permalink
Add test cases realted to board settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
zeckli committed Nov 3, 2023
1 parent 37baf4a commit 29971b5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 17 deletions.
14 changes: 8 additions & 6 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
BillboardTest:testBid() (gas: 187)
BillboardTest:testBidByAttacker() (gas: 188)
BillboardTest:testClearAuction() (gas: 143)
BillboardTest:testClearAuction() (gas: 210)
BillboardTest:testClearAuctionByAttacker() (gas: 144)
BillboardTest:testMintBoard() (gas: 177730)
BillboardTest:testMintBoardByAttacker() (gas: 165)
BillboardTest:testMintBoard() (gas: 177764)
BillboardTest:testMintBoardByAttacker() (gas: 20039)
BillboardTest:testSetBoardProperties() (gas: 306443)
BillboardTest:testSetBoardProprtiesByAttacker() (gas: 194455)
BillboardTest:testSetIsOpened() (gas: 49024)
BillboardTest:testSetIsOpenedByAttacker() (gas: 12302)
BillboardTest:testUpgradeAuctionByAttacker() (gas: 14008)
BillboardTest:testUpgradeRegistryByAttacker() (gas: 13997)
BillboardTest:testSetIsOpenedByAttacker() (gas: 12368)
BillboardTest:testUpgradeAuctionByAttacker() (gas: 13997)
BillboardTest:testUpgradeRegistryByAttacker() (gas: 14063)
62 changes: 51 additions & 11 deletions src/test/Billboard/BillboardTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract BillboardTest is BillboardTestBase {

function testUpgradeAuctionByAttacker() public {
vm.stopPrank();
vm.prank(ATTACKER);
vm.startPrank(ATTACKER);
vm.expectRevert(abi.encodeWithSignature("InvalidAddress()"));
operator.upgradeAuction(ZERO_ADDRESS);

Expand All @@ -20,7 +20,7 @@ contract BillboardTest is BillboardTestBase {

function testUpgradeRegistryByAttacker() public {
vm.stopPrank();
vm.prank(ATTACKER);
vm.startPrank(ATTACKER);
vm.expectRevert(abi.encodeWithSignature("InvalidAddress()"));
operator.upgradeRegistry(ZERO_ADDRESS);

Expand All @@ -30,7 +30,7 @@ contract BillboardTest is BillboardTestBase {

function testSetIsOpened() public {
vm.stopPrank();
vm.prank(ADMIN);
vm.startPrank(ADMIN);
operator.setIsOpened(true);

assertEq(true, auction.isOpened());
Expand All @@ -45,7 +45,7 @@ contract BillboardTest is BillboardTestBase {

function testSetIsOpenedByAttacker() public {
vm.stopPrank();
vm.prank(ATTACKER);
vm.startPrank(ATTACKER);
vm.expectRevert(abi.encodeWithSignature("Unauthorized(string)", "admin"));
operator.setIsOpened(true);
}
Expand All @@ -56,9 +56,9 @@ contract BillboardTest is BillboardTestBase {

function testMintBoard() public {
vm.stopPrank();
vm.startPrank(ADMIN);

// mint
vm.prank(ADMIN);
operator.mintBoard(ADMIN);
assertEq(1, registry.balanceOf(ADMIN));

Expand All @@ -72,16 +72,56 @@ contract BillboardTest is BillboardTestBase {
assertEq("", board.location);
assertEq("", board.contentURI);
assertEq("", board.redirectLink);
}

// set properties
function testMintBoardByAttacker() public {
vm.stopPrank();
vm.startPrank(ATTACKER);

// get board & check data
vm.expectRevert(abi.encodeWithSignature("Unauthorized(string)", "minter"));
operator.mintBoard(ATTACKER);
}

function testMintBoardByAttacker() public {
// mint
// set properties
// transfer
function testSetBoardProperties() public {
_mintBoard();

vm.stopPrank();
vm.startPrank(ADMIN);

operator.setBoardName(1, "name");
operator.setBoardDescription(1, "description");
operator.setBoardLocation(1, "location");
operator.setBoardContentURI(1, "contentURI");
operator.setBoardRedirectLink(1, "redirect link");

IBillboardRegistry.Board memory board = operator.getBoard(1);
assertEq("name", board.name);
assertEq("description", board.description);
assertEq("location", board.location);
assertEq("contentURI", board.contentURI);
assertEq("redirect link", board.redirectLink);
}

function testSetBoardProprtiesByAttacker() public {
_mintBoard();

vm.stopPrank();
vm.startPrank(ATTACKER);

vm.expectRevert(abi.encodeWithSignature("Unauthorized(string)", "board owner"));
operator.setBoardName(1, "name");

vm.expectRevert(abi.encodeWithSignature("Unauthorized(string)", "board owner"));
operator.setBoardDescription(1, "description");

vm.expectRevert(abi.encodeWithSignature("Unauthorized(string)", "board owner"));
operator.setBoardLocation(1, "location");

vm.expectRevert(abi.encodeWithSignature("Unauthorized(string)", "board tenant"));
operator.setBoardContentURI(1, "contentURI");

vm.expectRevert(abi.encodeWithSignature("Unauthorized(string)", "board tenant"));
operator.setBoardRedirectLink(1, "redirect link");
}

//////////////////////////////
Expand Down
9 changes: 9 additions & 0 deletions src/test/Billboard/BillboardTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ contract BillboardTestBase is Test {
operator.upgradeAuction(address(auction));
operator.upgradeRegistry(address(registry));
}

function _mintBoard() public {
vm.stopPrank();
vm.startPrank(ADMIN);

// mint
operator.mintBoard(ADMIN);
assertEq(1, registry.balanceOf(ADMIN));
}
}

0 comments on commit 29971b5

Please sign in to comment.