Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kulkarohan authored and oveddan committed Oct 17, 2023
1 parent edbab40 commit 2b887a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 83 deletions.
24 changes: 6 additions & 18 deletions packages/1155-contracts/test/factory/ZoraCreator1155Factory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,26 @@ contract ZoraCreator1155FactoryTest is Test {
assertEq(address(minters[2]), address(3));
}

function test_createContract(
string memory contractURI,
string memory name,
uint32 royaltyBPS,
uint32 royaltyMintSchedule,
address royaltyRecipient,
address payable admin
) external {
function test_createContract(string memory contractURI, string memory name, uint32 royaltyBPS, address royaltyRecipient, address payable admin) external {
// If the factory is the admin, the admin flag is cleared
// during multicall breaking a further test assumption.
// Additionally, this case makes no sense from a user perspective.
vm.assume(admin != payable(address(factory)));
vm.assume(royaltyMintSchedule != 1);
// Assume royalty recipient is not 0
vm.assume(royaltyRecipient != payable(address(0)));
bytes[] memory initSetup = new bytes[](1);
initSetup[0] = abi.encodeWithSelector(IZoraCreator1155.setupNewToken.selector, "ipfs://asdfadsf", 100);
address deployedAddress = factory.createContract(
contractURI,
name,
ICreatorRoyaltiesControl.RoyaltyConfiguration({
royaltyBPS: royaltyBPS,
royaltyRecipient: royaltyRecipient,
royaltyMintSchedule: royaltyMintSchedule
}),
ICreatorRoyaltiesControl.RoyaltyConfiguration({royaltyBPS: royaltyBPS, royaltyRecipient: royaltyRecipient, royaltyMintSchedule: 0}),
admin,
initSetup
);
ZoraCreator1155Impl target = ZoraCreator1155Impl(deployedAddress);

ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = target.getRoyalties(0);
assertEq(config.royaltyMintSchedule, royaltyMintSchedule);
assertEq(config.royaltyMintSchedule, 0);
assertEq(config.royaltyBPS, royaltyBPS);
assertEq(config.royaltyRecipient, royaltyRecipient);
assertEq(target.permissions(0, admin), target.PERMISSION_BIT_ADMIN());
Expand Down Expand Up @@ -170,7 +158,7 @@ contract ZoraCreator1155FactoryTest is Test {
ICreatorRoyaltiesControl.RoyaltyConfiguration memory royaltyConfig = ICreatorRoyaltiesControl.RoyaltyConfiguration({
royaltyBPS: 10,
royaltyRecipient: vm.addr(5),
royaltyMintSchedule: 100
royaltyMintSchedule: 0
});
bytes[] memory initSetup = new bytes[](1);
initSetup[0] = abi.encodeWithSelector(IZoraCreator1155.setupNewToken.selector, "ipfs://asdfadsf", 100);
Expand Down Expand Up @@ -220,7 +208,7 @@ contract ZoraCreator1155FactoryTest is Test {
ICreatorRoyaltiesControl.RoyaltyConfiguration memory royaltyConfig = ICreatorRoyaltiesControl.RoyaltyConfiguration({
royaltyBPS: 10,
royaltyRecipient: vm.addr(5),
royaltyMintSchedule: 100
royaltyMintSchedule: 0
});
bytes[] memory initSetup = new bytes[](1);
initSetup[0] = abi.encodeWithSelector(IZoraCreator1155.setupNewToken.selector, "ipfs://asdfadsf", 100);
Expand All @@ -241,7 +229,7 @@ contract ZoraCreator1155FactoryTest is Test {
ICreatorRoyaltiesControl.RoyaltyConfiguration memory royaltyConfig = ICreatorRoyaltiesControl.RoyaltyConfiguration({
royaltyBPS: 10,
royaltyRecipient: vm.addr(5),
royaltyMintSchedule: 100
royaltyMintSchedule: 0
});
bytes[] memory initSetup = new bytes[](1);
initSetup[0] = abi.encodeWithSelector(IZoraCreator1155.setupNewToken.selector, "ipfs://asdfadsf", 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ library Zora1155PremintFixtures {
}

function defaultRoyaltyConfig(address royaltyRecipient) internal pure returns (ICreatorRoyaltiesControl.RoyaltyConfiguration memory) {
return ICreatorRoyaltiesControl.RoyaltyConfiguration({royaltyBPS: 10, royaltyRecipient: royaltyRecipient, royaltyMintSchedule: 100});
return ICreatorRoyaltiesControl.RoyaltyConfiguration({royaltyBPS: 10, royaltyRecipient: royaltyRecipient, royaltyMintSchedule: 0});
}

function makeDefaultTokenCreationConfig(IMinter1155 fixedPriceMinter, address royaltyRecipient) internal pure returns (TokenCreationConfig memory) {
Expand Down
90 changes: 26 additions & 64 deletions packages/1155-contracts/test/nft/ZoraCreator1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,53 +112,30 @@ contract ZoraCreator1155Test is Test {
target.initialize("test", "test", ICreatorRoyaltiesControl.RoyaltyConfiguration(0, 0, address(0)), admin, _emptyInitData());
}

function init(uint32 royaltySchedule, uint32 royaltyBps, address royaltyRecipient) internal {
target.initialize(
"test",
"test",
ICreatorRoyaltiesControl.RoyaltyConfiguration(royaltySchedule, royaltyBps, royaltyRecipient),
admin,
_emptyInitData()
);
function init(uint32 royaltyBps, address royaltyRecipient) internal {
target.initialize("test", "test", ICreatorRoyaltiesControl.RoyaltyConfiguration(0, royaltyBps, royaltyRecipient), admin, _emptyInitData());
}

function test_packageJsonVersion() public {
string memory package = vm.readFile("./package.json");
assertEq(package.readString(".version"), target.contractVersion());
}

function test_initialize(uint32 royaltySchedule, uint32 royaltyBPS, address royaltyRecipient, address payable defaultAdmin) external {
vm.assume(royaltySchedule != 1);
vm.assume(royaltyRecipient != address(0) && royaltySchedule != 0 && royaltyBPS != 0);
ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = ICreatorRoyaltiesControl.RoyaltyConfiguration(
royaltySchedule,
royaltyBPS,
royaltyRecipient
);
function test_initialize(uint32 royaltyBPS, address royaltyRecipient, address payable defaultAdmin) external {
vm.assume(royaltyRecipient != address(0) && royaltyBPS != 0);
ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = ICreatorRoyaltiesControl.RoyaltyConfiguration(0, royaltyBPS, royaltyRecipient);
target.initialize("contract name", "test", config, defaultAdmin, _emptyInitData());

assertEq(target.contractURI(), "test");
assertEq(target.name(), "contract name");
(uint32 fetchedSchedule, uint256 fetchedBps, address fetchedRecipient) = target.royalties(0);
assertEq(fetchedSchedule, royaltySchedule);
(, uint256 fetchedBps, address fetchedRecipient) = target.royalties(0);
assertEq(fetchedBps, royaltyBPS);
assertEq(fetchedRecipient, royaltyRecipient);
}

function test_initialize_withSetupActions(
uint32 royaltySchedule,
uint32 royaltyBPS,
address royaltyRecipient,
address payable defaultAdmin,
uint256 maxSupply
) external {
vm.assume(royaltySchedule != 1);
vm.assume(royaltyRecipient != address(0) && royaltySchedule != 0 && royaltyBPS != 0);
ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = ICreatorRoyaltiesControl.RoyaltyConfiguration(
royaltySchedule,
royaltyBPS,
royaltyRecipient
);
function test_initialize_withSetupActions(uint32 royaltyBPS, address royaltyRecipient, address payable defaultAdmin, uint256 maxSupply) external {
vm.assume(royaltyRecipient != address(0) && royaltyBPS != 0);
ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = ICreatorRoyaltiesControl.RoyaltyConfiguration(0, royaltyBPS, royaltyRecipient);
bytes[] memory setupActions = new bytes[](1);
setupActions[0] = abi.encodeWithSelector(IZoraCreator1155.setupNewToken.selector, "test", maxSupply);
target.initialize("", "test", config, defaultAdmin, setupActions);
Expand All @@ -167,19 +144,9 @@ contract ZoraCreator1155Test is Test {
assertEq(tokenData.maxSupply, maxSupply);
}

function test_initialize_revertAlreadyInitialized(
uint32 royaltySchedule,
uint32 royaltyBPS,
address royaltyRecipient,
address payable defaultAdmin
) external {
vm.assume(royaltySchedule != 1);
vm.assume(royaltyRecipient != address(0) && royaltySchedule != 0 && royaltyBPS != 0);
ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = ICreatorRoyaltiesControl.RoyaltyConfiguration(
royaltySchedule,
royaltyBPS,
royaltyRecipient
);
function test_initialize_revertAlreadyInitialized(uint32 royaltyBPS, address royaltyRecipient, address payable defaultAdmin) external {
vm.assume(royaltyRecipient != address(0) && royaltyBPS != 0);
ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = ICreatorRoyaltiesControl.RoyaltyConfiguration(0, royaltyBPS, royaltyRecipient);
target.initialize("test", "test", config, defaultAdmin, _emptyInitData());

vm.expectRevert();
Expand Down Expand Up @@ -408,37 +375,35 @@ contract ZoraCreator1155Test is Test {
function test_adminMintWithScheduleSmall() external {
uint256 quantity = 100;
address royaltyRecipient = address(0x3334);
// every 10 royalty 100/10 = 10 tokens minted
init(10, 0, royaltyRecipient);

init(0, royaltyRecipient);

vm.prank(admin);
uint256 tokenId = target.setupNewToken("test", quantity);

vm.prank(admin);
target.adminMint(recipient, tokenId, 90, "");
target.adminMint(recipient, tokenId, quantity, "");

IZoraCreator1155TypesV1.TokenData memory tokenData = target.getTokenInfo(tokenId);
assertEq(tokenData.totalMinted, 100);
assertEq(target.balanceOf(recipient, tokenId), (quantity * 9) / 10);
assertEq(target.balanceOf(royaltyRecipient, tokenId), (quantity * 1) / 10);
assertEq(tokenData.totalMinted, quantity);
assertEq(target.balanceOf(recipient, tokenId), quantity);
}

function test_adminMintWithSchedule() external {
uint256 quantity = 1000;
address royaltyRecipient = address(0x3334);
// every 10 tokens, mint 1 to royalty 1000/10 = 100 tokens minted to royalty recipient
init(10, 0, royaltyRecipient);

init(0, royaltyRecipient);

vm.prank(admin);
uint256 tokenId = target.setupNewToken("test", 1000);

vm.prank(admin);
target.adminMint(recipient, tokenId, (quantity * 9) / 10, "");
target.adminMint(recipient, tokenId, quantity, "");

IZoraCreator1155TypesV1.TokenData memory tokenData = target.getTokenInfo(tokenId);
assertEq(tokenData.totalMinted, 1000);
assertEq(target.balanceOf(recipient, tokenId), (quantity * 9) / 10);
assertEq(target.balanceOf(royaltyRecipient, tokenId), (quantity * 1) / 10);
assertEq(target.balanceOf(recipient, tokenId), quantity);
}

function test_adminMint_revertOnlyAdminOrRole() external {
Expand Down Expand Up @@ -574,8 +539,8 @@ contract ZoraCreator1155Test is Test {
vm.assume(quantity2 < 900);

address royaltyRecipient = address(0x3334);
// every 10th token is a token for the royalty recipient
init(10, 0, royaltyRecipient);

init(0, royaltyRecipient);

vm.prank(admin);
uint256 tokenId1 = target.setupNewToken("test", 1000);
Expand All @@ -596,12 +561,10 @@ contract ZoraCreator1155Test is Test {
IZoraCreator1155TypesV1.TokenData memory tokenData1 = target.getTokenInfo(tokenId1);
IZoraCreator1155TypesV1.TokenData memory tokenData2 = target.getTokenInfo(tokenId2);

assertEq(tokenData1.totalMinted, quantity1 + (quantity1 / 9));
assertEq(tokenData2.totalMinted, quantity2 + (quantity2 / 9));
assertEq(tokenData1.totalMinted, quantity1);
assertEq(tokenData2.totalMinted, quantity2);
assertEq(target.balanceOf(recipient, tokenId1), quantity1);
assertEq(target.balanceOf(recipient, tokenId2), quantity2);
assertEq(target.balanceOf(royaltyRecipient, tokenId1), quantity1 / 9);
assertEq(target.balanceOf(royaltyRecipient, tokenId2), quantity2 / 9);
}

function test_adminMintWithInvalidScheduleSkipsSchedule() external {
Expand All @@ -611,8 +574,7 @@ contract ZoraCreator1155Test is Test {
}

function test_adminMintWithEmptyScheduleSkipsSchedule() external {
// every 0th token is sent so no tokens
init(0, 0, address(0x99a));
init(0, address(0x99a));

vm.prank(admin);
uint256 tokenId1 = target.setupNewToken("test", 1000);
Expand Down

0 comments on commit 2b887a0

Please sign in to comment.