|
4 | 4 | ensureOnlyExpectedMutativeFunctions,
|
5 | 5 | } = require('../utils/setupUtils');
|
6 | 6 | const { toBytes32 } = require('../../.');
|
| 7 | +const { ZERO_ADDRESS } = require('../utils/testUtils'); |
7 | 8 |
|
8 | 9 | require('.'); // import common test scaffolding
|
9 | 10 |
|
@@ -46,6 +47,14 @@ contract('DelegateApprovals', async accounts => {
|
46 | 47 | newEternalStorage: account1,
|
47 | 48 | });
|
48 | 49 | });
|
| 50 | + it('reverts if set to ZERO_ADDRESS', async () => { |
| 51 | + await assert.revert( |
| 52 | + delegateApprovals.setEternalStorage(ZERO_ADDRESS, { |
| 53 | + from: owner, |
| 54 | + }), |
| 55 | + "Can't set eternalStorage to address(0)" |
| 56 | + ); |
| 57 | + }); |
49 | 58 | });
|
50 | 59 |
|
51 | 60 | it('ensure only known functions are mutative', () => {
|
@@ -89,27 +98,26 @@ contract('DelegateApprovals', async accounts => {
|
89 | 98 | assert.isTrue(result);
|
90 | 99 |
|
91 | 100 | // remove approval
|
92 |
| - await delegateApprovals.removeAllDelegatePowers(delegate, { from: authoriser }); |
93 |
| - const newResult = await delegateApprovals.canBurnFor(authoriser, delegate); |
94 |
| - assert.isNotTrue(newResult); |
95 |
| - }); |
96 |
| - it('should add approval and emit an Approval event', async () => { |
97 |
| - const transaction = await delegateApprovals.approveAllDelegatePowers(delegate, { |
| 101 | + const transaction = await delegateApprovals.removeAllDelegatePowers(delegate, { |
98 | 102 | from: authoriser,
|
99 | 103 | });
|
100 | 104 |
|
101 |
| - assert.eventEqual(transaction, 'Approval', { |
| 105 | + // only WithdrawApproval event emitted for ApproveAll |
| 106 | + assert.eventEqual(transaction, 'WithdrawApproval', { |
102 | 107 | authoriser: account1,
|
103 | 108 | delegate: account2,
|
104 | 109 | action: toBytes32('ApproveAll'),
|
105 | 110 | });
|
| 111 | + |
| 112 | + const newResult = await delegateApprovals.canBurnFor(authoriser, delegate); |
| 113 | + assert.isNotTrue(newResult); |
106 | 114 | });
|
107 |
| - it('should withdraw approval and emit an WithdrawApproval event', async () => { |
108 |
| - const transaction = await delegateApprovals.removeAllDelegatePowers(delegate, { |
| 115 | + it('should add approval and emit an Approval event', async () => { |
| 116 | + const transaction = await delegateApprovals.approveAllDelegatePowers(delegate, { |
109 | 117 | from: authoriser,
|
110 | 118 | });
|
111 | 119 |
|
112 |
| - assert.eventEqual(transaction, 'WithdrawApproval', { |
| 120 | + assert.eventEqual(transaction, 'Approval', { |
113 | 121 | authoriser: account1,
|
114 | 122 | delegate: account2,
|
115 | 123 | action: toBytes32('ApproveAll'),
|
@@ -141,9 +149,81 @@ contract('DelegateApprovals', async accounts => {
|
141 | 149 | assert.isTrue(result);
|
142 | 150 |
|
143 | 151 | // remove approval
|
144 |
| - await delegateApprovals.removeExchangeOnBehalf(delegate, { from: authoriser }); |
| 152 | + const transaction = await delegateApprovals.removeExchangeOnBehalf(delegate, { |
| 153 | + from: authoriser, |
| 154 | + }); |
| 155 | + |
| 156 | + assert.eventEqual(transaction, 'WithdrawApproval', { |
| 157 | + authoriser: account1, |
| 158 | + delegate: account2, |
| 159 | + action: toBytes32('ExchangeForAddress'), |
| 160 | + }); |
| 161 | + |
145 | 162 | const newResult = await delegateApprovals.canExchangeFor(authoriser, delegate);
|
146 | 163 | assert.isNotTrue(newResult);
|
147 | 164 | });
|
148 | 165 | });
|
| 166 | + |
| 167 | + describe('when invoking removeAllDelegatePowers', async () => { |
| 168 | + const authoriser = account1; |
| 169 | + const delegate = account2; |
| 170 | + |
| 171 | + beforeEach(async () => { |
| 172 | + await delegateApprovals.approveExchangeOnBehalf(delegate, { from: authoriser }); |
| 173 | + await delegateApprovals.approveIssueOnBehalf(delegate, { from: authoriser }); |
| 174 | + await delegateApprovals.approveBurnOnBehalf(delegate, { from: authoriser }); |
| 175 | + await delegateApprovals.approveClaimOnBehalf(delegate, { from: authoriser }); |
| 176 | + }); |
| 177 | + |
| 178 | + it('should remove all delegate powers that have been set', async () => { |
| 179 | + // check approvals is all true |
| 180 | + assert.isTrue(await delegateApprovals.canExchangeFor(authoriser, delegate)); |
| 181 | + assert.isTrue(await delegateApprovals.canIssueFor(authoriser, delegate)); |
| 182 | + assert.isTrue(await delegateApprovals.canBurnFor(authoriser, delegate)); |
| 183 | + assert.isTrue(await delegateApprovals.canClaimFor(authoriser, delegate)); |
| 184 | + |
| 185 | + // invoke removeAllDelegatePowers |
| 186 | + await await delegateApprovals.removeAllDelegatePowers(delegate, { from: authoriser }); |
| 187 | + |
| 188 | + // each delegations revoked |
| 189 | + assert.isNotTrue(await delegateApprovals.canExchangeFor(authoriser, delegate)); |
| 190 | + assert.isNotTrue(await delegateApprovals.canIssueFor(authoriser, delegate)); |
| 191 | + assert.isNotTrue(await delegateApprovals.canBurnFor(authoriser, delegate)); |
| 192 | + assert.isNotTrue(await delegateApprovals.canClaimFor(authoriser, delegate)); |
| 193 | + }); |
| 194 | + |
| 195 | + it('should withdraw approval and emit an WithdrawApproval event for each withdrawn delegation', async () => { |
| 196 | + const transaction = await delegateApprovals.removeAllDelegatePowers(delegate, { |
| 197 | + from: authoriser, |
| 198 | + }); |
| 199 | + |
| 200 | + assert.eventsEqual( |
| 201 | + transaction, |
| 202 | + 'WithdrawApproval', |
| 203 | + { |
| 204 | + authoriser: account1, |
| 205 | + delegate: account2, |
| 206 | + action: toBytes32('BurnForAddress'), |
| 207 | + }, |
| 208 | + 'WithdrawApproval', |
| 209 | + { |
| 210 | + authoriser: account1, |
| 211 | + delegate: account2, |
| 212 | + action: toBytes32('IssueForAddress'), |
| 213 | + }, |
| 214 | + 'WithdrawApproval', |
| 215 | + { |
| 216 | + authoriser: account1, |
| 217 | + delegate: account2, |
| 218 | + action: toBytes32('ClaimForAddress'), |
| 219 | + }, |
| 220 | + 'WithdrawApproval', |
| 221 | + { |
| 222 | + authoriser: account1, |
| 223 | + delegate: account2, |
| 224 | + action: toBytes32('ExchangeForAddress'), |
| 225 | + } |
| 226 | + ); |
| 227 | + }); |
| 228 | + }); |
149 | 229 | });
|
0 commit comments