@@ -5,6 +5,7 @@ use pinocchio::program_error::ProgramError;
5
5
/// Instructions supported by the token program.
6
6
#[ repr( u8 ) ]
7
7
#[ derive( Clone , Debug , PartialEq ) ]
8
+ #[ cfg_attr( test, derive( strum_macros:: FromRepr , strum_macros:: EnumIter ) ) ]
8
9
pub enum TokenInstruction {
9
10
/// Initializes a new mint and optionally deposits all the newly minted
10
11
/// tokens in an account.
@@ -20,7 +21,7 @@ pub enum TokenInstruction {
20
21
/// 0. `[writable]` The mint to initialize.
21
22
/// 1. `[]` Rent sysvar.
22
23
///
23
- /// Instructions data expected by this instruction:
24
+ /// Data expected by this instruction:
24
25
///
25
26
/// - `u8` The number of base 10 digits to the right of the decimal place.
26
27
/// - `Pubkey` The authority/multisignature to mint tokens.
@@ -66,7 +67,7 @@ pub enum TokenInstruction {
66
67
/// 1. `[]` Rent sysvar.
67
68
/// 2. `..+N` `[signer]` The signer accounts, must equal to N where `1 <= N <= 11`.
68
69
///
69
- /// Instructions data expected by this instruction:
70
+ /// Data expected by this instruction:
70
71
///
71
72
/// - `u8` The number of signers (M) required to validate this multisignature account.
72
73
InitializeMultisig ,
@@ -89,7 +90,7 @@ pub enum TokenInstruction {
89
90
/// 2. `[]` The source account's multisignature owner/delegate.
90
91
/// 3. `..+M` `[signer]` M signer accounts.
91
92
///
92
- /// Instructions data expected by this instruction:
93
+ /// Data expected by this instruction:
93
94
///
94
95
/// - `u64` The amount of tokens to transfer.
95
96
Transfer ,
@@ -110,7 +111,7 @@ pub enum TokenInstruction {
110
111
/// 2. `[]` The source account's multisignature owner.
111
112
/// 3. `..+M` `[signer]` M signer accounts.
112
113
///
113
- /// Instructions data expected by this instruction:
114
+ /// Data expected by this instruction:
114
115
///
115
116
/// - `u64` The amount of tokens the delegate is approved for.
116
117
Approve ,
@@ -142,7 +143,7 @@ pub enum TokenInstruction {
142
143
/// 1. `[]` The mint's or account's current multisignature authority.
143
144
/// 2. `..+M` `[signer]` M signer accounts.
144
145
///
145
- /// Instructions data expected by this instruction:
146
+ /// Data expected by this instruction:
146
147
///
147
148
/// - `AuthorityType` The type of authority to update.
148
149
/// - `Option<Pubkey>` The new authority.
@@ -164,7 +165,7 @@ pub enum TokenInstruction {
164
165
/// 2. `[]` The mint's multisignature mint-tokens authority.
165
166
/// 3. `..+M` `[signer]` M signer accounts.
166
167
///
167
- /// Instructions data expected by this instruction:
168
+ /// Data expected by this instruction:
168
169
///
169
170
/// - `u64` The amount of new tokens to mint.
170
171
MintTo ,
@@ -185,7 +186,7 @@ pub enum TokenInstruction {
185
186
/// 2. `[]` The account's multisignature owner/delegate.
186
187
/// 3. `..+M` `[signer]` M signer accounts.
187
188
///
188
- /// Instructions data expected by this instruction:
189
+ /// Data expected by this instruction:
189
190
///
190
191
/// - `u64` The amount of tokens to burn.
191
192
Burn ,
@@ -264,7 +265,7 @@ pub enum TokenInstruction {
264
265
/// 3. `[]` The source account's multisignature owner/delegate.
265
266
/// 4. `..+M` `[signer]` M signer accounts.
266
267
///
267
- /// Instructions data expected by this instruction:
268
+ /// Data expected by this instruction:
268
269
///
269
270
/// - `u64` The amount of tokens to transfer.
270
271
/// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -292,7 +293,7 @@ pub enum TokenInstruction {
292
293
/// 3. `[]` The source account's multisignature owner.
293
294
/// 4. `..+M` `[signer]` M signer accounts.
294
295
///
295
- /// Instructions data expected by this instruction:
296
+ /// Data expected by this instruction:
296
297
///
297
298
/// - `u64` The amount of tokens the delegate is approved for.
298
299
/// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -318,7 +319,7 @@ pub enum TokenInstruction {
318
319
/// 2. `[]` The mint's multisignature mint-tokens authority.
319
320
/// 3. `..+M` `[signer]` M signer accounts.
320
321
///
321
- /// Instructions data expected by this instruction:
322
+ /// Data expected by this instruction:
322
323
///
323
324
/// - `u64` The amount of new tokens to mint.
324
325
/// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -345,7 +346,7 @@ pub enum TokenInstruction {
345
346
/// 2. `[]` The account's multisignature owner/delegate.
346
347
/// 3. `..+M` `[signer]` M signer accounts.
347
348
///
348
- /// Instructions data expected by this instruction:
349
+ /// Data expected by this instruction:
349
350
///
350
351
/// - `u64` The amount of tokens to burn.
351
352
/// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -362,7 +363,7 @@ pub enum TokenInstruction {
362
363
/// 1. `[]` The mint this account will be associated with.
363
364
/// 2. `[]` Rent sysvar.
364
365
///
365
- /// Instructions data expected by this instruction:
366
+ /// Data expected by this instruction:
366
367
///
367
368
/// - `Pubkey` The new account's owner/multisignature.
368
369
InitializeAccount2 ,
@@ -387,7 +388,7 @@ pub enum TokenInstruction {
387
388
/// 0. `[writable]` The account to initialize.
388
389
/// 1. `[]` The mint this account will be associated with.
389
390
///
390
- /// Instructions data expected by this instruction:
391
+ /// Data expected by this instruction:
391
392
///
392
393
/// - `Pubkey` The new account's owner/multisignature.
393
394
InitializeAccount3 ,
@@ -400,7 +401,7 @@ pub enum TokenInstruction {
400
401
/// 0. `[writable]` The multisignature account to initialize.
401
402
/// 1. `..+N` `[signer]` The signer accounts, must equal to N where `1 <= N <= 11`.
402
403
///
403
- /// Instructions data expected by this instruction:
404
+ /// Data expected by this instruction:
404
405
///
405
406
/// - `u8` The number of signers (M) required to validate this multisignature account.
406
407
InitializeMultisig2 ,
@@ -412,7 +413,7 @@ pub enum TokenInstruction {
412
413
///
413
414
/// 0. `[writable]` The mint to initialize.
414
415
///
415
- /// Instructions data expected by this instruction:
416
+ /// Data expected by this instruction:
416
417
///
417
418
/// - `u8` The number of base 10 digits to the right of the decimal place.
418
419
/// - `Pubkey` The authority/multisignature to mint tokens.
@@ -456,7 +457,7 @@ pub enum TokenInstruction {
456
457
///
457
458
/// 0. `[]` The mint to calculate for
458
459
///
459
- /// Instructions data expected by this instruction:
460
+ /// Data expected by this instruction:
460
461
///
461
462
/// - `u64` The amount of tokens to reformat.
462
463
AmountToUiAmount ,
@@ -472,7 +473,7 @@ pub enum TokenInstruction {
472
473
///
473
474
/// 0. `[]` The mint to calculate for.
474
475
///
475
- /// Instructions data expected by this instruction:
476
+ /// Data expected by this instruction:
476
477
///
477
478
/// - `&str` The `ui_amount` of tokens to reformat.
478
479
UiAmountToAmount ,
@@ -497,6 +498,7 @@ impl TryFrom<u8> for TokenInstruction {
497
498
/// Specifies the authority type for `SetAuthority` instructions
498
499
#[ repr( u8 ) ]
499
500
#[ derive( Clone , Debug , PartialEq ) ]
501
+ #[ cfg_attr( test, derive( strum_macros:: FromRepr , strum_macros:: EnumIter ) ) ]
500
502
pub enum AuthorityType {
501
503
/// Authority to mint new tokens
502
504
MintTokens ,
@@ -520,3 +522,33 @@ impl TryFrom<u8> for AuthorityType {
520
522
}
521
523
}
522
524
}
525
+
526
+ #[ cfg( test) ]
527
+ mod tests {
528
+ use super :: { AuthorityType , TokenInstruction } ;
529
+ use strum:: IntoEnumIterator ;
530
+
531
+ #[ test]
532
+ fn test_token_instruction_from_u8_exhaustive ( ) {
533
+ for variant in TokenInstruction :: iter ( ) {
534
+ let variant_u8 = variant. clone ( ) as u8 ;
535
+ assert_eq ! (
536
+ TokenInstruction :: from_repr( variant_u8) ,
537
+ Some ( TokenInstruction :: try_from( variant_u8) . unwrap( ) )
538
+ ) ;
539
+ assert_eq ! ( TokenInstruction :: try_from( variant_u8) . unwrap( ) , variant) ;
540
+ }
541
+ }
542
+
543
+ #[ test]
544
+ fn test_authority_type_from_u8_exhaustive ( ) {
545
+ for variant in AuthorityType :: iter ( ) {
546
+ let variant_u8 = variant. clone ( ) as u8 ;
547
+ assert_eq ! (
548
+ AuthorityType :: from_repr( variant_u8) ,
549
+ Some ( AuthorityType :: try_from( variant_u8) . unwrap( ) )
550
+ ) ;
551
+ assert_eq ! ( AuthorityType :: try_from( variant_u8) . unwrap( ) , variant) ;
552
+ }
553
+ }
554
+ }
0 commit comments