forked from thegostep/solidity-create2-deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
115 lines (97 loc) · 3.5 KB
/
test.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
import { ethers } from 'hardhat'
import { Contract, ContractFactory, Signer } from 'ethers'
import { assert } from 'chai'
import {
deployContract,
getCreate2Address,
isDeployed,
} from '../src/index'
import { factoryAbi, factoryBytecode } from '../src/factory'
describe('Happy Path', function () {
let signer: Signer
let accountContractFactory: ContractFactory
let factoryContract: Contract
before(async () => {
signer = (await ethers.getSigners())[0];
accountContractFactory = await ethers.getContractFactory('Account');
var proxy = new ethers.ContractFactory(factoryAbi, factoryBytecode, signer);
factoryContract = await proxy.deploy();
// Wait for the transaction to be mined so we can get the actual contract that was created
await factoryContract.deployTransaction.wait();
})
it('should deploy factory', async function () {
var proxy = new ethers.ContractFactory(factoryAbi, factoryBytecode, signer);
var deployedProxy = await proxy.deploy();
// Wait for the transaction to be mined so we can get the actual contract that was created
await deployedProxy.deployTransaction.wait();
})
it('should deploy a working contract', async function () {
const salt = 'owner'
const result = await deployContract({
salt,
factory: factoryContract,
contractBytecode: accountContractFactory.bytecode,
constructorTypes: ['address'],
constructorArgs: ['0x303de46de694cC75A2F66dA93Ac86c6a6EeE607e']
});
const accountContract = accountContractFactory.attach(result.address);
assert(
(await accountContract.owner()) === '0x303de46de694cC75A2F66dA93Ac86c6a6EeE607e',
'Owner is not the expcted one'
);
})
it('should deploy with string salt', async function () {
const salt = 'hello'
const computedAddr = getCreate2Address({
salt,
factoryAddress: factoryContract.address,
contractBytecode: accountContractFactory.bytecode,
constructorTypes: ['address'],
constructorArgs: ['0x303de46de694cc75a2f66da93ac86c6a6eee607e'],
});
assert(
!(await isDeployed(computedAddr, ethers.provider)),
'contract already deployed at this address',
);
const result = await deployContract({
salt,
factory: factoryContract,
contractBytecode: accountContractFactory.bytecode,
constructorTypes: ['address'],
constructorArgs: ['0x303de46de694cc75a2f66da93ac86c6a6eee607e']
});
assert(
await isDeployed(computedAddr, ethers.provider),
'contract not deployed at this address',
);
})
it('should deploy with number salt', async function () {
const salt = 1234
const computedAddr = getCreate2Address({
salt,
factoryAddress: factoryContract.address,
contractBytecode: accountContractFactory.bytecode,
constructorTypes: ['address'],
constructorArgs: ['0x303de46de694cc75a2f66da93ac86c6a6eee607e'],
});
assert(
!(await isDeployed(computedAddr, ethers.provider)),
'contract already deployed at this address',
);
const result = await deployContract({
salt,
factory: factoryContract,
contractBytecode: accountContractFactory.bytecode,
constructorTypes: ['address'],
constructorArgs: ['0x303de46de694cc75a2f66da93ac86c6a6eee607e']
});
assert(
result.receipt.status === 1,
'Deployment wasn\'t successful'
);
assert(
await isDeployed(computedAddr, ethers.provider),
'contract not deployed at this address',
);
})
})