@@ -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 } ,
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+ }
0 commit comments