@@ -327,8 +327,8 @@ impl Processor {
327
327
let authority_info = next_account_info ( account_info_iter) ?;
328
328
329
329
if account_info. data_len ( ) == Account :: get_packed_len ( ) {
330
- let mut account_data = account_info. data . borrow_mut ( ) ;
331
- Account :: unpack_mut ( & mut account_data , & mut | account : & mut Account | {
330
+ let mut account = Account :: unpack ( & account_info. data . borrow ( ) ) ? ;
331
+
332
332
if account. is_frozen ( ) {
333
333
return Err ( TokenError :: AccountFrozen . into ( ) ) ;
334
334
}
@@ -362,11 +362,9 @@ impl Processor {
362
362
return Err ( TokenError :: AuthorityTypeNotSupported . into ( ) ) ;
363
363
}
364
364
}
365
- Ok ( ( ) )
366
- } ) ?;
365
+ Account :: pack ( account, & mut account_info. data . borrow_mut ( ) ) ?;
367
366
} else if account_info. data_len ( ) == Mint :: get_packed_len ( ) {
368
- let mut mint_data = account_info. data . borrow_mut ( ) ;
369
- Mint :: unpack_mut ( & mut mint_data, & mut |mint : & mut Mint | {
367
+ let mut mint = Mint :: unpack ( & account_info. data . borrow ( ) ) ?;
370
368
match authority_type {
371
369
AuthorityType :: MintTokens => {
372
370
// Once a mint's supply is fixed, it cannot be undone by setting a new
@@ -400,8 +398,7 @@ impl Processor {
400
398
return Err ( TokenError :: AuthorityTypeNotSupported . into ( ) ) ;
401
399
}
402
400
}
403
- Ok ( ( ) )
404
- } ) ?;
401
+ Mint :: pack ( mint, & mut account_info. data . borrow_mut ( ) ) ?;
405
402
} else {
406
403
return Err ( ProgramError :: InvalidArgument ) ;
407
404
}
@@ -2184,6 +2181,114 @@ mod tests {
2184
2181
. unwrap ( ) ;
2185
2182
}
2186
2183
2184
+ #[ test]
2185
+ fn test_set_authority_dups ( ) {
2186
+ let program_id = pubkey_rand ( ) ;
2187
+ let account1_key = pubkey_rand ( ) ;
2188
+ let mut account1_account = SolanaAccount :: new (
2189
+ account_minimum_balance ( ) ,
2190
+ Account :: get_packed_len ( ) ,
2191
+ & program_id,
2192
+ ) ;
2193
+ let account1_info: AccountInfo = ( & account1_key, true , & mut account1_account) . into ( ) ;
2194
+ let owner_key = pubkey_rand ( ) ;
2195
+ let mint_key = pubkey_rand ( ) ;
2196
+ let mut mint_account =
2197
+ SolanaAccount :: new ( mint_minimum_balance ( ) , Mint :: get_packed_len ( ) , & program_id) ;
2198
+ let mint_info: AccountInfo = ( & mint_key, true , & mut mint_account) . into ( ) ;
2199
+ let rent_key = rent:: id ( ) ;
2200
+ let mut rent_sysvar = rent_sysvar ( ) ;
2201
+ let rent_info: AccountInfo = ( & rent_key, false , & mut rent_sysvar) . into ( ) ;
2202
+
2203
+ // create mint
2204
+ do_process_instruction_dups (
2205
+ initialize_mint ( & program_id, & mint_key, & mint_key, Some ( & mint_key) , 2 ) . unwrap ( ) ,
2206
+ vec ! [ mint_info. clone( ) , rent_info. clone( ) ] ,
2207
+ )
2208
+ . unwrap ( ) ;
2209
+
2210
+ // create account
2211
+ do_process_instruction_dups (
2212
+ initialize_account ( & program_id, & account1_key, & mint_key, & account1_key) . unwrap ( ) ,
2213
+ vec ! [
2214
+ account1_info. clone( ) ,
2215
+ mint_info. clone( ) ,
2216
+ account1_info. clone( ) ,
2217
+ rent_info. clone( ) ,
2218
+ ] ,
2219
+ )
2220
+ . unwrap ( ) ;
2221
+
2222
+ // set mint_authority when currently self
2223
+ do_process_instruction_dups (
2224
+ set_authority (
2225
+ & program_id,
2226
+ & mint_key,
2227
+ Some ( & owner_key) ,
2228
+ AuthorityType :: MintTokens ,
2229
+ & mint_key,
2230
+ & [ ] ,
2231
+ )
2232
+ . unwrap ( ) ,
2233
+ vec ! [ mint_info. clone( ) , mint_info. clone( ) ] ,
2234
+ )
2235
+ . unwrap ( ) ;
2236
+
2237
+ // set freeze_authority when currently self
2238
+ do_process_instruction_dups (
2239
+ set_authority (
2240
+ & program_id,
2241
+ & mint_key,
2242
+ Some ( & owner_key) ,
2243
+ AuthorityType :: FreezeAccount ,
2244
+ & mint_key,
2245
+ & [ ] ,
2246
+ )
2247
+ . unwrap ( ) ,
2248
+ vec ! [ mint_info. clone( ) , mint_info. clone( ) ] ,
2249
+ )
2250
+ . unwrap ( ) ;
2251
+
2252
+ // set account owner when currently self
2253
+ do_process_instruction_dups (
2254
+ set_authority (
2255
+ & program_id,
2256
+ & account1_key,
2257
+ Some ( & owner_key) ,
2258
+ AuthorityType :: AccountOwner ,
2259
+ & account1_key,
2260
+ & [ ] ,
2261
+ )
2262
+ . unwrap ( ) ,
2263
+ vec ! [ account1_info. clone( ) , account1_info. clone( ) ] ,
2264
+ )
2265
+ . unwrap ( ) ;
2266
+
2267
+ // set close_authority when currently self
2268
+ Account :: unpack_unchecked_mut (
2269
+ & mut account1_info. data . borrow_mut ( ) ,
2270
+ & mut |account : & mut Account | {
2271
+ account. close_authority = COption :: Some ( account1_key) ;
2272
+ Ok ( ( ) )
2273
+ } ,
2274
+ )
2275
+ . unwrap ( ) ;
2276
+
2277
+ do_process_instruction_dups (
2278
+ set_authority (
2279
+ & program_id,
2280
+ & account1_key,
2281
+ Some ( & owner_key) ,
2282
+ AuthorityType :: CloseAccount ,
2283
+ & account1_key,
2284
+ & [ ] ,
2285
+ )
2286
+ . unwrap ( ) ,
2287
+ vec ! [ account1_info. clone( ) , account1_info. clone( ) ] ,
2288
+ )
2289
+ . unwrap ( ) ;
2290
+ }
2291
+
2187
2292
#[ test]
2188
2293
fn test_set_authority ( ) {
2189
2294
let program_id = pubkey_rand ( ) ;
0 commit comments