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:
Jon Cinque 2021-02-08 14:35:55 +01:00 committed by GitHub
parent 424a3a93d4
commit 65c3af3217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

1
.gitignore vendored
View File

@ -7,5 +7,4 @@ node_modules
./package-lock.json
hfuzz_target
hfuzz_workspace
proptest-regressions
**/*.so

View File

@ -0,0 +1 @@
cc 39c6d681e691839313426bb0801cf3f46d0befb69b568a28cf6d8e752d74526b

View File

@ -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,