chia-blockchain/tests/clvm/test_puzzle_drivers.py
Kyle Altendorf 3b084a165b
configure isort to add the future annotations import (#13327)
* configure isort to add the future annotations import

* apply the new isort setting

* remove type ignores for new mypy (#13539)

https://pypi.org/project/mypy/0.981/

* another
2022-09-30 03:40:22 -05:00

46 lines
1.4 KiB
Python

from __future__ import annotations
from typing import Any, Dict, Union
import pytest
from chia.types.blockchain_format.program import Program
from chia.wallet.puzzle_drivers import PuzzleInfo, Solver
def test_puzzle_info() -> None:
test_driver: Dict[str, Any] = {
"string": "hello",
"bytes": "0xcafef00d",
"int": "123",
"program": "(q . 'hello')",
"zero": "0",
"nil": "()",
}
test_also: Dict[str, Any] = {"type": "TEST", "string": "hello"}
test_driver["also"] = test_also
with pytest.raises(ValueError, match="A type is required"):
PuzzleInfo(test_driver)
solver = Solver(test_driver)
test_driver["type"] = "TEST"
puzzle_info = PuzzleInfo(test_driver)
assert puzzle_info.type() == "TEST"
assert puzzle_info.also() == PuzzleInfo(test_also)
capitalize_bytes = test_driver.copy()
capitalize_bytes["bytes"] = "0xCAFEF00D"
assert solver == Solver(capitalize_bytes)
assert puzzle_info == PuzzleInfo(capitalize_bytes)
obj: Union[PuzzleInfo, Solver]
for obj in (puzzle_info, solver): # type: ignore
assert obj["string"] == "hello"
assert obj["bytes"] == bytes.fromhex("cafef00d")
assert obj["int"] == 123
assert obj["program"] == Program.to((1, "hello"))
assert obj["zero"] == 0
assert obj["nil"] == Program.to([])