1- import { expect } from ' chai' ;
2- import { BigNumber , constants } from ' ethers' ;
3- import { minDeposit , kinds } from ' ../../ utils/constants' ;
4- import { randomId , createSupplierId , createPermitSignature } from ' ./utils' ;
5- import { User , setup , registerEntity } from ' ./setup' ;
1+ import { expect } from " chai" ;
2+ import { BigNumber , constants } from " ethers" ;
3+ import { minDeposit , kinds } from " ../utils/constants" ;
4+ import { randomId , createSupplierId , createPermitSignature } from " ./utils" ;
5+ import { User , setup , registerEntity } from " ./setup" ;
66
7- describe ( ' EntitiesRegistry' , ( ) => {
7+ describe ( " EntitiesRegistry" , ( ) => {
88 let owner : User ;
99 let buyer : User ;
1010 let supplierOwner : User ;
@@ -21,9 +21,9 @@ describe('EntitiesRegistry', () => {
2121 supplierSigner = users . supplierSigner ;
2222 retailerOwner = users . retailerOwner ;
2323
24- await owner . erc20 . mint ( buyer . address , ' 1000000000000000000000000' ) ;
25- await owner . lif . mint ( supplierOwner . address , ' 1000000000000000000000000' ) ;
26- await owner . lif . mint ( retailerOwner . address , ' 1000000000000000000000000' ) ;
24+ await owner . erc20 . mint ( buyer . address , " 1000000000000000000000000" ) ;
25+ await owner . lif . mint ( supplierOwner . address , " 1000000000000000000000000" ) ;
26+ await owner . lif . mint ( retailerOwner . address , " 1000000000000000000000000" ) ;
2727 } ) ;
2828
2929 beforeEach ( async ( ) => {
@@ -36,33 +36,32 @@ describe('EntitiesRegistry', () => {
3636 kinds . supplier ,
3737 supplierSalt ,
3838 supplierOwner . lif ,
39- false ,
39+ false
4040 ) ;
4141 } ) ;
4242
43- describe ( '#toggleEntity(bytes32); #isEntityEnabled(bytes32)' , ( ) => {
44- it ( 'should throw if called not by a owner' , async ( ) => {
45- await expect ( owner . entities . toggleEntity ( supplierId ) ) . to . revertedWithCustomError (
46- owner . entities ,
47- 'NotEntityOwner' ,
48- ) ;
43+ describe ( "#toggleEntity(bytes32); #isEntityEnabled(bytes32)" , ( ) => {
44+ it ( "should throw if called not by a owner" , async ( ) => {
45+ await expect (
46+ owner . entities . toggleEntity ( supplierId )
47+ ) . to . revertedWithCustomError ( owner . entities , "NotEntityOwner" ) ;
4948 } ) ;
5049
51- it ( ' should toggle the supplier state' , async ( ) => {
50+ it ( " should toggle the supplier state" , async ( ) => {
5251 expect ( await supplierOwner . entities . isEntityEnabled ( supplierId ) ) . to . false ;
5352 await supplierOwner . entities . toggleEntity ( supplierId ) ;
5453 expect ( await supplierOwner . entities . isEntityEnabled ( supplierId ) ) . to . true ;
5554 } ) ;
5655 } ) ;
5756
58- describe ( ' #changeSigner(bytes32,address)' , ( ) => {
59- it ( ' should throw if called not by a owner' , async ( ) => {
57+ describe ( " #changeSigner(bytes32,address)" , ( ) => {
58+ it ( " should throw if called not by a owner" , async ( ) => {
6059 await expect (
61- owner . entities . changeSigner ( supplierId , owner . address ) ,
62- ) . to . revertedWithCustomError ( owner . entities , ' NotEntityOwner' ) ;
60+ owner . entities . changeSigner ( supplierId , owner . address )
61+ ) . to . revertedWithCustomError ( owner . entities , " NotEntityOwner" ) ;
6362 } ) ;
6463
65- it ( ' should change the supplier signer' , async ( ) => {
64+ it ( " should change the supplier signer" , async ( ) => {
6665 let supplier = await supplierSigner . entities . getEntity ( supplierId ) ;
6766 expect ( supplier . signer ) . to . eq ( supplierSigner . address ) ;
6867 await supplierOwner . entities . changeSigner ( supplierId , owner . address ) ;
@@ -71,32 +70,32 @@ describe('EntitiesRegistry', () => {
7170 } ) ;
7271 } ) ;
7372
74- describe ( ' #register(bytes32,address)' , ( ) => {
75- it ( ' should register the supplier' , async ( ) => {
73+ describe ( " #register(bytes32,address)" , ( ) => {
74+ it ( " should register the supplier" , async ( ) => {
7675 const supplier = await supplierOwner . entities . getEntity ( supplierId ) ;
7776 expect ( supplier . id ) . to . eq ( supplierId ) ;
7877 } ) ;
7978
80- it ( ' should be initially disabled' , async ( ) => {
79+ it ( " should be initially disabled" , async ( ) => {
8180 expect ( await supplierOwner . entities . isEntityEnabled ( supplierId ) ) . to . false ;
8281 } ) ;
8382
84- it ( ' should throw on attempt to register twice' , async ( ) => {
83+ it ( " should throw on attempt to register twice" , async ( ) => {
8584 await expect (
8685 supplierOwner . entities . register (
8786 kinds . supplier ,
8887 supplierSalt ,
89- supplierSigner . address ,
90- ) ,
91- ) . to . revertedWithCustomError ( supplierOwner . entities , ' EntityExists' ) ;
88+ supplierSigner . address
89+ )
90+ ) . to . revertedWithCustomError ( supplierOwner . entities , " EntityExists" ) ;
9291 } ) ;
9392 } ) ;
9493
95- describe ( ' #addDeposit(bytes32,uit256,bytes); #balanceOfSupplier(bytes32)' , ( ) => {
96- const value = BigNumber . from ( '1' ) ;
94+ describe ( " #addDeposit(bytes32,uit256,bytes); #balanceOfSupplier(bytes32)" , ( ) => {
95+ const value = BigNumber . from ( "1" ) ;
9796 const deadline = Math . floor ( Date . now ( ) / 1000 ) + 3600 ;
9897
99- it ( ' should throw if deposit value to small' , async ( ) => {
98+ it ( " should throw if deposit value to small" , async ( ) => {
10099 const supplierSalt = randomId ( ) ;
101100 const supplierId = createSupplierId ( supplierOwner . address , supplierSalt ) ;
102101
@@ -106,90 +105,110 @@ describe('EntitiesRegistry', () => {
106105 kinds . supplier ,
107106 supplierSalt ,
108107 undefined ,
109- false ,
108+ false
110109 ) ;
111110
112- const notEnoughValue = minDeposit . sub ( BigNumber . from ( '1' ) ) ;
111+ const notEnoughValue = minDeposit . sub ( BigNumber . from ( "1" ) ) ;
113112
114- await supplierOwner . lif . approve ( supplierOwner . entities . address , notEnoughValue ) ;
113+ await supplierOwner . lif . approve (
114+ supplierOwner . entities . address ,
115+ notEnoughValue
116+ ) ;
115117 await expect (
116- supplierOwner . entities [ 'addDeposit(bytes32,uint256)' ] ( supplierId , notEnoughValue ) ,
118+ supplierOwner . entities [ "addDeposit(bytes32,uint256)" ] (
119+ supplierId ,
120+ notEnoughValue
121+ )
117122 ) . to . rejected ;
118123 } ) ;
119124
120- it ( 'should throw if tokens not approved' , async ( ) => {
121- await expect ( supplierOwner . entities [ 'addDeposit(bytes32,uint256)' ] ( supplierId , '1' ) )
122- . to . rejected ;
125+ it ( "should throw if tokens not approved" , async ( ) => {
126+ await expect (
127+ supplierOwner . entities [ "addDeposit(bytes32,uint256)" ] ( supplierId , "1" )
128+ ) . to . rejected ;
123129 } ) ;
124130
125- it ( 'should add deposit' , async ( ) => {
126- const lifBefore = await supplierOwner . lif . balanceOf ( supplierOwner . address ) ;
127- expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq ( minDeposit ) ;
128- const value = BigNumber . from ( '1' ) ;
131+ it ( "should add deposit" , async ( ) => {
132+ const lifBefore = await supplierOwner . lif . balanceOf (
133+ supplierOwner . address
134+ ) ;
135+ expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq (
136+ minDeposit
137+ ) ;
138+ const value = BigNumber . from ( "1" ) ;
129139 await supplierOwner . lif . approve ( supplierOwner . entities . address , value ) ;
130- await supplierOwner . entities [ 'addDeposit(bytes32,uint256)' ] ( supplierId , value ) ;
140+ await supplierOwner . entities [ "addDeposit(bytes32,uint256)" ] (
141+ supplierId ,
142+ value
143+ ) ;
131144 expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq (
132- minDeposit . add ( value ) ,
145+ minDeposit . add ( value )
133146 ) ;
134147 expect ( await supplierOwner . lif . balanceOf ( supplierOwner . address ) ) . to . eq (
135- lifBefore . sub ( value ) ,
148+ lifBefore . sub ( value )
136149 ) ;
137150 } ) ;
138151
139- it ( ' should throw if invalid permit signature provided' , async ( ) => {
152+ it ( " should throw if invalid permit signature provided" , async ( ) => {
140153 await expect (
141- supplierOwner . entities [ ' addDeposit(bytes32,uint256,uint256,bytes)' ] (
154+ supplierOwner . entities [ " addDeposit(bytes32,uint256,uint256,bytes)" ] (
142155 supplierId ,
143156 value ,
144157 deadline ,
145- constants . HashZero ,
146- ) ,
147- ) . to . revertedWithCustomError ( supplierOwner . market , ' InvalidSignature' ) ;
158+ constants . HashZero
159+ )
160+ ) . to . revertedWithCustomError ( supplierOwner . market , " InvalidSignature" ) ;
148161 } ) ;
149162
150- it ( ' should add deposit using permit' , async ( ) => {
163+ it ( " should add deposit using permit" , async ( ) => {
151164 const signature = await createPermitSignature (
152165 supplierOwner . signer ,
153166 supplierOwner . lif ,
154167 supplierOwner . address ,
155168 supplierOwner . entities . address ,
156169 value ,
157- deadline ,
170+ deadline
158171 ) ;
159172
160- expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq ( minDeposit ) ;
161- await supplierOwner . entities [ 'addDeposit(bytes32,uint256,uint256,bytes)' ] (
173+ expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq (
174+ minDeposit
175+ ) ;
176+ await supplierOwner . entities [ "addDeposit(bytes32,uint256,uint256,bytes)" ] (
162177 supplierId ,
163178 value ,
164179 deadline ,
165- signature ,
180+ signature
166181 ) ;
167182 expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq (
168- minDeposit . add ( value ) ,
183+ minDeposit . add ( value )
169184 ) ;
170185 } ) ;
171186 } ) ;
172187
173- describe ( ' #withdrawDeposit(bytes32,uit256,bytes)' , ( ) => {
174- it ( ' should throw if balance not enough' , async ( ) => {
188+ describe ( " #withdrawDeposit(bytes32,uit256,bytes)" , ( ) => {
189+ it ( " should throw if balance not enough" , async ( ) => {
175190 const balance = await supplierOwner . entities . balanceOfEntity ( supplierId ) ;
176191 await expect (
177192 supplierOwner . entities . withdrawDeposit (
178193 supplierId ,
179- balance . add ( BigNumber . from ( '1' ) ) ,
180- ) ,
194+ balance . add ( BigNumber . from ( "1" ) )
195+ )
181196 ) . to . rejected ;
182197 } ) ;
183198
184- it ( 'should withdraw deposit' , async ( ) => {
185- const lifBefore = await supplierOwner . lif . balanceOf ( supplierOwner . address ) ;
186- expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq ( minDeposit ) ;
199+ it ( "should withdraw deposit" , async ( ) => {
200+ const lifBefore = await supplierOwner . lif . balanceOf (
201+ supplierOwner . address
202+ ) ;
203+ expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq (
204+ minDeposit
205+ ) ;
187206 await supplierOwner . entities . withdrawDeposit ( supplierId , minDeposit ) ;
188207 expect ( await supplierOwner . entities . balanceOfEntity ( supplierId ) ) . to . eq (
189- constants . Zero ,
208+ constants . Zero
190209 ) ;
191210 expect ( await supplierOwner . lif . balanceOf ( supplierOwner . address ) ) . to . eq (
192- lifBefore . add ( minDeposit ) ,
211+ lifBefore . add ( minDeposit )
193212 ) ;
194213 } ) ;
195214 } ) ;
0 commit comments