osmosis-labs / isotonic

Smart Contracts for the Lendex Protocol
MIT License
1 stars 0 forks source link

CA authorizes borrows and transfers #51

Closed ueco-jb closed 2 years ago

ueco-jb commented 2 years ago

closes https://github.com/confio/lendex/issues/26

I've created additionaly Credit Agency's mock for market contract multitest in order to avoid circular dependency between market and CA. It contains query TotalCreditLine - same as in Credit Agency. This query is called in multitest for all operations that does can_borrow or can_withdraw checks. Because of that, I had to set through additional helpers arbitrary high credit line and price ratio to 1.0 in tests that now requires it (because of query), but don't actually need those informations.

Mock response for particular account is set through ExecuteMsg::SetCreditLine. I did so, because that was fastest way to use mutable map that's unique per test and set automatically... I could replace it with some custom HashMap, but then I'd have to resolve issue of access (mutex?), mutability, probably wrap it around lazy_static... Please share your thoughts.

ethanfrey commented 2 years ago

Mock response for particular account is set through ExecuteMsg::SetCreditLine. I did so, because that was fastest way to use mutable map that's unique per test and set automatically...

Just read the Readme but I agree with this approach. Make such a contract with contract interfaces. It may never make sense outside of tests but let's leverage the infrastructure we have for dealing with state