Skip to main content

perpl_sdk/testing/
account.rs

1use alloy::primitives::{Address, U256};
2use fastnum::UD128;
3
4use super::TestExchange;
5use crate::types;
6
7#[derive(Debug)]
8pub struct TestAccount<'e> {
9    pub id: types::AccountId,
10    pub address: Address,
11    pub exchange: &'e TestExchange,
12}
13
14impl<'e> TestAccount<'e> {
15    pub async fn balance(&self) -> UD128 {
16        let acc = self
17            .exchange
18            .exchange
19            .getAccountById(U256::from(self.id))
20            .call()
21            .await
22            .unwrap();
23        self.exchange
24            .collateral_converter
25            .from_unsigned(acc.balanceCNS)
26    }
27
28    pub async fn locked_balance(&self) -> UD128 {
29        let acc = self
30            .exchange
31            .exchange
32            .getAccountById(U256::from(self.id))
33            .call()
34            .await
35            .unwrap();
36        self.exchange
37            .collateral_converter
38            .from_unsigned(acc.lockedBalanceCNS)
39    }
40}