1
1
const { ethers } = require ( 'hardhat' ) ;
2
2
const { expect } = require ( 'chai' ) ;
3
3
const { loadFixture } = require ( '@nomicfoundation/hardhat-network-helpers' ) ;
4
+ const { PANIC_CODES } = require ( '@nomicfoundation/hardhat-chai-matchers/panic' ) ;
5
+
6
+ const { RevertType } = require ( '../helpers/enums' ) ;
4
7
5
8
async function fixture ( ) {
6
9
const [ deployer , other ] = await ethers . getSigners ( ) ;
@@ -19,7 +22,9 @@ async function fixture() {
19
22
. getContractFactory ( '$Create2' )
20
23
. then ( ( { bytecode, interface } ) => ethers . concat ( [ bytecode , interface . encodeDeploy ( [ ] ) ] ) ) ;
21
24
22
- return { deployer, other, factory, constructorByteCode, constructorLessBytecode } ;
25
+ const mockFactory = await ethers . getContractFactory ( 'ConstructorMock' ) ;
26
+
27
+ return { deployer, other, factory, constructorByteCode, constructorLessBytecode, mockFactory } ;
23
28
}
24
29
25
30
describe ( 'Create2' , function ( ) {
@@ -130,5 +135,56 @@ describe('Create2', function () {
130
135
. to . be . revertedWithCustomError ( this . factory , 'InsufficientBalance' )
131
136
. withArgs ( 0n , 1n ) ;
132
137
} ) ;
138
+
139
+ describe ( 'reverts error thrown during contract creation' , function ( ) {
140
+ it ( 'bubbles up without message' , async function ( ) {
141
+ await expect (
142
+ this . factory . $deploy (
143
+ 0n ,
144
+ saltHex ,
145
+ ethers . concat ( [
146
+ this . mockFactory . bytecode ,
147
+ this . mockFactory . interface . encodeDeploy ( [ RevertType . RevertWithoutMessage ] ) ,
148
+ ] ) ,
149
+ ) ,
150
+ ) . to . be . revertedWithCustomError ( this . factory , 'FailedDeployment' ) ;
151
+ } ) ;
152
+
153
+ it ( 'bubbles up message' , async function ( ) {
154
+ await expect (
155
+ this . factory . $deploy (
156
+ 0n ,
157
+ saltHex ,
158
+ ethers . concat ( [
159
+ this . mockFactory . bytecode ,
160
+ this . mockFactory . interface . encodeDeploy ( [ RevertType . RevertWithMessage ] ) ,
161
+ ] ) ,
162
+ ) ,
163
+ ) . to . be . revertedWith ( 'ConstructorMock: reverting' ) ;
164
+ } ) ;
165
+
166
+ it ( 'bubbles up custom error' , async function ( ) {
167
+ await expect (
168
+ this . factory . $deploy (
169
+ 0n ,
170
+ saltHex ,
171
+ ethers . concat ( [
172
+ this . mockFactory . bytecode ,
173
+ this . mockFactory . interface . encodeDeploy ( [ RevertType . RevertWithCustomError ] ) ,
174
+ ] ) ,
175
+ ) ,
176
+ ) . to . be . revertedWithCustomError ( { interface : this . mockFactory . interface } , 'CustomError' ) ;
177
+ } ) ;
178
+
179
+ it ( 'bubbles up panic' , async function ( ) {
180
+ await expect (
181
+ this . factory . $deploy (
182
+ 0n ,
183
+ saltHex ,
184
+ ethers . concat ( [ this . mockFactory . bytecode , this . mockFactory . interface . encodeDeploy ( [ RevertType . Panic ] ) ] ) ,
185
+ ) ,
186
+ ) . to . be . revertedWithPanic ( PANIC_CODES . DIVISION_BY_ZERO ) ;
187
+ } ) ;
188
+ } ) ;
133
189
} ) ;
134
190
} ) ;
0 commit comments