|
| 1 | +const expectEvent = require('../expectEvent'); |
| 2 | +const EventEmitter = artifacts.require('EventEmitter'); |
| 3 | + |
| 4 | +const BigNumber = web3.BigNumber; |
| 5 | +const should = require('chai') |
| 6 | + .use(require('chai-bignumber')(BigNumber)) |
| 7 | + .should(); |
| 8 | + |
| 9 | +describe('expectEvent', function () { |
| 10 | + beforeEach(async function () { |
| 11 | + this.emitter = await EventEmitter.new(); |
| 12 | + }); |
| 13 | + |
| 14 | + describe('inLogs', function () { |
| 15 | + describe('with no arguments', function () { |
| 16 | + beforeEach(async function () { |
| 17 | + ({ logs: this.logs } = await this.emitter.emitArgumentless()); |
| 18 | + }); |
| 19 | + |
| 20 | + it('accepts emitted events', function () { |
| 21 | + expectEvent.inLogs(this.logs, 'Argumentless'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('throws if an unemitted event is requested', function () { |
| 25 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent')); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('with single argument', function () { |
| 30 | + context('short uint value', function () { |
| 31 | + beforeEach(async function () { |
| 32 | + this.value = 42; |
| 33 | + ({ logs: this.logs } = await this.emitter.emitShortUint(this.value)); |
| 34 | + }); |
| 35 | + |
| 36 | + it('accepts emitted events with correct JavaScript number', function () { |
| 37 | + expectEvent.inLogs(this.logs, 'ShortUint', { value: this.value }); |
| 38 | + }); |
| 39 | + |
| 40 | + it('accepts emitted events with correct BigNumber', function () { |
| 41 | + expectEvent.inLogs(this.logs, 'ShortUint', { value: new BigNumber(this.value) }); |
| 42 | + }); |
| 43 | + |
| 44 | + it('throws if an unemitted event is requested', function () { |
| 45 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value })); |
| 46 | + }); |
| 47 | + |
| 48 | + it('throws if an incorrect value is passed', function () { |
| 49 | + should.Throw(() => expectEvent.inLogs(this.logs, 'ShortUint', { value: 23 })); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + context('short int value', function () { |
| 54 | + beforeEach(async function () { |
| 55 | + this.value = -42; |
| 56 | + ({ logs: this.logs } = await this.emitter.emitShortInt(this.value)); |
| 57 | + }); |
| 58 | + |
| 59 | + it('accepts emitted events with correct JavaScript number', function () { |
| 60 | + expectEvent.inLogs(this.logs, 'ShortInt', { value: this.value }); |
| 61 | + }); |
| 62 | + |
| 63 | + it('accepts emitted events with correct BigNumber', function () { |
| 64 | + expectEvent.inLogs(this.logs, 'ShortInt', { value: new BigNumber(this.value) }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('throws if an unemitted event is requested', function () { |
| 68 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value })); |
| 69 | + }); |
| 70 | + |
| 71 | + it('throws if an incorrect value is passed', function () { |
| 72 | + should.Throw(() => expectEvent.inLogs(this.logs, 'ShortInt', { value: -23 })); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + context('long uint value', function () { |
| 77 | + beforeEach(async function () { |
| 78 | + this.bigNumValue = new BigNumber('123456789012345678901234567890'); |
| 79 | + ({ logs: this.logs } = await this.emitter.emitLongUint(this.bigNumValue)); |
| 80 | + }); |
| 81 | + |
| 82 | + it('accepts emitted events with correct BigNumber', function () { |
| 83 | + expectEvent.inLogs(this.logs, 'LongUint', { value: this.bigNumValue }); |
| 84 | + }); |
| 85 | + |
| 86 | + it('throws if an unemitted event is requested', function () { |
| 87 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.bigNumValue })); |
| 88 | + }); |
| 89 | + |
| 90 | + it('throws if an incorrect value is passed', function () { |
| 91 | + should.Throw(() => expectEvent.inLogs(this.logs, 'LongUint', { value: 2300 })); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + context('long int value', function () { |
| 96 | + beforeEach(async function () { |
| 97 | + this.bigNumValue = new BigNumber('-123456789012345678901234567890'); |
| 98 | + ({ logs: this.logs } = await this.emitter.emitLongInt(this.bigNumValue)); |
| 99 | + }); |
| 100 | + |
| 101 | + it('accepts emitted events with correct BigNumber', function () { |
| 102 | + expectEvent.inLogs(this.logs, 'LongInt', { value: this.bigNumValue }); |
| 103 | + }); |
| 104 | + |
| 105 | + it('throws if an unemitted event is requested', function () { |
| 106 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.bigNumValue })); |
| 107 | + }); |
| 108 | + |
| 109 | + it('throws if an incorrect value is passed', function () { |
| 110 | + should.Throw(() => expectEvent.inLogs(this.logs, 'LongInt', { value: -2300 })); |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + context('address value', function () { |
| 115 | + beforeEach(async function () { |
| 116 | + this.value = '0x811412068e9fbf25dc300a29e5e316f7122b282c'; |
| 117 | + ({ logs: this.logs } = await this.emitter.emitAddress(this.value)); |
| 118 | + }); |
| 119 | + |
| 120 | + it('accepts emitted events with correct address', function () { |
| 121 | + expectEvent.inLogs(this.logs, 'Address', { value: this.value }); |
| 122 | + }); |
| 123 | + |
| 124 | + it('throws if an unemitted event is requested', function () { |
| 125 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value })); |
| 126 | + }); |
| 127 | + |
| 128 | + it('throws if an incorrect value is passed', function () { |
| 129 | + should.Throw(() => |
| 130 | + expectEvent.inLogs(this.logs, 'Address', { value: '0x21d04e022e0b52b5d5bcf90b7f1aabf406be002d' }) |
| 131 | + ); |
| 132 | + }); |
| 133 | + }); |
| 134 | + |
| 135 | + context('boolean value', function () { |
| 136 | + beforeEach(async function () { |
| 137 | + this.value = true; |
| 138 | + ({ logs: this.logs } = await this.emitter.emitBoolean(this.value)); |
| 139 | + }); |
| 140 | + |
| 141 | + it('accepts emitted events with correct address', function () { |
| 142 | + expectEvent.inLogs(this.logs, 'Boolean', { value: this.value }); |
| 143 | + }); |
| 144 | + |
| 145 | + it('throws if an unemitted event is requested', function () { |
| 146 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value })); |
| 147 | + }); |
| 148 | + |
| 149 | + it('throws if an incorrect value is passed', function () { |
| 150 | + should.Throw(() => expectEvent.inLogs(this.logs, 'Boolean', { value: false })); |
| 151 | + }); |
| 152 | + }); |
| 153 | + |
| 154 | + context('string value', function () { |
| 155 | + beforeEach(async function () { |
| 156 | + this.value = 'OpenZeppelin'; |
| 157 | + ({ logs: this.logs } = await this.emitter.emitString(this.value)); |
| 158 | + }); |
| 159 | + |
| 160 | + it('accepts emitted events with correct string', function () { |
| 161 | + expectEvent.inLogs(this.logs, 'String', { value: this.value }); |
| 162 | + }); |
| 163 | + |
| 164 | + it('throws if an unemitted event is requested', function () { |
| 165 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value })); |
| 166 | + }); |
| 167 | + |
| 168 | + it('throws if an incorrect value is passed', function () { |
| 169 | + should.Throw(() => expectEvent.inLogs(this.logs, 'String', { value: 'ClosedZeppelin' })); |
| 170 | + }); |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + describe('with multiple arguments', function () { |
| 175 | + beforeEach(async function () { |
| 176 | + this.uintValue = new BigNumber('123456789012345678901234567890'); |
| 177 | + this.booleanValue = true; |
| 178 | + this.stringValue = 'OpenZeppelin'; |
| 179 | + ({ logs: this.logs } = |
| 180 | + await this.emitter.emitLongUintBooleanString(this.uintValue, this.booleanValue, this.stringValue)); |
| 181 | + }); |
| 182 | + |
| 183 | + it('accepts correct values', function () { |
| 184 | + expectEvent.inLogs(this.logs, 'LongUintBooleanString', { |
| 185 | + uintValue: this.uintValue, booleanValue: this.booleanValue, stringValue: this.stringValue, |
| 186 | + }); |
| 187 | + }); |
| 188 | + |
| 189 | + it('throws with correct values assigned to wrong arguments', function () { |
| 190 | + should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', { |
| 191 | + uintValue: this.booleanValue, booleanValue: this.uintValue, stringValue: this.stringValue, |
| 192 | + })); |
| 193 | + }); |
| 194 | + |
| 195 | + it('throws when any of the values is incorrect', function () { |
| 196 | + should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', { |
| 197 | + uintValue: 23, booleanValue: this.booleanValue, stringValue: this.stringValue, |
| 198 | + })); |
| 199 | + |
| 200 | + should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', { |
| 201 | + uintValue: this.uintValue, booleanValue: false, stringValue: this.stringValue, |
| 202 | + })); |
| 203 | + |
| 204 | + should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', { |
| 205 | + uintValue: this.uintValue, booleanValue: this.booleanValue, stringValue: 'ClosedZeppelin', |
| 206 | + })); |
| 207 | + }); |
| 208 | + }); |
| 209 | + |
| 210 | + describe('with multiple events', function () { |
| 211 | + beforeEach(async function () { |
| 212 | + this.uintValue = 42; |
| 213 | + this.booleanValue = true; |
| 214 | + ({ logs: this.logs } = await this.emitter.emitLongUintAndBoolean(this.uintValue, this.booleanValue)); |
| 215 | + }); |
| 216 | + |
| 217 | + it('accepts all emitted events with correct values', function () { |
| 218 | + expectEvent.inLogs(this.logs, 'LongUint', { value: this.uintValue }); |
| 219 | + expectEvent.inLogs(this.logs, 'Boolean', { value: this.booleanValue }); |
| 220 | + }); |
| 221 | + |
| 222 | + it('throws if an unemitted event is requested', function () { |
| 223 | + should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.uintValue })); |
| 224 | + }); |
| 225 | + |
| 226 | + it('throws if incorrect values are passed', function () { |
| 227 | + should.Throw(() => expectEvent.inLogs(this.logs, 'LongUint', { value: 23 })); |
| 228 | + should.Throw(() => expectEvent.inLogs(this.logs, 'Boolean', { value: false })); |
| 229 | + }); |
| 230 | + }); |
| 231 | + }); |
| 232 | +}); |
0 commit comments