|
@@ -1,6 +1,9 @@
|
|
|
const { ethers } = require('hardhat');
|
|
|
const { expect } = require('chai');
|
|
|
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
|
|
+const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');
|
|
|
+
|
|
|
+const { RevertType } = require('../helpers/enums');
|
|
|
|
|
|
async function fixture() {
|
|
|
const [deployer, other] = await ethers.getSigners();
|
|
@@ -19,7 +22,9 @@ async function fixture() {
|
|
|
.getContractFactory('$Create2')
|
|
|
.then(({ bytecode, interface }) => ethers.concat([bytecode, interface.encodeDeploy([])]));
|
|
|
|
|
|
- return { deployer, other, factory, constructorByteCode, constructorLessBytecode };
|
|
|
+ const mockFactory = await ethers.getContractFactory('ConstructorMock');
|
|
|
+
|
|
|
+ return { deployer, other, factory, constructorByteCode, constructorLessBytecode, mockFactory };
|
|
|
}
|
|
|
|
|
|
describe('Create2', function () {
|
|
@@ -130,5 +135,56 @@ describe('Create2', function () {
|
|
|
.to.be.revertedWithCustomError(this.factory, 'InsufficientBalance')
|
|
|
.withArgs(0n, 1n);
|
|
|
});
|
|
|
+
|
|
|
+ describe('reverts error thrown during contract creation', function () {
|
|
|
+ it('bubbles up without message', async function () {
|
|
|
+ await expect(
|
|
|
+ this.factory.$deploy(
|
|
|
+ 0n,
|
|
|
+ saltHex,
|
|
|
+ ethers.concat([
|
|
|
+ this.mockFactory.bytecode,
|
|
|
+ this.mockFactory.interface.encodeDeploy([RevertType.RevertWithoutMessage]),
|
|
|
+ ]),
|
|
|
+ ),
|
|
|
+ ).to.be.revertedWithCustomError(this.factory, 'FailedDeployment');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('bubbles up message', async function () {
|
|
|
+ await expect(
|
|
|
+ this.factory.$deploy(
|
|
|
+ 0n,
|
|
|
+ saltHex,
|
|
|
+ ethers.concat([
|
|
|
+ this.mockFactory.bytecode,
|
|
|
+ this.mockFactory.interface.encodeDeploy([RevertType.RevertWithMessage]),
|
|
|
+ ]),
|
|
|
+ ),
|
|
|
+ ).to.be.revertedWith('ConstructorMock: reverting');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('bubbles up custom error', async function () {
|
|
|
+ await expect(
|
|
|
+ this.factory.$deploy(
|
|
|
+ 0n,
|
|
|
+ saltHex,
|
|
|
+ ethers.concat([
|
|
|
+ this.mockFactory.bytecode,
|
|
|
+ this.mockFactory.interface.encodeDeploy([RevertType.RevertWithCustomError]),
|
|
|
+ ]),
|
|
|
+ ),
|
|
|
+ ).to.be.revertedWithCustomError({ interface: this.mockFactory.interface }, 'CustomError');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('bubbles up panic', async function () {
|
|
|
+ await expect(
|
|
|
+ this.factory.$deploy(
|
|
|
+ 0n,
|
|
|
+ saltHex,
|
|
|
+ ethers.concat([this.mockFactory.bytecode, this.mockFactory.interface.encodeDeploy([RevertType.Panic])]),
|
|
|
+ ),
|
|
|
+ ).to.be.revertedWithPanic(PANIC_CODES.DIVISION_BY_ZERO);
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
});
|