/
shouldFail.test.js
95 lines (75 loc) · 2.69 KB
/
shouldFail.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const shouldFail = require('../shouldFail');
const BigNumber = web3.BigNumber;
const should = require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const Failer = artifacts.require('Failer');
async function assertFailure (promise) {
try {
await promise;
} catch (error) {
return;
}
should.fail();
}
describe('shouldFail', function () {
beforeEach(async function () {
this.failer = await Failer.new();
});
describe('shouldFail', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail(this.failer.dontFail()));
});
it('accepts a revert', async function () {
await shouldFail(this.failer.failWithRevert());
});
it('accepts a throw', async function () {
await shouldFail(this.failer.failWithThrow());
});
it('accepts an out of gas', async function () {
await shouldFail(this.failer.failWithOutOfGas({ gas: 2000000 }));
});
});
describe('reverting', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail.reverting(this.failer.dontFail()));
});
it('accepts a revert', async function () {
await shouldFail.reverting(this.failer.failWithRevert());
});
it('rejects a throw', async function () {
await assertFailure(shouldFail.reverting(this.failer.failWithThrow()));
});
it('rejects an outOfGas', async function () {
await assertFailure(shouldFail.reverting(this.failer.failWithOutOfGas({ gas: 2000000 })));
});
});
describe('throwing', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail.throwing(this.failer.dontFail()));
});
it('accepts a throw', async function () {
await shouldFail.throwing(this.failer.failWithThrow());
});
it('rejects a throw', async function () {
await assertFailure(shouldFail.throwing(this.failer.failWithRevert()));
});
it('rejects an outOfGas', async function () {
await assertFailure(shouldFail.throwing(this.failer.failWithOutOfGas({ gas: 2000000 })));
});
});
describe('outOfGas', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail.outOfGas(this.failer.dontFail()));
});
it('accepts an out of gas', async function () {
await shouldFail.outOfGas(this.failer.failWithOutOfGas({ gas: 2000000 }));
});
it('rejects a revert', async function () {
await assertFailure(shouldFail.outOfGas(this.failer.failWithRevert()));
});
it('rejects a throw', async function () {
await assertFailure(shouldFail.outOfGas(this.failer.failWithThrow()));
});
});
});