|
| 1 | +mod program_test; |
| 2 | +use { |
| 3 | + program_test::{TestContext, TokenContext}, |
| 4 | + solana_program_error::ProgramError, |
| 5 | + solana_program_test::tokio, |
| 6 | + solana_sdk::{ |
| 7 | + instruction::InstructionError, pubkey::Pubkey, signature::Signer, signer::keypair::Keypair, |
| 8 | + transaction::TransactionError, transport::TransportError, |
| 9 | + }, |
| 10 | + spl_token_2022_interface::extension::BaseStateWithExtensions, |
| 11 | + spl_token_2022_interface::{ |
| 12 | + error::TokenError, extension::permissioned_burn::PermissionedBurnConfig, |
| 13 | + }, |
| 14 | + spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError}, |
| 15 | +}; |
| 16 | + |
| 17 | +#[tokio::test] |
| 18 | +async fn success_initialize() { |
| 19 | + let authority = Pubkey::new_unique(); |
| 20 | + let mut context = TestContext::new().await; |
| 21 | + context |
| 22 | + .init_token_with_mint(vec![ |
| 23 | + ExtensionInitializationParams::PermissionedBurnConfig { authority }, |
| 24 | + ]) |
| 25 | + .await |
| 26 | + .unwrap(); |
| 27 | + let TokenContext { |
| 28 | + token, |
| 29 | + mint_authority, |
| 30 | + alice, |
| 31 | + .. |
| 32 | + } = context.token_context.unwrap(); |
| 33 | + |
| 34 | + let state = token.get_mint_info().await.unwrap(); |
| 35 | + let extension = state.get_extension::<PermissionedBurnConfig>().unwrap(); |
| 36 | + assert_eq!(Option::<Pubkey>::from(extension.authority), Some(authority)); |
| 37 | + |
| 38 | + // mint a token |
| 39 | + let amount = 10; |
| 40 | + token |
| 41 | + .mint_to( |
| 42 | + &alice.pubkey(), |
| 43 | + &mint_authority.pubkey(), |
| 44 | + amount, |
| 45 | + &[&mint_authority], |
| 46 | + ) |
| 47 | + .await |
| 48 | + .unwrap(); |
| 49 | + |
| 50 | + // regular burn fails |
| 51 | + let error = token |
| 52 | + .burn(&alice.pubkey(), &alice.pubkey(), 1, &[&alice]) |
| 53 | + .await |
| 54 | + .unwrap_err(); |
| 55 | + // assert_eq!( |
| 56 | + // error, |
| 57 | + // TokenClientError::Client(Box::new(TransportError::TransactionError( |
| 58 | + // TransactionError::InstructionError( |
| 59 | + // 0, |
| 60 | + // InstructionError::Custom(ProgramError::MissingRequiredSignature as u32) |
| 61 | + // ) |
| 62 | + // ))) |
| 63 | + // ); |
| 64 | + |
| 65 | + // // checked is ok |
| 66 | + // token |
| 67 | + // .burn(&alice_account, &alice.pubkey(), 1, &[&alice]) |
| 68 | + // .await |
| 69 | + // .unwrap(); |
| 70 | + |
| 71 | + // // burn too much is not ok |
| 72 | + // let error = token |
| 73 | + // .burn(&alice_account, &alice.pubkey(), amount, &[&alice]) |
| 74 | + // .await |
| 75 | + // .unwrap_err(); |
| 76 | + // assert_eq!( |
| 77 | + // error, |
| 78 | + // TokenClientError::Client(Box::new(TransportError::TransactionError( |
| 79 | + // TransactionError::InstructionError( |
| 80 | + // 0, |
| 81 | + // InstructionError::Custom(TokenError::InsufficientFunds as u32) |
| 82 | + // ) |
| 83 | + // ))) |
| 84 | + // ); |
| 85 | + |
| 86 | + // // wrong signer |
| 87 | + // let error = token |
| 88 | + // .burn(&alice_account, &bob.pubkey(), 1, &[&bob]) |
| 89 | + // .await |
| 90 | + // .unwrap_err(); |
| 91 | + // assert_eq!( |
| 92 | + // error, |
| 93 | + // TokenClientError::Client(Box::new(TransportError::TransactionError( |
| 94 | + // TransactionError::InstructionError( |
| 95 | + // 0, |
| 96 | + // InstructionError::Custom(TokenError::OwnerMismatch as u32) |
| 97 | + // ) |
| 98 | + // ))) |
| 99 | + // ); |
| 100 | +} |
0 commit comments