Skip to content

Commit

Permalink
test: Add a test for borrowing from loan_pool.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovipu committed Sep 10, 2024
1 parent a389ae9 commit ad9707c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions contracts/loan_pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,40 @@ mod test {
assert_eq!(result, amount);
}

#[test]
fn borrow() {
let e = Env::default();
e.mock_all_auths();

let admin = Address::generate(&e);

let token_contract_id = e.register_stellar_asset_contract(admin.clone());
let asset = StellarAssetClient::new(&e, &token_contract_id);

let token_client = TokenClient::new(&e, &token_contract_id);
let currency = Currency {
token_address: token_contract_id,
ticker: Symbol::new(&e, "XLM"),
};

let contract_id = e.register_contract(None, LoanPoolContract);
let contract_client = LoanPoolContractClient::new(&e, &contract_id);
contract_client.initialize(&currency, &TEST_LIQUIDATION_THRESHOLD);

// Deposit funds for the borrower to loan.
let depositer = Address::generate(&e);
asset.mint(&depositer, &100);
contract_client.deposit(&depositer, &100);

// Borrow some of those funds
let borrower = Address::generate(&e);
contract_client.borrow(&borrower, &50);

// Did the funds move?
assert_eq!(token_client.balance(&depositer), 0);
assert_eq!(token_client.balance(&borrower), 50);
}

#[test]
fn withdraw() {
let e: Env = Env::default();
Expand Down

0 comments on commit ad9707c

Please sign in to comment.