Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit fd29474

Browse files
committed
fix tests
1 parent 0c003dc commit fd29474

File tree

4 files changed

+121
-46
lines changed

4 files changed

+121
-46
lines changed

token/program-2022-test/tests/confidential_mint_burn.rs

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(feature = "test-sbf")]
1+
//#![cfg(feature = "test-sbf")]
22

33
mod program_test;
44
use {
@@ -19,7 +19,7 @@ use {
1919
},
2020
spl_token_client::{
2121
client::ProgramBanksClientProcessTransaction,
22-
token::{ExtensionInitializationParams, ProofAccount, Token},
22+
token::{ExtensionInitializationParams, ProofAccount, ProofAccountWithCiphertext, Token},
2323
},
2424
spl_token_confidential_transfer_proof_generation::{
2525
burn::burn_split_proof_data, mint::mint_split_proof_data,
@@ -36,21 +36,27 @@ async fn test_confidential_mint() {
3636
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
3737
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
3838
let supply_aes_key = AeKey::new_rand();
39+
let mint_account = Keypair::new();
3940

4041
let mut context = TestContext::new().await;
4142
context
42-
.init_token_with_mint(vec![
43-
ExtensionInitializationParams::ConfidentialTransferMint {
44-
authority: Some(authority.pubkey()),
45-
auto_approve_new_accounts: true,
46-
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
47-
},
48-
ExtensionInitializationParams::ConfidentialMintBurnMint {
49-
authority: authority.pubkey(),
50-
confidential_supply_pubkey: Some(auditor_elgamal_pubkey),
51-
decryptable_supply: Some(supply_aes_key.encrypt(0).into()),
52-
},
53-
])
43+
.init_token_with_mint_keypair_and_freeze_authority_and_mint_authority(
44+
mint_account,
45+
vec![
46+
ExtensionInitializationParams::ConfidentialTransferMint {
47+
authority: Some(authority.pubkey()),
48+
auto_approve_new_accounts: true,
49+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
50+
},
51+
ExtensionInitializationParams::ConfidentialMintBurnMint {
52+
confidential_supply_pubkey: auditor_elgamal_pubkey,
53+
decryptable_supply: supply_aes_key.encrypt(0).into(),
54+
},
55+
],
56+
None,
57+
// hacky but we have to clone somehow
58+
Keypair::from_bytes(&authority.to_bytes()).unwrap(),
59+
)
5460
.await
5561
.unwrap();
5662

@@ -121,21 +127,26 @@ async fn test_confidential_burn() {
121127
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
122128
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
123129
let supply_aes_key = AeKey::new_rand();
130+
let mint_account = Keypair::new();
124131

125132
let mut context = TestContext::new().await;
126133
context
127-
.init_token_with_mint(vec![
128-
ExtensionInitializationParams::ConfidentialTransferMint {
129-
authority: Some(authority.pubkey()),
130-
auto_approve_new_accounts: true,
131-
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
132-
},
133-
ExtensionInitializationParams::ConfidentialMintBurnMint {
134-
authority: authority.pubkey(),
135-
confidential_supply_pubkey: Some(auditor_elgamal_pubkey),
136-
decryptable_supply: Some(supply_aes_key.encrypt(0).into()),
137-
},
138-
])
134+
.init_token_with_mint_keypair_and_freeze_authority_and_mint_authority(
135+
mint_account,
136+
vec![
137+
ExtensionInitializationParams::ConfidentialTransferMint {
138+
authority: Some(authority.pubkey()),
139+
auto_approve_new_accounts: true,
140+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
141+
},
142+
ExtensionInitializationParams::ConfidentialMintBurnMint {
143+
confidential_supply_pubkey: auditor_elgamal_pubkey,
144+
decryptable_supply: supply_aes_key.encrypt(0).into(),
145+
},
146+
],
147+
None,
148+
Keypair::from_bytes(&authority.to_bytes()).unwrap(),
149+
)
139150
.await
140151
.unwrap();
141152

@@ -227,7 +238,9 @@ async fn test_confidential_burn() {
227238
.confidential_transfer_create_context_state_account(
228239
&ciphertext_validity_proof_context_pubkey,
229240
&context_state_auth_pubkey,
230-
&proof_data.ciphertext_validity_proof_data,
241+
&proof_data
242+
.ciphertext_validity_proof_data_with_ciphertext
243+
.proof_data,
231244
false,
232245
ciphertext_validity_proof_signer,
233246
)
@@ -247,6 +260,15 @@ async fn test_confidential_burn() {
247260
let equality_proof_location = ProofAccount::ContextAccount(equality_proof_context_pubkey);
248261
let ciphertext_validity_proof_location =
249262
ProofAccount::ContextAccount(ciphertext_validity_proof_context_pubkey);
263+
let ciphertext_validity_proof_location = ProofAccountWithCiphertext {
264+
proof_account: ciphertext_validity_proof_location,
265+
ciphertext_lo: proof_data
266+
.ciphertext_validity_proof_data_with_ciphertext
267+
.ciphertext_lo,
268+
ciphertext_hi: proof_data
269+
.ciphertext_validity_proof_data_with_ciphertext
270+
.ciphertext_hi,
271+
};
250272
let range_proof_location = ProofAccount::ContextAccount(range_proof_context_pubkey);
251273

252274
// do the burn
@@ -324,21 +346,26 @@ async fn test_rotate_supply_elgamal() {
324346
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
325347
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
326348
let supply_aes_key = AeKey::new_rand();
349+
let mint_account = Keypair::new();
327350

328351
let mut context = TestContext::new().await;
329352
context
330-
.init_token_with_mint(vec![
331-
ExtensionInitializationParams::ConfidentialTransferMint {
332-
authority: Some(authority.pubkey()),
333-
auto_approve_new_accounts: true,
334-
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
335-
},
336-
ExtensionInitializationParams::ConfidentialMintBurnMint {
337-
authority: authority.pubkey(),
338-
confidential_supply_pubkey: Some(auditor_elgamal_pubkey),
339-
decryptable_supply: Some(supply_aes_key.encrypt(0).into()),
340-
},
341-
])
353+
.init_token_with_mint_keypair_and_freeze_authority_and_mint_authority(
354+
mint_account,
355+
vec![
356+
ExtensionInitializationParams::ConfidentialTransferMint {
357+
authority: Some(authority.pubkey()),
358+
auto_approve_new_accounts: true,
359+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
360+
},
361+
ExtensionInitializationParams::ConfidentialMintBurnMint {
362+
confidential_supply_pubkey: auditor_elgamal_pubkey,
363+
decryptable_supply: supply_aes_key.encrypt(0).into(),
364+
},
365+
],
366+
None,
367+
Keypair::from_bytes(&authority.to_bytes()).unwrap(),
368+
)
342369
.await
343370
.unwrap();
344371

@@ -400,11 +427,7 @@ async fn test_rotate_supply_elgamal() {
400427

401428
assert_eq!(
402429
mint_burn_extension.supply_elgamal_pubkey,
403-
Some(Into::<PodElGamalPubkey>::into(
404-
*new_supply_elgamal_keypair.pubkey(),
405-
))
406-
.try_into()
407-
.unwrap(),
430+
Into::<PodElGamalPubkey>::into(*new_supply_elgamal_keypair.pubkey(),),
408431
);
409432
}
410433

@@ -465,7 +488,9 @@ async fn mint_tokens(
465488
.confidential_transfer_create_context_state_account(
466489
&ciphertext_validity_proof_context_pubkey,
467490
&context_state_auth.pubkey(),
468-
&proof_data.ciphertext_validity_proof_data,
491+
&proof_data
492+
.ciphertext_validity_proof_data_with_ciphertext
493+
.proof_data,
469494
false,
470495
ciphertext_validity_proof_signer,
471496
)
@@ -485,8 +510,21 @@ async fn mint_tokens(
485510
let equality_proof_location = ProofAccount::ContextAccount(equality_proof_context_pubkey);
486511
let ciphertext_validity_proof_location =
487512
ProofAccount::ContextAccount(ciphertext_validity_proof_context_pubkey);
513+
let ciphertext_validity_proof_location = ProofAccountWithCiphertext {
514+
proof_account: ciphertext_validity_proof_location,
515+
ciphertext_lo: proof_data
516+
.ciphertext_validity_proof_data_with_ciphertext
517+
.ciphertext_lo,
518+
ciphertext_hi: proof_data
519+
.ciphertext_validity_proof_data_with_ciphertext
520+
.ciphertext_hi,
521+
};
488522
let range_proof_location = ProofAccount::ContextAccount(range_proof_context_pubkey);
489523

524+
println!(
525+
"TOKEN: {}, ata: {token_account}, auth: {authority}",
526+
token.get_address()
527+
);
490528
token
491529
.confidential_mint(
492530
token_account,

token/program-2022-test/tests/program_test.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ impl TestContext {
103103
mint_account: Keypair,
104104
extension_init_params: Vec<ExtensionInitializationParams>,
105105
freeze_authority: Option<Keypair>,
106+
) -> TokenResult<()> {
107+
let mint_authority = Keypair::new();
108+
self.init_token_with_mint_keypair_and_freeze_authority_and_mint_authority(
109+
mint_account,
110+
extension_init_params,
111+
freeze_authority,
112+
mint_authority,
113+
)
114+
.await
115+
}
116+
117+
pub async fn init_token_with_mint_keypair_and_freeze_authority_and_mint_authority(
118+
&mut self,
119+
mint_account: Keypair,
120+
extension_init_params: Vec<ExtensionInitializationParams>,
121+
freeze_authority: Option<Keypair>,
122+
mint_authority: Keypair,
106123
) -> TokenResult<()> {
107124
let payer = keypair_clone(&self.context.lock().await.payer);
108125
let client: Arc<dyn ProgramClient<ProgramBanksClientProcessTransaction>> =
@@ -113,7 +130,6 @@ impl TestContext {
113130

114131
let decimals: u8 = 9;
115132

116-
let mint_authority = Keypair::new();
117133
let mint_authority_pubkey = mint_authority.pubkey();
118134
let freeze_authority_pubkey = freeze_authority
119135
.as_ref()

token/program-2022/src/extension/confidential_mint_burn/processor.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,39 +150,48 @@ fn process_confidential_mint(
150150
accounts: &[AccountInfo],
151151
data: &MintInstructionData,
152152
) -> ProgramResult {
153+
println!("MINT 1");
153154
let account_info_iter = &mut accounts.iter();
154155
let token_account_info = next_account_info(account_info_iter)?;
155156
let mint_info = next_account_info(account_info_iter)?;
157+
println!("MINT 2");
156158

157159
check_program_account(mint_info.owner)?;
158160
let mint_data = &mut mint_info.data.borrow_mut();
159161
let mut mint = PodStateWithExtensionsMut::<PodMint>::unpack(mint_data)?;
160162
let mint_authority = mint.base.mint_authority;
163+
println!("MINT 3");
161164

162165
let auditor_elgamal_pubkey = mint
163166
.get_extension::<ConfidentialTransferMint>()?
164167
.auditor_elgamal_pubkey;
168+
println!("MINT 4");
165169
if let Ok(extension) = mint.get_extension::<PausableConfig>() {
166170
if extension.paused.into() {
167171
return Err(TokenError::MintPaused.into());
168172
}
169173
}
174+
println!("MINT 5");
170175
let mint_burn_extension = mint.get_extension_mut::<ConfidentialMintBurn>()?;
176+
println!("MINT 6");
171177

172178
let proof_context = verify_mint_proof(
173179
account_info_iter,
174180
data.equality_proof_instruction_offset,
175181
data.ciphertext_validity_proof_instruction_offset,
176182
data.range_proof_instruction_offset,
177183
)?;
184+
println!("MINT 7");
178185

179186
check_program_account(token_account_info.owner)?;
180187
let token_account_data = &mut token_account_info.data.borrow_mut();
181188
let mut token_account = PodStateWithExtensionsMut::<PodAccount>::unpack(token_account_data)?;
189+
println!("MINT 8");
182190

183191
let authority_info = next_account_info(account_info_iter)?;
184192
let authority_info_data_len = authority_info.data_len();
185193
let authority = mint_authority.ok_or(TokenError::NoAuthorityExists)?;
194+
println!("MINT 9");
186195

187196
Processor::validate_owner(
188197
program_id,
@@ -191,6 +200,7 @@ fn process_confidential_mint(
191200
authority_info_data_len,
192201
account_info_iter.as_slice(),
193202
)?;
203+
println!("MINT 10");
194204

195205
if token_account.base.is_frozen() {
196206
return Err(TokenError::AccountFrozen.into());
@@ -206,6 +216,7 @@ fn process_confidential_mint(
206216
token_account.get_extension_mut::<ConfidentialTransferAccount>()?;
207217
confidential_transfer_account.valid_as_destination()?;
208218

219+
println!("MINT 12");
209220
if proof_context.mint_pubkeys.destination != confidential_transfer_account.elgamal_pubkey {
210221
return Err(ProgramError::InvalidInstructionData);
211222
}
@@ -215,6 +226,7 @@ fn process_confidential_mint(
215226
return Err(ProgramError::InvalidInstructionData);
216227
}
217228
}
229+
println!("MINT 13");
218230

219231
let proof_context_auditor_ciphertext_lo = proof_context
220232
.mint_amount_ciphertext_lo
@@ -224,13 +236,15 @@ fn process_confidential_mint(
224236
.mint_amount_ciphertext_hi
225237
.try_extract_ciphertext(2)
226238
.map_err(TokenError::from)?;
239+
println!("MINT 14");
227240

228241
check_auditor_ciphertext(
229242
&data.mint_amount_auditor_ciphertext_lo,
230243
&data.mint_amount_auditor_ciphertext_hi,
231244
&proof_context_auditor_ciphertext_lo,
232245
&proof_context_auditor_ciphertext_hi,
233246
)?;
247+
println!("MINT 15");
234248

235249
confidential_transfer_account.pending_balance_lo = ciphertext_arithmetic::add(
236250
&confidential_transfer_account.pending_balance_lo,
@@ -240,6 +254,7 @@ fn process_confidential_mint(
240254
.map_err(TokenError::from)?,
241255
)
242256
.ok_or(TokenError::CiphertextArithmeticFailed)?;
257+
println!("MINT 16");
243258
confidential_transfer_account.pending_balance_hi = ciphertext_arithmetic::add(
244259
&confidential_transfer_account.pending_balance_hi,
245260
&proof_context
@@ -248,6 +263,7 @@ fn process_confidential_mint(
248263
.map_err(TokenError::from)?,
249264
)
250265
.ok_or(TokenError::CiphertextArithmeticFailed)?;
266+
println!("MINT 17");
251267

252268
confidential_transfer_account.increment_pending_balance_credit_counter()?;
253269

@@ -268,6 +284,7 @@ fn process_confidential_mint(
268284
.map_err(|_| ProgramError::InvalidAccountData)?,
269285
)
270286
.ok_or(TokenError::CiphertextArithmeticFailed)?;
287+
println!("MINT 18");
271288
mint_burn_extension.decryptable_supply = data.new_decryptable_supply;
272289

273290
Ok(())

token/program-2022/src/processor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,10 @@ impl Processor {
19031903
owner_account_data_len: usize,
19041904
signers: &[AccountInfo],
19051905
) -> ProgramResult {
1906+
println!(
1907+
"expected owner: {expected_owner}; acc_info_owner: {}",
1908+
owner_account_info.key
1909+
);
19061910
if expected_owner != owner_account_info.key {
19071911
return Err(TokenError::OwnerMismatch.into());
19081912
}

0 commit comments

Comments
 (0)