File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments