Skip to content

Instantly share code, notes, and snippets.

@0x3b33
Last active November 6, 2023 23:19
Show Gist options
  • Save 0x3b33/677f86f30603dfa213541cf764bbc0e8 to your computer and use it in GitHub Desktop.
Save 0x3b33/677f86f30603dfa213541cf764bbc0e8 to your computer and use it in GitHub Desktop.
Multiple mints can brick any form of `salesOption` 3 mintings
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// forge test --match-test test_multipleMints --lib-paths ../smart-contracts
import {Test} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";
import {NextGenAdmins} from "contracts/NextGenAdmins.sol";
import {randomPool as XRandoms} from "contracts/XRandoms.sol";
import {NextGenCore} from "contracts/NextGenCore.sol";
import {NextGenRandomizerNXT as RandomizerNXT} from "contracts/RandomizerNXT.sol";
import {DelegationManagementContract as NFTDelegation} from "contracts/NFTdelegation.sol";
import {NextGenMinterContract as MinterContract} from "contracts/MinterContract.sol";
import {IERC721Receiver} from "contracts/IERC721Receiver.sol";
import {MerkleProof} from "contracts/MerkleProof.sol";
contract FullTest is Test {
NextGenAdmins public nextGenAdmins;
XRandoms public xRandoms;
NextGenCore public nextGenCore;
RandomizerNXT public randomizerNXT;
NFTDelegation public nftDelegation;
MinterContract public minterContract;
uint256 mintCycle;
address user1;
address user2;
function setUp() public {
user1 = address(111);
user2 = address(222);
vm.label(user1, "user1");
vm.label(user2, "user2");
nextGenAdmins = new NextGenAdmins();
xRandoms = new XRandoms();
nextGenCore = new NextGenCore(
"NextGen Core",
"Core",
address(nextGenAdmins)
);
randomizerNXT = new RandomizerNXT(
address(xRandoms),
address(nextGenAdmins),
address(nextGenCore)
);
nftDelegation = new NFTDelegation();
minterContract = new MinterContract(
address(nextGenCore),
address(nftDelegation),
address(nextGenAdmins)
);
nextGenCore.addMinterContract(address(minterContract));
}
function initCollection() public {
string[] memory script = new string[](1);
bytes32 merkleRoot = 0x00;
script[0] = "canvas.square();";
// create a fix priced collection
nextGenCore.createCollection(
"CollectionName", "Artist", "Description", "www.collection.com", "MIT", "localhost:3000//", "GenArt", script
);
nextGenCore.setCollectionData(
1, // ID
address(0x3b), // artist
1000, // maxNFTs
1000, // TotalSupp
1000 //timeAfterintEnd
);
nextGenCore.addRandomizer(1, address(randomizerNXT));
minterContract.setCollectionCosts(
1, // ID
1e18, // mintCost
2e18, //endMintCost
10, // rate
60, // timePeriod
1, // salesOption
address(0x3b)
);
minterContract.setCollectionPhases(
1, // ID
block.timestamp, //allowStart
block.timestamp + 1 days, // allowEnd
block.timestamp + 3600 * 4, //publicStart
block.timestamp + 3 days, // publicEnd
merkleRoot
);
}
// forge test --match-test test_multipleMints --lib-paths ../smart-contracts -vv
function test_multipleMints() public {
bytes32 merkleRoot = 0x00;
bytes32[] memory merkleProof = new bytes32[](0);
bytes memory arithmeticError = abi.encodeWithSignature("Panic(uint256)", 0x11);
vm.warp(block.timestamp + 100 days);
deal(user1, 1e24);
// Phase 1
initCollection();
// Users mint 500 tokens
vm.warp(block.timestamp + 2 days);
vm.prank(user1);
minterContract.mint{value: 500e18}(1, 500, 2, "Hello", user1, merkleProof, address(0), 0);
// Phase 2
minterContract.setCollectionCosts(
1, // ID
1e18, // mintCost
2e18, //endMintCost
10, // rate
60, // timePeriod
3, // salesOption
address(0x3b)
);
minterContract.setCollectionPhases(
1, // ID
block.timestamp, //allowStart
block.timestamp + 3600 * 2, // allowEnd
block.timestamp + 3600 * 3, //publicStart
block.timestamp + 3 days, // publicEnd
merkleRoot
);
vm.startPrank(user1);
//first mint
vm.warp(block.timestamp + 3600 * 5);
minterContract.mint{value: 500e18}(1, 1, 2, "Hello", user1, merkleProof, address(0), 0);
//second mint should revert
vm.warp(block.timestamp + 120);
vm.expectRevert(arithmeticError);
minterContract.mint{value: 500e18}(1, 1, 2, "Hello", user1, merkleProof, address(0), 0);
// third should pass as it way over the 500 * 60 mark
vm.warp(block.timestamp + 500 * 60);
minterContract.mint{value: 500e18}(1, 1, 2, "Hello", user1, merkleProof, address(0), 0);
vm.stopPrank();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment