Don't import a wallet file from util. (#18742)

* Don't import a `wallet` file from `util`.

* coverage
This commit is contained in:
Richard Kiss
2024-10-29 09:31:25 -07:00
committed by GitHub
parent 11eba04e28
commit f126023591
3 changed files with 17 additions and 4 deletions
+10
View File
@@ -21,6 +21,7 @@ from chia.wallet.util.tx_config import (
CoinSelectionConfigLoader,
TXConfigLoader,
)
from chia.wallet.util.wallet_types import WalletType
def test_compute_spend_hints_and_additions() -> None:
@@ -175,3 +176,12 @@ def test_lineage_proof_errors() -> None:
LineageProof.from_program(Program.to([bytes32([1] * 32)]), [LineageProofField.AMOUNT])
with pytest.raises(ValueError):
LineageProof.from_program(Program.to([uint64(0)]), [LineageProofField.PARENT_NAME])
# this is the only test that has coverage for `WalletType.to_json_dict`
# it's possible it could even be deleted
def test_wallet_type_to_json() -> None:
for w in WalletType:
assert w.to_json_dict() == w.name
-4
View File
@@ -5,8 +5,6 @@ from typing import Any
from aiohttp import web
from chia.wallet.util.wallet_types import WalletType
class EnhancedJSONEncoder(json.JSONEncoder):
"""
@@ -16,8 +14,6 @@ class EnhancedJSONEncoder(json.JSONEncoder):
def default(self, o: Any) -> Any:
if hasattr(type(o), "to_json_dict"):
return o.to_json_dict()
elif isinstance(o, WalletType):
return o.name
elif hasattr(type(o), "__bytes__"):
return f"0x{bytes(o).hex()}"
elif isinstance(o, bytes):
+7
View File
@@ -30,6 +30,13 @@ class WalletType(IntEnum):
DAO_CAT = 15
CRCAT = 57
def to_json_dict(self) -> str:
# yes, this isn't a `dict`, but it is json and
# unfortunately the magic method name is misleading
# not sure this code is used
# TODO: determine if this code is used and if not, remove it
return self.name
class CoinType(IntEnum):
NORMAL = 0