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`.
This commit is contained in:
parent
424a3a93d4
commit
65c3af3217
|
@ -7,5 +7,4 @@ node_modules
|
|||
./package-lock.json
|
||||
hfuzz_target
|
||||
hfuzz_workspace
|
||||
proptest-regressions
|
||||
**/*.so
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
cc 39c6d681e691839313426bb0801cf3f46d0befb69b568a28cf6d8e752d74526b
|
|
@ -854,6 +854,16 @@ mod test {
|
|||
..Obligation::default()
|
||||
};
|
||||
|
||||
// Ensure that the token conversion fits in a Decimal
|
||||
{
|
||||
let token_converter = MockConverter(token_conversion_rate);
|
||||
let decimal_repay_amount = Decimal::from(obligation.max_liquidation_amount()?);
|
||||
// Calculate the amount of collateral that will be received
|
||||
let receive_liquidity_amount_result =
|
||||
token_converter.convert(decimal_repay_amount, &Pubkey::default());
|
||||
prop_assume!(receive_liquidity_amount_result.is_ok());
|
||||
}
|
||||
|
||||
// Liquidate with max amount to ensure obligation can be liquidated
|
||||
let liquidate_result = Reserve::_liquidate_obligation(
|
||||
&obligation,
|
||||
|
|
Loading…
Reference in New Issue