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

Commit 57c5fd8

Browse files
token-2022: check destination accounts on confidential token tests (#3281)
* token-2022: check destination accounts on confidential token tests * token-2022: cargo clippy
1 parent c3137af commit 57c5fd8

File tree

1 file changed

+47
-75
lines changed

1 file changed

+47
-75
lines changed

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

Lines changed: 47 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -852,28 +852,25 @@ async fn ct_transfer() {
852852
)
853853
.await
854854
.unwrap_err();
855+
855856
assert_eq!(
856857
err,
857858
TokenClientError::Client(Box::new(TransportError::TransactionError(
858859
TransactionError::InstructionError(1, InstructionError::InvalidAccountData)
859860
)))
860861
);
861862

862-
let state = token
863-
.get_account_info(&bob_meta.token_account)
864-
.await
865-
.unwrap();
866-
let extension = state
867-
.get_extension::<ConfidentialTransferAccount>()
868-
.unwrap();
869-
870-
// TODO: verify bob_meta pending and available balance once syscall lands
871-
assert_eq!(
872-
bob_meta
873-
.ae_key
874-
.decrypt(&extension.decryptable_available_balance.try_into().unwrap()),
875-
Some(0),
876-
);
863+
bob_meta
864+
.check_balances(
865+
&token,
866+
ConfidentialTokenAccountBalances {
867+
pending_balance_lo: 42,
868+
pending_balance_hi: 0,
869+
available_balance: 0,
870+
decryptable_available_balance: 0,
871+
},
872+
)
873+
.await;
877874

878875
token
879876
.confidential_transfer_apply_pending_balance(
@@ -885,21 +882,17 @@ async fn ct_transfer() {
885882
.await
886883
.unwrap();
887884

888-
let state = token
889-
.get_account_info(&bob_meta.token_account)
890-
.await
891-
.unwrap();
892-
let extension = state
893-
.get_extension::<ConfidentialTransferAccount>()
894-
.unwrap();
895-
896-
// TODO: verify bob_meta pending and available balance once syscall lands
897-
assert_eq!(
898-
bob_meta
899-
.ae_key
900-
.decrypt(&extension.decryptable_available_balance.try_into().unwrap()),
901-
Some(42),
902-
);
885+
bob_meta
886+
.check_balances(
887+
&token,
888+
ConfidentialTokenAccountBalances {
889+
pending_balance_lo: 0,
890+
pending_balance_hi: 0,
891+
available_balance: 42,
892+
decryptable_available_balance: 42,
893+
},
894+
)
895+
.await;
903896
}
904897

905898
#[tokio::test]
@@ -1039,20 +1032,6 @@ async fn ct_transfer_with_fee() {
10391032
)
10401033
.await;
10411034

1042-
let state = token
1043-
.get_account_info(&alice_meta.token_account)
1044-
.await
1045-
.unwrap();
1046-
let extension = state
1047-
.get_extension::<ConfidentialTransferAccount>()
1048-
.unwrap();
1049-
assert_eq!(
1050-
alice_meta
1051-
.ae_key
1052-
.decrypt(&extension.decryptable_available_balance.try_into().unwrap()),
1053-
Some(0),
1054-
);
1055-
10561035
// Alice account cannot be closed since there are withheld fees from self-transfer
10571036
token
10581037
.confidential_transfer_empty_account(
@@ -1071,54 +1050,47 @@ async fn ct_transfer_with_fee() {
10711050
)
10721051
.await
10731052
.unwrap_err();
1053+
10741054
assert_eq!(
10751055
err,
10761056
TokenClientError::Client(Box::new(TransportError::TransactionError(
10771057
TransactionError::InstructionError(1, InstructionError::InvalidAccountData)
10781058
)))
10791059
);
10801060

1081-
let state = token
1082-
.get_account_info(&bob_meta.token_account)
1083-
.await
1084-
.unwrap();
1085-
let extension = state
1086-
.get_extension::<ConfidentialTransferAccount>()
1087-
.unwrap();
1088-
1089-
// TODO: check pending and available balance once curve syscall lands
1090-
assert_eq!(
1091-
bob_meta
1092-
.ae_key
1093-
.decrypt(&extension.decryptable_available_balance.try_into().unwrap()),
1094-
Some(0),
1095-
);
1061+
bob_meta
1062+
.check_balances(
1063+
&token,
1064+
ConfidentialTokenAccountBalances {
1065+
pending_balance_lo: 97,
1066+
pending_balance_hi: 0,
1067+
available_balance: 0,
1068+
decryptable_available_balance: 0,
1069+
},
1070+
)
1071+
.await;
10961072

10971073
token
10981074
.confidential_transfer_apply_pending_balance(
10991075
&bob_meta.token_account,
11001076
&bob,
11011077
1,
1102-
bob_meta.ae_key.encrypt(94_u64),
1078+
bob_meta.ae_key.encrypt(97_u64),
11031079
)
11041080
.await
11051081
.unwrap();
11061082

1107-
let state = token
1108-
.get_account_info(&bob_meta.token_account)
1109-
.await
1110-
.unwrap();
1111-
let extension = state
1112-
.get_extension::<ConfidentialTransferAccount>()
1113-
.unwrap();
1114-
1115-
// TODO: check pending and available balance once curve syscall lands
1116-
assert_eq!(
1117-
bob_meta
1118-
.ae_key
1119-
.decrypt(&extension.decryptable_available_balance.try_into().unwrap()),
1120-
Some(94),
1121-
);
1083+
bob_meta
1084+
.check_balances(
1085+
&token,
1086+
ConfidentialTokenAccountBalances {
1087+
pending_balance_lo: 0,
1088+
pending_balance_hi: 0,
1089+
available_balance: 97,
1090+
decryptable_available_balance: 97,
1091+
},
1092+
)
1093+
.await;
11221094
}
11231095

11241096
#[tokio::test]

0 commit comments

Comments
 (0)