Skip to content

Commit

Permalink
Budget optimization integration tests: borrow()
Browse files Browse the repository at this point in the history
  • Loading branch information
artur-abliazimov authored Sep 20, 2023
2 parents f838f3d + 79076c0 commit c39a5be
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 36 deletions.
2 changes: 1 addition & 1 deletion contracts/pool/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod account_position;
pub mod borrow;
// #[cfg(feature = "budget")]
#[cfg(feature = "budget")]
pub mod budget;
pub mod collat_coeff;
pub mod configure_as_collateral;
Expand Down
66 changes: 33 additions & 33 deletions contracts/pool/src/tests/snapshots/budget_utilization.snap
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
['pool::tests::budget::account_position'] = {
"cpu_cost": 85009300,
"cpu_cost": 85009264,
"memory_cost": 18025534,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::borrow'] = {
"cpu_cost": 115080954,
"cpu_cost": 115080578,
"memory_cost": 26154416,
"cpu_limit_exceeded": true,
"memory_limit_exceeded": false,
}
['pool::tests::budget::collat_coeff'] = {
"cpu_cost": 33308127,
"cpu_cost": 33321381,
"memory_cost": 3641467,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::configure_as_collateral'] = {
"cpu_cost": 33499967,
"cpu_cost": 33504620,
"memory_cost": 3672541,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::debt_coeff'] = {
"cpu_cost": 33201344,
"cpu_cost": 33204062,
"memory_cost": 3640748,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::deposit'] = {
"cpu_cost": 57506415,
"cpu_cost": 57507628,
"memory_cost": 7801939,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::enable_borrowing_on_reserve'] = {
"cpu_cost": 33464217,
"cpu_cost": 33461724,
"memory_cost": 3670866,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::flash_loan_fee'] = {
"cpu_cost": 33050259,
"cpu_cost": 33050151,
"memory_cost": 3631399,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::flash_loan_with_borrow'] = {
"cpu_cost": 179616487,
"cpu_cost": 179607527,
"memory_cost": 44176818,
"cpu_limit_exceeded": true,
"memory_limit_exceeded": true,
}
['pool::tests::budget::flash_loan_without_borrow'] = {
"cpu_cost": 76931953,
"cpu_cost": 76922644,
"memory_cost": 14169119,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::get_reserve'] = {
"cpu_cost": 33132553,
"cpu_cost": 33137881,
"memory_cost": 3633318,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::init_reserve'] = {
"cpu_cost": 262235,
"cpu_cost": 261191,
"memory_cost": 19794,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::ir_params'] = {
"cpu_cost": 33149831,
"cpu_cost": 33149615,
"memory_cost": 3640748,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::liquidate_receive_stoken'] = {
"cpu_cost": 160225857,
"cpu_cost": 160224640,
"memory_cost": 38063730,
"cpu_limit_exceeded": true,
"memory_limit_exceeded": false,
}
['pool::tests::budget::liquidate_receive_underlying'] = {
"cpu_cost": 77218241,
"cpu_cost": 77210498,
"memory_cost": 19949790,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::paused'] = {
"cpu_cost": 33038395,
"cpu_cost": 33038287,
"memory_cost": 3631189,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
Expand All @@ -101,67 +101,67 @@
"memory_limit_exceeded": false,
}
['pool::tests::budget::repay_full'] = {
"cpu_cost": 46818052,
"cpu_cost": 46787486,
"memory_cost": 7043235,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::repay_partial'] = {
"cpu_cost": 46862748,
"cpu_cost": 46838678,
"memory_cost": 7034537,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::s_token_transfer'] = {
"cpu_cost": 79953718,
"cpu_cost": 79945130,
"memory_cost": 17685848,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_as_collateral'] = {
"cpu_cost": 62356353,
"cpu_cost": 62358927,
"memory_cost": 12850139,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_base_asset'] = {
"cpu_cost": 33445371,
"cpu_cost": 33449304,
"memory_cost": 3670386,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_decimals'] = {
"cpu_cost": 33444151,
"cpu_cost": 33440182,
"memory_cost": 3670352,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_flash_loan_fee'] = {
"cpu_cost": 33332393,
"cpu_cost": 33332933,
"memory_cost": 3667999,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_ir_params'] = {
"cpu_cost": 33377906,
"cpu_cost": 33378482,
"memory_cost": 3670110,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_pause'] = {
"cpu_cost": 33323556,
"cpu_cost": 33323268,
"memory_cost": 3667959,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_price_feed'] = {
"cpu_cost": 167757,
"cpu_cost": 168045,
"memory_cost": 12292,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_reserve_status'] = {
"cpu_cost": 33461093,
"cpu_cost": 33469067,
"memory_cost": 3670824,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
Expand All @@ -179,37 +179,37 @@
"memory_limit_exceeded": false,
}
['pool::tests::budget::upgrade'] = {
"cpu_cost": 33359807,
"cpu_cost": 33361535,
"memory_cost": 3669997,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::upgrade_debt_token'] = {
"cpu_cost": 39031973,
"cpu_cost": 39027113,
"memory_cost": 5253684,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::upgrade_s_token'] = {
"cpu_cost": 44564944,
"cpu_cost": 44570128,
"memory_cost": 5665520,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::user_configuration'] = {
"cpu_cost": 32944537,
"cpu_cost": 32943340,
"memory_cost": 3628849,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::withdraw_full'] = {
"cpu_cost": 92333825,
"cpu_cost": 92347725,
"memory_cost": 19763624,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::withdraw_partial'] = {
"cpu_cost": 92226088,
"cpu_cost": 92221202,
"memory_cost": 19754496,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
Expand Down
1 change: 1 addition & 0 deletions contracts/pool/src/tests/sut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub(crate) fn fill_pool_three<'a, 'b>(
(lender, borrower, liquidator, debt_config)
}

#[cfg(feature = "budget")]
pub(crate) fn fill_pool_four<'a, 'b>(env: &'b Env, sut: &'a Sut) -> (Address, Address) {
let lender = Address::random(&env);
let borrower1 = Address::random(&env);
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/tests/pool.sut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ export async function mintBurn(
client: SorobanClient,
mintsBurns: Array<MintBurn>
): Promise<void> {
return;

for (let i = 0; i < mintsBurns.length; i++) {
const response = await client.sendTransaction(
mintsBurns[i].asset_balance.get("asset"),
Expand Down
67 changes: 67 additions & 0 deletions integration-tests/tests/pool/6.tx.budget.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { SorobanClient } from "../soroban.client";
import {
borrow,
cleanSlenderEnvKeys,
deploy,
deposit,
init,
mintUnderlyingTo,
} from "../pool.sut";
import {
borrower1Keys,
borrower2Keys,
lender1Keys,
} from "../soroban.config";
import { expect, use } from "chai";
import chaiAsPromised from 'chai-as-promised';
use(chaiAsPromised);

describe("LendingPool: methods must not exceed CPU/MEM limits", function () {
let client: SorobanClient;
let lender1Address: string;
let borrower1Address: string;
let borrower2Address: string;

before(async function () {
client = new SorobanClient();

await cleanSlenderEnvKeys();
await deploy();
await init(client);

lender1Address = lender1Keys.publicKey();
borrower1Address = borrower1Keys.publicKey();
borrower2Address = borrower2Keys.publicKey();

await client.registerAccount(lender1Address);
await client.registerAccount(borrower1Address);
await client.registerAccount(borrower2Address);

await mintUnderlyingTo(client, "XLM", lender1Address, 100_000_000_000n);
await mintUnderlyingTo(client, "XRP", lender1Address, 100_000_000_000n);
await mintUnderlyingTo(client, "USDC", lender1Address, 100_000_000_000n);
await mintUnderlyingTo(client, "XLM", borrower1Address, 100_000_000_000n);
await mintUnderlyingTo(client, "XRP", borrower1Address, 100_000_000_000n);
await mintUnderlyingTo(client, "USDC", borrower2Address, 100_000_000_000n);

// Lender1 deposits 10_000_000_000 XLM, XRP, USDC
await deposit(client, lender1Keys, "XLM", 10_000_000_000n);
await deposit(client, lender1Keys, "XRP", 10_000_000_000n);
await deposit(client, lender1Keys, "USDC", 10_000_000_000n);

// Borrower1 deposits 10_000_000_000 XLM, XRP, borrows 6_000_000_000 USDC
await deposit(client, borrower1Keys, "XLM", 10_000_000_000n);
await deposit(client, borrower1Keys, "XRP", 10_000_000_000n);
await borrow(client, borrower1Keys, "USDC", 6_000_000_000n);

// Borrower2 deposits 20_000_000_000 USDC, borrows 6_000_000_000 XLM, 5_999_000_000 XRP
await deposit(client, borrower2Keys, "USDC", 20_000_000_000n);
await borrow(client, borrower2Keys, "XLM", 6_000_000_000n);
await borrow(client, borrower2Keys, "XRP", 5_900_000_000n);
});

it("Case 1: borrow()", async function () {
// Borrower1 borrows 20_000_000 USDC
await expect(borrow(client, borrower1Keys, "USDC", 20_000_000n)).to.not.eventually.rejected;
});
});

0 comments on commit c39a5be

Please sign in to comment.