1
1
#![ cfg( feature = "test-sbf" ) ]
2
2
3
- use {
4
- solana_program:: system_instruction, solana_program_test:: tokio:: sync:: Mutex ,
5
- spl_token_2022:: extension:: ExtensionType ,
6
- } ;
7
-
8
3
mod program_test;
9
4
use {
10
5
program_test:: { TestContext , TokenContext } ,
11
- solana_program_test:: { processor, tokio, ProgramTest , ProgramTestContext } ,
6
+ solana_program_test:: {
7
+ processor,
8
+ tokio:: { self , sync:: Mutex } ,
9
+ ProgramTest , ProgramTestContext ,
10
+ } ,
12
11
solana_sdk:: {
13
12
account:: Account as SolanaAccount ,
14
13
instruction:: InstructionError ,
@@ -21,14 +20,10 @@ use {
21
20
spl_token_2022:: {
22
21
error:: TokenError ,
23
22
extension:: {
24
- group_member_pointer:: {
25
- instruction:: { initialize, update} ,
26
- GroupMemberPointer ,
27
- } ,
23
+ group_member_pointer:: { instruction:: update, GroupMemberPointer } ,
28
24
BaseStateWithExtensions ,
29
25
} ,
30
26
processor:: Processor ,
31
- state:: Mint ,
32
27
} ,
33
28
spl_token_client:: token:: { ExtensionInitializationParams , TokenError as TokenClientError } ,
34
29
std:: { convert:: TryInto , sync:: Arc } ,
@@ -91,26 +86,21 @@ async fn setup_token_group(
91
86
async fn setup_member_mint (
92
87
context : Arc < Mutex < ProgramTestContext > > ,
93
88
mint : Keypair ,
94
- group_address : & Pubkey ,
95
89
authority : & Pubkey ,
96
- group_update_authority : & Keypair ,
97
90
) -> TestContext {
98
91
let mut context = TestContext {
99
92
context,
100
93
token_context : None ,
101
94
} ;
102
95
let member_address = Some ( mint. pubkey ( ) ) ;
103
96
context
104
- . init_token_with_mint_keypair_and_freeze_authority_and_additional_signers (
97
+ . init_token_with_mint_keypair_and_freeze_authority (
105
98
mint,
106
99
vec ! [ ExtensionInitializationParams :: GroupMemberPointer {
107
100
authority: Some ( * authority) ,
108
- group_address: * group_address,
109
- group_update_authority: group_update_authority. pubkey( ) ,
110
101
member_address,
111
102
} ] ,
112
103
None ,
113
- & [ & group_update_authority] ,
114
104
)
115
105
. await
116
106
. unwrap ( ) ;
@@ -158,9 +148,7 @@ async fn success_init() {
158
148
let member_token = setup_member_mint (
159
149
context,
160
150
member_mint. insecure_clone ( ) ,
161
- & group_mint. pubkey ( ) ,
162
151
& member_authority. pubkey ( ) ,
163
- & group_update_authority,
164
152
)
165
153
. await
166
154
. token_context
@@ -175,7 +163,6 @@ async fn success_init() {
175
163
extension. authority,
176
164
Some ( member_authority. pubkey( ) ) . try_into( ) . unwrap( )
177
165
) ;
178
- assert_eq ! ( extension. group_address, group_mint. pubkey( ) ) ;
179
166
assert_eq ! (
180
167
extension. member_address,
181
168
Some ( member_mint. pubkey( ) ) . try_into( ) . unwrap( )
@@ -187,8 +174,6 @@ async fn fail_init() {
187
174
let payer = Keypair :: new ( ) ;
188
175
let group_mint = Keypair :: new ( ) ;
189
176
let group_update_authority = Keypair :: new ( ) ;
190
- let member_mint = Keypair :: new ( ) ;
191
- let member_authority = Keypair :: new ( ) ;
192
177
193
178
let program_test = setup_program_test ( ) ;
194
179
let mut context = program_test. start_with_context ( ) . await ;
@@ -226,16 +211,13 @@ async fn fail_init() {
226
211
token_context : None ,
227
212
} ;
228
213
let err = context
229
- . init_token_with_mint_keypair_and_freeze_authority_and_additional_signers (
214
+ . init_token_with_mint_keypair_and_freeze_authority (
230
215
Keypair :: new ( ) ,
231
216
vec ! [ ExtensionInitializationParams :: GroupMemberPointer {
232
217
authority: None ,
233
- group_address: group_mint. pubkey( ) ,
234
- group_update_authority: group_update_authority. pubkey( ) ,
235
218
member_address: None ,
236
219
} ] ,
237
220
None ,
238
- & [ & group_update_authority] ,
239
221
)
240
222
. await
241
223
. unwrap_err ( ) ;
@@ -248,53 +230,6 @@ async fn fail_init() {
248
230
)
249
231
) ) )
250
232
) ;
251
-
252
- // fail missing group update authority signature
253
- let mut context = context. context . lock ( ) . await ;
254
- let space =
255
- ExtensionType :: try_calculate_account_len :: < Mint > ( & [ ExtensionType :: GroupMemberPointer ] )
256
- . unwrap ( ) ;
257
- let lamports = context
258
- . banks_client
259
- . get_rent ( )
260
- . await
261
- . unwrap ( )
262
- . minimum_balance ( space) ;
263
- let mut instruction = initialize (
264
- & spl_token_2022:: id ( ) ,
265
- & member_mint. pubkey ( ) ,
266
- Some ( member_authority. pubkey ( ) ) ,
267
- & group_update_authority. pubkey ( ) ,
268
- & group_mint. pubkey ( ) ,
269
- Some ( member_mint. pubkey ( ) ) ,
270
- )
271
- . unwrap ( ) ;
272
- instruction. accounts [ 2 ] . is_signer = false ;
273
- let transaction = Transaction :: new_signed_with_payer (
274
- & [
275
- system_instruction:: create_account (
276
- & payer. pubkey ( ) ,
277
- & member_mint. pubkey ( ) ,
278
- lamports,
279
- space as u64 ,
280
- & spl_token_2022:: id ( ) ,
281
- ) ,
282
- instruction,
283
- ] ,
284
- Some ( & payer. pubkey ( ) ) ,
285
- & [ & payer, & member_mint] ,
286
- context. last_blockhash ,
287
- ) ;
288
- let error = context
289
- . banks_client
290
- . process_transaction ( transaction)
291
- . await
292
- . unwrap_err ( )
293
- . unwrap ( ) ;
294
- assert_eq ! (
295
- error,
296
- TransactionError :: InstructionError ( 1 , InstructionError :: MissingRequiredSignature , )
297
- ) ;
298
233
}
299
234
300
235
#[ tokio:: test]
@@ -338,9 +273,7 @@ async fn success_update() {
338
273
let member_token = setup_member_mint (
339
274
context. clone ( ) ,
340
275
member_mint. insecure_clone ( ) ,
341
- & group_mint. pubkey ( ) ,
342
276
& member_authority. pubkey ( ) ,
343
- & group_update_authority,
344
277
)
345
278
. await
346
279
. token_context
@@ -354,8 +287,6 @@ async fn success_update() {
354
287
member_token
355
288
. update_group_member_address (
356
289
& member_authority. pubkey ( ) ,
357
- & group_update_authority. pubkey ( ) ,
358
- & group_mint. pubkey ( ) ,
359
290
Some ( new_member_address) ,
360
291
& [ & group_update_authority, & member_authority] ,
361
292
)
@@ -368,7 +299,6 @@ async fn success_update() {
368
299
extension. authority,
369
300
Some ( member_authority. pubkey( ) ) . try_into( ) . unwrap( )
370
301
) ;
371
- assert_eq ! ( extension. group_address, group_mint. pubkey( ) ) ;
372
302
assert_eq ! (
373
303
extension. member_address,
374
304
Some ( new_member_address) . try_into( ) . unwrap( )
@@ -378,8 +308,6 @@ async fn success_update() {
378
308
member_token
379
309
. update_group_member_address (
380
310
& member_authority. pubkey ( ) ,
381
- & group_update_authority. pubkey ( ) ,
382
- & group_mint. pubkey ( ) ,
383
311
None ,
384
312
& [ & group_update_authority, & member_authority] ,
385
313
)
@@ -392,7 +320,6 @@ async fn success_update() {
392
320
extension. authority,
393
321
Some ( member_authority. pubkey( ) ) . try_into( ) . unwrap( )
394
322
) ;
395
- assert_eq ! ( extension. group_address, group_mint. pubkey( ) ) ;
396
323
assert_eq ! ( extension. member_address, None . try_into( ) . unwrap( ) ) ;
397
324
}
398
325
@@ -437,9 +364,7 @@ async fn fail_update() {
437
364
let member_token = setup_member_mint (
438
365
context. clone ( ) ,
439
366
member_mint. insecure_clone ( ) ,
440
- & group_mint. pubkey ( ) ,
441
367
& member_authority. pubkey ( ) ,
442
- & group_update_authority,
443
368
)
444
369
. await
445
370
. token_context
@@ -450,33 +375,10 @@ async fn fail_update() {
450
375
let wrong = Keypair :: new ( ) ;
451
376
let new_member_address = Pubkey :: new_unique ( ) ;
452
377
453
- // fail, wrong signature for group update authority
454
- let err = member_token
455
- . update_group_member_address (
456
- & member_authority. pubkey ( ) ,
457
- & wrong. pubkey ( ) ,
458
- & group_mint. pubkey ( ) ,
459
- Some ( new_member_address) ,
460
- & [ & wrong, & member_authority] ,
461
- )
462
- . await
463
- . unwrap_err ( ) ;
464
- assert_eq ! (
465
- err,
466
- TokenClientError :: Client ( Box :: new( TransportError :: TransactionError (
467
- TransactionError :: InstructionError (
468
- 0 ,
469
- InstructionError :: Custom ( TokenError :: OwnerMismatch as u32 )
470
- )
471
- ) ) )
472
- ) ;
473
-
474
- // fail, wrong signature for member pointer authority
378
+ // fail, wrong signature for authority
475
379
let err = member_token
476
380
. update_group_member_address (
477
381
& wrong. pubkey ( ) ,
478
- & group_update_authority. pubkey ( ) ,
479
- & group_mint. pubkey ( ) ,
480
382
Some ( new_member_address) ,
481
383
& [ & group_update_authority, & wrong] ,
482
384
)
@@ -494,51 +396,20 @@ async fn fail_update() {
494
396
495
397
let mut context = context. lock ( ) . await ;
496
398
497
- // fail, missing group update authority signature
399
+ // fail, missing authority signature
498
400
let mut instruction = update (
499
401
& spl_token_2022:: id ( ) ,
500
402
& member_mint. pubkey ( ) ,
501
403
& member_authority. pubkey ( ) ,
502
- & group_update_authority. pubkey ( ) ,
503
- & [ ] ,
504
- & group_mint. pubkey ( ) ,
505
- Some ( member_mint. pubkey ( ) ) ,
506
- )
507
- . unwrap ( ) ;
508
- instruction. accounts [ 3 ] . is_signer = false ;
509
- let transaction = Transaction :: new_signed_with_payer (
510
- & [ instruction] ,
511
- Some ( & payer. pubkey ( ) ) ,
512
- & [ & payer, & member_authority] ,
513
- context. last_blockhash ,
514
- ) ;
515
- let error = context
516
- . banks_client
517
- . process_transaction ( transaction)
518
- . await
519
- . unwrap_err ( )
520
- . unwrap ( ) ;
521
- assert_eq ! (
522
- error,
523
- TransactionError :: InstructionError ( 0 , InstructionError :: MissingRequiredSignature , )
524
- ) ;
525
-
526
- // fail, missing member pointer authority signature
527
- let mut instruction = update (
528
- & spl_token_2022:: id ( ) ,
529
- & member_mint. pubkey ( ) ,
530
- & member_authority. pubkey ( ) ,
531
- & group_update_authority. pubkey ( ) ,
532
404
& [ ] ,
533
- & group_mint. pubkey ( ) ,
534
405
Some ( member_mint. pubkey ( ) ) ,
535
406
)
536
407
. unwrap ( ) ;
537
- instruction. accounts [ 2 ] . is_signer = false ;
408
+ instruction. accounts [ 1 ] . is_signer = false ;
538
409
let transaction = Transaction :: new_signed_with_payer (
539
410
& [ instruction] ,
540
411
Some ( & payer. pubkey ( ) ) ,
541
- & [ & payer, & group_update_authority ] ,
412
+ & [ & payer] ,
542
413
context. last_blockhash ,
543
414
) ;
544
415
let error = context
0 commit comments