Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
257ee14
Port `spend_clawback_coins` to `@marshal`
Quexington Aug 15, 2025
4e7a385
fix tests
Quexington Aug 15, 2025
8252040
fix test again
Quexington Aug 15, 2025
c8a2fa1
how do I keep missing these?
Quexington Aug 18, 2025
c41a5f6
Port `select_coins` to `@marshal`
Quexington Aug 18, 2025
d5f6323
fix tests
Quexington Aug 19, 2025
4a97361
fix test
Quexington Aug 20, 2025
7677d00
Port `get_spendable_coins`
Quexington Aug 22, 2025
d1d1386
Port `get_coin_records_by_names`
Quexington Aug 22, 2025
2463c96
Port `send_notifications` to `@marshal`
Quexington Aug 22, 2025
afb4e9c
Fixing the thing that is always broken
Quexington Aug 25, 2025
fa4d6de
Merge remote-tracking branch 'origin/main' into quex.port_send_notifi…
Quexington Sep 15, 2025
91ede61
Remove accidental import
Quexington Sep 15, 2025
16e4cbd
Port `get_default_cat_list`
Quexington Aug 26, 2025
c84eabd
Port `cat_set_name`
Quexington Aug 26, 2025
04f14eb
Port `cat_get_name`
Quexington Aug 26, 2025
1afd980
Port `get_stray_cats`
Quexington Aug 26, 2025
29d63ae
Port `cat_get_asset_id`
Quexington Aug 26, 2025
4dd9027
Port `cat_asset_id_to_name`
Quexington Aug 26, 2025
8f3908b
Port `check_offer_validity`
Quexington Aug 27, 2025
95a22d9
Port `get_offers_count`
Quexington Aug 27, 2025
eaea78d
Port `cat_spend` to `@marshal`
Quexington Aug 28, 2025
151ce93
fix tests
Quexington Aug 29, 2025
db3a51f
Port `create_offer_for_ids` to `@marshal`
Quexington Sep 10, 2025
81d86e6
Self from typing_extensions
Quexington Sep 10, 2025
424b184
Fix support for "" in PuzzleInfo/Solver
Quexington Sep 10, 2025
e5cb31b
Port `get_offer_summary` to `@marshal`
Quexington Sep 11, 2025
1b5fda4
test coverage
Quexington Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions chia/_tests/cmds/cmd_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
from chia.wallet.util.tx_config import TXConfig
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_request_types import (
CATAssetIDToName,
CATAssetIDToNameResponse,
CATGetName,
CATGetNameResponse,
GetSyncStatusResponse,
GetTransaction,
GetTransactionResponse,
Expand Down Expand Up @@ -146,9 +150,9 @@ async def get_transaction(self, request: GetTransaction) -> GetTransactionRespon
bytes32([2] * 32),
)

async def get_cat_name(self, wallet_id: int) -> str:
self.add_to_log("get_cat_name", (wallet_id,))
return "test" + str(wallet_id)
async def get_cat_name(self, request: CATGetName) -> CATGetNameResponse:
self.add_to_log("get_cat_name", (request.wallet_id,))
return CATGetNameResponse(request.wallet_id, "test" + str(request.wallet_id))

async def sign_message_by_address(self, request: SignMessageByAddress) -> SignMessageByAddressResponse:
self.add_to_log("sign_message_by_address", (request.address, request.message))
Expand Down Expand Up @@ -182,15 +186,15 @@ async def sign_message_by_id(self, request: SignMessageByID) -> SignMessageByIDR
signing_mode = SigningMode.CHIP_0002.value
return SignMessageByIDResponse(pubkey, signature, bytes32.zeros, signing_mode)

async def cat_asset_id_to_name(self, asset_id: bytes32) -> Optional[tuple[Optional[uint32], str]]:
async def cat_asset_id_to_name(self, request: CATAssetIDToName) -> CATAssetIDToNameResponse:
"""
if bytes32([1] * 32), return (uint32(2), "test1"), if bytes32([1] * 32), return (uint32(3), "test2")
"""
self.add_to_log("cat_asset_id_to_name", (asset_id,))
self.add_to_log("cat_asset_id_to_name", (request.asset_id,))
for i in range(256):
if asset_id == get_bytes32(i):
return uint32(i + 1), "test" + str(i)
return None
if request.asset_id == get_bytes32(i):
return CATAssetIDToNameResponse(uint32(i + 1), "test" + str(i))
return CATAssetIDToNameResponse(wallet_id=None, name=None)

async def get_nft_info(self, request: NFTGetInfo) -> NFTGetInfoResponse:
self.add_to_log("get_nft_info", (request.coin_id, request.latest))
Expand Down
36 changes: 19 additions & 17 deletions chia/_tests/cmds/wallet/test_notifications.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
from __future__ import annotations

from pathlib import Path
from typing import cast

from chia_rs.sized_bytes import bytes32
from chia_rs.sized_ints import uint32, uint64

