Skip to content

Commit

Permalink
custom error refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio committed Jul 8, 2022
1 parent 20231ea commit 1b32427
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 51 deletions.
3 changes: 2 additions & 1 deletion contracts/Create.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ contract Create {
public
returns (address newContract)
{
if (address(this).balance < amount) revert InsufficientBalance(address(this));
if (address(this).balance < amount)
revert InsufficientBalance(address(this));
if (bytecode.length == 0) revert ZeroBytecodeLength(address(this));
// solhint-disable-next-line no-inline-assembly
assembly ("memory-safe") {
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @type import('hardhat/config').HardhatUserConfig
*/
require("@nomiclabs/hardhat-truffle5");
require("@nomicfoundation/hardhat-chai-matchers");

module.exports = {
solidity: {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@ethereumjs/tx": "^3.5.2",
"@ethersproject/abi": "^5.6.4",
"@ethersproject/providers": "^5.6.8",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.2",
"@nomicfoundation/hardhat-toolbox": "^1.0.1",
"@nomiclabs/hardhat-ethers": "^2.1.0",
Expand Down
22 changes: 9 additions & 13 deletions test/Create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { balance, BN, ether, send } = require("@openzeppelin/test-helpers");
const { expect } = require("chai");
const { Address } = require("ethereumjs-util");
const { web3 } = require("hardhat");
const { expectRevertCustomError } = require("./customError");

const Create = artifacts.require("Create");
const ERC20Mock = artifacts.require("ERC20Mock");
Expand Down Expand Up @@ -156,24 +155,21 @@ contract("Create", function (accounts) {
});

it("fails deploying a contract with invalid constructor bytecode", async function () {
await expectRevertCustomError(
this.factory.deploy(0, 0x1),
`Failed("${this.factory.address}")`
);
expect(await this.factory.deploy(0, 0x1))
.to.be.expectRevertCustomError(this.factory, "Failed")
.withArgs(this.factory.address);
});

it("fails deploying a contract if the bytecode length is zero", async function () {
await expectRevertCustomError(
this.factory.deploy(0, "0x"),
`ZeroBytecodeLength("${this.factory.address}")`
);
expect(await this.factory.deploy(0, "0x"))
.to.be.expectRevertCustomError(this.factory, "ZeroBytecodeLength")
.withArgs(this.factory.address);
});

it("fails deploying a contract if factory contract does not have sufficient balance", async function () {
await expectRevertCustomError(
this.factory.deploy(1, constructorByteCode),
`InsufficientBalance("${this.factory.address}")`
);
expect(await this.factory.deploy(1, constructorByteCode))
.to.be.expectRevertCustomError(this.factory, "InsufficientBalance")
.withArgs(this.factory.address);
});
});
});
29 changes: 0 additions & 29 deletions test/customError.js

This file was deleted.

0 comments on commit 1b32427

Please sign in to comment.