@@ -238,4 +238,73 @@ export const changeEtherBalancesTest = (
238
238
} ) ;
239
239
} ) ;
240
240
} ) ;
241
+
242
+ describe ( 'changeEtherBalances - error margin' , ( ) => {
243
+ it ( 'positive' , async ( ) => {
244
+ await expect ( sender . sendTransaction ( {
245
+ to : receiver . address ,
246
+ value : 200
247
+ } ) ) . to . changeEtherBalances ( [ receiver , sender ] , [ 300 , - 300 ] , { errorMargin : 100 } ) ;
248
+ } ) ;
249
+
250
+ it ( 'negative' , async ( ) => {
251
+ await expect ( sender . sendTransaction ( {
252
+ to : receiver . address ,
253
+ value : 200
254
+ } ) ) . to . not . changeEtherBalances ( [ receiver , sender ] , [ 300 , - 300 ] , { errorMargin : 99 } ) ;
255
+ } ) ;
256
+
257
+ describe ( 'Throws' , ( ) => {
258
+ it ( 'too high' , async ( ) => {
259
+ await expect (
260
+ expect ( await sender . sendTransaction ( {
261
+ to : receiver . address ,
262
+ value : 300
263
+ } ) ) . to . changeEtherBalances ( [ receiver , sender ] , [ 250 , - 250 ] , { errorMargin : 40 } )
264
+ ) . to . be . eventually . rejectedWith (
265
+ AssertionError ,
266
+ `Expected "${ receiver . address } " balance to change within [210,290] wei, ` +
267
+ 'but it has changed by 300 wei'
268
+ ) ;
269
+ } ) ;
270
+
271
+ it ( 'too low' , async ( ) => {
272
+ await expect (
273
+ expect ( await sender . sendTransaction ( {
274
+ to : receiver . address ,
275
+ value : 200
276
+ } ) ) . to . changeEtherBalances ( [ receiver , sender ] , [ 250 , - 250 ] , { errorMargin : 40 } )
277
+ ) . to . be . eventually . rejectedWith (
278
+ AssertionError ,
279
+ `Expected "${ receiver . address } " balance to change within [210,290] wei, ` +
280
+ 'but it has changed by 200 wei'
281
+ ) ;
282
+ } ) ;
283
+
284
+ it ( 'negated' , async ( ) => {
285
+ await expect (
286
+ expect ( await sender . sendTransaction ( {
287
+ to : receiver . address ,
288
+ value : 300
289
+ } ) ) . to . not . changeEtherBalances ( [ receiver , sender ] , [ 290 , - 290 ] , { errorMargin : 40 } )
290
+ ) . to . be . eventually . rejectedWith (
291
+ AssertionError ,
292
+ `Expected "${ receiver . address } " balance to not change within [250,330] wei`
293
+ ) ;
294
+ } ) ;
295
+
296
+ it ( 'second address' , async ( ) => {
297
+ await expect (
298
+ expect ( await sender . sendTransaction ( {
299
+ to : receiver . address ,
300
+ value : 200
301
+ } ) ) . to . changeEtherBalances ( [ receiver , sender ] , [ 210 , - 250 ] , { errorMargin : 40 } )
302
+ ) . to . be . eventually . rejectedWith (
303
+ AssertionError ,
304
+ `Expected "${ sender . address } " balance to change within [-290,-210] wei, ` +
305
+ 'but it has changed by -200 wei'
306
+ ) ;
307
+ } ) ;
308
+ } ) ;
309
+ } ) ;
241
310
} ;
0 commit comments