Skip to content

Commit f352681

Browse files
committed
add unit testing for Panic
1 parent 05aa60e commit f352681

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/utils/Panic.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { ethers } = require('hardhat');
2+
const { expect } = require('chai');
3+
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
4+
const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');
5+
6+
async function fixture() {
7+
return { mock: await ethers.deployContract('$Panic') };
8+
}
9+
10+
describe('Panic', function () {
11+
beforeEach(async function () {
12+
Object.assign(this, await loadFixture(fixture));
13+
});
14+
15+
for (const [ name, code ] of Object.entries(PANIC_CODES)) {
16+
describe(name, function () {
17+
it(`exposes panic code as constant`, async function () {
18+
expect(await this.mock.getFunction(`$${name}`)()).to.equal(code);
19+
});
20+
21+
it(`throw panic code ${ethers.toBeHex(code)}`, async function () {
22+
await expect(this.mock.$panic(code)).to.be.revertedWithPanic(code);
23+
});
24+
});
25+
}
26+
});

0 commit comments

Comments
 (0)