This repository was archived by the owner on Aug 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy path12_holograph_genesis_tests.ts
More file actions
189 lines (165 loc) · 7.39 KB
/
12_holograph_genesis_tests.ts
File metadata and controls
189 lines (165 loc) · 7.39 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { generateInitCode, zeroAddress, ownerCall, remove0x } from '../scripts/utils/helpers';
describe('Holograph Genesis Contract', async () => {
let HolographGenesis: any;
let holographGenesis: any;
let HolographGenesisChild: any;
let holographGenesisChild: any;
let Mock: any;
let mock: any;
let accounts: SignerWithAddress[];
let deployer: SignerWithAddress;
let newDeployer: SignerWithAddress;
let anotherNewDeployer: SignerWithAddress;
let mockOwner: SignerWithAddress;
before(async () => {
accounts = await ethers.getSigners();
deployer = accounts[0];
newDeployer = accounts[1];
anotherNewDeployer = accounts[2];
mockOwner = accounts[3];
HolographGenesis = await ethers.getContractFactory('HolographGenesis');
holographGenesis = await HolographGenesis.deploy();
await holographGenesis.deployed();
HolographGenesisChild = await ethers.getContractFactory('MockHolographGenesisChild');
holographGenesisChild = await HolographGenesisChild.deploy();
await holographGenesisChild.deployed();
Mock = await ethers.getContractFactory('Mock');
mock = await Mock.deploy();
await mock.deployed();
mock = mock.connect(mockOwner);
await mock.init(generateInitCode(['bytes32'], ['0x' + 'ff'.repeat(32)]));
});
describe('constructor', async () => {
it('should successfully deploy', async () => {
const holographGenesisAddress = holographGenesis.address;
const events = await holographGenesis.queryFilter('Message');
if (events[0].args) {
expect(events[0].args[0]).to.equal('The future of NFTs is Holograph.');
} else {
throw new Error('No events found after deployment of HolographGenesis');
}
expect(holographGenesisAddress).to.not.equal(zeroAddress);
expect(events.length).to.equal(1);
});
});
describe('deploy()', async () => {
it('should succeed in deploying a contract', async () => {
const chainId = (await ethers.provider.getNetwork()).chainId;
await expect(
holographGenesis.deploy(
chainId,
// while running tests, keep in mind that the blockchain might retain some of this data
// because of that, keep incrementing/alternating salts for same contract types
`0x${'00'.repeat(11) + '01'}`,
Mock.bytecode,
generateInitCode(['bytes32'], ['0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd'])
)
).to.not.be.reverted;
});
it('should fail if chainId is not this blockchains chainId', async () => {
const chainId = (await ethers.provider.getNetwork()).chainId;
await expect(
holographGenesis.deploy(
chainId + 1,
`0x${'00'.repeat(11) + '01'}`,
Mock.bytecode,
generateInitCode(['bytes32'], ['0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd'])
)
).to.revertedWith('HOLOGRAPH: incorrect chain id');
});
it('should fail if contract was already deployed', async () => {
const chainId = (await ethers.provider.getNetwork()).chainId;
await expect(
holographGenesis.deploy(
chainId,
`0x${'00'.repeat(11) + '01'}`,
Mock.bytecode,
generateInitCode(['bytes32'], ['0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd'])
)
).to.revertedWith('HOLOGRAPH: already deployed');
});
it('should fail if the deployment failed', async () => {
const chainId = (await ethers.provider.getNetwork()).chainId;
await expect(
holographGenesis.deploy(
chainId,
`0x${'00'.repeat(11) + '02'}`, // incrementing salt with last byte
'0x',
generateInitCode(['bytes32'], ['0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd'])
)
).to.revertedWith('HOLOGRAPH: deployment failed');
});
it('should fail if contract init code does not match the init selector', async () => {
const chainId = (await ethers.provider.getNetwork()).chainId;
await expect(
holographGenesisChild.deploy(
chainId,
`0x${'00'.repeat(11) + '03'}`,
Mock.bytecode,
generateInitCode(['bytes32'], ['0x00000000000000000000000000000000000000000000000000000000000000'])
)
).to.revertedWith('HOLOGRAPH: initialization failed');
});
});
describe(`approveDeployer()`, async () => {
it('Should allow deployer wallet to add to approved deployers', async () => {
const tx = await holographGenesis.approveDeployer(newDeployer.address, true);
await tx.wait();
const isApprovedDeployer = await holographGenesis.isApprovedDeployer(newDeployer.address);
expect(isApprovedDeployer).to.equal(true);
});
it('should fail non-deployer wallet to add approved deployers', async () => {
await expect(holographGenesis.connect(mockOwner).approveDeployer(newDeployer.address, true)).to.be.revertedWith(
'HOLOGRAPH: deployer not approved'
);
});
it('Should allow external contract to call fn', async () => {
let tx = await holographGenesis.approveDeployer(mock.address, true);
await tx.wait();
expect(await holographGenesis.isApprovedDeployer(mock.address)).to.equal(true);
await expect(
mock.mockCall(
holographGenesis.address,
(
await holographGenesis.populateTransaction.approveDeployer(anotherNewDeployer.address, true)
).data
)
).to.not.be.reverted;
expect(await holographGenesis.isApprovedDeployer(anotherNewDeployer.address)).to.equal(true);
});
it('should allow inherited contract to call fn', async () => {
let tx = await holographGenesisChild.approveDeployer(newDeployer.address, true);
await tx.wait();
const isApprovedDeployer = await holographGenesisChild.isApprovedDeployer(newDeployer.address);
expect(isApprovedDeployer).to.equal(true);
});
});
describe(`isApprovedDeployer()`, async () => {
it('Should return true to approved deployer wallet', async () => {
const isApprovedDeployer = await holographGenesis.isApprovedDeployer(deployer.address);
expect(isApprovedDeployer).to.equal(true);
});
it('Should return false to non-approved deployer wallet', async () => {
const isApprovedDeployer = await holographGenesis.isApprovedDeployer(accounts[10].address);
expect(isApprovedDeployer).to.equal(false);
});
it('Should allow external contract to call fn', async () => {
// setting fallback address
await mock.setStorage(0, '0x' + remove0x(holographGenesis.address).padStart(64, '0'));
// this triggers mock contract fallback which then directly calls the real target contract
expect(await holographGenesis.attach(mock.address).isApprovedDeployer(deployer.address)).to.equal(true);
});
it('should allow inherited contract to call fn', async () => {
const isApprovedDeployer = await holographGenesisChild.isApprovedDeployerMock(deployer.address);
expect(isApprovedDeployer).to.equal(true);
});
});
describe.skip('_isContract()', async () => {
it('should not be callable from an external contract', async () => {
await expect(holographGenesis.connect(mock.address)['_isContract'](deployer.address)).to.be.revertedWith('TODO');
});
});
});