@@ -10,27 +10,85 @@ contract('SafeERC20', function () {
10
10
this . helper = await SafeERC20Helper . new ( ) ;
11
11
} ) ;
12
12
13
- it ( 'should throw on failed transfer' , async function ( ) {
14
- await shouldFail . reverting ( this . helper . doFailingTransfer ( ) ) ;
15
- } ) ;
13
+ describe ( 'with token that returns false on all calls' , function ( ) {
14
+ it ( 'reverts on transfer' , async function ( ) {
15
+ await shouldFail . reverting ( this . helper . doFailingTransfer ( ) ) ;
16
+ } ) ;
16
17
17
- it ( 'should throw on failed transferFrom' , async function ( ) {
18
- await shouldFail . reverting ( this . helper . doFailingTransferFrom ( ) ) ;
19
- } ) ;
18
+ it ( 'reverts on transferFrom' , async function ( ) {
19
+ await shouldFail . reverting ( this . helper . doFailingTransferFrom ( ) ) ;
20
+ } ) ;
20
21
21
- it ( 'should throw on failed approve' , async function ( ) {
22
- await shouldFail . reverting ( this . helper . doFailingApprove ( ) ) ;
23
- } ) ;
22
+ it ( 'reverts on approve' , async function ( ) {
23
+ await shouldFail . reverting ( this . helper . doFailingApprove ( ) ) ;
24
+ } ) ;
24
25
25
- it ( 'should not throw on succeeding transfer ' , async function ( ) {
26
- await this . helper . doSucceedingTransfer ( ) ;
27
- } ) ;
26
+ it ( 'reverts on increaseAllowance ' , async function ( ) {
27
+ await shouldFail . reverting ( this . helper . doFailingIncreaseAllowance ( ) ) ;
28
+ } ) ;
28
29
29
- it ( 'should not throw on succeeding transferFrom' , async function ( ) {
30
- await this . helper . doSucceedingTransferFrom ( ) ;
30
+ it ( 'reverts on decreaseAllowance' , async function ( ) {
31
+ await shouldFail . reverting ( this . helper . doFailingDecreaseAllowance ( ) ) ;
32
+ } ) ;
31
33
} ) ;
32
34
33
- it ( 'should not throw on succeeding approve' , async function ( ) {
34
- await this . helper . doSucceedingApprove ( ) ;
35
+ describe ( 'with token that returns true on all calls' , function ( ) {
36
+ it ( 'doesn\'t revert on transfer' , async function ( ) {
37
+ await this . helper . doSucceedingTransfer ( ) ;
38
+ } ) ;
39
+
40
+ it ( 'doesn\'t revert on transferFrom' , async function ( ) {
41
+ await this . helper . doSucceedingTransferFrom ( ) ;
42
+ } ) ;
43
+
44
+ describe ( 'approvals' , function ( ) {
45
+ context ( 'with zero allowance' , function ( ) {
46
+ beforeEach ( async function ( ) {
47
+ await this . helper . setAllowance ( 0 ) ;
48
+ } ) ;
49
+
50
+ it ( 'doesn\'t revert when approving a non-zero allowance' , async function ( ) {
51
+ await this . helper . doSucceedingApprove ( 100 ) ;
52
+ } ) ;
53
+
54
+ it ( 'doesn\'t revert when approving a zero allowance' , async function ( ) {
55
+ await this . helper . doSucceedingApprove ( 0 ) ;
56
+ } ) ;
57
+
58
+ it ( 'doesn\'t revert when increasing the allowance' , async function ( ) {
59
+ await this . helper . doSucceedingIncreaseAllowance ( 10 ) ;
60
+ } ) ;
61
+
62
+ it ( 'reverts when decreasing the allowance' , async function ( ) {
63
+ await shouldFail . reverting ( this . helper . doSucceedingDecreaseAllowance ( 10 ) ) ;
64
+ } ) ;
65
+ } ) ;
66
+
67
+ context ( 'with non-zero allowance' , function ( ) {
68
+ beforeEach ( async function ( ) {
69
+ await this . helper . setAllowance ( 100 ) ;
70
+ } ) ;
71
+
72
+ it ( 'reverts when approving a non-zero allowance' , async function ( ) {
73
+ await shouldFail . reverting ( this . helper . doSucceedingApprove ( 20 ) ) ;
74
+ } ) ;
75
+
76
+ it ( 'doesn\'t revert when approving a zero allowance' , async function ( ) {
77
+ await this . helper . doSucceedingApprove ( 0 ) ;
78
+ } ) ;
79
+
80
+ it ( 'doesn\'t revert when increasing the allowance' , async function ( ) {
81
+ await this . helper . doSucceedingIncreaseAllowance ( 10 ) ;
82
+ } ) ;
83
+
84
+ it ( 'doesn\'t revert when decreasing the allowance to a positive value' , async function ( ) {
85
+ await this . helper . doSucceedingDecreaseAllowance ( 50 ) ;
86
+ } ) ;
87
+
88
+ it ( 'reverts when decreasing the allowance to a negative value' , async function ( ) {
89
+ await shouldFail . reverting ( this . helper . doSucceedingDecreaseAllowance ( 200 ) ) ;
90
+ } ) ;
91
+ } ) ;
92
+ } ) ;
35
93
} ) ;
36
94
} ) ;
0 commit comments