Example #1
0
 def test_min_value_should_reject_comparison_with_ints(self):
     with pytest.raises(ArithmeticError):
         Wad.min(Wad(10), 20)
     with pytest.raises(ArithmeticError):
         Wad.min(20, Wad(10))
Example #2
0
 def boomable_amount_in_sai(self, tap: Tap):
     return Wad.max(tap.joy() - tap.woe(), Wad.from_number(0))
Example #3
0
 def profit(self, token: Address) -> Wad:
     """Calculates the expected profit brought by executing this sequence (in token `token`)."""
     return sum(map(lambda s: s.target_amount, filter(lambda s: s.target_token == token, self.steps)), Wad(0)) \
            - sum(map(lambda s: s.source_amount, filter(lambda s: s.source_token == token, self.steps)), Wad(0))
Example #4
0
 def test_multiply(self):
     assert Wad.from_number(2) * Wad.from_number(3) == Wad.from_number(6)
     assert Wad.from_number(2) * Wad(3) == Wad(6)
     assert Wad.from_number(2.5) * Wad(3) == Wad(7)
     assert Wad.from_number(2.99999) * Wad(3) == Wad(8)
Example #5
0
 def test_multiply_by_int(self):
     assert Wad.from_number(2) * 3 == Wad.from_number(6)
     assert Wad.from_number(2) * 1 == Wad.from_number(2)
Example #6
0
 def test_add(self):
     assert Wad(1) + Wad(2) == Wad(3)
Example #7
0
 def test_subtract(self):
     assert Wad(10) - Wad(2) == Wad(8)
     assert Wad(1) - Wad(2) == Wad(-1)
Example #8
0
 def test_should_support_values_greater_than_uint256(self):
     Wad(2**256)
     Wad(2**256 + 1)
     Wad(2**512)
Example #9
0
 def test_add_should_not_work_with_wads(self):
     with pytest.raises(ArithmeticError):
         Ray(1) + Wad(2)
Example #10
0
 def test_should_support_negative_values(self):
     Wad(-1)
Example #11
0
 def test_should_instantiate_from_a_wad(self):
     assert Ray(
         Wad(10000000000000000000)) == Ray(10000000000000000000000000000)
Example #12
0
 def test_round(self):
     assert round(Wad.from_number(123.4567), 2) == Wad.from_number(123.46)
     assert round(Wad.from_number(123.4567), 0) == Wad.from_number(123.0)
     assert round(Wad.from_number(123.4567), -2) == Wad.from_number(100.0)
Example #13
0
 def test_max_value_should_reject_comparison_with_ints(self):
     with pytest.raises(ArithmeticError):
         Wad.max(Wad(10), 20)
     with pytest.raises(ArithmeticError):
         Wad.max(15, Wad(25))
Example #14
0
 def test_max_value(self):
     assert Wad.max(Wad(10), Wad(20)) == Wad(20)
     assert Wad.max(Wad(25), Wad(15)) == Wad(25)
     assert Wad.max(Wad(25), Wad(15), Wad(40)) == Wad(40)
Example #15
0
 def test_should_fail_to_instantiate_from_a_float(self):
     with pytest.raises(ArithmeticError):
         assert Wad(10.5)
Example #16
0
 def test_subtract_should_not_work_with_wads(self):
     with pytest.raises(ArithmeticError):
         Ray(10) - Wad(2)
Example #17
0
 def test_should_have_nice_printable_representation(self):
     for wad in [Wad(1), Wad(100), Wad.from_number(2.5), Wad(-1)]:
         assert repr(wad) == f"Wad({wad.value})"
Example #18
0
 def test_multiply_by_wad(self):
     assert Ray.from_number(2) * Wad.from_number(3) == Ray.from_number(6)
     assert Ray.from_number(2) * Wad(3) == Ray(6000000000)
     assert Ray(2) * Wad(3) == Ray(0)
     assert Ray(2) * Wad(999999999999999999) == Ray(1)
     assert Ray(2) * Wad(1000000000000000000) == Ray(2)
Example #19
0
 def test_add_should_not_work_with_ints(self):
     with pytest.raises(ArithmeticError):
         Wad(1) + 2
Example #20
0
 def test_should_fail_to_divide_by_wads(self):
     with pytest.raises(ArithmeticError):
         Ray(4) / Wad(2)
Example #21
0
 def test_subtract_should_not_work_with_rays(self):
     with pytest.raises(ArithmeticError):
         Wad(10) - Ray(2)
Example #22
0
 def test_should_instantiate_from_a_wad(self):
     assert Wad(Wad(1)) == Wad(1)
Example #23
0
 def test_multiply_by_ray(self):
     assert Wad.from_number(2) * Ray.from_number(3) == Wad.from_number(6)
     assert Wad.from_number(2) * Ray(3) == Wad(0)
     assert Wad(2) * Ray(499999999999999999999999999) == Wad(0)
     assert Wad(2) * Ray(500000000000000000000000000) == Wad(1)
     assert Wad(2) * Ray(999999999999999999999999999) == Wad(1)
     assert Wad(2) * Ray(1000000000000000000000000000) == Wad(2)
Example #24
0
 def test_should_instantiate_from_a_ray(self):
     assert Wad(
         Ray(10000000000000001010101010101)) == Wad(10000000000000001010)
     assert Wad(
         Ray(10000000000000001019999999999)) == Wad(10000000000000001019)
Example #25
0
 def test_should_fail_to_multiply_by_float(self):
     with pytest.raises(ArithmeticError):
         Wad(2) * 3.0
Example #26
0
 def test_should_instantiate_from_an_int(self):
     assert Wad(10).value == 10
Example #27
0
 def boomable_amount_in_skr(self, tap: Tap):
     # we deduct 0.000001 in order to avoid rounding errors
     return Wad.max(
         Wad(self.boomable_amount_in_sai(tap) / (tap.bid())) -
         Wad.from_number(0.000001), Wad.from_number(0))
Example #28
0
 def test_max_value_should_reject_comparison_with_wads(self):
     with pytest.raises(ArithmeticError):
         Ray.max(Ray(10), Wad(20))
     with pytest.raises(ArithmeticError):
         Ray.max(Ray(25), Wad(15))
Example #29
0
 def tx_costs(self) -> Wad:
     """Calculates the transaction costs that this sequence will take to execute."""
     # TODO transaction costs are still in a fixed currency (SAI) here
     return Wad.from_number(0.25) * Wad.from_number(len(self.steps))
Example #30
0
 def test_min_value_should_reject_comparison_with_rays(self):
     with pytest.raises(ArithmeticError):
         Wad.min(Wad(10), Ray(20))
     with pytest.raises(ArithmeticError):
         Wad.min(Ray(25), Wad(15))