Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions chia/_tests/cmds/cmd_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from contextlib import asynccontextmanager
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Optional, Union, cast
from typing import Any, Optional, cast

from chia_rs import BlockRecord, Coin, G2Element
from chia_rs.sized_bytes import bytes32
Expand Down Expand Up @@ -35,11 +35,14 @@
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_request_types import (
GetSyncStatusResponse,
GetWallets,
GetWalletsResponse,
NFTCalculateRoyalties,
NFTCalculateRoyaltiesResponse,
NFTGetInfo,
NFTGetInfoResponse,
SendTransactionMultiResponse,
WalletInfoResponse,
)
from chia.wallet.wallet_rpc_client import WalletRpcClient
from chia.wallet.wallet_spend_bundle import WalletSpendBundle
Expand Down Expand Up @@ -93,11 +96,11 @@ async def get_sync_status(self) -> GetSyncStatusResponse:
self.add_to_log("get_sync_status", ())
return GetSyncStatusResponse(synced=True, syncing=False)

async def get_wallets(self, wallet_type: Optional[WalletType] = None) -> list[dict[str, Union[str, int]]]:
self.add_to_log("get_wallets", (wallet_type,))
async def get_wallets(self, request: GetWallets) -> GetWalletsResponse:
self.add_to_log("get_wallets", (request,))
# we cant start with zero because ints cant have a leading zero
if wallet_type is not None:
w_type = wallet_type
if request.type is not None:
w_type = WalletType(request.type)
elif str(self.fingerprint).startswith(str(WalletType.STANDARD_WALLET.value + 1)):
w_type = WalletType.STANDARD_WALLET
elif str(self.fingerprint).startswith(str(WalletType.CAT.value + 1)):
Expand All @@ -110,7 +113,7 @@ async def get_wallets(self, wallet_type: Optional[WalletType] = None) -> list[di
w_type = WalletType.POOLING_WALLET
else:
raise ValueError(f"Invalid fingerprint: {self.fingerprint}")
return [{"id": 1, "type": w_type}]
return GetWalletsResponse([WalletInfoResponse(id=uint32(1), name="", type=uint8(w_type.value), data="")])

async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
self.add_to_log("get_transaction", (transaction_id,))
Expand Down
3 changes: 2 additions & 1 deletion chia/_tests/cmds/wallet/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from chia.wallet.vc_wallet.vc_drivers import VCLineageProof, VerifiedCredential
from chia.wallet.vc_wallet.vc_store import VCRecord
from chia.wallet.wallet_request_types import (
GetWallets,
VCAddProofs,
VCGet,
VCGetList,
Expand Down Expand Up @@ -395,6 +396,6 @@ async def crcat_approve_pending(
test_condition_valid_times,
)
],
"get_wallets": [(None,)],
"get_wallets": [(GetWallets(type=None, include_data=True),)],
}
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)
54 changes: 31 additions & 23 deletions chia/_tests/cmds/wallet/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@
CreateOfferForIDsResponse,
FungibleAsset,
GetHeightInfoResponse,
GetWallets,
GetWalletsResponse,
NFTCalculateRoyalties,
NFTGetWalletDID,
NFTGetWalletDIDResponse,
RoyaltyAsset,
SendTransactionResponse,
TakeOfferResponse,
WalletInfoResponse,
)
from chia.wallet.wallet_spend_bundle import WalletSpendBundle

