From 9b1cb7d6bf74ebf45dff680da6a40cd50b33f5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Fingen?= Date: Mon, 22 Mar 2021 12:18:44 +0100 Subject: [PATCH] contracts: economic simulation: Adapt to last changes Troves cannot be closed in Recovery Mode. Besides, catch reverts when the result would leave the system in Recovery Mode. (TODO: predict it in advance to avoid the try/catch) --- packages/contracts/tests/simulation_helpers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/contracts/tests/simulation_helpers.py b/packages/contracts/tests/simulation_helpers.py index 3619d8911f..dc96f52325 100644 --- a/packages/contracts/tests/simulation_helpers.py +++ b/packages/contracts/tests/simulation_helpers.py @@ -357,9 +357,15 @@ def close_troves(accounts, contracts, active_accounts, inactive_accounts, price_ account = accounts[account_index] pending = get_lusd_to_repay(accounts, contracts, active_accounts, inactive_accounts, account, get_total_debt(contracts, account)) if pending == 0: - contracts.borrowerOperations.closeTrove({ 'from': account }) - inactive_accounts.append(account_index) - active_accounts.pop(drops[i]) + # TODO: try to predict it! + try: # to skip “BorrowerOps: An operation that would result in TCR < CCR is not permitted” errors + contracts.borrowerOperations.closeTrove({ 'from': account }) + inactive_accounts.append(account_index) + active_accounts.pop(drops[i]) + except: + print("\n ***Error closing Trove!") + if is_recovery_mode(contracts, price_ether_current): + break return [number_closetroves]