Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
Add test verifying deterministic deployment of proxy (#398)
Browse files Browse the repository at this point in the history
Add a unit test that verifies that the authenticator proxy is at a deterministically deployed.

### Test Plan

It is a test!
  • Loading branch information
nlordell authored Feb 3, 2021
1 parent 9b5796c commit 0758224
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
19 changes: 14 additions & 5 deletions src/ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Artifact, "abi" | "bytecode">;

/**
* An artifact with a contract name matching one of the deterministically
* deployed contracts.
*/
export interface NamedArtifact<C extends ContractName>
extends Pick<Artifact, "abi" | "bytecode"> {
export interface NamedArtifactDeployment<C extends ContractName>
extends ArtifactDeployment {
contractName: C;
}

type MaybeNamedArtifactArtifactDeployment<C> = C extends ContractName
? NamedArtifactDeployment<C>
: 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.
Expand All @@ -56,8 +65,8 @@ export interface NamedArtifact<C extends ContractName>
* @param deploymentArguments Extra arguments that are necessary to deploy.
* @returns The address that is expected to store the deployed code.
*/
export function deterministicDeploymentAddress<C extends ContractName>(
{ abi, bytecode }: NamedArtifact<C> | Artifact,
export function deterministicDeploymentAddress<C>(
{ abi, bytecode }: MaybeNamedArtifactArtifactDeployment<C>,
deploymentArguments: DeploymentArguments<C>,
): string {
const contractInterface = new utils.Interface(abi);
Expand Down
23 changes: 19 additions & 4 deletions test/e2e/deployment.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 0758224

Please sign in to comment.