-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathMinimalProxyFactory.ts
118 lines (98 loc) · 3.91 KB
/
MinimalProxyFactory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { describeBehaviorOfMinimalProxyFactory } from '@solidstate/spec';
import {
MinimalProxyFactoryMock,
MinimalProxyFactoryMock__factory,
} from '@solidstate/typechain-types';
import { expect } from 'chai';
import { ethers } from 'hardhat';
describe('MinimalProxyFactory', function () {
let instance: MinimalProxyFactoryMock;
beforeEach(async function () {
const [deployer] = await ethers.getSigners();
instance = await new MinimalProxyFactoryMock__factory(deployer).deploy();
});
describeBehaviorOfMinimalProxyFactory(async () => instance, {});
describe('__internal', function () {
describe('#_deployMinimalProxy(address)', function () {
it('deploys minimal proxy and returns deployment address', async function () {
const target = instance.address;
const address = await instance.callStatic[
'__deployMinimalProxy(address)'
](target);
expect(address).to.be.properAddress;
await instance['__deployMinimalProxy(address)'](target);
expect(await ethers.provider.getCode(address)).to.equal(
'0x' +
[
'363d3d373d3d3d363d73',
target.replace('0x', '').toLowerCase(),
'5af43d82803e903d91602b57fd5bf3',
].join(''),
);
});
describe('reverts if', function () {
it('contract creation fails');
});
});
describe('#_deployMinimalProxy(address,bytes32)', function () {
it('deploys minimal proxy and returns deployment address', async function () {
const target = instance.address;
const salt = ethers.utils.randomBytes(32);
const address = await instance.callStatic[
'__deployMinimalProxy(address,bytes32)'
](target, salt);
expect(address).to.be.properAddress;
await instance['__deployMinimalProxy(address,bytes32)'](target, salt);
expect(await ethers.provider.getCode(address)).to.equal(
'0x' +
[
'363d3d373d3d3d363d73',
target.replace('0x', '').toLowerCase(),
'5af43d82803e903d91602b57fd5bf3',
].join(''),
);
});
describe('reverts if', function () {
it('contract creation fails');
it('salt has already been used', async function () {
const target = instance.address;
const salt = ethers.utils.randomBytes(32);
await instance['__deployMinimalProxy(address,bytes32)'](target, salt);
await expect(
instance['__deployMinimalProxy(address,bytes32)'](target, salt),
).to.be.revertedWith('Factory: failed deployment');
});
});
});
describe('#_calculateMinimalProxyDeploymentAddress(address,bytes32)', function () {
it('returns address of not-yet-deployed contract', async function () {
const target = instance.address;
const initCode =
await instance.callStatic.__generateMinimalProxyInitCode(target);
const initCodeHash = ethers.utils.keccak256(initCode);
const salt = ethers.utils.randomBytes(32);
expect(
await instance.callStatic.__calculateMinimalProxyDeploymentAddress(
target,
salt,
),
).to.equal(ethers.utils.getCreate2Address(target, salt, initCodeHash));
});
});
describe('#_generateMinimalProxyInitCode(address)', function () {
it('returns packed encoding of initialization code prefix, target address, and initialization code suffix', async function () {
const target = instance.address;
const initCode =
await instance.callStatic.__generateMinimalProxyInitCode(target);
expect(initCode).to.equal(
'0x' +
[
'3d602d80600a3d3981f3363d3d373d3d3d363d73',
target.replace('0x', '').toLowerCase(),
'5af43d82803e903d91602b57fd5bf3',
].join(''),
);
});
});
});
});