Skip to content

Commit

Permalink
Allow fork rpc and block number to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Nov 15, 2023
1 parent 140e699 commit 06db23c
Showing 1 changed file with 64 additions and 47 deletions.
111 changes: 64 additions & 47 deletions packages/protocol-sdk/src/anvil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,74 @@ async function waitForAnvilInit(anvil: any) {
});
}

export const anvilTest = test.extend<AnvilViemClientsTest>({
viemClients: async ({ task }, use) => {
console.log("setting up clients for ", task.name);
const port = Math.floor(Math.random() * 2000) + 4000;
const anvil = spawn(
"anvil",
[
"--port",
`${port}`,
"--fork-url",
"https://rpc.zora.co/",
"--fork-block-number",
"6133407",
"--chain-id",
"31337",
],
{
cwd: join(__dirname, ".."),
killSignal: "SIGINT",
},
);
const anvilHost = `http://0.0.0.0:${port}`;
await waitForAnvilInit(anvil);
export const makeAnvilTest = ({
forkUrl,
forkBlockNumber,
}: {
forkUrl: string;
forkBlockNumber: number;
}) =>
test.extend<AnvilViemClientsTest>({
viemClients: async ({ task }, use) => {
console.log("setting up clients for ", task.name);
const port = Math.floor(Math.random() * 2000) + 4000;
const anvil = spawn(
"anvil",
[
"--port",
`${port}`,
"--fork-url",
forkUrl,
"--fork-block-number",
`${forkBlockNumber}`,
"--chain-id",
"31337",
],
{
cwd: join(__dirname, ".."),
killSignal: "SIGINT",
},
);
const anvilHost = `http://0.0.0.0:${port}`;
await waitForAnvilInit(anvil);

const chain = {
...foundry,
};
const chain = {
...foundry,
};

const walletClient = createWalletClient({
chain,
transport: http(anvilHost),
});
const walletClient = createWalletClient({
chain,
transport: http(anvilHost),
});

const testClient = createTestClient({
chain,
mode: "anvil",
transport: http(anvilHost),
});
const testClient = createTestClient({
chain,
mode: "anvil",
transport: http(anvilHost),
});

const publicClient = createPublicClient({
chain,
transport: http(anvilHost),
});
const publicClient = createPublicClient({
chain,
transport: http(anvilHost),
});

await use({
publicClient,
walletClient,
testClient,
});
await use({
publicClient,
walletClient,
testClient,
});

// clean up function, called once after all tests run
anvil.kill("SIGINT");
},
});

export const forkUrls = {
zoraMainnet: "https://rpc.zora.co/",
zoraGoerli: "https://testnet.rpc.zora.co",
};

// clean up function, called once after all tests run
anvil.kill("SIGINT");
},
export const anvilTest = makeAnvilTest({
forkUrl: forkUrls.zoraMainnet,
forkBlockNumber: 6133407,
});

0 comments on commit 06db23c

Please sign in to comment.