Skip to content

Commit

Permalink
test: add fixtures to unit test upgradable contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
adjisb committed Sep 20, 2023
1 parent 8f00ef8 commit ca7ca8c
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions packages/marketplace/test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import {ethers} from 'hardhat';
import {Contract, Signer} from 'ethers';

export async function deploy(
name: string,
users: Signer[] = []
): Promise<Contract[]> {
const Contract = await ethers.getContractFactory(name);
const contract = await Contract.deploy();
await contract.waitForDeployment();
const ret = [];
for (const s of users) {
ret.push(await contract.connect(s));
}
ret.push(contract);
return ret;
}

export async function deployWithProxy(
name: string,
users: Signer[] = []
): Promise<Contract[]> {
const contract = await deploy(name, users);

const Proxy = await ethers.getContractFactory('FakeProxy');
// This uses signers[0]
const proxy = await Proxy.deploy(await contract[0].getAddress());
await proxy.waitForDeployment();
const ret = [];
for (let i = 0; i < contract.length; i++) {
ret[i] = await contract[i].attach(await proxy.getAddress());
}
// add implementation contract
ret.push(contract[contract.length - 1]);
return ret;
}

export async function deployAssetMatcher() {
const [deployer, user] = await ethers.getSigners();

const AssetMatcher = await ethers.getContractFactory('AssetMatcher');
const assetMatcherAsDeployer = await AssetMatcher.deploy();
const assetMatcherAsUser = await assetMatcherAsDeployer.connect(user);
// const AssetMatcher = await ethers.getContractFactory('AssetMatcher');
// const assetMatcherAsDeployer = await AssetMatcher.deploy();
// const assetMatcherAsUser = await assetMatcherAsDeployer.connect(user);
const [assetMatcherAsDeployer, assetMatcherAsUser] = await deployWithProxy(
'AssetMatcher',
[deployer, user]
);

return {
assetMatcherAsDeployer,
Expand Down

0 comments on commit ca7ca8c

Please sign in to comment.