@@ -13,22 +13,56 @@ use {
13
13
confidential_transfer:: { ConfidentialTransferAccount , ConfidentialTransferMint } ,
14
14
ExtensionType ,
15
15
} ,
16
- solana_zk_token_sdk:: encryption:: { auth_encryption :: * , elgamal:: * } ,
16
+ solana_zk_token_sdk:: encryption:: elgamal:: * ,
17
17
} ,
18
18
spl_token_client:: token:: { ExtensionInitializationParams , TokenError as TokenClientError } ,
19
19
std:: convert:: TryInto ,
20
20
} ;
21
21
22
+ struct ConfidentialTransferMintWithKeypairs {
23
+ ct_mint : ConfidentialTransferMint ,
24
+ ct_mint_authority : Keypair ,
25
+ #[ allow( dead_code) ]
26
+ ct_mint_auditor : ElGamalKeypair ,
27
+ #[ allow( dead_code) ]
28
+ ct_mint_withdraw_withheld_authority : ElGamalKeypair ,
29
+ }
30
+
31
+ impl ConfidentialTransferMintWithKeypairs {
32
+ fn new ( ) -> Self {
33
+ let ct_mint_authority = Keypair :: new ( ) ;
34
+ let ct_mint_auditor = ElGamalKeypair :: new_rand ( ) ;
35
+ let ct_mint_withdraw_withheld_authority = ElGamalKeypair :: new_rand ( ) ;
36
+ let ct_mint = ConfidentialTransferMint {
37
+ authority : ct_mint_authority. pubkey ( ) . into ( ) ,
38
+ auto_approve_new_accounts : true . into ( ) ,
39
+ auditor_pubkey : ct_mint_auditor. public . into ( ) ,
40
+ withdraw_withheld_authority_pubkey : ct_mint_withdraw_withheld_authority. public . into ( ) ,
41
+ } ;
42
+ Self {
43
+ ct_mint,
44
+ ct_mint_authority,
45
+ ct_mint_auditor,
46
+ ct_mint_withdraw_withheld_authority,
47
+ }
48
+ }
49
+
50
+ fn without_auto_approve ( ) -> Self {
51
+ let mut x = Self :: new ( ) ;
52
+ x. ct_mint . auto_approve_new_accounts = false . into ( ) ;
53
+ x
54
+ }
55
+ }
56
+
22
57
#[ tokio:: test]
23
58
async fn ct_initialize_and_update_mint ( ) {
24
59
let wrong_keypair = Keypair :: new ( ) ;
25
60
26
- let ct_mint_authority = Keypair :: new ( ) ;
27
- let ct_mint = ConfidentialTransferMint {
28
- authority : ct_mint_authority. pubkey ( ) ,
29
- ..ConfidentialTransferMint :: default ( )
30
- } ;
31
-
61
+ let ConfidentialTransferMintWithKeypairs {
62
+ ct_mint,
63
+ ct_mint_authority,
64
+ ..
65
+ } = ConfidentialTransferMintWithKeypairs :: new ( ) ;
32
66
let mut context = TestContext :: new ( ) . await ;
33
67
context
34
68
. init_token_with_mint ( vec ! [
@@ -91,11 +125,11 @@ async fn ct_initialize_and_update_mint() {
91
125
92
126
#[ tokio:: test]
93
127
async fn ct_configure_token_account ( ) {
94
- let ct_mint_authority = Keypair :: new ( ) ;
95
- let ct_mint = ConfidentialTransferMint {
96
- authority : ct_mint_authority. pubkey ( ) ,
97
- ..ConfidentialTransferMint :: default ( )
98
- } ;
128
+ let ConfidentialTransferMintWithKeypairs {
129
+ ct_mint ,
130
+ ct_mint_authority,
131
+ ..
132
+ } = ConfidentialTransferMintWithKeypairs :: without_auto_approve ( ) ;
99
133
100
134
let mut context = TestContext :: new ( ) . await ;
101
135
context
@@ -116,16 +150,8 @@ async fn ct_configure_token_account() {
116
150
. await
117
151
. unwrap ( ) ;
118
152
119
- let alice_elgamal_keypair = ElGamalKeypair :: new_rand ( ) ;
120
- let alice_ae_key = AeKey :: new ( & alice, & alice_token_account) . unwrap ( ) ;
121
-
122
- token
123
- . confidential_transfer_configure_token_account (
124
- & alice_token_account,
125
- & alice,
126
- alice_elgamal_keypair. public ,
127
- alice_ae_key. encrypt ( 0_u64 ) ,
128
- )
153
+ let ( alice_elgamal_keypair, alice_ae_key) = token
154
+ . confidential_transfer_configure_token_account_and_keypairs ( & alice_token_account, & alice)
129
155
. await
130
156
. unwrap ( ) ;
131
157
@@ -160,7 +186,8 @@ async fn ct_configure_token_account() {
160
186
161
187
#[ tokio:: test]
162
188
async fn ct_enable_disable_balance_credits ( ) {
163
- let ct_mint = ConfidentialTransferMint :: default ( ) ;
189
+ let ConfidentialTransferMintWithKeypairs { ct_mint, .. } =
190
+ ConfidentialTransferMintWithKeypairs :: new ( ) ;
164
191
let mut context = TestContext :: new ( ) . await ;
165
192
context
166
193
. init_token_with_mint ( vec ! [
@@ -180,16 +207,8 @@ async fn ct_enable_disable_balance_credits() {
180
207
. await
181
208
. unwrap ( ) ;
182
209
183
- let alice_elgamal_keypair = ElGamalKeypair :: new_rand ( ) ;
184
- let alice_ae_key = AeKey :: new ( & alice, & alice_token_account) . unwrap ( ) ;
185
-
186
- token
187
- . confidential_transfer_configure_token_account (
188
- & alice_token_account,
189
- & alice,
190
- alice_elgamal_keypair. public ,
191
- alice_ae_key. encrypt ( 0_u64 ) ,
192
- )
210
+ let _ = token
211
+ . confidential_transfer_configure_token_account_and_keypairs ( & alice_token_account, & alice)
193
212
. await
194
213
. unwrap ( ) ;
195
214
0 commit comments