The Contracts SDK also supports testing Contract helper functions directly with the run_contract_function method. Note that the mocked vault object will not be available to the Contract helper functions unless the function itself takes it as an argument. In which case it should be passed as one of the args or kwargs to run_contract_function.
xxxxxxxxxx
from decimal import Decimal
from utils.tools import SmartContracts380TestCase
class SavingsAccountTestCase(SmartContracts380TestCase):
contract_code = """
def _interest_rate_precision(amount):
return amount.quantize(Decimal('.000001'), rounding=ROUND_HALF_UP)
"""
def test_interest_rate_precision_is_correct(self):
rounded_amount = self.run_contract_function(
self.contract_code,
'_interest_rate_precision', Decimal(2.0000011)
)
self.assertEqual(
Decimal('2.000001'),
rounded_amount
)