Skip to content

make workflow changes #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: v2.0.3_upcoming
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/pull-request-token-lending.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
cargo-test-bpf:
runs-on: ubuntu-latest-16-cores
runs-on: blacksmith-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v2

Expand All @@ -24,26 +24,27 @@ jobs:
source ci/solana-version.sh
echo "SOLANA_VERSION=$solana_version" >> $GITHUB_ENV


- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_STABLE }}
override: true
profile: minimal

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ env.RUST_STABLE}}

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cargo/bin/rustfilt
key: cargo-bpf-bins-${{ runner.os }}

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cache
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
all_github_action_checks:
runs-on: ubuntu-latest
runs-on: blacksmith-16vcpu-ubuntu-2204
needs:
- rustfmt
- clippy
Expand All @@ -20,7 +20,7 @@ jobs:
- run: echo "Done"

rustfmt:
runs-on: ubuntu-latest
runs-on: blacksmith-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v2

Expand All @@ -43,7 +43,7 @@ jobs:
args: --all -- --check

clippy:
runs-on: ubuntu-latest
runs-on: blacksmith-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v2

Expand All @@ -59,7 +59,7 @@ jobs:
profile: minimal
components: clippy

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cargo/registry
Expand All @@ -79,7 +79,7 @@ jobs:
args: --workspace --all-targets -- --deny=warnings

cargo-build-test:
runs-on: ubuntu-latest
runs-on: blacksmith-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v2

Expand All @@ -96,21 +96,21 @@ jobs:
override: true
profile: minimal

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
# target # Removed due to build dependency caching conflicts
key: cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ env.RUST_STABLE}}

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cargo/bin/rustfilt
key: cargo-bpf-bins-${{ runner.os }}

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cache
Expand All @@ -126,7 +126,7 @@ jobs:
run: ./ci/cargo-build-test.sh

cargo-coverage:
runs-on: ubuntu-latest-16-cores
runs-on: blacksmith-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v2

Expand All @@ -143,7 +143,7 @@ jobs:
override: true
profile: minimal

- uses: actions/cache@v2
- uses: useblacksmith/cache@v5
with:
path: |
~/.cargo/registry
Expand Down
4 changes: 2 additions & 2 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ fn _refresh_reserve<'a>(

/// Lite version of refresh_reserve that should be used when the oracle price doesn't need to be updated
/// BE CAREFUL WHEN USING THIS
fn _refresh_reserve_interest<'a>(
fn _refresh_reserve_interest(
program_id: &Pubkey,
reserve_info: &AccountInfo<'a>,
reserve_info: &AccountInfo<'_>,
clock: &Clock,
) -> ProgramResult {
let mut reserve = Box::new(Reserve::unpack(&reserve_info.data.borrow())?);
Expand Down
2 changes: 1 addition & 1 deletion token-lending/program/tests/helpers/mock_pyth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Processor {
msg!("Mock Pyth: Set price");
let price_account_info = next_account_info(account_info_iter)?;
let data = &mut price_account_info.try_borrow_mut_data()?;
let mut price_account: &mut PriceAccount = load_mut(data).unwrap();
let price_account: &mut PriceAccount = load_mut(data).unwrap();

price_account.agg.price = price;
price_account.agg.conf = conf;
Expand Down
5 changes: 1 addition & 4 deletions token-lending/program/tests/helpers/solend_program_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1758,10 +1758,7 @@ pub async fn custom_scenario(
.or_insert(arg.liquidity_amount);
}

let mints_and_liquidity_amounts = mints_and_liquidity_amounts
.into_iter()
.map(|(mint, liquidity_amount)| (mint, liquidity_amount))
.collect::<Vec<_>>();
let mints_and_liquidity_amounts = mints_and_liquidity_amounts.into_iter().collect::<Vec<_>>();

let lending_market_owner =
User::new_with_balances(&mut test, &mints_and_liquidity_amounts).await;
Expand Down
1 change: 1 addition & 0 deletions token-lending/program/tests/two_prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ async fn test_liquidation_doesnt_use_smoothed_price() {
diff: -((LAMPORTS_PER_SOL / 5) as i128),
},
]);
println!("hello");

