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 path17_holographer_tests.ts
More file actions
161 lines (133 loc) · 6.95 KB
/
17_holographer_tests.ts
File metadata and controls
161 lines (133 loc) · 6.95 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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { Holographer, MockExternalCall, MockExternalCall__factory } from '../typechain-types';
import Web3 from 'web3';
import setup, { PreTest } from './utils';
import { HOLOGRAPHER_ALREADY_INITIALIZED_ERROR_MSG } from './utils/error_constants';
import { generateErc721Config, generateInitCode, Signature, StrictECDSA } from '../scripts/utils/helpers';
import { ConfigureEvents, HolographERC721Event } from '../scripts/utils/events';
import { DeploymentConfigStruct } from '../typechain-types/HolographFactory';
describe('Holograph Holographer Contract', function () {
const web3 = new Web3();
let chain1: PreTest;
let holographer: Holographer;
let mockExternalCall: MockExternalCall;
let deployer: SignerWithAddress;
let holograph: string;
let erc721ConfigEncodedInfo: DeploymentConfigStruct;
const contractType = '0x' + web3.utils.asciiToHex('HolographERC721').substring(2).padStart(64, '0');
before(async () => {
[deployer] = await ethers.getSigners();
chain1 = await setup();
let { erc721Config, erc721ConfigHash, erc721ConfigHashBytes } = await generateErc721Config(
chain1.network, // reference to hardhat network object
chain1.deployer.address, // address of creator of contract
'SampleERC721', // contract bytecode to use
'Sample ERC721 Contract: unit test', // name of contract
'SMPLR', // token symbol of contract
1000, // royalties to use (bps 10%) <- erc721 specific
ConfigureEvents([
// events to connect / capture for SampleERC721
HolographERC721Event.bridgeIn,
HolographERC721Event.bridgeOut,
HolographERC721Event.afterBurn,
]),
generateInitCode(['address'], [chain1.deployer.address]), // init code for SampleERC721 itself
chain1.salt // random bytes32 salt that you decide to assign this config, used again on other chains to guarantee uniqueness if all above vars are same for another contract for some reason
);
const sig = await deployer.signMessage(erc721ConfigHashBytes);
const signature: Signature = StrictECDSA({
r: '0x' + sig.substring(2, 66),
s: '0x' + sig.substring(66, 130),
v: '0x' + sig.substring(130, 132),
} as Signature);
const depoyTx = await chain1.factory
.connect(deployer)
.deployHolographableContract(erc721Config, signature, deployer.address);
const deployResult = await depoyTx.wait();
const event = deployResult.events?.find((event: any) => event.event === 'BridgeableContractDeployed');
if (!event) throw new Error('BridgeableContractDeployed event not fired');
const [holographerAddress] = event?.args || ['', ''];
holographer = await ethers.getContractAt('Holographer', holographerAddress);
const mockExternalCallFactory = await ethers.getContractFactory<MockExternalCall__factory>('MockExternalCall');
mockExternalCall = await mockExternalCallFactory.deploy();
await mockExternalCall.deployed();
erc721ConfigEncodedInfo = erc721Config;
holograph = chain1.holograph.address;
});
describe('constructor', async function () {
it('should successfully deploy', async function () {
expect(holographer.address).to.not.equal(ethers.constants.AddressZero);
});
});
describe('init()', () => {
it('should fail if already initialized', async () => {
const initCode = generateInitCode(['address', 'bytes32[]'], [deployer.address, []]);
await expect(holographer.connect(deployer).init(initCode)).to.be.revertedWith(
HOLOGRAPHER_ALREADY_INITIALIZED_ERROR_MSG
);
});
});
describe(`getDeploymentBlock()`, async function () {
it('Should return valid _blockHeightSlot', async () => {
expect(await holographer.getDeploymentBlock()).to.not.equal(ethers.constants.AddressZero);
});
it('Should allow external contract to call fn', async () => {
let ABI = ['function getDeploymentBlock() external view returns (address holograph) '];
let iface = new ethers.utils.Interface(ABI);
let encodedFunctionData = iface.encodeFunctionData('getDeploymentBlock', []);
await expect(mockExternalCall.connect(deployer).callExternalFn(holographer.address, encodedFunctionData)).to.not
.be.reverted;
});
});
describe(`getHolograph()`, async function () {
it('Should return valid _holographSlot', async () => {
expect(await holographer.getHolograph()).to.equal(holograph);
});
it('Should allow external contract to call fn', async () => {
let ABI = ['function getHolograph() external view returns (address holograph)'];
let iface = new ethers.utils.Interface(ABI);
let encodedFunctionData = iface.encodeFunctionData('getHolograph', []);
await expect(mockExternalCall.connect(deployer).callExternalFn(holographer.address, encodedFunctionData)).to.not
.be.reverted;
});
});
describe(`getOriginChain()`, async function () {
it('Should return valid _originChainSlot', async () => {
const chainID = await chain1.holograph.getHolographChainId();
expect(await holographer.getOriginChain()).to.equal(chainID);
});
it('Should allow external contract to call fn', async () => {
let ABI = ['function getOriginChain() external view returns (uint32 originChain)'];
let iface = new ethers.utils.Interface(ABI);
let encodedFunctionData = iface.encodeFunctionData('getOriginChain', []);
await expect(mockExternalCall.connect(deployer).callExternalFn(holographer.address, encodedFunctionData)).to.not
.be.reverted;
});
});
describe(`getSourceContract()`, async function () {
it('Should return valid _sourceContractSlot', async () => {
expect(await holographer.getSourceContract()).to.not.equal(ethers.constants.AddressZero);
});
it('Should allow external contract to call fn', async () => {
let ABI = ['function getSourceContract() external view returns (address sourceContract)'];
let iface = new ethers.utils.Interface(ABI);
let encodedFunctionData = iface.encodeFunctionData('getSourceContract', []);
await expect(mockExternalCall.connect(deployer).callExternalFn(holographer.address, encodedFunctionData)).to.not
.be.reverted;
});
});
describe(`getHolographEnforcer()`, async function () {
it('Should return Holograph smart contract that controls and enforces the ERC standards', async () => {
expect(await holographer.getHolographEnforcer()).to.not.equal(ethers.constants.AddressZero);
});
it('Should allow external contract to call fn', async () => {
let ABI = ['function getHolographEnforcer() public view returns (address)'];
let iface = new ethers.utils.Interface(ABI);
let encodedFunctionData = iface.encodeFunctionData('getHolographEnforcer', []);
await expect(mockExternalCall.connect(deployer).callExternalFn(holographer.address, encodedFunctionData)).to.not
.be.reverted;
});
});
});