@@ -30,36 +30,39 @@ async function setupContracts () {
30
30
await xcAmple . setController ( deployer . getAddress ( ) ) ;
31
31
}
32
32
33
- describe ( 'XCAmple:burn :accessControl' , function ( ) {
33
+ describe ( 'XCAmple:burnFrom :accessControl' , function ( ) {
34
34
before ( 'setup XCAmple contract' , setupContracts ) ;
35
35
beforeEach ( async function ( ) {
36
36
await xcAmple
37
37
. connect ( deployer )
38
38
. mint ( otherUser . getAddress ( ) , unitTokenAmount ) ;
39
+ await xcAmple
40
+ . connect ( otherUser )
41
+ . approve ( await deployer . getAddress ( ) , unitTokenAmount ) ;
39
42
} ) ;
40
43
41
44
it ( 'should NOT be callable by other user' , async function ( ) {
42
45
await expect (
43
- xcAmple . connect ( otherUser ) . burn ( otherUser . getAddress ( ) , unitTokenAmount ) ,
46
+ xcAmple . connect ( otherUser ) . burnFrom ( otherUser . getAddress ( ) , unitTokenAmount ) ,
44
47
) . to . be . reverted ;
45
48
} ) ;
46
49
47
- it ( 'should be callable by controller ' , async function ( ) {
50
+ it ( 'should be callable by spender ' , async function ( ) {
48
51
await expect (
49
- xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , unitTokenAmount ) ,
52
+ xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , unitTokenAmount ) ,
50
53
) . not . to . be . reverted ;
51
54
} ) ;
52
55
} ) ;
53
56
54
- describe ( 'XCAmple:burn ' , ( ) => {
57
+ describe ( 'XCAmple:burnFrom ' , ( ) => {
55
58
beforeEach ( 'setup XCAmple contract' , setupContracts ) ;
56
59
57
60
describe ( 'when burn address is zero address' , ( ) => {
58
61
it ( 'should revert' , async function ( ) {
59
62
await expect (
60
63
xcAmple
61
64
. connect ( deployer )
62
- . burn ( ethers . constants . AddressZero , unitTokenAmount ) ,
65
+ . burnFrom ( ethers . constants . AddressZero , 0 ) ,
63
66
) . to . be . reverted ;
64
67
} ) ;
65
68
} ) ;
@@ -69,8 +72,21 @@ describe('XCAmple:burn', () => {
69
72
const mintAmt = toUFrgDenomination ( '1000000' ) ;
70
73
await xcAmple . connect ( deployer ) . mint ( otherUser . getAddress ( ) , mintAmt ) ;
71
74
const burnAmt = ( await xcAmple . balanceOf ( otherUser . getAddress ( ) ) ) . add ( 1 ) ;
75
+ await xcAmple . connect ( otherUser ) . approve ( await deployer . getAddress ( ) , burnAmt ) ;
76
+
72
77
await expect (
73
- xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , burnAmt ) ,
78
+ xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ,
79
+ ) . to . be . reverted ;
80
+ } ) ;
81
+ } ) ;
82
+
83
+ describe ( 'when burn value > approved amount' , ( ) => {
84
+ it ( 'should revert' , async function ( ) {
85
+ const mintAmt = toUFrgDenomination ( '1000000' ) ;
86
+ await xcAmple . connect ( deployer ) . mint ( otherUser . getAddress ( ) , mintAmt ) ;
87
+ await xcAmple . connect ( otherUser ) . approve ( await deployer . getAddress ( ) , mintAmt . sub ( 1 ) ) ;
88
+ await expect (
89
+ xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , mintAmt ) ,
74
90
) . to . be . reverted ;
75
91
} ) ;
76
92
} ) ;
@@ -82,23 +98,29 @@ describe('XCAmple:burn', () => {
82
98
beforeEach ( async function ( ) {
83
99
await xcAmple . connect ( deployer ) . mint ( deployer . getAddress ( ) , amt2 ) ;
84
100
await xcAmple . connect ( deployer ) . mint ( otherUser . getAddress ( ) , amt1 ) ;
101
+ await xcAmple . connect ( otherUser ) . approve ( deployer . getAddress ( ) , amt1 )
85
102
} ) ;
86
103
it ( 'should burn tokens from wallet' , async function ( ) {
87
- await xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , amt1 ) ;
104
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , amt1 ) ;
88
105
expect ( await xcAmple . balanceOf ( otherUser . getAddress ( ) ) ) . to . eq ( 0 ) ;
89
106
} ) ;
90
107
it ( 'should NOT affect other wallets' , async function ( ) {
91
108
expect ( await xcAmple . balanceOf ( deployer . getAddress ( ) ) ) . to . eq ( amt2 ) ;
92
- await xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , amt1 ) ;
109
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , amt1 ) ;
93
110
expect ( await xcAmple . balanceOf ( deployer . getAddress ( ) ) ) . to . eq ( amt2 ) ;
94
111
} ) ;
95
112
it ( 'should update the total supply' , async function ( ) {
96
113
expect ( await xcAmple . totalSupply ( ) ) . to . eq ( totalAmt ) ;
97
- await xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , amt1 ) ;
114
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , amt1 ) ;
98
115
expect ( await xcAmple . totalSupply ( ) ) . to . eq ( amt2 ) ;
99
116
} ) ;
117
+ it ( 'should reduce the approved amount' , async function ( ) {
118
+ const allowanceBefore = await xcAmple . allowance ( otherUser . getAddress ( ) , deployer . getAddress ( ) ) ;
119
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , amt1 ) ;
120
+ expect ( await xcAmple . allowance ( otherUser . getAddress ( ) , deployer . getAddress ( ) ) ) . to . eq ( allowanceBefore - amt1 ) ;
121
+ } ) ;
100
122
it ( 'should log Transfer to zero address' , async function ( ) {
101
- await expect ( xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , amt1 ) )
123
+ await expect ( xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , amt1 ) )
102
124
. to . emit ( xcAmple , 'Transfer' )
103
125
. withArgs (
104
126
await otherUser . getAddress ( ) ,
@@ -115,21 +137,27 @@ describe('XCAmple:burn', () => {
115
137
116
138
beforeEach ( async function ( ) {
117
139
await xcAmple . connect ( deployer ) . mint ( otherUser . getAddress ( ) , mintAmt ) ;
140
+ await xcAmple . connect ( otherUser ) . approve ( deployer . getAddress ( ) , mintAmt ) ;
118
141
} ) ;
119
142
it ( 'should burn tokens from wallet' , async function ( ) {
120
- await xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , burnAmt ) ;
143
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ;
121
144
expect ( await xcAmple . balanceOf ( otherUser . getAddress ( ) ) ) . to . eq (
122
145
remainingBal ,
123
146
) ;
124
147
} ) ;
125
148
it ( 'should update the total supply' , async function ( ) {
126
149
expect ( await xcAmple . totalSupply ( ) ) . to . eq ( mintAmt ) ;
127
- await xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , burnAmt ) ;
150
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ;
128
151
expect ( await xcAmple . totalSupply ( ) ) . to . eq ( remainingBal ) ;
129
152
} ) ;
153
+ it ( 'should reduce the approved amount' , async function ( ) {
154
+ const allowanceBefore = await xcAmple . allowance ( otherUser . getAddress ( ) , deployer . getAddress ( ) ) ;
155
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ;
156
+ expect ( await xcAmple . allowance ( otherUser . getAddress ( ) , deployer . getAddress ( ) ) ) . to . eq ( allowanceBefore - burnAmt ) ;
157
+ } ) ;
130
158
it ( 'should log Transfer to zero address' , async function ( ) {
131
159
await expect (
132
- xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , burnAmt ) ,
160
+ xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ,
133
161
)
134
162
. to . emit ( xcAmple , 'Transfer' )
135
163
. withArgs (
@@ -147,22 +175,28 @@ describe('XCAmple:burn', () => {
147
175
beforeEach ( async function ( ) {
148
176
await xcAmple . rebase ( 1 , MAX_SUPPLY ) ;
149
177
await xcAmple . connect ( deployer ) . mint ( otherUser . getAddress ( ) , MAX_SUPPLY ) ;
178
+ await xcAmple . connect ( otherUser ) . approve ( deployer . getAddress ( ) , MAX_SUPPLY ) ;
150
179
} ) ;
151
180
152
181
it ( 'should burn tokens from wallet' , async function ( ) {
153
- await xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , burnAmt ) ;
182
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ;
154
183
expect ( await xcAmple . balanceOf ( otherUser . getAddress ( ) ) ) . to . eq (
155
184
remainingBal ,
156
185
) ;
157
186
} ) ;
158
187
it ( 'should update the total supply' , async function ( ) {
159
188
expect ( await xcAmple . totalSupply ( ) ) . to . eq ( MAX_SUPPLY ) ;
160
- await xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , burnAmt ) ;
189
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ;
161
190
expect ( await xcAmple . totalSupply ( ) ) . to . eq ( remainingBal ) ;
162
191
} ) ;
192
+ it ( 'should reduce the approved amount' , async function ( ) {
193
+ const allowanceBefore = await xcAmple . allowance ( otherUser . getAddress ( ) , deployer . getAddress ( ) ) ;
194
+ await xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ;
195
+ expect ( await xcAmple . allowance ( otherUser . getAddress ( ) , deployer . getAddress ( ) ) ) . to . eq ( allowanceBefore . sub ( burnAmt ) ) ;
196
+ } ) ;
163
197
it ( 'should log Transfer to zero address' , async function ( ) {
164
198
await expect (
165
- xcAmple . connect ( deployer ) . burn ( otherUser . getAddress ( ) , burnAmt ) ,
199
+ xcAmple . connect ( deployer ) . burnFrom ( otherUser . getAddress ( ) , burnAmt ) ,
166
200
)
167
201
. to . emit ( xcAmple , 'Transfer' )
168
202
. withArgs (
0 commit comments