Skip to content

Commit

Permalink
Add some initializer() function tests for improved coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSamWitch committed Jan 30, 2024
1 parent aa559ff commit 7f64252
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/SamWitchOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable
if (_devAddr == address(0)) {
revert ZeroAddress();
} else if (_devFee > 1000) {
revert DevFeeNotSet();
revert DevFeeTooHigh();
}
} else if (_devAddr != address(0)) {
revert DevFeeNotSet();
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/ISamWitchOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface ISamWitchOrderBook is IERC1155Receiver {

error ZeroAddress();
error DevFeeNotSet();
error DevFeeTooHigh();
error NotERC1155();
error NoQuantity();
error OrderNotFound(uint orderId, uint price);
Expand Down
9 changes: 9 additions & 0 deletions contracts/test/MockERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";

contract MockERC721 is ERC721 {
constructor() ERC721("name", "symbol") {}
}
75 changes: 75 additions & 0 deletions test/SamWitchOrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,81 @@ describe("SamWitchOrderBook", function () {
};
}

it("Initialize function constraints", async function () {
const {dev, brush, erc1155} = await loadFixture(deployContractsFixture);

const maxOrdersPerPrice = 100;
const OrderBook = await ethers.getContractFactory("SamWitchOrderBook");
let devFee = 0;
let burntFee = 30;
await expect(
upgrades.deployProxy(
OrderBook,
[await erc1155.getAddress(), await brush.getAddress(), dev.address, devFee, burntFee, maxOrdersPerPrice],
{
kind: "uups",
},
),
).to.be.revertedWithCustomError(OrderBook, "DevFeeNotSet");

// Set the dev fee but don't set the dev address
devFee = 30;
await expect(
upgrades.deployProxy(
OrderBook,
[await erc1155.getAddress(), await brush.getAddress(), ethers.ZeroAddress, devFee, burntFee, maxOrdersPerPrice],
{
kind: "uups",
},
),
).to.be.revertedWithCustomError(OrderBook, "ZeroAddress");

devFee = 10000;
await expect(
upgrades.deployProxy(
OrderBook,
[await erc1155.getAddress(), await brush.getAddress(), dev.address, devFee, burntFee, maxOrdersPerPrice],
{
kind: "uups",
},
),
).to.be.revertedWithCustomError(OrderBook, "DevFeeTooHigh");

devFee = 30;
const erc721 = await ethers.deployContract("MockERC721");
await expect(
upgrades.deployProxy(
OrderBook,
[await erc721.getAddress(), await brush.getAddress(), dev.address, devFee, burntFee, maxOrdersPerPrice],
{
kind: "uups",
},
),
).to.be.revertedWithCustomError(OrderBook, "NotERC1155");

// No dev fee set
devFee = 0;
await upgrades.deployProxy(
OrderBook,
[await erc1155.getAddress(), await brush.getAddress(), ethers.ZeroAddress, devFee, burntFee, maxOrdersPerPrice],
{
kind: "uups",
},
);

const orderBook = await OrderBook.deploy();
await expect(
orderBook.initialize(
erc1155.getAddress(),
await brush.getAddress(),
dev.address,
devFee,
burntFee,
maxOrdersPerPrice,
),
);
});

it("Add to order book", async function () {
const {orderBook, tokenId} = await loadFixture(deployContractsFixture);

Expand Down

0 comments on commit 7f64252

Please sign in to comment.