Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 65c3af3

Browse files
authored
lending: Add overflow check in proptest (#1199)
This issue was discovered during CI: https://github.com/solana-labs/solana-program-library/runs/1833196857 The approach is to do the same calc as `_liquidate_obligation` and make sure that the `MockConverter` doesn't overflow `Decimal`. This seemed like a simpler approach than doing a complex local proptest constraint. On top of that, it includes the proptest regression to run it on every `cargo test`.
1 parent 424a3a9 commit 65c3af3

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ node_modules
77
./package-lock.json
88
hfuzz_target
99
hfuzz_workspace
10-
proptest-regressions
1110
**/*.so
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cc 39c6d681e691839313426bb0801cf3f46d0befb69b568a28cf6d8e752d74526b

token-lending/program/src/state/reserve.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,16 @@ mod test {
854854
..Obligation::default()
855855
};
856856

857+
// Ensure that the token conversion fits in a Decimal
858+
{
859+
let token_converter = MockConverter(token_conversion_rate);
860+
let decimal_repay_amount = Decimal::from(obligation.max_liquidation_amount()?);
861+
// Calculate the amount of collateral that will be received
862+
let receive_liquidity_amount_result =
863+
token_converter.convert(decimal_repay_amount, &Pubkey::default());
864+
prop_assume!(receive_liquidity_amount_result.is_ok());
865+
}
866+
857867
// Liquidate with max amount to ensure obligation can be liquidated
858868
let liquidate_result = Reserve::_liquidate_obligation(
859869
&obligation,

0 commit comments

Comments
 (0)