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

Commit 4862464

Browse files
committed
add tests for configure account with registry
1 parent 1a8dc29 commit 4862464

File tree

3 files changed

+129
-1
lines changed

3 files changed

+129
-1
lines changed

token/program-2022-test/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ solana-program = "2.0.3"
2424
solana-program-test = "2.0.3"
2525
solana-sdk = "2.0.3"
2626
spl-associated-token-account = { version = "5.0.1", path = "../../associated-token-account/program" }
27+
spl-elgamal-registry = { version = "0.1.0", path = "../confidential-transfer/elgamal-registry" }
2728
spl-memo = { version = "5.0.0", path = "../../memo/program", features = [
2829
"no-entrypoint",
2930
] }
@@ -34,6 +35,7 @@ spl-record = { version = "0.2.1", path = "../../record/program", features = [
3435
spl-token-2022 = { version = "5.0.2", path = "../program-2022", features = [
3536
"no-entrypoint",
3637
] }
38+
spl-token-confidential-transfer-proof-extraction = { version = "0.1.0", path = "../confidential-transfer/proof-extraction" }
3739
spl-token-confidential-transfer-proof-generation = { version = "0.1.0", path = "../confidential-transfer/proof-generation" }
3840
spl-instruction-padding = { version = "0.2.0", path = "../../instruction-padding/program", features = [
3941
"no-entrypoint",

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

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ use {
1313
pubkey::Pubkey,
1414
signature::Signer,
1515
signer::{keypair::Keypair, signers::Signers},
16-
transaction::TransactionError,
16+
transaction::{Transaction, TransactionError},
1717
transport::TransportError,
1818
},
1919
spl_record::state::RecordData,
2020
spl_token_2022::{
2121
error::TokenError,
2222
extension::{
2323
confidential_transfer::{
24+
self,
2425
account_info::{EmptyAccountAccountInfo, TransferAccountInfo, WithdrawAccountInfo},
2526
ConfidentialTransferAccount, MAXIMUM_DEPOSIT_TRANSFER_AMOUNT,
2627
},
@@ -38,6 +39,7 @@ use {
3839
TokenResult,
3940
},
4041
},
42+
spl_token_confidential_transfer_proof_extraction::{ProofData, ProofLocation},
4143
spl_token_confidential_transfer_proof_generation::{
4244
transfer::TransferProofData, transfer_with_fee::TransferWithFeeProofData,
4345
withdraw::WithdrawProofData,
@@ -2810,3 +2812,122 @@ async fn confidential_transfer_transfer_with_fee_and_memo_option(
28102812
)
28112813
.await;
28122814
}
2815+
2816+
#[tokio::test]
2817+
async fn confidential_transfer_configure_token_account_with_registry() {
2818+
let authority = Keypair::new();
2819+
let auto_approve_new_accounts = false;
2820+
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
2821+
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
2822+
2823+
let mut context = TestContext::new().await;
2824+
context
2825+
.init_token_with_mint(vec![
2826+
ExtensionInitializationParams::ConfidentialTransferMint {
2827+
authority: Some(authority.pubkey()),
2828+
auto_approve_new_accounts,
2829+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
2830+
},
2831+
])
2832+
.await
2833+
.unwrap();
2834+
2835+
let TokenContext { token, alice, .. } = context.token_context.unwrap();
2836+
let alice_account_keypair = Keypair::new();
2837+
token
2838+
.create_auxiliary_token_account_with_extension_space(
2839+
&alice_account_keypair,
2840+
&alice.pubkey(),
2841+
vec![ExtensionType::ConfidentialTransferAccount],
2842+
)
2843+
.await
2844+
.unwrap();
2845+
let elgamal_keypair = ElGamalKeypair::new_rand();
2846+
2847+
// create ElGamal registry
2848+
let mut ctx = context.context.lock().await;
2849+
let proof_data =
2850+
confidential_transfer::instruction::PubkeyValidityProofData::new(&elgamal_keypair).unwrap();
2851+
let proof_location = ProofLocation::InstructionOffset(
2852+
1.try_into().unwrap(),
2853+
ProofData::InstructionData(&proof_data),
2854+
);
2855+
2856+
let instructions = spl_elgamal_registry::instruction::create_registry(
2857+
&ctx.payer.pubkey(),
2858+
&alice.pubkey(),
2859+
proof_location,
2860+
)
2861+
.unwrap();
2862+
let tx = Transaction::new_signed_with_payer(
2863+
&instructions,
2864+
Some(&ctx.payer.pubkey()),
2865+
&[&ctx.payer],
2866+
ctx.last_blockhash,
2867+
);
2868+
ctx.banks_client.process_transaction(tx).await.unwrap();
2869+
2870+
// update ElGamal registry
2871+
let new_elgamal_keypair =
2872+
ElGamalKeypair::new_from_signer(&alice, &alice_account_keypair.pubkey().to_bytes())
2873+
.unwrap();
2874+
let proof_data =
2875+
confidential_transfer::instruction::PubkeyValidityProofData::new(&new_elgamal_keypair)
2876+
.unwrap();
2877+
let proof_location = ProofLocation::InstructionOffset(
2878+
1.try_into().unwrap(),
2879+
ProofData::InstructionData(&proof_data),
2880+
);
2881+
2882+
let elgamal_registry_address = spl_elgamal_registry::get_elgamal_registry_address(
2883+
&alice.pubkey(),
2884+
&spl_elgamal_registry::id(),
2885+
);
2886+
2887+
let instructions = spl_elgamal_registry::instruction::update_registry(
2888+
&elgamal_registry_address,
2889+
&alice.pubkey(),
2890+
proof_location,
2891+
)
2892+
.unwrap();
2893+
let tx = Transaction::new_signed_with_payer(
2894+
&instructions,
2895+
Some(&ctx.payer.pubkey()),
2896+
&[&ctx.payer, &alice],
2897+
ctx.last_blockhash,
2898+
);
2899+
ctx.banks_client.process_transaction(tx).await.unwrap();
2900+
drop(ctx);
2901+
2902+
// configure account using ElGamal registry
2903+
let alice_account_keypair = Keypair::new();
2904+
let alice_token_account = alice_account_keypair.pubkey();
2905+
token
2906+
.create_auxiliary_token_account_with_extension_space(
2907+
&alice_account_keypair,
2908+
&alice_token_account,
2909+
vec![ExtensionType::ConfidentialTransferAccount],
2910+
)
2911+
.await
2912+
.unwrap();
2913+
2914+
token
2915+
.confidential_transfer_configure_token_account_with_registry(
2916+
&alice_account_keypair.pubkey(),
2917+
&elgamal_registry_address,
2918+
&alice.pubkey(),
2919+
)
2920+
.await
2921+
.unwrap();
2922+
2923+
let state = token.get_account_info(&alice_token_account).await.unwrap();
2924+
let extension = state
2925+
.get_extension::<ConfidentialTransferAccount>()
2926+
.unwrap();
2927+
assert!(!bool::from(&extension.approved));
2928+
assert!(bool::from(&extension.allow_confidential_credits));
2929+
assert_eq!(
2930+
extension.elgamal_pubkey,
2931+
(*new_elgamal_keypair.pubkey()).into()
2932+
);
2933+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ impl TestContext {
5050
spl_record::id(),
5151
processor!(spl_record::processor::process_instruction),
5252
);
53+
program_test.add_program(
54+
"spl_elgamal_registry",
55+
spl_elgamal_registry::id(),
56+
processor!(spl_elgamal_registry::processor::process_instruction),
57+
);
5358
let context = program_test.start_with_context().await;
5459
let context = Arc::new(Mutex::new(context));
5560

0 commit comments

Comments
 (0)