Skip to content

Commit

Permalink
Don't import a wallet file from util. (#18742)
Browse files Browse the repository at this point in the history
* Don't import a `wallet` file from `util`.

* coverage
  • Loading branch information
richardkiss authored Oct 29, 2024
1 parent 11eba04 commit f126023
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions chia/_tests/wallet/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CoinSelectionConfigLoader,
TXConfigLoader,
)
from chia.wallet.util.wallet_types import WalletType


def test_compute_spend_hints_and_additions() -> None:
Expand Down Expand Up @@ -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 changes: 0 additions & 4 deletions chia/util/json_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from aiohttp import web

from chia.wallet.util.wallet_types import WalletType


class EnhancedJSONEncoder(json.JSONEncoder):
"""
Expand All @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions chia/wallet/util/wallet_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f126023

Please sign in to comment.