11const { ethers } = require ( 'hardhat' ) ;
22const { expect } = require ( 'chai' ) ;
33const { loadFixture } = require ( '@nomicfoundation/hardhat-network-helpers' ) ;
4+ const { PANIC_CODES } = require ( '@nomicfoundation/hardhat-chai-matchers/panic' ) ;
45const { StandardMerkleTree } = require ( '@openzeppelin/merkle-tree' ) ;
56
67const makeTree = ( leafs = [ ethers . ZeroHash ] ) =>
@@ -32,7 +33,7 @@ describe('Merklee tree', function () {
3233 } ) ;
3334
3435 it ( 'setup' , async function ( ) {
35- const merkleTree = makeTree ( Array ( 2 ** Number ( DEPTH ) ) . fill ( ethers . ZeroHash ) ) ;
36+ const merkleTree = makeTree ( Array . from ( { length : 2 ** Number ( DEPTH ) } , ( ) => ethers . ZeroHash ) ) ;
3637
3738 expect ( await this . mock . getDepth ( ) ) . to . equal ( DEPTH ) ;
3839 expect ( await this . mock . getLength ( ) ) . to . equal ( LENGTH ) ;
@@ -50,7 +51,7 @@ describe('Merklee tree', function () {
5051
5152 describe ( 'insert' , function ( ) {
5253 it ( 'tree is correctly updated' , async function ( ) {
53- const leafs = Array ( 2 ** Number ( DEPTH ) ) . fill ( ethers . ZeroHash ) ;
54+ const leafs = Array . from ( { length : 2 ** Number ( DEPTH ) } , ( ) => ethers . ZeroHash ) ;
5455 const roots = [ ] ;
5556
5657 // for each leaf slot
@@ -81,10 +82,9 @@ describe('Merklee tree', function () {
8182 } ) ;
8283
8384 it ( 'revert when tree is full' , async function ( ) {
84- for ( let i = 0 ; i < 2 ** Number ( DEPTH ) ; ++ i ) {
85- await this . mock . insert ( ethers . ZeroHash ) ;
86- }
87- await expect ( this . mock . insert ( ethers . ZeroHash ) ) . to . be . revertedWithCustomError ( this . mock , 'MerkleTreeFull' ) ;
85+ await Promise . all ( Array . from ( { length : 2 ** Number ( DEPTH ) } ) . map ( ( ) => this . mock . insert ( ethers . ZeroHash ) ) ) ;
86+
87+ await expect ( this . mock . insert ( ethers . ZeroHash ) ) . to . be . revertedWithPanic ( PANIC_CODES . TOO_MUCH_MEMORY_ALLOCATED ) ;
8888 } ) ;
8989 } ) ;
9090} ) ;
0 commit comments