Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add sale time validation in FixedPriceAllowedMintersStrategy #479

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ interface IFixedPriceAllowedMintersStrategy {
event MinterSet(address indexed mediaContract, uint256 indexed tokenId, address indexed minter, bool allowed);

error ONLY_MINTER();
error InvalidSaleTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ contract FixedPriceAllowedMintersStrategy is Enjoy, SaleStrategy, LimitedMintPer
/// @param tokenId The token id to set the sale config for
/// @param salesConfig The sales config to set
function setSale(uint256 tokenId, SalesConfig calldata salesConfig) external {
if (salesConfig.saleStart >= salesConfig.saleEnd) {
revert InvalidSaleTime();
}
salesConfigs[msg.sender][tokenId] = salesConfig;

emit SaleSet(msg.sender, tokenId, salesConfig);
Expand Down Expand Up @@ -157,7 +160,7 @@ contract FixedPriceAllowedMintersStrategy is Enjoy, SaleStrategy, LimitedMintPer

/// @notice The version of the sale strategy
function contractVersion() external pure override returns (string memory) {
return "1.0.0";
return "1.0.1";
}

function contractURI() external pure override returns (string memory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect } from "chai";
import { ethers } from "hardhat";
import { time } from "@nomicfoundation/hardhat-network-helpers";
import { FixedPriceAllowedMintersStrategy } from "../../../typechain-types";

describe("FixedPriceAllowedMintersStrategy", () => {
let fixedPriceMinter: FixedPriceAllowedMintersStrategy;

beforeEach(async () => {
const FixedPriceMinter = await ethers.getContractFactory("FixedPriceAllowedMintersStrategy");
fixedPriceMinter = await FixedPriceMinter.deploy();
await fixedPriceMinter.deployed();
});

describe("setSale", () => {
it("should set sale with valid time window", async () => {
const now = await time.latest();
const saleConfig = {
saleStart: now + 100,
saleEnd: now + 1000,
maxTokensPerAddress: 5,
pricePerToken: ethers.utils.parseEther("0.1"),
fundsRecipient: ethers.constants.AddressZero
};

await expect(fixedPriceMinter.setSale(1, saleConfig))
.to.emit(fixedPriceMinter, "SaleSet");
});

it("should revert when saleEnd is before saleStart", async () => {
const now = await time.latest();
const saleConfig = {
saleStart: now + 1000,
saleEnd: now + 100,
maxTokensPerAddress: 5,
pricePerToken: ethers.utils.parseEther("0.1"),
fundsRecipient: ethers.constants.AddressZero
};

await expect(fixedPriceMinter.setSale(1, saleConfig))
.to.be.revertedWithCustomError(fixedPriceMinter, "InvalidSaleTime");
});

it("should revert when saleStart equals saleEnd", async () => {
const now = await time.latest();
const saleConfig = {
saleStart: now + 100,
saleEnd: now + 100,
maxTokensPerAddress: 5,
pricePerToken: ethers.utils.parseEther("0.1"),
fundsRecipient: ethers.constants.AddressZero
};

await expect(fixedPriceMinter.setSale(1, saleConfig))
.to.be.revertedWithCustomError(fixedPriceMinter, "InvalidSaleTime");
});
});
});