@@ -5,6 +5,7 @@ use pinocchio::program_error::ProgramError;
55/// Instructions supported by the token program.
66#[ repr( u8 ) ]
77#[ derive( Clone , Debug , PartialEq ) ]
8+ #[ cfg_attr( test, derive( strum_macros:: FromRepr , strum_macros:: EnumIter ) ) ]
89pub enum TokenInstruction {
910 /// Initializes a new mint and optionally deposits all the newly minted
1011 /// tokens in an account.
@@ -20,7 +21,7 @@ pub enum TokenInstruction {
2021 /// 0. `[writable]` The mint to initialize.
2122 /// 1. `[]` Rent sysvar.
2223 ///
23- /// Instructions data expected by this instruction:
24+ /// Data expected by this instruction:
2425 ///
2526 /// - `u8` The number of base 10 digits to the right of the decimal place.
2627 /// - `Pubkey` The authority/multisignature to mint tokens.
@@ -66,7 +67,7 @@ pub enum TokenInstruction {
6667 /// 1. `[]` Rent sysvar.
6768 /// 2. `..+N` `[signer]` The signer accounts, must equal to N where `1 <= N <= 11`.
6869 ///
69- /// Instructions data expected by this instruction:
70+ /// Data expected by this instruction:
7071 ///
7172 /// - `u8` The number of signers (M) required to validate this multisignature account.
7273 InitializeMultisig ,
@@ -89,7 +90,7 @@ pub enum TokenInstruction {
8990 /// 2. `[]` The source account's multisignature owner/delegate.
9091 /// 3. `..+M` `[signer]` M signer accounts.
9192 ///
92- /// Instructions data expected by this instruction:
93+ /// Data expected by this instruction:
9394 ///
9495 /// - `u64` The amount of tokens to transfer.
9596 Transfer ,
@@ -110,7 +111,7 @@ pub enum TokenInstruction {
110111 /// 2. `[]` The source account's multisignature owner.
111112 /// 3. `..+M` `[signer]` M signer accounts.
112113 ///
113- /// Instructions data expected by this instruction:
114+ /// Data expected by this instruction:
114115 ///
115116 /// - `u64` The amount of tokens the delegate is approved for.
116117 Approve ,
@@ -142,7 +143,7 @@ pub enum TokenInstruction {
142143 /// 1. `[]` The mint's or account's current multisignature authority.
143144 /// 2. `..+M` `[signer]` M signer accounts.
144145 ///
145- /// Instructions data expected by this instruction:
146+ /// Data expected by this instruction:
146147 ///
147148 /// - `AuthorityType` The type of authority to update.
148149 /// - `Option<Pubkey>` The new authority.
@@ -164,7 +165,7 @@ pub enum TokenInstruction {
164165 /// 2. `[]` The mint's multisignature mint-tokens authority.
165166 /// 3. `..+M` `[signer]` M signer accounts.
166167 ///
167- /// Instructions data expected by this instruction:
168+ /// Data expected by this instruction:
168169 ///
169170 /// - `u64` The amount of new tokens to mint.
170171 MintTo ,
@@ -185,7 +186,7 @@ pub enum TokenInstruction {
185186 /// 2. `[]` The account's multisignature owner/delegate.
186187 /// 3. `..+M` `[signer]` M signer accounts.
187188 ///
188- /// Instructions data expected by this instruction:
189+ /// Data expected by this instruction:
189190 ///
190191 /// - `u64` The amount of tokens to burn.
191192 Burn ,
@@ -264,7 +265,7 @@ pub enum TokenInstruction {
264265 /// 3. `[]` The source account's multisignature owner/delegate.
265266 /// 4. `..+M` `[signer]` M signer accounts.
266267 ///
267- /// Instructions data expected by this instruction:
268+ /// Data expected by this instruction:
268269 ///
269270 /// - `u64` The amount of tokens to transfer.
270271 /// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -292,7 +293,7 @@ pub enum TokenInstruction {
292293 /// 3. `[]` The source account's multisignature owner.
293294 /// 4. `..+M` `[signer]` M signer accounts.
294295 ///
295- /// Instructions data expected by this instruction:
296+ /// Data expected by this instruction:
296297 ///
297298 /// - `u64` The amount of tokens the delegate is approved for.
298299 /// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -318,7 +319,7 @@ pub enum TokenInstruction {
318319 /// 2. `[]` The mint's multisignature mint-tokens authority.
319320 /// 3. `..+M` `[signer]` M signer accounts.
320321 ///
321- /// Instructions data expected by this instruction:
322+ /// Data expected by this instruction:
322323 ///
323324 /// - `u64` The amount of new tokens to mint.
324325 /// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -345,7 +346,7 @@ pub enum TokenInstruction {
345346 /// 2. `[]` The account's multisignature owner/delegate.
346347 /// 3. `..+M` `[signer]` M signer accounts.
347348 ///
348- /// Instructions data expected by this instruction:
349+ /// Data expected by this instruction:
349350 ///
350351 /// - `u64` The amount of tokens to burn.
351352 /// - `u8` Expected number of base 10 digits to the right of the decimal place.
@@ -362,7 +363,7 @@ pub enum TokenInstruction {
362363 /// 1. `[]` The mint this account will be associated with.
363364 /// 2. `[]` Rent sysvar.
364365 ///
365- /// Instructions data expected by this instruction:
366+ /// Data expected by this instruction:
366367 ///
367368 /// - `Pubkey` The new account's owner/multisignature.
368369 InitializeAccount2 ,
@@ -387,7 +388,7 @@ pub enum TokenInstruction {
387388 /// 0. `[writable]` The account to initialize.
388389 /// 1. `[]` The mint this account will be associated with.
389390 ///
390- /// Instructions data expected by this instruction:
391+ /// Data expected by this instruction:
391392 ///
392393 /// - `Pubkey` The new account's owner/multisignature.
393394 InitializeAccount3 ,
@@ -400,7 +401,7 @@ pub enum TokenInstruction {
400401 /// 0. `[writable]` The multisignature account to initialize.
401402 /// 1. `..+N` `[signer]` The signer accounts, must equal to N where `1 <= N <= 11`.
402403 ///
403- /// Instructions data expected by this instruction:
404+ /// Data expected by this instruction:
404405 ///
405406 /// - `u8` The number of signers (M) required to validate this multisignature account.
406407 InitializeMultisig2 ,
@@ -412,7 +413,7 @@ pub enum TokenInstruction {
412413 ///
413414 /// 0. `[writable]` The mint to initialize.
414415 ///
415- /// Instructions data expected by this instruction:
416+ /// Data expected by this instruction:
416417 ///
417418 /// - `u8` The number of base 10 digits to the right of the decimal place.
418419 /// - `Pubkey` The authority/multisignature to mint tokens.
@@ -456,7 +457,7 @@ pub enum TokenInstruction {
456457 ///
457458 /// 0. `[]` The mint to calculate for
458459 ///
459- /// Instructions data expected by this instruction:
460+ /// Data expected by this instruction:
460461 ///
461462 /// - `u64` The amount of tokens to reformat.
462463 AmountToUiAmount ,
@@ -472,7 +473,7 @@ pub enum TokenInstruction {
472473 ///
473474 /// 0. `[]` The mint to calculate for.
474475 ///
475- /// Instructions data expected by this instruction:
476+ /// Data expected by this instruction:
476477 ///
477478 /// - `&str` The `ui_amount` of tokens to reformat.
478479 UiAmountToAmount ,
@@ -497,6 +498,7 @@ impl TryFrom<u8> for TokenInstruction {
497498/// Specifies the authority type for `SetAuthority` instructions
498499#[ repr( u8 ) ]
499500#[ derive( Clone , Debug , PartialEq ) ]
501+ #[ cfg_attr( test, derive( strum_macros:: FromRepr , strum_macros:: EnumIter ) ) ]
500502pub enum AuthorityType {
501503 /// Authority to mint new tokens
502504 MintTokens ,
@@ -520,3 +522,33 @@ impl TryFrom<u8> for AuthorityType {
520522 }
521523 }
522524}
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