diff --git a/packages/contracts/tests/PollFactory.test.ts b/packages/contracts/tests/PollFactory.test.ts index 50a0b12ea8..258325a79b 100644 --- a/packages/contracts/tests/PollFactory.test.ts +++ b/packages/contracts/tests/PollFactory.test.ts @@ -18,7 +18,7 @@ describe("pollFactory", () => { before(async () => { signer = await getDefaultSigner(); - pollFactory = (await deployPollFactory(signer, true)) as BaseContract as PollFactory; + pollFactory = (await deployPollFactory(signer, undefined, true)) as BaseContract as PollFactory; }); describe("deployment", () => { diff --git a/packages/contracts/ts/deploy.ts b/packages/contracts/ts/deploy.ts index 13e1fcd946..11316e3654 100644 --- a/packages/contracts/ts/deploy.ts +++ b/packages/contracts/ts/deploy.ts @@ -236,7 +236,11 @@ export const deployContractWithLinkedLibraries = async ( * @param quiet - whether to suppress console output * @returns the deployed Poll Factory contract */ -export const deployPollFactory = async (signer: Signer, quiet = false): Promise => { +export const deployPollFactory = async ( + signer: Signer, + factory: typeof PollFactoryFactory | undefined, + quiet = false, +): Promise => { const poseidonContracts = await deployPoseidonContracts(signer, {}, quiet); const [poseidonT3Contract, poseidonT4Contract, poseidonT5Contract, poseidonT6Contract] = await Promise.all([ poseidonContracts.PoseidonT3Contract.getAddress(), @@ -245,9 +249,11 @@ export const deployPollFactory = async (signer: Signer, quiet = false): Promise< poseidonContracts.PoseidonT6Contract.getAddress(), ]); + const pollFactory = factory || PollFactoryFactory; + const contractFactory = await createContractFactory( - PollFactoryFactory.abi, - PollFactoryFactory.linkBytecode({ + pollFactory.abi, + pollFactory.linkBytecode({ "contracts/crypto/PoseidonT3.sol:PoseidonT3": poseidonT3Contract, "contracts/crypto/PoseidonT4.sol:PoseidonT4": poseidonT4Contract, "contracts/crypto/PoseidonT5.sol:PoseidonT5": poseidonT5Contract, @@ -270,6 +276,7 @@ export const deployMaci = async ({ signer, poseidonAddresses, stateTreeDepth = 10, + factories, quiet = true, }: IDeployMaciArgs): Promise => { const emptyBallotRoots = genEmptyBallotRoots(stateTreeDepth); @@ -289,7 +296,12 @@ export const deployMaci = async ({ poseidonT6, })); - const contractsToLink = [MACIFactory, PollFactoryFactory, MessageProcessorFactoryFactory, TallyFactoryFactory]; + const contractsToLink = factories || [ + MACIFactory, + PollFactoryFactory, + MessageProcessorFactoryFactory, + TallyFactoryFactory, + ]; // Link Poseidon contracts to MACI const linkedContractFactories = await Promise.all( diff --git a/packages/contracts/ts/types.ts b/packages/contracts/ts/types.ts index 3aa2c72f49..996bca35a0 100644 --- a/packages/contracts/ts/types.ts +++ b/packages/contracts/ts/types.ts @@ -2,12 +2,16 @@ import type { ConstantInitialVoiceCreditProxy, FreeForAllGatekeeper, MACI, + MACI__factory as MACIFactory, + MessageProcessorFactory__factory as MessageProcessorFactoryFactory, MockVerifier, PollFactory, + PollFactory__factory as PollFactoryFactory, PoseidonT3, PoseidonT4, PoseidonT5, PoseidonT6, + TallyFactory__factory as TallyFactoryFactory, VkRegistry, } from "../typechain-types"; import type { BigNumberish, Signer } from "ethers"; @@ -144,6 +148,16 @@ export interface IDeployMaciArgs { poseidonT6: string; }>; + /** + * Custom user defined factories + */ + factories?: [ + typeof MACIFactory, + typeof PollFactoryFactory, + typeof MessageProcessorFactoryFactory, + typeof TallyFactoryFactory, + ]; + /** * The depth of the state tree */