Expand Down Expand Up @@ -91,7 +94,7 @@ def test_get_transaction(capsys: object, get_test_cli_clients: tuple[TestRpcClie
run_cli_command_and_assert(capsys, root_dir, [*command_args, CAT_FINGERPRINT_ARG], cat_assert_list)
# these are various things that should be in the output
expected_calls: logType = {
"get_wallets": [(None,), (None,), (None,)],
"get_wallets": [(GetWallets(type=None, include_data=True),)] * 3,
"get_cat_name": [(1,)],
"get_transaction": [
(bytes32.from_hexstr(bytes32_hexstr),),
Expand Down Expand Up @@ -192,7 +195,7 @@ async def get_coin_records(self, request: GetCoinRecords) -> dict[str, Any]:
# these are various things that should be in the output
expected_coin_id = Coin(get_bytes32(4), get_bytes32(5), uint64(12345678)).name()
expected_calls: logType = {
"get_wallets": [(None,), (None,)],
"get_wallets": [(GetWallets(type=None, include_data=True),)] * 2,
"get_transactions": [
(1, 2, 4, SortKey.RELEVANCE, True, None, None, None),
(1, 2, 4, SortKey.RELEVANCE, True, None, None, None),
Expand All @@ -210,28 +213,30 @@ def test_show(capsys: object, get_test_cli_clients: tuple[TestRpcClients, Path])

# set RPC Client
class ShowRpcClient(TestWalletRpcClient):
async def get_wallets(self, wallet_type: Optional[WalletType] = None) -> list[dict[str, Union[str, int]]]:
self.add_to_log("get_wallets", (wallet_type,))
wallet_list: list[dict[str, Union[str, int]]] = [
{"data": "", "id": 1, "name": "Chia Wallet", "type": WalletType.STANDARD_WALLET},
{
"data": "dc59bcd60ce5fc9c93a5d3b11875486b03efb53a53da61e453f5cf61a774686001ff02ffff01ff02ffff03ff2f"
async def get_wallets(self, request: GetWallets) -> GetWalletsResponse:
self.add_to_log("get_wallets", (request,))
wallet_list: list[WalletInfoResponse] = [
WalletInfoResponse(
data="", id=uint32(1), name="Chia Wallet", type=uint8(WalletType.STANDARD_WALLET.value)
),
WalletInfoResponse(
data="dc59bcd60ce5fc9c93a5d3b11875486b03efb53a53da61e453f5cf61a774686001ff02ffff01ff02ffff03ff2f"
"ffff01ff0880ffff01ff02ffff03ffff09ff2dff0280ff80ffff01ff088080ff018080ff0180ffff04ffff01a09848f0ef"
"6587565c48ee225cc837abbe406b91946c938e1739da49fc26c04286ff018080",
"id": 2,
"name": "test2",
"type": WalletType.CAT,
},
{
"data": '{"did_id": "0xcee228b8638c67cb66a55085be99fa3b457ae5b56915896f581990f600b2c652"}',
"id": 3,
"name": "NFT Wallet",
"type": WalletType.NFT,
},
id=uint32(2),
name="test2",
type=uint8(WalletType.CAT.value),
),
WalletInfoResponse(
data='{"did_id": "0xcee228b8638c67cb66a55085be99fa3b457ae5b56915896f581990f600b2c652"}',
id=uint32(3),
name="NFT Wallet",
type=uint8(WalletType.NFT.value),
),
]
if wallet_type is WalletType.CAT:
return [wallet_list[1]]
return wallet_list
if request.type is not None and WalletType(request.type) is WalletType.CAT:
return GetWalletsResponse([wallet_list[1]])
return GetWalletsResponse(wallet_list)

async def get_height_info(self) -> GetHeightInfoResponse:
self.add_to_log("get_height_info", ())
Expand Down Expand Up @@ -296,7 +301,10 @@ async def get_connections(
run_cli_command_and_assert(capsys, root_dir, [*command_args, "--wallet_type", "cat"], other_assert_list)
# these are various things that should be in the output
expected_calls: logType = {
"get_wallets": [(None,), (WalletType.CAT,)],
"get_wallets": [
(GetWallets(type=None, include_data=True),),
(GetWallets(type=uint16(WalletType.CAT.value), include_data=True),),
],
"get_sync_status": [(), ()],
"get_height_info": [(), ()],
"get_wallet_balance": [(1,), (2,), (3,), (2,)],
Expand Down Expand Up @@ -427,7 +435,7 @@ async def cat_spend(

# these are various things that should be in the output
expected_calls: logType = {
"get_wallets": [(None,), (None,)],
"get_wallets": [(GetWallets(type=None, include_data=True),)] * 2,
"send_transaction": [
(
1,
Expand Down
10 changes: 5 additions & 5 deletions chia/_tests/pools/test_pool_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest
from chia_rs import G1Element
from chia_rs.sized_bytes import bytes32
from chia_rs.sized_ints import uint32, uint64
from chia_rs.sized_ints import uint16, uint32, uint64

# TODO: update after resolution in https://github.com/pytest-dev/pytest/issues/7469
from pytest_mock import MockerFixture
Expand Down Expand Up @@ -46,7 +46,7 @@
from chia.wallet.util.address_type import AddressType
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_request_types import PWStatus
from chia.wallet.wallet_request_types import GetWallets, PWStatus
from chia.wallet.wallet_rpc_client import WalletRpcClient
from chia.wallet.wallet_state_manager import WalletStateManager

Expand Down Expand Up @@ -153,9 +153,9 @@ async def test_plotnft_cli_create(
]
)

summaries_response = await wallet_rpc.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1
wallet_id: int = summaries_response[0]["id"]
summaries_response = await wallet_rpc.get_wallets(GetWallets(type=uint16(WalletType.POOLING_WALLET)))
assert len(summaries_response.wallets) == 1
wallet_id: int = summaries_response.wallets[0].id

await verify_pool_state(wallet_rpc, wallet_id, PoolSingletonState.SELF_POOLING)

Expand Down
Loading
Loading