Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contracts): support custom factories for maci test deployment #1773

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/contracts/tests/PollFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
20 changes: 16 additions & 4 deletions packages/contracts/ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ export const deployContractWithLinkedLibraries = async <T extends BaseContract>(
* @param quiet - whether to suppress console output
* @returns the deployed Poll Factory contract
*/
export const deployPollFactory = async (signer: Signer, quiet = false): Promise<PollFactory> => {
export const deployPollFactory = async (
signer: Signer,
factory: typeof PollFactoryFactory | undefined,
quiet = false,
): Promise<PollFactory> => {
const poseidonContracts = await deployPoseidonContracts(signer, {}, quiet);
const [poseidonT3Contract, poseidonT4Contract, poseidonT5Contract, poseidonT6Contract] = await Promise.all([
poseidonContracts.PoseidonT3Contract.getAddress(),
Expand All @@ -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,
Expand All @@ -270,6 +276,7 @@ export const deployMaci = async ({
signer,
poseidonAddresses,
stateTreeDepth = 10,
factories,
quiet = true,
}: IDeployMaciArgs): Promise<IDeployedMaci> => {
const emptyBallotRoots = genEmptyBallotRoots(stateTreeDepth);
Expand All @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions packages/contracts/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
*/
Expand Down
Loading