Skip to content

Commit

Permalink
Fix creator attribution tests.
Browse files Browse the repository at this point in the history
Having issues with external lib
  • Loading branch information
oveddan committed Aug 17, 2023
1 parent 5a80440 commit ce80051
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 36 deletions.
79 changes: 52 additions & 27 deletions package/preminter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { parseEther } from "viem";
import {
zoraCreator1155PremintExecutorABI as preminterAbi,
zoraCreator1155ImplABI,
zoraCreator1155PremintExecutorAddress,
zoraCreator1155FactoryImplAddress,
zoraCreator1155FactoryImplConfig,
} from "./wagmiGenerated";
import ZoraCreator1155Attribution from "../out/ZoraCreator1155Attribution.sol/ZoraCreator1155Attribution.json";
import zoraCreator1155PremintExecutor from "../out/ZoraCreator1155PremintExecutor.sol/ZoraCreator1155PremintExecutor.json";
Expand Down Expand Up @@ -125,9 +125,7 @@ export const deployFactoryProxy = async () => {
return { factoryProxyAddress, zora1155Address, fixedPriceMinterAddress };
};

export const deployPreminterContract = async () => {
const factoryProxyAddress = (await deployFactoryProxy()).factoryProxyAddress;

export const deployPreminterContract = async (factoryProxyAddress: Address) => {
const deployPreminterHash = await walletClient.deployContract({
abi: zoraCreator1155PremintExecutor.abi,
bytecode: zoraCreator1155PremintExecutor.bytecode.object as `0x${string}`,
Expand All @@ -145,8 +143,12 @@ export const deployPreminterContract = async () => {
};

// create token and contract creation config:
const defaultContractConfig = (): ContractCreationConfig => ({
contractAdmin: creatorAccount,
const defaultContractConfig = ({
contractAdmin,
}: {
contractAdmin: Address;
}): ContractCreationConfig => ({
contractAdmin,
contractURI: "ipfs://asdfasdfasdf",
contractName: "My fun NFT",
});
Expand All @@ -157,7 +159,7 @@ const defaultTokenConfig = (
tokenURI: "ipfs://tokenIpfsId0",
maxSupply: 100n,
maxTokensPerAddress: 10n,
pricePerToken: parseEther("0.1"),
pricePerToken: 0n,
mintStart: 0n,
mintDuration: 100n,
royaltyMintSchedule: 30,
Expand Down Expand Up @@ -189,10 +191,19 @@ describe("ZoraCreator1155Preminter", () => {
let preminterAddress: Address;

if (useForkContract) {
preminterAddress =
zoraCreator1155PremintExecutorAddress[ctx.forkedChainId];
const factoryProxyAddress =
zoraCreator1155FactoryImplAddress[ctx.forkedChainId];
ctx.fixedPriceMinterAddress = await publicClient.readContract({
abi: zoraCreator1155FactoryImplConfig.abi,
address: zoraCreator1155FactoryImplAddress[ctx.forkedChainId],
functionName: "fixedPriceMinter",
});
const deployed = await deployPreminterContract(factoryProxyAddress);
preminterAddress = deployed.preminterAddress;
} else {
const deployed = await deployPreminterContract();
const factoryProxyAddress = (await deployFactoryProxy())
.factoryProxyAddress;
const deployed = await deployPreminterContract(factoryProxyAddress);
preminterAddress = deployed.preminterAddress;
}

Expand All @@ -205,7 +216,9 @@ describe("ZoraCreator1155Preminter", () => {
"can sign for another chain",
async ({ preminterAddress: preminterAddress, fixedPriceMinterAddress }) => {
const premintConfig = defaultPremintConfig(fixedPriceMinterAddress);
const contractConfig = defaultContractConfig();
const contractConfig = defaultContractConfig({
contractAdmin: creatorAccount,
});

const contractAddress = await publicClient.readContract({
abi: preminterAbi,
Expand All @@ -231,7 +244,7 @@ describe("ZoraCreator1155Preminter", () => {
abi: preminterAbi,
address: preminterAddress,
functionName: "getContractAddress",
args: [defaultContractConfig()],
args: [contractConfig],
}),
});
},
Expand All @@ -245,7 +258,9 @@ describe("ZoraCreator1155Preminter", () => {
fixedPriceMinterAddress,
}) => {
const premintConfig = defaultPremintConfig(fixedPriceMinterAddress);
const contractConfig = defaultContractConfig();
const contractConfig = defaultContractConfig({
contractAdmin: creatorAccount,
});

const contractAddress = await publicClient.readContract({
abi: preminterAbi,
Expand Down Expand Up @@ -294,7 +309,9 @@ describe("ZoraCreator1155Preminter", () => {
}) => {
// setup contract and token creation parameters
const premintConfig = defaultPremintConfig(fixedPriceMinterAddress);
const contractConfig = defaultContractConfig();
const contractConfig = defaultContractConfig({
contractAdmin: creatorAccount,
});

// lets make it a random number to not break the existing tests that expect fresh data
premintConfig.uid = Math.round(Math.random() * 1000000);
Expand All @@ -310,11 +327,11 @@ describe("ZoraCreator1155Preminter", () => {
// and the token
const signedMessage = await walletClient.signTypedData({
...preminterTypedDataDefinition({
verifyingContract: preminterAddress,
verifyingContract: contractAddress,
// we need to sign here for the anvil chain, cause thats where it is run on
chainId: anvilChainId,
premintConfig,
}),
// signer account is the creator
account: creatorAccount,
});

Expand All @@ -328,20 +345,28 @@ describe("ZoraCreator1155Preminter", () => {

await testClient.setBalance({
address: collectorAccount,
value: 10n * 10n ** 18n,
value: parseEther("10"),
});

// get the premint status - it should not be minted
let tokenId = await publicClient.readContract({
abi: zoraCreator1155ImplABI,
address: contractAddress,
functionName: "delegatedTokenId",
args: [premintConfig.uid],
const simulatedResult = await publicClient.simulateContract({
abi: preminterAbi,
functionName: "premint",
account: collectorAccount,
address: preminterAddress,
args: [
contractConfig,
premintConfig,
signedMessage,
quantityToMint,
comment,
],
value: valueToSend,
});

expect(tokenId).toBe(0n);
// expect(contractAddress).toBe(zeroAddress);
console.log({ simulatedResult });

// get the premint status - it should not be minted
let tokenId: bigint;
// now have the collector execute the first signed message;
// it should create the contract, the token,
// and min the quantity to mint tokens to the collector
Expand All @@ -366,7 +391,7 @@ describe("ZoraCreator1155Preminter", () => {
const receipt = await publicClient.waitForTransactionReceipt({
hash: mintHash,
});
// console.log(receipt);

expect(receipt.status).toBe("success");

// fetch the premint token id
Expand Down Expand Up @@ -403,7 +428,7 @@ describe("ZoraCreator1155Preminter", () => {
// sign the message to create the second token
const signedMessage2 = await walletClient.signTypedData({
...preminterTypedDataDefinition({
verifyingContract: preminterAddress,
verifyingContract: contractAddress,
chainId: foundry.id,
premintConfig: premintConfig2,
}),
Expand Down
14 changes: 5 additions & 9 deletions package/preminter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@ export const preminterTypedDataDefinition = ({
}) => {
const { tokenConfig, uid, version, deleted } = premintConfig;
const types = {
Premint: [
CreatorAttribution: [
{ name: "tokenConfig", type: "TokenCreationConfig" },
{ name: "uid", type: "uint32" },
{ name: "version", type: "uint32" },
{ name: "deleted", type: "bool" },
],
ContractCreationConfig: [
{ name: "contractAdmin", type: "address" },
{ name: "contractURI", type: "string" },
{ name: "contractName", type: "string" },
],
TokenCreationConfig: [
{ name: "tokenURI", type: "string" },
{ name: "maxSupply", type: "uint256" },
Expand All @@ -48,14 +43,15 @@ export const preminterTypedDataDefinition = ({
{ name: "royaltyMintSchedule", type: "uint32" },
{ name: "royaltyBPS", type: "uint32" },
{ name: "royaltyRecipient", type: "address" },
{ name: "fixedPriceMinter", type: "address" },
],
};

const result: TypedDataDefinition<typeof types, "Premint"> = {
const result: TypedDataDefinition<typeof types, "CreatorAttribution"> = {
domain: {
chainId,
name: "Preminter",
version: "0.0.1",
version: "1",
verifyingContract: verifyingContract,
},
types,
Expand All @@ -65,7 +61,7 @@ export const preminterTypedDataDefinition = ({
version,
deleted,
},
primaryType: "Premint",
primaryType: "CreatorAttribution",
};

// console.log({ result, deleted });
Expand Down

0 comments on commit ce80051

Please sign in to comment.