From f9e1b9b182a89c1855d6741b77978e7167dce25b Mon Sep 17 00:00:00 2001 From: markuspluna <59978114+markuspluna@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:22:15 -0600 Subject: [PATCH] Tests: added auction underflow panic test --- Cargo.toml | 2 +- test-suites/tests/test_liquidation.rs | 69 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7bdd0f10..51f365e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ debug-assertions = true [profile.release] opt-level = "z" -overflow-checks = true +overflow-checks = true # DEV: Do not remove this check - doing so will create vulnerabilities debug = 0 strip = "symbols" debug-assertions = false diff --git a/test-suites/tests/test_liquidation.rs b/test-suites/tests/test_liquidation.rs index 6a7ce85b..75114f3f 100644 --- a/test-suites/tests/test_liquidation.rs +++ b/test-suites/tests/test_liquidation.rs @@ -1121,3 +1121,72 @@ fn test_user_restore_position_and_delete_liquidation() { ); assert!(pool_fixture.pool.try_get_auction(&0, &samwise).is_err()); } + +#[test] +#[should_panic] +fn test_auction_underflow_panics() { + let fixture = create_fixture_with_data(true); + let frodo = fixture.users.get(0).unwrap(); + let pool_fixture = &fixture.pools[0]; + + // Create a user + let samwise = Address::generate(&fixture.env); //sam will be supplying XLM and borrowing STABLE + + // Mint users tokens + fixture.tokens[TokenIndex::XLM].mint(&samwise, &(500_000 * SCALAR_7)); + + // Supply and borrow sam tokens + let sam_requests: Vec = vec![ + &fixture.env, + Request { + request_type: 2, + address: fixture.tokens[TokenIndex::XLM].address.clone(), + amount: 6_000 * SCALAR_7, + }, + Request { + request_type: 4, + address: fixture.tokens[TokenIndex::STABLE].address.clone(), + amount: 200 * 10i128.pow(6), + }, + ]; + pool_fixture + .pool + .submit(&samwise, &samwise, &samwise, &sam_requests); + + //tank xlm price + fixture.oracle.set_price_stable(&vec![ + &fixture.env, + 1000_0000000, // eth + 1_0000000, // usdc + 0_0000100, // xlm + 1_0000000, // stable + ]); + + //fully liquidate user + let liq_pct = 100; + let auction_data_2 = pool_fixture + .pool + .new_liquidation_auction(&samwise, &liq_pct); + + let usdc_bid_amount = auction_data_2 + .bid + .get_unchecked(fixture.tokens[TokenIndex::STABLE].address.clone()); + + //fill user liquidation + let fill_requests = vec![ + &fixture.env, + Request { + request_type: 6, + address: samwise.clone(), + amount: 100, + }, + Request { + request_type: 5, + address: fixture.tokens[TokenIndex::STABLE].address.clone(), + amount: usdc_bid_amount, + }, + ]; + pool_fixture + .pool + .submit(&frodo, &frodo, &frodo, &fill_requests); +}