1
1
const expectEvent = require ( '../expectEvent' ) ;
2
+ const shouldFail = require ( '../shouldFail' ) ;
3
+
2
4
const EventEmitter = artifacts . require ( 'EventEmitter' ) ;
5
+ const IndirectEventEmitter = artifacts . require ( 'IndirectEventEmitter' ) ;
3
6
4
7
const BigNumber = web3 . BigNumber ;
5
8
const should = require ( 'chai' )
@@ -8,7 +11,57 @@ const should = require('chai')
8
11
9
12
describe ( 'expectEvent' , function ( ) {
10
13
beforeEach ( async function ( ) {
11
- this . emitter = await EventEmitter . new ( ) ;
14
+ this . constructionValues = {
15
+ uint : 42 ,
16
+ boolean : true ,
17
+ string : 'OpenZeppelin' ,
18
+ } ;
19
+
20
+ this . emitter = await EventEmitter . new (
21
+ this . constructionValues . uint ,
22
+ this . constructionValues . boolean ,
23
+ this . constructionValues . string
24
+ ) ;
25
+ } ) ;
26
+
27
+ describe ( 'inConstructor' , function ( ) {
28
+ context ( 'short uint value' , function ( ) {
29
+ it ( 'accepts emitted events with correct number' , async function ( ) {
30
+ await expectEvent . inConstruction ( this . emitter , 'ShortUint' ,
31
+ { value : this . constructionValues . uint }
32
+ ) ;
33
+ } ) ;
34
+
35
+ it ( 'throws if an incorrect value is passed' , async function ( ) {
36
+ await shouldFail ( expectEvent . inConstruction ( this . emitter , 'ShortUint' , { value : 23 } ) ) ;
37
+ } ) ;
38
+ } ) ;
39
+
40
+ context ( 'boolean value' , function ( ) {
41
+ it ( 'accepts emitted events with correct value' , async function ( ) {
42
+ await expectEvent . inConstruction ( this . emitter , 'Boolean' , { value : this . constructionValues . boolean } ) ;
43
+ } ) ;
44
+
45
+ it ( 'throws if an incorrect value is passed' , async function ( ) {
46
+ await shouldFail ( expectEvent . inConstruction ( this . emitter , 'Boolean' ,
47
+ { value : ! this . constructionValues . boolean }
48
+ ) ) ;
49
+ } ) ;
50
+ } ) ;
51
+
52
+ context ( 'string value' , function ( ) {
53
+ it ( 'accepts emitted events with correct string' , async function ( ) {
54
+ await expectEvent . inConstruction ( this . emitter , 'String' , { value : this . constructionValues . string } ) ;
55
+ } ) ;
56
+
57
+ it ( 'throws if an incorrect string is passed' , async function ( ) {
58
+ await shouldFail ( expectEvent . inConstruction ( this . emitter , 'String' , { value : 'ClosedZeppelin' } ) ) ;
59
+ } ) ;
60
+ } ) ;
61
+
62
+ it ( 'throws if an unemitted event is requested' , async function ( ) {
63
+ await shouldFail ( expectEvent . inConstruction ( this . emitter , 'UnemittedEvent' ) ) ;
64
+ } ) ;
12
65
} ) ;
13
66
14
67
describe ( 'inLogs' , function ( ) {
@@ -228,5 +281,98 @@ describe('expectEvent', function () {
228
281
should . Throw ( ( ) => expectEvent . inLogs ( this . logs , 'Boolean' , { value : false } ) ) ;
229
282
} ) ;
230
283
} ) ;
284
+
285
+ describe ( 'with events emitted by an indirectly called contract' , function ( ) {
286
+ beforeEach ( async function ( ) {
287
+ this . secondEmitter = await IndirectEventEmitter . new ( ) ;
288
+
289
+ this . value = 'OpenZeppelin' ;
290
+ ( { logs : this . logs } = await this . emitter . emitStringAndEmitIndirectly ( this . value , this . secondEmitter . address ) ) ;
291
+ } ) ;
292
+
293
+ it ( 'accepts events emitted by the directly called contract' , function ( ) {
294
+ expectEvent . inLogs ( this . logs , 'String' , { value : this . value } ) ;
295
+ } ) ;
296
+
297
+ it ( 'throws when passing events emitted by the indirectly called contract' , function ( ) {
298
+ should . Throw ( ( ) => expectEvent . inLogs ( this . logs , 'IndirectString' , { value : this . value } ) ) ;
299
+ } ) ;
300
+ } ) ;
301
+ } ) ;
302
+
303
+ describe ( 'inTransaction' , function ( ) {
304
+ describe ( 'when emitting from called contract and indirect calls' , function ( ) {
305
+ context ( 'string value' , function ( ) {
306
+ beforeEach ( async function ( ) {
307
+ this . secondEmitter = await IndirectEventEmitter . new ( ) ;
308
+
309
+ this . value = 'OpenZeppelin' ;
310
+ const receipt = await this . emitter . emitStringAndEmitIndirectly ( this . value , this . secondEmitter . address ) ;
311
+ this . txHash = receipt . tx ;
312
+ } ) ;
313
+
314
+ context ( 'with directly called contract' , function ( ) {
315
+ it ( 'accepts emitted events with correct string' , async function ( ) {
316
+ await expectEvent . inTransaction ( this . txHash , EventEmitter , 'String' , { value : this . value } ) ;
317
+ } ) ;
318
+
319
+ it ( 'throws if an unemitted event is requested' , async function ( ) {
320
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , EventEmitter , 'UnemittedEvent' ,
321
+ { value : this . value }
322
+ ) ) ;
323
+ } ) ;
324
+
325
+ it ( 'throws if an incorrect string is passed' , async function ( ) {
326
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , EventEmitter , 'String' ,
327
+ { value : 'ClosedZeppelin' }
328
+ ) ) ;
329
+ } ) ;
330
+
331
+ it ( 'throws if an event emitted from other contract is passed' , async function ( ) {
332
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , EventEmitter , 'IndirectString' ,
333
+ { value : this . value }
334
+ ) ) ;
335
+ } ) ;
336
+
337
+ it ( 'throws if an incorrect emitter is passed' , async function ( ) {
338
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , IndirectEventEmitter , 'String' ,
339
+ { value : this . value }
340
+ ) ) ;
341
+ } ) ;
342
+ } ) ;
343
+
344
+ context ( 'with indirectly called contract' , function ( ) {
345
+ it ( 'accepts events emitted from other contracts' , async function ( ) {
346
+ await expectEvent . inTransaction ( this . txHash , IndirectEventEmitter , 'IndirectString' ,
347
+ { value : this . value }
348
+ ) ;
349
+ } ) ;
350
+
351
+ it ( 'throws if an unemitted event is requested' , async function ( ) {
352
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , IndirectEventEmitter , 'UnemittedEvent' ,
353
+ { value : this . value }
354
+ ) ) ;
355
+ } ) ;
356
+
357
+ it ( 'throws if an incorrect string is passed' , async function ( ) {
358
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , IndirectEventEmitter , 'IndirectString' ,
359
+ { value : 'ClosedZeppelin' }
360
+ ) ) ;
361
+ } ) ;
362
+
363
+ it ( 'throws if an event emitted from other contract is passed' , async function ( ) {
364
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , IndirectEventEmitter , 'String' ,
365
+ { value : this . value }
366
+ ) ) ;
367
+ } ) ;
368
+
369
+ it ( 'throws if an incorrect emitter is passed' , async function ( ) {
370
+ await shouldFail ( expectEvent . inTransaction ( this . txHash , EventEmitter , 'IndirectString' ,
371
+ { value : this . value }
372
+ ) ) ;
373
+ } ) ;
374
+ } ) ;
375
+ } ) ;
376
+ } ) ;
231
377
} ) ;
232
378
} ) ;
0 commit comments