from chia._tests.cmds.cmd_test_utils import TestRpcClients, TestWalletRpcClient, logType, run_cli_command_and_assert
from chia._tests.cmds.wallet.test_consts import FINGERPRINT, FINGERPRINT_ARG, get_bytes32
from chia._tests.cmds.wallet.test_consts import FINGERPRINT, FINGERPRINT_ARG, STD_TX, STD_UTX, get_bytes32
from chia.util.bech32m import encode_puzzle_hash
from chia.wallet.conditions import ConditionValidTimes
from chia.wallet.conditions import Condition, ConditionValidTimes
from chia.wallet.notification_store import Notification
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.wallet_request_types import DeleteNotifications, GetNotifications, GetNotificationsResponse
from chia.wallet.util.tx_config import TXConfig
from chia.wallet.wallet_request_types import (
DeleteNotifications,
GetNotifications,
GetNotificationsResponse,
SendNotification,
SendNotificationResponse,
)

test_condition_valid_times: ConditionValidTimes = ConditionValidTimes(min_time=uint64(100), max_time=uint64(150))

Expand All @@ -26,20 +31,17 @@ def test_notifications_send(capsys: object, get_test_cli_clients: tuple[TestRpcC
class NotificationsSendRpcClient(TestWalletRpcClient):
async def send_notification(
self,
target: bytes32,
msg: bytes,
amount: uint64,
fee: uint64 = uint64(0),
push: bool = True,
request: SendNotification,
tx_config: TXConfig,
extra_conditions: tuple[Condition, ...] = tuple(),
timelock_info: ConditionValidTimes = ConditionValidTimes(),
) -> TransactionRecord:
self.add_to_log("send_notification", (target, msg, amount, fee, push, timelock_info))

class FakeTransactionRecord:
def __init__(self, name: str) -> None:
self.name = name
) -> SendNotificationResponse:
self.add_to_log(
"send_notification",
(request.target, request.message, request.amount, request.fee, request.push, timelock_info),
)

return cast(TransactionRecord, FakeTransactionRecord(get_bytes32(2).hex()))
return SendNotificationResponse([STD_UTX], [STD_TX], tx=STD_TX)

inst_rpc_client = NotificationsSendRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
Expand Down
146 changes: 89 additions & 57 deletions chia/_tests/cmds/wallet/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
)
from chia.cmds.cmds_util import TransactionBundle
from chia.protocols.outbound_message import NodeType
from chia.types.blockchain_format.program import Program
from chia.types.signing_mode import SigningMode
from chia.util.bech32m import encode_puzzle_hash
from chia.wallet.conditions import Condition, ConditionValidTimes
from chia.wallet.puzzle_drivers import PuzzleInfo
from chia.wallet.trade_record import TradeRecord
from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
Expand All @@ -43,8 +43,14 @@
from chia.wallet.wallet_request_types import (
BalanceResponse,
CancelOfferResponse,
CATAssetIDToName,
CATAssetIDToNameResponse,
CATSetName,
CATSetNameResponse,
CATSpend,
CATSpendResponse,
ClawbackPuzzleDecoratorOverride,
CreateOfferForIDs,
CreateOfferForIDsResponse,
DeleteUnconfirmedTransactions,
ExtendDerivationIndex,
Expand Down Expand Up @@ -75,6 +81,29 @@
)
from chia.wallet.wallet_spend_bundle import WalletSpendBundle

TEMP = PuzzleInfo(
{
"type": "singleton",
"launcher_id": "0x0101010101010101010101010101010101010101010101010101010101010101",
"launcher_ph": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9",
"also": {
"type": "metadata",
"metadata": "",
"updater_hash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"also": {
"type": "ownership",
"owner": "()",
"transfer_program": {
"type": "royalty transfer program",
"launcher_id": "0x0101010101010101010101010101010101010101010101010101010101010101",
"royalty_address": "0x0303030303030303030303030303030303030303030303030303030303030303",
"royalty_percentage": "1000",
},
},
},
}
)

