Skip to content

Commit

Permalink
Fixed premint client test by having it use the latest anvil fork block #
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Nov 27, 2023
1 parent d06a39b commit 3760350
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions packages/protocol-sdk/src/premint/premint-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { foundry } from "viem/chains";
import { describe, expect, vi } from "vitest";
import { createPremintClient } from "./premint-client";
import { anvilTest } from "src/anvil";
import { anvilTest, forkUrls, makeAnvilTest } from "src/anvil";
import { BackendChainNamesLookup } from "src/apis/chain-constants";

describe("ZoraCreator1155Premint", () => {
anvilTest(
makeAnvilTest({
forkUrl: forkUrls.zoraGoerli,
forkBlockNumber: 1763437,
})(
"can sign on the forked premint contract",
async ({ viemClients: { walletClient, publicClient } }) => {
const [deployerAccount] = await walletClient.getAddresses();
Expand Down
7 changes: 4 additions & 3 deletions packages/protocol-sdk/src/premint/premint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
PremintConfigV1,
PremintConfigV2,
PremintConfigVersion,
getPremintExecutorAddress,
isValidSignature,
premintTypedDataDefinition,
} from "./preminter";
Expand Down Expand Up @@ -389,7 +390,7 @@ class PremintClient extends ClientBase {
tokenContract: verifyingContract,
originalContractAdmin: collection.contractAdmin as Address,
...premintConfigAndVersion,
publicClient: this.getPublicClient(),
publicClient,
signature
});
if (!isAuthorized) {
Expand Down Expand Up @@ -456,7 +457,7 @@ class PremintClient extends ClientBase {
publicClient = this.getPublicClient(publicClient);

const newContractAddress = await publicClient.readContract({
address: this.getExecutorAddress(),
address: getPremintExecutorAddress(),
abi: zoraCreator1155PremintExecutorImplABI,
functionName: "getContractAddress",
args: [convertCollection(collection)],
Expand Down Expand Up @@ -484,7 +485,7 @@ class PremintClient extends ClientBase {

let deleted = executionSettings?.deleted || false;

const premintConfig = {
const premintConfig: PremintConfigV1 = {
tokenConfig: tokenConfig,
uid,
version: 1,
Expand Down
11 changes: 5 additions & 6 deletions packages/protocol-sdk/src/premint/preminter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export async function recoverAndValidateSignature({
signature: Hex;
publicClient: PublicClient;
}): Promise<IsValidSignatureReturn> {
let recoveredAddress: Address;
let recoveredAddress: Address | undefined;

try {
recoveredAddress = await recoverTypedDataAddress({
Expand All @@ -243,12 +243,11 @@ export async function recoverAndValidateSignature({
};
}

// premint executor is same address on all chains
const premintExecutorAddress = getPremintExecutorAddress();

const isAuthorized = await publicClient.readContract({
let isAuthorized = false;
if (recoveredAddress)
isAuthorized = await publicClient.readContract({
abi: preminterAbi,
address: premintExecutorAddress,
address: getPremintExecutorAddress(),
functionName: "isAuthorizedToCreatePremint",
args: [recoveredAddress, premintConfigContractAdmin, tokenContract],
});
Expand Down

0 comments on commit 3760350

Please sign in to comment.