@@ -471,8 +471,8 @@ impl Processor {
471
471
pub fn process_revoke ( program_id : & Pubkey , accounts : & [ AccountInfo ] ) -> ProgramResult {
472
472
let account_info_iter = & mut accounts. iter ( ) ;
473
473
let source_account_info = next_account_info ( account_info_iter) ?;
474
- let owner_info = next_account_info ( account_info_iter) ?;
475
- let owner_info_data_len = owner_info . data_len ( ) ;
474
+ let authority_info = next_account_info ( account_info_iter) ?;
475
+ let authority_info_data_len = authority_info . data_len ( ) ;
476
476
477
477
let mut source_account = Account :: unpack ( & source_account_info. data . borrow ( ) ) ?;
478
478
if source_account. is_frozen ( ) {
@@ -481,9 +481,14 @@ impl Processor {
481
481
482
482
Self :: validate_owner (
483
483
program_id,
484
- & source_account. owner ,
485
- owner_info,
486
- owner_info_data_len,
484
+ match source_account. delegate {
485
+ COption :: Some ( ref delegate) if cmp_pubkeys ( authority_info. key , delegate) => {
486
+ delegate
487
+ }
488
+ _ => & source_account. owner ,
489
+ } ,
490
+ authority_info,
491
+ authority_info_data_len,
487
492
account_info_iter. as_slice ( ) ,
488
493
) ?;
489
494
@@ -3248,6 +3253,36 @@ mod tests {
3248
3253
] ,
3249
3254
)
3250
3255
. unwrap ( ) ;
3256
+
3257
+ // approve to source
3258
+ do_process_instruction_dups (
3259
+ approve_checked (
3260
+ & program_id,
3261
+ & account2_key,
3262
+ & mint_key,
3263
+ & account2_key,
3264
+ & owner_key,
3265
+ & [ ] ,
3266
+ 500 ,
3267
+ 2 ,
3268
+ )
3269
+ . unwrap ( ) ,
3270
+ vec ! [
3271
+ account2_info. clone( ) ,
3272
+ mint_info. clone( ) ,
3273
+ account2_info. clone( ) ,
3274
+ owner_info. clone( ) ,
3275
+ ] ,
3276
+ )
3277
+ . unwrap ( ) ;
3278
+
3279
+ // source-delegate revoke, force account2 to be a signer
3280
+ let account2_info: AccountInfo = ( & account2_key, true , & mut account2_account) . into ( ) ;
3281
+ do_process_instruction_dups (
3282
+ revoke ( & program_id, & account2_key, & account2_key, & [ ] ) . unwrap ( ) ,
3283
+ vec ! [ account2_info. clone( ) , account2_info. clone( ) ] ,
3284
+ )
3285
+ . unwrap ( ) ;
3251
3286
}
3252
3287
3253
3288
#[ test]
@@ -3453,6 +3488,44 @@ mod tests {
3453
3488
vec ! [ & mut account_account, & mut owner_account] ,
3454
3489
)
3455
3490
. unwrap ( ) ;
3491
+
3492
+ // approve delegate 3
3493
+ do_process_instruction (
3494
+ approve_checked (
3495
+ & program_id,
3496
+ & account_key,
3497
+ & mint_key,
3498
+ & delegate_key,
3499
+ & owner_key,
3500
+ & [ ] ,
3501
+ 100 ,
3502
+ 2 ,
3503
+ )
3504
+ . unwrap ( ) ,
3505
+ vec ! [
3506
+ & mut account_account,
3507
+ & mut mint_account,
3508
+ & mut delegate_account,
3509
+ & mut owner_account,
3510
+ ] ,
3511
+ )
3512
+ . unwrap ( ) ;
3513
+
3514
+ // revoke by delegate
3515
+ do_process_instruction (
3516
+ revoke ( & program_id, & account_key, & delegate_key, & [ ] ) . unwrap ( ) ,
3517
+ vec ! [ & mut account_account, & mut delegate_account] ,
3518
+ )
3519
+ . unwrap ( ) ;
3520
+
3521
+ // fails the second time
3522
+ assert_eq ! (
3523
+ Err ( TokenError :: OwnerMismatch . into( ) ) ,
3524
+ do_process_instruction(
3525
+ revoke( & program_id, & account_key, & delegate_key, & [ ] ) . unwrap( ) ,
3526
+ vec![ & mut account_account, & mut delegate_account] ,
3527
+ )
3528
+ ) ;
3456
3529
}
3457
3530
3458
3531
#[ test]
0 commit comments