|
20 | 20 | extension::{
|
21 | 21 | confidential_transfer::{
|
22 | 22 | self,
|
23 |
| - account_info::TransferAccountInfo, |
| 23 | + account_info::{EmptyAccountAccountInfo, TransferAccountInfo, WithdrawAccountInfo}, |
24 | 24 | instruction::{
|
25 | 25 | CloseSplitContextStateAccounts, TransferSplitContextStateAccounts,
|
26 | 26 | TransferWithFeeSplitContextStateAccounts,
|
|
38 | 38 | },
|
39 | 39 | },
|
40 | 40 | spl_token_client::{
|
41 |
| - proof_generation::transfer_with_fee_split_proof_data, |
| 41 | + proof_generation::{transfer_with_fee_split_proof_data, ProofAccount}, |
42 | 42 | token::{ComputeUnitLimit, ExtensionInitializationParams, TokenError as TokenClientError},
|
43 | 43 | },
|
44 | 44 | std::{convert::TryInto, mem::size_of},
|
@@ -445,6 +445,83 @@ async fn confidential_transfer_empty_account() {
|
445 | 445 | .unwrap();
|
446 | 446 | }
|
447 | 447 |
|
| 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 | + |
448 | 525 | #[cfg(feature = "zk-ops")]
|
449 | 526 | #[tokio::test]
|
450 | 527 | async fn confidential_transfer_deposit() {
|
@@ -809,6 +886,134 @@ async fn confidential_transfer_withdraw() {
|
809 | 886 | .unwrap();
|
810 | 887 | }
|
811 | 888 |
|
| 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 | + |
812 | 1017 | #[cfg(feature = "zk-ops")]
|
813 | 1018 | #[tokio::test]
|
814 | 1019 | async fn confidential_transfer_transfer() {
|
@@ -1635,7 +1840,9 @@ async fn confidential_transfer_configure_token_account_with_proof_context() {
|
1635 | 1840 | .confidential_transfer_configure_token_account(
|
1636 | 1841 | &token_account,
|
1637 | 1842 | &alice.pubkey(),
|
1638 |
| - Some(&context_state_account.pubkey()), |
| 1843 | + Some(&ProofAccount::ContextAccount( |
| 1844 | + context_state_account.pubkey(), |
| 1845 | + )), |
1639 | 1846 | None,
|
1640 | 1847 | &elgamal_keypair,
|
1641 | 1848 | &aes_key,
|
@@ -1722,7 +1929,9 @@ async fn confidential_transfer_configure_token_account_with_proof_context() {
|
1722 | 1929 | .confidential_transfer_configure_token_account(
|
1723 | 1930 | &token_account,
|
1724 | 1931 | &bob.pubkey(),
|
1725 |
| - Some(&context_state_account.pubkey()), |
| 1932 | + Some(&ProofAccount::ContextAccount( |
| 1933 | + context_state_account.pubkey(), |
| 1934 | + )), |
1726 | 1935 | None,
|
1727 | 1936 | &elgamal_keypair,
|
1728 | 1937 | &aes_key,
|
@@ -1809,7 +2018,9 @@ async fn confidential_transfer_empty_account_with_proof_context() {
|
1809 | 2018 | .confidential_transfer_empty_account(
|
1810 | 2019 | &alice_meta.token_account,
|
1811 | 2020 | &alice.pubkey(),
|
1812 |
| - Some(&context_state_account.pubkey()), |
| 2021 | + Some(&ProofAccount::ContextAccount( |
| 2022 | + context_state_account.pubkey(), |
| 2023 | + )), |
1813 | 2024 | None,
|
1814 | 2025 | &alice_meta.elgamal_keypair,
|
1815 | 2026 | &[&alice],
|
@@ -1864,7 +2075,9 @@ async fn confidential_transfer_empty_account_with_proof_context() {
|
1864 | 2075 | .confidential_transfer_empty_account(
|
1865 | 2076 | &bob_meta.token_account,
|
1866 | 2077 | &bob.pubkey(),
|
1867 |
| - Some(&context_state_account.pubkey()), |
| 2078 | + Some(&ProofAccount::ContextAccount( |
| 2079 | + context_state_account.pubkey(), |
| 2080 | + )), |
1868 | 2081 | None,
|
1869 | 2082 | &bob_meta.elgamal_keypair,
|
1870 | 2083 | &[&bob],
|
@@ -1977,7 +2190,9 @@ async fn confidential_transfer_withdraw_with_proof_context() {
|
1977 | 2190 | .confidential_transfer_withdraw(
|
1978 | 2191 | &alice_meta.token_account,
|
1979 | 2192 | &alice.pubkey(),
|
1980 |
| - Some(&context_state_account.pubkey()), |
| 2193 | + Some(&ProofAccount::ContextAccount( |
| 2194 | + context_state_account.pubkey(), |
| 2195 | + )), |
1981 | 2196 | 0,
|
1982 | 2197 | decimals,
|
1983 | 2198 | None,
|
@@ -2035,7 +2250,9 @@ async fn confidential_transfer_withdraw_with_proof_context() {
|
2035 | 2250 | .confidential_transfer_withdraw(
|
2036 | 2251 | &bob_meta.token_account,
|
2037 | 2252 | &bob.pubkey(),
|
2038 |
| - Some(&context_state_account.pubkey()), |
| 2253 | + Some(&ProofAccount::ContextAccount( |
| 2254 | + context_state_account.pubkey(), |
| 2255 | + )), |
2039 | 2256 | 0,
|
2040 | 2257 | decimals,
|
2041 | 2258 | None,
|
@@ -2169,7 +2386,9 @@ async fn confidential_transfer_transfer_with_proof_context() {
|
2169 | 2386 | &alice_meta.token_account,
|
2170 | 2387 | &bob_meta.token_account,
|
2171 | 2388 | &alice.pubkey(),
|
2172 |
| - Some(&context_state_account.pubkey()), |
| 2389 | + Some(&ProofAccount::ContextAccount( |
| 2390 | + context_state_account.pubkey(), |
| 2391 | + )), |
2173 | 2392 | 42,
|
2174 | 2393 | None,
|
2175 | 2394 | &alice_meta.elgamal_keypair,
|
@@ -2241,7 +2460,9 @@ async fn confidential_transfer_transfer_with_proof_context() {
|
2241 | 2460 | &alice_meta.token_account,
|
2242 | 2461 | &bob_meta.token_account,
|
2243 | 2462 | &alice.pubkey(),
|
2244 |
| - Some(&context_state_account.pubkey()), |
| 2463 | + Some(&ProofAccount::ContextAccount( |
| 2464 | + context_state_account.pubkey(), |
| 2465 | + )), |
2245 | 2466 | 0,
|
2246 | 2467 | None,
|
2247 | 2468 | &alice_meta.elgamal_keypair,
|
|
0 commit comments