diff --git a/chia/_tests/clvm/test_program.py b/chia/_tests/clvm/test_program.py index e742b4391e3d..fe751a648bb2 100644 --- a/chia/_tests/clvm/test_program.py +++ b/chia/_tests/clvm/test_program.py @@ -119,6 +119,16 @@ def test_run() -> None: ret = div.run([10, -5]) assert ret.atom == bytes([0xFE]) + # run() + with pytest.raises(ValueError, match="div operator with negative operands is deprecated"): + cost, ret = div.run_with_cost(100000, [10, -5], 0) + + cost, ret = div.run_with_cost(100000, [10, -5], ENABLE_FIXED_DIV) + assert cost == 1107 + print(ret) + assert ret.atom == bytes([0xFE]) + + # run_with_flags() with pytest.raises(ValueError, match="div operator with negative operands is deprecated"): cost, ret = div.run_with_flags(100000, 0, [10, -5]) @@ -126,3 +136,11 @@ def test_run() -> None: assert cost == 1107 print(ret) assert ret.atom == bytes([0xFE]) + + # run_with_cost() + with pytest.raises(ValueError, match="div operator with negative operands is deprecated"): + cost, ret = div.run([10, -5], 100000, 0) + + ret = div.run([10, -5], 100000, ENABLE_FIXED_DIV) + print(ret) + assert ret.atom == bytes([0xFE]) diff --git a/chia/types/blockchain_format/program.py b/chia/types/blockchain_format/program.py index 9c0f12e7beef..e96ec0324ae1 100644 --- a/chia/types/blockchain_format/program.py +++ b/chia/types/blockchain_format/program.py @@ -29,6 +29,15 @@ INFINITE_COST = 11000000000 +DEFAULT_FLAGS = ( + ENABLE_SOFTFORK_CONDITION + | ENABLE_BLS_OPS_OUTSIDE_GUARD + | ENABLE_FIXED_DIV + | AGG_SIG_ARGS + | ENABLE_MESSAGE_CONDITIONS + | DISALLOW_INFINITY_G1 + | MEMPOOL_MODE +) T_CLVMStorage = TypeVar("T_CLVMStorage", bound=CLVMStorage) T_Program = TypeVar("T_Program", bound="Program") @@ -139,22 +148,13 @@ def _run(self, max_cost: int, flags: int, args: Any) -> Tuple[int, Program]: cost, r = run_chia_program(self.as_bin(), prog_args.as_bin(), max_cost, flags) return cost, Program.to(r) - def run_with_cost(self, max_cost: int, args: Any) -> Tuple[int, Program]: + def run_with_cost(self, max_cost: int, args: Any, flags=DEFAULT_FLAGS) -> Tuple[int, Program]: # when running puzzles in the wallet, default to enabling all soft-forks # as well as enabling mempool-mode (i.e. strict mode) - default_flags = ( - ENABLE_SOFTFORK_CONDITION - | ENABLE_BLS_OPS_OUTSIDE_GUARD - | ENABLE_FIXED_DIV - | AGG_SIG_ARGS - | ENABLE_MESSAGE_CONDITIONS - | DISALLOW_INFINITY_G1 - | MEMPOOL_MODE - ) - return self._run(max_cost, default_flags, args) + return self._run(max_cost, flags, args) - def run(self, args: Any) -> Program: - cost, r = self.run_with_cost(INFINITE_COST, args) + def run(self, args: Any, max_cost=INFINITE_COST, flags=DEFAULT_FLAGS) -> Program: + cost, r = self._run(max_cost, flags, args) return r def run_with_flags(self, max_cost: int, flags: int, args: Any) -> Tuple[int, Program]: