Skip to content

Commit 8a04278

Browse files
committed
small fix & add to rust-legacy
1 parent 52931da commit 8a04278

File tree

3 files changed

+111
-5
lines changed

3 files changed

+111
-5
lines changed

clients/rust-legacy/src/token.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ use {
4444
self, ConfidentialTransferFeeAmount, ConfidentialTransferFeeConfig,
4545
},
4646
cpi_guard, default_account_state, group_member_pointer, group_pointer,
47-
interest_bearing_mint, memo_transfer, metadata_pointer, pausable, scaled_ui_amount,
48-
transfer_fee, transfer_hook, BaseStateWithExtensions, Extension, ExtensionType,
49-
StateWithExtensionsOwned,
47+
interest_bearing_mint, memo_transfer, metadata_pointer, pausable, permissioned_burn,
48+
scaled_ui_amount, transfer_fee, transfer_hook, BaseStateWithExtensions, Extension,
49+
ExtensionType, StateWithExtensionsOwned,
5050
},
5151
instruction,
5252
solana_zk_sdk::{
@@ -201,6 +201,9 @@ pub enum ExtensionInitializationParams {
201201
PausableConfig {
202202
authority: Pubkey,
203203
},
204+
PermissionedBurnConfig {
205+
authority: Pubkey,
206+
},
204207
ConfidentialMintBurn {
205208
supply_elgamal_pubkey: PodElGamalPubkey,
206209
decryptable_supply: PodAeCiphertext,
@@ -226,6 +229,7 @@ impl ExtensionInitializationParams {
226229
Self::GroupMemberPointer { .. } => ExtensionType::GroupMemberPointer,
227230
Self::ScaledUiAmountConfig { .. } => ExtensionType::ScaledUiAmount,
228231
Self::PausableConfig { .. } => ExtensionType::Pausable,
232+
Self::PermissionedBurnConfig { .. } => ExtensionType::PermissionedBurn,
229233
Self::ConfidentialMintBurn { .. } => ExtensionType::ConfidentialMintBurn,
230234
}
231235
}
@@ -348,6 +352,9 @@ impl ExtensionInitializationParams {
348352
Self::PausableConfig { authority } => {
349353
pausable::instruction::initialize(token_program_id, mint, &authority)
350354
}
355+
Self::PermissionedBurnConfig { authority } => {
356+
permissioned_burn::instruction::initialize(token_program_id, mint, &authority)
357+
}
351358
Self::ConfidentialMintBurn {
352359
supply_elgamal_pubkey,
353360
decryptable_supply,
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
}

program/src/processor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,6 @@ impl Processor {
11021102
let source_account_info = next_account_info(account_info_iter)?;
11031103
let mint_info = next_account_info(account_info_iter)?;
11041104
let authority_info = next_account_info(account_info_iter)?;
1105-
let authority_info_data_len = authority_info.data_len();
11061105

11071106
let mut mint_data = mint_info.data.borrow_mut();
11081107
let mint = PodStateWithExtensionsMut::<PodMint>::unpack(&mut mint_data)?;
@@ -1816,7 +1815,7 @@ impl Processor {
18161815
PodTokenInstruction::PermissionedBurn => {
18171816
msg!("Instruction: PermissionedBurn");
18181817
let data = decode_instruction_data::<AmountData>(input)?;
1819-
Self::process_burn(
1818+
Self::process_permissioned_burn(
18201819
program_id,
18211820
accounts,
18221821
data.amount.into(),

0 commit comments

Comments
 (0)