From 075822413851ffbd56567ca77def6e44014babde Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Wed, 3 Feb 2021 16:54:52 +0100 Subject: [PATCH] Add test verifying deterministic deployment of proxy (#398) Add a unit test that verifies that the authenticator proxy is at a deterministically deployed. ### Test Plan It is a test! --- src/ts/deploy.ts | 19 ++++++++++++++----- test/e2e/deployment.test.ts | 23 +++++++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/ts/deploy.ts b/src/ts/deploy.ts index 9afd436a..7824ad88 100644 --- a/src/ts/deploy.ts +++ b/src/ts/deploy.ts @@ -32,22 +32,31 @@ export type ContractName = typeof CONTRACT_NAMES[keyof typeof CONTRACT_NAMES]; * The deployment args for a contract. */ export type DeploymentArguments< - T extends ContractName + T > = T extends typeof CONTRACT_NAMES.authenticator ? never : T extends typeof CONTRACT_NAMES.settlement ? [string] : unknown[]; +/** + * Artifact information important for computing deterministic deployments. + */ +export type ArtifactDeployment = Pick; + /** * An artifact with a contract name matching one of the deterministically * deployed contracts. */ -export interface NamedArtifact - extends Pick { +export interface NamedArtifactDeployment + extends ArtifactDeployment { contractName: C; } +type MaybeNamedArtifactArtifactDeployment = C extends ContractName + ? NamedArtifactDeployment + : ArtifactDeployment; + /** * Computes the deterministic address at which the contract will be deployed. * This address does not depend on which network the contract is deployed to. @@ -56,8 +65,8 @@ export interface NamedArtifact * @param deploymentArguments Extra arguments that are necessary to deploy. * @returns The address that is expected to store the deployed code. */ -export function deterministicDeploymentAddress( - { abi, bytecode }: NamedArtifact | Artifact, +export function deterministicDeploymentAddress( + { abi, bytecode }: MaybeNamedArtifactArtifactDeployment, deploymentArguments: DeploymentArguments, ): string { const contractInterface = new utils.Interface(abi); diff --git a/test/e2e/deployment.test.ts b/test/e2e/deployment.test.ts index 0d0cb481..519e2ac9 100644 --- a/test/e2e/deployment.test.ts +++ b/test/e2e/deployment.test.ts @@ -1,6 +1,7 @@ import { expect } from "chai"; import { Contract, Wallet } from "ethers"; import { artifacts } from "hardhat"; +import Proxy from "hardhat-deploy/extendedArtifacts/EIP173Proxy.json"; import { ContractName, @@ -72,10 +73,24 @@ describe("E2E: Deployment", () => { }); describe("deterministic addresses", () => { - it("authenticator", async () => { - expect(await contractAddress("GPv2AllowListAuthentication")).to.equal( - await implementationAddress(authenticator.address), - ); + describe("authenticator", () => { + it("proxy", async () => { + expect( + deterministicDeploymentAddress(Proxy, [ + await implementationAddress(authenticator.address), + authenticator.interface.encodeFunctionData("initializeManager", [ + owner.address, + ]), + owner.address, + ]), + ).to.equal(authenticator.address); + }); + + it("implementation", async () => { + expect(await contractAddress("GPv2AllowListAuthentication")).to.equal( + await implementationAddress(authenticator.address), + ); + }); }); it("settlement", async () => {