@@ -236,4 +236,63 @@ contract('SRTToken', function(accounts) {
236
236
assert . equal ( allowance . toNumber ( ) , amount , "Amount wasn't correctly approved" ) ;
237
237
} ) ;
238
238
} ) ;
239
+
240
+ it ( "should increase approval 1 token correctly" , function ( ) {
241
+ var token ;
242
+
243
+ var amount = 1 ;
244
+
245
+ var approval_starting_balance ;
246
+ var approval_ending_balance ;
247
+
248
+ return SRTToken . deployed ( ) . then ( function ( instance ) {
249
+ token = instance ;
250
+ return token . allowance . call ( accounts [ 1 ] , accounts [ 2 ] ) ;
251
+ } ) . then ( function ( balance ) {
252
+ approval_starting_balance = balance . toNumber ( ) ;
253
+ return token . increaseApproval ( accounts [ 2 ] , amount , { from :accounts [ 1 ] } ) ;
254
+ } ) . then ( function ( allowance ) {
255
+ return token . allowance . call ( accounts [ 1 ] , accounts [ 2 ] ) ;
256
+ } ) . then ( function ( balance ) {
257
+ approval_ending_balance = balance . toNumber ( ) ;
258
+ assert . equal ( approval_ending_balance , approval_starting_balance + amount , "Amount wasn't correctly approved" ) ;
259
+ } ) ;
260
+ } ) ;
261
+
262
+ it ( "should decrease approval 1 token correctly" , function ( ) {
263
+ var token ;
264
+
265
+ var amount = 1 ;
266
+
267
+ var approval_starting_balance ;
268
+ var approval_ending_balance ;
269
+
270
+ return SRTToken . deployed ( ) . then ( function ( instance ) {
271
+ token = instance ;
272
+ return token . allowance . call ( accounts [ 1 ] , accounts [ 2 ] ) ;
273
+ } ) . then ( function ( balance ) {
274
+ approval_starting_balance = balance . toNumber ( ) ;
275
+ return token . decreaseApproval ( accounts [ 2 ] , amount , { from :accounts [ 1 ] } ) ;
276
+ } ) . then ( function ( allowance ) {
277
+ return token . allowance . call ( accounts [ 1 ] , accounts [ 2 ] ) ;
278
+ } ) . then ( function ( balance ) {
279
+ approval_ending_balance = balance . toNumber ( ) ;
280
+ assert . equal ( approval_ending_balance , approval_starting_balance - amount , "Amount wasn't correctly approved" ) ;
281
+ } ) ;
282
+ } ) ;
283
+
284
+ it ( "should fail when try to approve 1 token when allowance already exists" , function ( ) {
285
+ var token ;
286
+
287
+ var amount = 1 ;
288
+
289
+ return SRTToken . deployed ( ) . then ( function ( instance ) {
290
+ token = instance ;
291
+ return token . approve ( accounts [ 2 ] , amount , { from :accounts [ 1 ] } ) ;
292
+ } ) . then ( function ( status ) {
293
+ assert . isFalse ( status , "transaction should have thrown error" ) ;
294
+ } ) . catch ( function ( err ) {
295
+ assert . isDefined ( err , "transaction should have thrown error" ) ;
296
+ } ) ;
297
+ } ) ;
239
298
} ) ;
0 commit comments