test_offer_file_path = importlib_resources.files(__name__.rpartition(".")[0]).joinpath("test_offer.toffer")
test_offer_file_bech32 = test_offer_file_path.read_text(encoding="utf-8")
test_offer_id: str = "0xdfb7e8643376820ec995b0bcdb3fc1f764c16b814df5e074631263fcf1e00839"
Expand Down Expand Up @@ -381,31 +410,24 @@ async def send_transaction(

async def cat_spend(
self,
wallet_id: int,
request: CATSpend,
tx_config: TXConfig,
amount: Optional[uint64] = None,
inner_address: Optional[str] = None,
fee: uint64 = uint64(0),
memos: Optional[list[str]] = None,
additions: Optional[list[dict[str, Any]]] = None,
removals: Optional[list[Coin]] = None,
cat_discrepancy: Optional[tuple[int, Program, Program]] = None, # (extra_delta, tail_reveal, tail_solution)
push: bool = True,
extra_conditions: tuple[Condition, ...] = tuple(),
timelock_info: ConditionValidTimes = ConditionValidTimes(),
) -> CATSpendResponse:
self.add_to_log(
"cat_spend",
(
wallet_id,
request.wallet_id,
tx_config,
amount,
inner_address,
fee,
memos,
additions,
removals,
cat_discrepancy,
push,
request.amount,
request.inner_address,
request.fee,
request.memos,
request.additions,
request.coins,
request.cat_discrepancy,
request.push,
timelock_info,
),
)
Expand Down Expand Up @@ -683,8 +705,9 @@ async def create_wallet_for_existing_cat(self, asset_id: bytes) -> dict[str, int
self.add_to_log("create_wallet_for_existing_cat", (asset_id,))
return {"wallet_id": 3}

async def set_cat_name(self, wallet_id: int, name: str) -> None:
self.add_to_log("set_cat_name", (wallet_id, name))
async def set_cat_name(self, request: CATSetName) -> CATSetNameResponse:
self.add_to_log("set_cat_name", (request.wallet_id, request.name))
return CATSetNameResponse(wallet_id=request.wallet_id)

inst_rpc_client = AddTokenRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
Expand Down Expand Up @@ -765,17 +788,22 @@ def test_make_offer(capsys: object, get_test_cli_clients: tuple[TestRpcClients,
class MakeOfferRpcClient(TestWalletRpcClient):
async def create_offer_for_ids(
self,
offer_dict: dict[uint32, int],
request: CreateOfferForIDs,
tx_config: TXConfig,
driver_dict: Optional[dict[str, Any]] = None,
solver: Optional[dict[str, Any]] = None,
fee: uint64 = uint64(0),
validate_only: bool = False,
extra_conditions: tuple[Condition, ...] = tuple(),
timelock_info: ConditionValidTimes = ConditionValidTimes(),
) -> CreateOfferForIDsResponse:
self.add_to_log(
"create_offer_for_ids",
(offer_dict, tx_config, driver_dict, solver, fee, validate_only, timelock_info),
(
request.offer,
tx_config,
request.driver_dict,
request.solver,
request.fee,
request.validate_only,
timelock_info,
),
)

created_offer = Offer({}, WalletSpendBundle([], G2Element()), {})
Expand Down Expand Up @@ -868,35 +896,39 @@ async def create_offer_for_ids(
"create_offer_for_ids": [
(
{
1: -10000000000000,
3: -100000,
"0404040404040404040404040404040404040404040404040404040404040404": -100000,
"0202020202020202020202020202020202020202020202020202020202020202": 10000,
"0101010101010101010101010101010101010101010101010101010101010101": 1,
"1": "-10000000000000",
"3": "-100000",
"0404040404040404040404040404040404040404040404040404040404040404": "-100000",
"0202020202020202020202020202020202020202020202020202020202020202": "10000",
"0101010101010101010101010101010101010101010101010101010101010101": "1",
},
DEFAULT_TX_CONFIG.override(reuse_puzhash=True),
{
"0101010101010101010101010101010101010101010101010101010101010101": {
"type": "singleton",
"launcher_id": "0x0101010101010101010101010101010101010101010101010101010101010101",
"launcher_ph": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9",
"also": {
"type": "metadata",
"metadata": "",
"updater_hash": "0x0707070707070707070707070707070707070707070707070707070707070707",
bytes32([1] * 32): PuzzleInfo(
{
"type": "singleton",
"launcher_id": "0x0101010101010101010101010101010101010101010101010101010101010101",
"launcher_ph": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9",
"also": {
"type": "ownership",
"owner": "()",
"transfer_program": {
"type": "royalty transfer program",
"launcher_id": "0x0101010101010101010101010101010101010101010101010101010101010101",
"royalty_address": "0x0303030303030303030303030303030303030303030"
"303030303030303030303",
"royalty_percentage": "1000",
"type": "metadata",
"metadata": "",
"updater_hash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"also": {
"type": "ownership",
"owner": "()",
"transfer_program": {
"type": "royalty transfer program",
"launcher_id": (
"0x0101010101010101010101010101010101010101010101010101010101010101"
),
"royalty_address": "0x0303030303030303030303030303030303030303030"
"303030303030303030303",
"royalty_percentage": "1000",
},
},
},
},
}
}
)
},
None,
500000000000,
Expand Down Expand Up @@ -1051,14 +1083,14 @@ async def take_offer(
),
)

async def cat_asset_id_to_name(self, asset_id: bytes32) -> Optional[tuple[Optional[uint32], str]]:
self.add_to_log("cat_asset_id_to_name", (asset_id,))
if asset_id == cat_offered_id:
return uint32(2), "offered cat"
elif asset_id == cat_requested_id:
return uint32(3), "requested cat"
async def cat_asset_id_to_name(self, request: CATAssetIDToName) -> CATAssetIDToNameResponse:
self.add_to_log("cat_asset_id_to_name", (request.asset_id,))
if request.asset_id == cat_offered_id:
return CATAssetIDToNameResponse(uint32(2), "offered cat")
elif request.asset_id == cat_requested_id:
return CATAssetIDToNameResponse(uint32(3), "requested cat")
else:
return None
return CATAssetIDToNameResponse(wallet_id=None, name=None)

inst_rpc_client = TakeOfferRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
Expand Down
Loading
Loading