Skip to content

Commit

Permalink
checking if premint sig is valid using v1 method to get test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Oct 24, 2023
1 parent 8d21936 commit 763ff69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ contract ZoraCreator1155PremintExecutorImpl is
return (true, ERC1155DelegationStorageV1(contractAddress).delegatedTokenId(uid));
}

/// deprecated - use isValidSignatureForV1
/// deprecated - use isValidSignatureV1
function isValidSignature(
ContractCreationConfig calldata contractConfig,
PremintConfig calldata premintConfig,
bytes calldata signature
) public view returns (bool isValid, address contractAddress, address recoveredSigner) {
contractAddress = getContractAddress(contractConfig);

(isValid, recoveredSigner) = isValidSignatureForV1(contractConfig.contractAdmin, contractAddress, premintConfig, signature);
(isValid, recoveredSigner) = isValidSignatureV1(contractConfig.contractAdmin, contractAddress, premintConfig, signature);
}

function isValidSignatureForV1(
function isValidSignatureV1(
address originalContractAdmin,
address contractAddress,
PremintConfig calldata premintConfig,
Expand All @@ -174,7 +174,7 @@ contract ZoraCreator1155PremintExecutorImpl is
);
}

function isValidSignatureForV2(
function isValidSignatureV2(
address originalContractAdmin,
address contractAddress,
PremintConfigV2 calldata premintConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
// this account will be used to execute the premint, and should result in a contract being created
vm.deal(premintExecutor, mintCost);

// make sure sig is still valid using legacy method
(bool isValid, , ) = preminter.isValidSignature(contractConfig, premintConfig, signature);
assertTrue(isValid);

// now check using new method
(isValid, ) = preminter.isValidSignatureV1(contractConfig.contractAdmin, contractAddress, premintConfig, signature);
assertTrue(isValid);

// now call the premint function, using the same config that was used to generate the digest, and the signature
vm.prank(premintExecutor);
uint256 tokenId = preminter.premintV1{value: mintCost}(contractConfig, premintConfig, signature, quantityToMint, defaultMintArguments).tokenId;
Expand Down Expand Up @@ -720,7 +728,7 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
// sign and execute premint
bytes memory signature = _signPremint(contractAddress, premintConfig, creatorPrivateKey, block.chainid);

(bool isValidSignature, address recoveredSigner) = preminter.isValidSignatureForV2(
(bool isValidSignature, address recoveredSigner) = preminter.isValidSignatureV2(
contractConfig.contractAdmin,
contractAddress,
premintConfig,
Expand All @@ -744,7 +752,7 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
bytes memory newCreatorSignature = _signPremint(contractAddress, premintConfig2, newCreatorPrivateKey, block.chainid);

// it should not be considered a valid signature
(isValidSignature, ) = preminter.isValidSignatureForV2(contractConfig.contractAdmin, contractAddress, premintConfig2, newCreatorSignature);
(isValidSignature, ) = preminter.isValidSignatureV2(contractConfig.contractAdmin, contractAddress, premintConfig2, newCreatorSignature);

assertFalse(isValidSignature, "signature should not be valid");

Expand All @@ -762,7 +770,7 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
IZoraCreator1155(contractAddress).addPermission(CONTRACT_BASE_ID, newCreator, PERMISSION_BIT_MINTER);

// should now be considered a valid signature
(isValidSignature, ) = preminter.isValidSignatureForV2(contractConfig.contractAdmin, contractAddress, premintConfig2, newCreatorSignature);
(isValidSignature, ) = preminter.isValidSignatureV2(contractConfig.contractAdmin, contractAddress, premintConfig2, newCreatorSignature);
assertTrue(isValidSignature, "valid signature after granted permission");

vm.deal(premintExecutor, mintCost);
Expand Down

0 comments on commit 763ff69

Please sign in to comment.