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

Commit 92caf61

Browse files
committed
add record program tests
1 parent b245e14 commit 92caf61

File tree

5 files changed

+599
-13
lines changed

5 files changed

+599
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/program-2022-test/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ spl-memo = { version = "5.0.0", path = "../../memo/program", features = [
2727
"no-entrypoint",
2828
] }
2929
spl-pod = { version = "0.3.0", path = "../../libraries/pod" }
30+
spl-record = { version = "0.2.0", path = "../../record/program", features = [
31+
"no-entrypoint",
32+
]}
3033
spl-token-2022 = { version = "4.0.0", path = "../program-2022", features = [
3134
"no-entrypoint",
3235
] }

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

Lines changed: 231 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use {
2020
extension::{
2121
confidential_transfer::{
2222
self,
23-
account_info::TransferAccountInfo,
23+
account_info::{EmptyAccountAccountInfo, TransferAccountInfo, WithdrawAccountInfo},
2424
instruction::{
2525
CloseSplitContextStateAccounts, TransferSplitContextStateAccounts,
2626
TransferWithFeeSplitContextStateAccounts,
@@ -38,7 +38,7 @@ use {
3838
},
3939
},
4040
spl_token_client::{
41-
proof_generation::transfer_with_fee_split_proof_data,
41+
proof_generation::{transfer_with_fee_split_proof_data, ProofAccount},
4242
token::{ComputeUnitLimit, ExtensionInitializationParams, TokenError as TokenClientError},
4343
},
4444
std::{convert::TryInto, mem::size_of},
@@ -445,6 +445,83 @@ async fn confidential_transfer_empty_account() {
445445
.unwrap();
446446
}
447447

448+
#[tokio::test]
449+
async fn confidential_transfer_empty_account_with_record() {
450+
let authority = Keypair::new();
451+
let auto_approve_new_accounts = true;
452+
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
453+
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
454+
455+
let mut context = TestContext::new().await;
456+
457+
// newly created confidential transfer account should hold no balance and
458+
// therefore, immediately closable
459+
context
460+
.init_token_with_mint(vec![
461+
ExtensionInitializationParams::ConfidentialTransferMint {
462+
authority: Some(authority.pubkey()),
463+
auto_approve_new_accounts,
464+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
465+
},
466+
])
467+
.await
468+
.unwrap();
469+
470+
let TokenContext { token, alice, .. } = context.token_context.unwrap();
471+
let alice_meta = ConfidentialTokenAccountMeta::new(&token, &alice, None, false, false).await;
472+
473+
let state = token
474+
.get_account_info(&alice_meta.token_account)
475+
.await
476+
.unwrap();
477+
let extension = state
478+
.get_extension::<ConfidentialTransferAccount>()
479+
.unwrap();
480+
let account_info = EmptyAccountAccountInfo::new(extension);
481+
482+
let zero_balance_proof = account_info
483+
.generate_proof_data(&alice_meta.elgamal_keypair)
484+
.unwrap();
485+
486+
let record_account = Keypair::new();
487+
let record_account_authority = Keypair::new();
488+
489+
token
490+
.confidential_transfer_create_record_account(
491+
&record_account.pubkey(),
492+
&record_account_authority.pubkey(),
493+
&zero_balance_proof,
494+
&record_account,
495+
&record_account_authority,
496+
)
497+
.await
498+
.unwrap();
499+
500+
let proof_account = ProofAccount::RecordAccount(record_account.pubkey());
501+
502+
token
503+
.confidential_transfer_empty_account(
504+
&alice_meta.token_account,
505+
&alice.pubkey(),
506+
Some(&proof_account),
507+
None,
508+
&alice_meta.elgamal_keypair,
509+
&[&alice],
510+
)
511+
.await
512+
.unwrap();
513+
514+
token
515+
.confidential_transfer_close_record_account(
516+
&record_account.pubkey(),
517+
&record_account_authority.pubkey(),
518+
&alice.pubkey(),
519+
&record_account_authority,
520+
)
521+
.await
522+
.unwrap();
523+
}
524+
448525
#[cfg(feature = "zk-ops")]
449526
#[tokio::test]
450527
async fn confidential_transfer_deposit() {
@@ -809,6 +886,134 @@ async fn confidential_transfer_withdraw() {
809886
.unwrap();
810887
}
811888

889+
#[cfg(feature = "zk-ops")]
890+
#[tokio::test]
891+
async fn confidential_transfer_withdraw_with_record_account() {
892+
let authority = Keypair::new();
893+
let auto_approve_new_accounts = true;
894+
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
895+
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
896+
897+
let mut context = TestContext::new().await;
898+
context
899+
.init_token_with_mint(vec![
900+
ExtensionInitializationParams::ConfidentialTransferMint {
901+
authority: Some(authority.pubkey()),
902+
auto_approve_new_accounts,
903+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
904+
},
905+
])
906+
.await
907+
.unwrap();
908+
909+
let TokenContext {
910+
token,
911+
alice,
912+
mint_authority,
913+
decimals,
914+
..
915+
} = context.token_context.unwrap();
916+
let alice_meta = ConfidentialTokenAccountMeta::new_with_tokens(
917+
&token,
918+
&alice,
919+
None,
920+
false,
921+
false,
922+
&mint_authority,
923+
42,
924+
decimals,
925+
)
926+
.await;
927+
928+
let state = token
929+
.get_account_info(&alice_meta.token_account)
930+
.await
931+
.unwrap();
932+
assert_eq!(state.base.amount, 0);
933+
alice_meta
934+
.check_balances(
935+
&token,
936+
ConfidentialTokenAccountBalances {
937+
pending_balance_lo: 0,
938+
pending_balance_hi: 0,
939+
available_balance: 42,
940+
decryptable_available_balance: 42,
941+
},
942+
)
943+
.await;
944+
945+
let state = token
946+
.get_account_info(&alice_meta.token_account)
947+
.await
948+
.unwrap();
949+
let extension = state
950+
.get_extension::<ConfidentialTransferAccount>()
951+
.unwrap();
952+
let account_info = WithdrawAccountInfo::new(extension);
953+
954+
let withdraw_proof = account_info
955+
.generate_proof_data(42, &alice_meta.elgamal_keypair, &alice_meta.aes_key)
956+
.unwrap();
957+
958+
let record_account = Keypair::new();
959+
let record_account_authority = Keypair::new();
960+
961+
token
962+
.confidential_transfer_create_record_account(
963+
&record_account.pubkey(),
964+
&record_account_authority.pubkey(),
965+
&withdraw_proof,
966+
&record_account,
967+
&record_account_authority,
968+
)
969+
.await
970+
.unwrap();
971+
972+
let proof_account = ProofAccount::RecordAccount(record_account.pubkey());
973+
974+
token
975+
.confidential_transfer_withdraw(
976+
&alice_meta.token_account,
977+
&alice.pubkey(),
978+
Some(&proof_account),
979+
42,
980+
decimals,
981+
None,
982+
&alice_meta.elgamal_keypair,
983+
&alice_meta.aes_key,
984+
&[&alice],
985+
)
986+
.await
987+
.unwrap();
988+
989+
let state = token
990+
.get_account_info(&alice_meta.token_account)
991+
.await
992+
.unwrap();
993+
assert_eq!(state.base.amount, 42);
994+
alice_meta
995+
.check_balances(
996+
&token,
997+
ConfidentialTokenAccountBalances {
998+
pending_balance_lo: 0,
999+
pending_balance_hi: 0,
1000+
available_balance: 0,
1001+
decryptable_available_balance: 0,
1002+
},
1003+
)
1004+
.await;
1005+
1006+
token
1007+
.confidential_transfer_close_record_account(
1008+
&record_account.pubkey(),
1009+
&record_account_authority.pubkey(),
1010+
&alice.pubkey(),
1011+
&record_account_authority,
1012+
)
1013+
.await
1014+
.unwrap();
1015+
}
1016+
8121017
#[cfg(feature = "zk-ops")]
8131018
#[tokio::test]
8141019
async fn confidential_transfer_transfer() {
@@ -1635,7 +1840,9 @@ async fn confidential_transfer_configure_token_account_with_proof_context() {
16351840
.confidential_transfer_configure_token_account(
16361841
&token_account,
16371842
&alice.pubkey(),
1638-
Some(&context_state_account.pubkey()),
1843+
Some(&ProofAccount::ContextAccount(
1844+
context_state_account.pubkey(),
1845+
)),
16391846
None,
16401847
&elgamal_keypair,
16411848
&aes_key,
@@ -1722,7 +1929,9 @@ async fn confidential_transfer_configure_token_account_with_proof_context() {
17221929
.confidential_transfer_configure_token_account(
17231930
&token_account,
17241931
&bob.pubkey(),
1725-
Some(&context_state_account.pubkey()),
1932+
Some(&ProofAccount::ContextAccount(
1933+
context_state_account.pubkey(),
1934+
)),
17261935
None,
17271936
&elgamal_keypair,
17281937
&aes_key,
@@ -1809,7 +2018,9 @@ async fn confidential_transfer_empty_account_with_proof_context() {
18092018
.confidential_transfer_empty_account(
18102019
&alice_meta.token_account,
18112020
&alice.pubkey(),
1812-
Some(&context_state_account.pubkey()),
2021+
Some(&ProofAccount::ContextAccount(
2022+
context_state_account.pubkey(),
2023+
)),
18132024
None,
18142025
&alice_meta.elgamal_keypair,
18152026
&[&alice],
@@ -1864,7 +2075,9 @@ async fn confidential_transfer_empty_account_with_proof_context() {
18642075
.confidential_transfer_empty_account(
18652076
&bob_meta.token_account,
18662077
&bob.pubkey(),
1867-
Some(&context_state_account.pubkey()),
2078+
Some(&ProofAccount::ContextAccount(
2079+
context_state_account.pubkey(),
2080+
)),
18682081
None,
18692082
&bob_meta.elgamal_keypair,
18702083
&[&bob],
@@ -1977,7 +2190,9 @@ async fn confidential_transfer_withdraw_with_proof_context() {
19772190
.confidential_transfer_withdraw(
19782191
&alice_meta.token_account,
19792192
&alice.pubkey(),
1980-
Some(&context_state_account.pubkey()),
2193+
Some(&ProofAccount::ContextAccount(
2194+
context_state_account.pubkey(),
2195+
)),
19812196
0,
19822197
decimals,
19832198
None,
@@ -2035,7 +2250,9 @@ async fn confidential_transfer_withdraw_with_proof_context() {
20352250
.confidential_transfer_withdraw(
20362251
&bob_meta.token_account,
20372252
&bob.pubkey(),
2038-
Some(&context_state_account.pubkey()),
2253+
Some(&ProofAccount::ContextAccount(
2254+
context_state_account.pubkey(),
2255+
)),
20392256
0,
20402257
decimals,
20412258
None,
@@ -2169,7 +2386,9 @@ async fn confidential_transfer_transfer_with_proof_context() {
21692386
&alice_meta.token_account,
21702387
&bob_meta.token_account,
21712388
&alice.pubkey(),
2172-
Some(&context_state_account.pubkey()),
2389+
Some(&ProofAccount::ContextAccount(
2390+
context_state_account.pubkey(),
2391+
)),
21732392
42,
21742393
None,
21752394
&alice_meta.elgamal_keypair,
@@ -2241,7 +2460,9 @@ async fn confidential_transfer_transfer_with_proof_context() {
22412460
&alice_meta.token_account,
22422461
&bob_meta.token_account,
22432462
&alice.pubkey(),
2244-
Some(&context_state_account.pubkey()),
2463+
Some(&ProofAccount::ContextAccount(
2464+
context_state_account.pubkey(),
2465+
)),
22452466
0,
22462467
None,
22472468
&alice_meta.elgamal_keypair,

0 commit comments

Comments
 (0)