assert_eq!(balance_changes, expected_balances_changes);
}
156 changes: 78 additions & 78 deletions token-lending/sdk/src/state/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,84 +141,6 @@ impl RateLimiter {
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_rate_limiter() {
let mut rate_limiter = RateLimiter::new(
RateLimiterConfig {
window_duration: 10,
max_outflow: 100,
},
10,
);

assert_eq!(
rate_limiter.update(9, Decimal::from(1u64)),
Err(LendingError::InvalidAccountInput.into())
);

// case 1: no prev window, all quantity is taken up in first slot
assert_eq!(
rate_limiter.update(10, Decimal::from(101u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);
assert_eq!(
rate_limiter.remaining_outflow(10),
Ok(Decimal::from(100u64))
);

assert_eq!(rate_limiter.update(10, Decimal::from(100u64)), Ok(()));
assert_eq!(rate_limiter.remaining_outflow(10), Ok(Decimal::from(0u64)));
for i in 11..20 {
assert_eq!(
rate_limiter.update(i, Decimal::from(1u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);
assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64)));
}

// case 2: prev window qty affects cur window's allowed qty. exactly 10 qty frees up every
// slot.
for i in 20..30 {
assert_eq!(
rate_limiter.update(i, Decimal::from(11u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);

assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(10u64)));
assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(()));
assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64)));

assert_eq!(
rate_limiter.update(i, Decimal::from(1u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);
}

// case 3: new slot is so far ahead, prev window is dropped
assert_eq!(
rate_limiter.remaining_outflow(100),
Ok(Decimal::from(100u64))
);
assert_eq!(rate_limiter.update(100, Decimal::from(10u64)), Ok(()));
for i in 101..109 {
assert_eq!(
rate_limiter.remaining_outflow(i),
Ok(Decimal::from(100u64 - 10 * (i - 100)))
);
assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(()));
assert_eq!(
rate_limiter.remaining_outflow(i),
Ok(Decimal::from(90u64 - 10 * (i - 100)))
);
}
println!("{:#?}", rate_limiter);
}
}

impl Default for RateLimiter {
fn default() -> Self {
Self::new(
Expand Down Expand Up @@ -301,3 +223,81 @@ pub fn rand_rate_limiter() -> RateLimiter {
cur_qty: rand_decimal(),
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_rate_limiter() {
let mut rate_limiter = RateLimiter::new(
RateLimiterConfig {
window_duration: 10,
max_outflow: 100,
},
10,
);

assert_eq!(
rate_limiter.update(9, Decimal::from(1u64)),
Err(LendingError::InvalidAccountInput.into())
);

// case 1: no prev window, all quantity is taken up in first slot
assert_eq!(
rate_limiter.update(10, Decimal::from(101u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);
assert_eq!(
rate_limiter.remaining_outflow(10),
Ok(Decimal::from(100u64))
);

assert_eq!(rate_limiter.update(10, Decimal::from(100u64)), Ok(()));
assert_eq!(rate_limiter.remaining_outflow(10), Ok(Decimal::from(0u64)));
for i in 11..20 {
assert_eq!(
rate_limiter.update(i, Decimal::from(1u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);
assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64)));
}

// case 2: prev window qty affects cur window's allowed qty. exactly 10 qty frees up every
// slot.
for i in 20..30 {
assert_eq!(
rate_limiter.update(i, Decimal::from(11u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);

assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(10u64)));
assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(()));
assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64)));

assert_eq!(
rate_limiter.update(i, Decimal::from(1u64)),
Err(LendingError::OutflowRateLimitExceeded.into())
);
}

// case 3: new slot is so far ahead, prev window is dropped
assert_eq!(
rate_limiter.remaining_outflow(100),
Ok(Decimal::from(100u64))
);
assert_eq!(rate_limiter.update(100, Decimal::from(10u64)), Ok(()));
for i in 101..109 {
assert_eq!(
rate_limiter.remaining_outflow(i),
Ok(Decimal::from(100u64 - 10 * (i - 100)))
);
assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(()));
assert_eq!(
rate_limiter.remaining_outflow(i),
Ok(Decimal::from(90u64 - 10 * (i - 100)))
);
}
println!("{:#?}", rate_limiter);
}
}
10 changes: 2 additions & 8 deletions token-lending/sdk/src/state/reserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2605,14 +2605,8 @@ mod test {
}

fn calculate_liquidation_test_cases() -> impl Strategy<Value = LiquidationTestCase> {
let close_factor: Decimal = Rate::from_percent(LIQUIDATION_CLOSE_FACTOR)
.try_into()
.unwrap();
let liquidation_bonus: Decimal = Rate::from_percent(5)
.try_add(Rate::one())
.unwrap()
.try_into()
.unwrap();
let close_factor: Decimal = Rate::from_percent(LIQUIDATION_CLOSE_FACTOR).into();
let liquidation_bonus: Decimal = Rate::from_percent(5).try_add(Rate::one()).unwrap().into();

prop_oneof![
// collateral market value > liquidation value
Expand Down