Skip to content

Commit 0909514

Browse files
committed
Merge remote-tracking branch 'origin/main' into HEAD
2 parents 5353a38 + 74d5c45 commit 0909514

20 files changed

+837
-585
lines changed

chia/_tests/cmds/cmd_test_utils.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any, Optional, cast
99

10-
from chia_rs import BlockRecord, Coin, G2Element
10+
from chia_rs import BlockRecord, Coin, G1Element, G2Element
1111
from chia_rs.sized_bytes import bytes32
1212
from chia_rs.sized_ints import uint8, uint16, uint32, uint64
1313

@@ -44,6 +44,10 @@
4444
NFTGetInfo,
4545
NFTGetInfoResponse,
4646
SendTransactionMultiResponse,
47+
SignMessageByAddress,
48+
SignMessageByAddressResponse,
49+
SignMessageByID,
50+
SignMessageByIDResponse,
4751
WalletInfoResponse,
4852
)
4953
from chia.wallet.wallet_rpc_client import WalletRpcClient
@@ -147,19 +151,37 @@ async def get_cat_name(self, wallet_id: int) -> str:
147151
self.add_to_log("get_cat_name", (wallet_id,))
148152
return "test" + str(wallet_id)
149153

150-
async def sign_message_by_address(self, address: str, message: str) -> tuple[str, str, str]:
151-
self.add_to_log("sign_message_by_address", (address, message))
152-
pubkey = bytes([3] * 48).hex()
153-
signature = bytes([6] * 576).hex()
154+
async def sign_message_by_address(self, request: SignMessageByAddress) -> SignMessageByAddressResponse:
155+
self.add_to_log("sign_message_by_address", (request.address, request.message))
156+
pubkey = G1Element.from_bytes(
157+
bytes.fromhex(
158+
"b5acf3599bc5fa5da1c00f6cc3d5bcf1560def67778b7f50a8c373a83f78761505b6250ab776e38a292e26628009aec4"
159+
)
160+
)
161+
signature = G2Element.from_bytes(
162+
bytes.fromhex(
163+
"c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
164+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
165+
)
166+
)
154167
signing_mode = SigningMode.CHIP_0002.value
155-
return pubkey, signature, signing_mode
168+
return SignMessageByAddressResponse(pubkey, signature, signing_mode)
156169

157-
async def sign_message_by_id(self, id: str, message: str) -> tuple[str, str, str]:
158-
self.add_to_log("sign_message_by_id", (id, message))
159-
pubkey = bytes([4] * 48).hex()
160-
signature = bytes([7] * 576).hex()
170+
async def sign_message_by_id(self, request: SignMessageByID) -> SignMessageByIDResponse:
171+
self.add_to_log("sign_message_by_id", (request.id, request.message))
172+
pubkey = G1Element.from_bytes(
173+
bytes.fromhex(
174+
"a9e652cb551d5978a9ee4b7aa52a4e826078a54b08a3d903c38611cb8a804a9a29c926e4f8549314a079e04ecde10cc1"
175+
)
176+
)
177+
signature = G2Element.from_bytes(
178+
bytes.fromhex(
179+
"c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
180+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
181+
)
182+
)
161183
signing_mode = SigningMode.CHIP_0002.value
162-
return pubkey, signature, signing_mode
184+
return SignMessageByIDResponse(pubkey, signature, bytes32.zeros, signing_mode)
163185

164186
async def cat_asset_id_to_name(self, asset_id: bytes32) -> Optional[tuple[Optional[uint32], str]]:
165187
"""
@@ -250,14 +272,6 @@ async def get_spendable_coins(
250272
unconfirmed_additions = [Coin(bytes32([7] * 32), bytes32([8] * 32), uint64(1234580000))]
251273
return confirmed_records, unconfirmed_removals, unconfirmed_additions
252274

253-
async def get_next_address(self, wallet_id: int, new_address: bool) -> str:
254-
self.add_to_log("get_next_address", (wallet_id, new_address))
255-
addr = encode_puzzle_hash(bytes32([self.wallet_index] * 32), "xch")
256-
self.wallet_index += 1
257-
if self.wallet_index > 254:
258-
self.wallet_index = 1
259-
return addr
260-
261275
async def send_transaction_multi(
262276
self,
263277
wallet_id: int,

chia/_tests/cmds/wallet/test_did.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def test_did_sign_message(capsys: object, get_test_cli_clients: tuple[TestRpcCli
116116
# these are various things that should be in the output
117117
assert_list = [
118118
f"Message: {message.hex()}",
119-
f"Public Key: {bytes([4] * 48).hex()}",
120-
f"Signature: {bytes([7] * 576).hex()}",
119+
"Public Key: a9e652cb551d5978a9ee4b7aa52a4e826078a54b08a3d903c38611cb8a804a9a29c926e4f8549314a079e04ecde10cc1",
120+
"Signature: c0" + "00" * (42 - 1),
121121
f"Signing Mode: {SigningMode.CHIP_0002.value}",
122122
]
123123
run_cli_command_and_assert(capsys, root_dir, [*command_args, f"-i{did_id}"], assert_list)

chia/_tests/cmds/wallet/test_nft.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ def test_nft_sign_message(capsys: object, get_test_cli_clients: tuple[TestRpcCli
6464

6565
inst_rpc_client = TestWalletRpcClient()
6666
test_rpc_clients.wallet_rpc_client = inst_rpc_client
67-
did_id = encode_puzzle_hash(get_bytes32(1), "nft")
67+
nft_id = encode_puzzle_hash(get_bytes32(1), "nft")
6868
message = b"hello nft world!!"
69-
command_args = ["wallet", "did", "sign_message", FINGERPRINT_ARG, f"-m{message.hex()}"]
69+
command_args = ["wallet", "nft", "sign_message", FINGERPRINT_ARG, f"-m{message.hex()}"]
7070
# these are various things that should be in the output
7171
assert_list = [
7272
f"Message: {message.hex()}",
73-
f"Public Key: {bytes([4] * 48).hex()}",
74-
f"Signature: {bytes([7] * 576).hex()}",
73+
"Public Key: a9e652cb551d5978a9ee4b7aa52a4e826078a54b08a3d903c38611cb8a804a9a29c926e4f8549314a079e04ecde10cc1",
74+
"Signature: c0" + "00" * (42 - 1),
7575
f"Signing Mode: {SigningMode.CHIP_0002.value}",
7676
]
77-
run_cli_command_and_assert(capsys, root_dir, [*command_args, f"-i{did_id}"], assert_list)
77+
run_cli_command_and_assert(capsys, root_dir, [*command_args, f"-i{nft_id}"], assert_list)
7878
expected_calls: logType = {
79-
"sign_message_by_id": [(did_id, message.hex())], # xch std
79+
"sign_message_by_id": [(nft_id, message.hex())], # xch std
8080
}
8181
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)
8282

chia/_tests/cmds/wallet/test_notifications.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import Optional, cast
4+
from typing import cast
55

66
from chia_rs.sized_bytes import bytes32
77
from chia_rs.sized_ints import uint32, uint64
@@ -12,7 +12,7 @@
1212
from chia.wallet.conditions import ConditionValidTimes
1313
from chia.wallet.notification_store import Notification
1414
from chia.wallet.transaction_record import TransactionRecord
15-
from chia.wallet.wallet_request_types import GetNotifications, GetNotificationsResponse
15+
from chia.wallet.wallet_request_types import DeleteNotifications, GetNotifications, GetNotificationsResponse
1616

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

@@ -111,15 +111,31 @@ def test_notifications_delete(capsys: object, get_test_cli_clients: tuple[TestRp
111111

112112
# set RPC Client
113113
class NotificationsDeleteRpcClient(TestWalletRpcClient):
114-
async def delete_notifications(self, ids: Optional[list[bytes32]] = None) -> bool:
115-
self.add_to_log("delete_notifications", (ids,))
116-
return True
114+
async def delete_notifications(self, request: DeleteNotifications) -> None:
115+
self.add_to_log("delete_notifications", (request.ids,))
117116

118117
inst_rpc_client = NotificationsDeleteRpcClient()
119118
test_rpc_clients.wallet_rpc_client = inst_rpc_client
119+
# Try all first
120120
command_args = ["wallet", "notifications", "delete", FINGERPRINT_ARG, "--all"]
121121
# these are various things that should be in the output
122-
assert_list = ["Success: True"]
122+
assert_list = ["Success!"]
123123
run_cli_command_and_assert(capsys, root_dir, command_args, assert_list)
124124
expected_calls: logType = {"delete_notifications": [(None,)]}
125125
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)
126+
# Next try specifying IDs
127+
command_args = [
128+
"wallet",
129+
"notifications",
130+
"delete",
131+
FINGERPRINT_ARG,
132+
"--id",
133+
bytes32.zeros.hex(),
134+
"--id",
135+
bytes32.zeros.hex(),
136+
]
137+
# these are various things that should be in the output
138+
assert_list = ["Success!"]
139+
run_cli_command_and_assert(capsys, root_dir, command_args, assert_list)
140+
expected_calls = {"delete_notifications": [([bytes32.zeros, bytes32.zeros],)]}
141+
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)

chia/_tests/cmds/wallet/test_wallet.py

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from chia.types.blockchain_format.program import Program
3030
from chia.types.signing_mode import SigningMode
3131
from chia.util.bech32m import encode_puzzle_hash
32-
from chia.wallet.conditions import ConditionValidTimes
32+
from chia.wallet.conditions import Condition, ConditionValidTimes
3333
from chia.wallet.trade_record import TradeRecord
3434
from chia.wallet.trading.offer import Offer
3535
from chia.wallet.trading.trade_status import TradeStatus
@@ -44,9 +44,16 @@
4444
BalanceResponse,
4545
CancelOfferResponse,
4646
CATSpendResponse,
47+
ClawbackPuzzleDecoratorOverride,
4748
CreateOfferForIDsResponse,
49+
DeleteUnconfirmedTransactions,
50+
ExtendDerivationIndex,
51+
ExtendDerivationIndexResponse,
4852
FungibleAsset,
53+
GetCurrentDerivationIndexResponse,
4954
GetHeightInfoResponse,
55+
GetNextAddress,
56+
GetNextAddressResponse,
5057
GetTransaction,
5158
GetTransactions,
5259
GetTransactionsResponse,
@@ -58,7 +65,10 @@
5865
NFTGetWalletDID,
5966
NFTGetWalletDIDResponse,
6067
RoyaltyAsset,
68+
SendTransaction,
6169
SendTransactionResponse,
70+
SpendClawbackCoins,
71+
SpendClawbackCoinsResponse,
6272
TakeOfferResponse,
6373
TransactionRecordWithMetadata,
6474
WalletInfoResponse,
@@ -327,19 +337,24 @@ def test_send(capsys: object, get_test_cli_clients: tuple[TestRpcClients, Path])
327337
class SendWalletRpcClient(TestWalletRpcClient):
328338
async def send_transaction(
329339
self,
330-
wallet_id: int,
331-
amount: uint64,
332-
address: str,
340+
request: SendTransaction,
333341
tx_config: TXConfig,
334-
fee: uint64 = uint64(0),
335-
memos: Optional[list[str]] = None,
336-
puzzle_decorator_override: Optional[list[dict[str, Union[str, int, bool]]]] = None,
337-
push: bool = True,
342+
extra_conditions: tuple[Condition, ...] = tuple(),
338343
timelock_info: ConditionValidTimes = ConditionValidTimes(),
339344
) -> SendTransactionResponse:
340345
self.add_to_log(
341346
"send_transaction",
342-
(wallet_id, amount, address, tx_config, fee, memos, puzzle_decorator_override, push, timelock_info),
347+
(
348+
request.wallet_id,
349+
request.amount,
350+
request.address,
351+
tx_config,
352+
request.fee,
353+
request.memos,
354+
request.puzzle_decorator,
355+
request.push,
356+
timelock_info,
357+
),
343358
)
344359
name = get_bytes32(2)
345360
tx_rec = TransactionRecord(
@@ -457,7 +472,7 @@ async def cat_spend(
457472
),
458473
500000000000,
459474
["0x6262626262626262626262626262626262626262626262626262626262626262"],
460-
[{"decorator": "CLAWBACK", "clawback_timelock": 60}],
475+
[ClawbackPuzzleDecoratorOverride(decorator="CLAWBACK", clawback_timelock=uint64(60))],
461476
True,
462477
test_condition_valid_times,
463478
)
@@ -493,11 +508,11 @@ def test_get_address(capsys: object, get_test_cli_clients: tuple[TestRpcClients,
493508

494509
# set RPC Client
495510
class GetAddressWalletRpcClient(TestWalletRpcClient):
496-
async def get_next_address(self, wallet_id: int, new_address: bool) -> str:
497-
self.add_to_log("get_next_address", (wallet_id, new_address))
498-
if new_address:
499-
return encode_puzzle_hash(get_bytes32(3), "xch")
500-
return encode_puzzle_hash(get_bytes32(4), "xch")
511+
async def get_next_address(self, request: GetNextAddress) -> GetNextAddressResponse:
512+
self.add_to_log("get_next_address", (request.wallet_id, request.new_address))
513+
if request.new_address:
514+
return GetNextAddressResponse(request.wallet_id, encode_puzzle_hash(get_bytes32(3), "xch"))
515+
return GetNextAddressResponse(request.wallet_id, encode_puzzle_hash(get_bytes32(4), "xch"))
501516

502517
inst_rpc_client = GetAddressWalletRpcClient()
503518
test_rpc_clients.wallet_rpc_client = inst_rpc_client
@@ -526,23 +541,25 @@ def test_clawback(capsys: object, get_test_cli_clients: tuple[TestRpcClients, Pa
526541
class ClawbackWalletRpcClient(TestWalletRpcClient):
527542
async def spend_clawback_coins(
528543
self,
529-
coin_ids: list[bytes32],
530-
fee: int = 0,
531-
force: bool = False,
532-
push: bool = True,
544+
request: SpendClawbackCoins,
545+
tx_config: TXConfig,
546+
extra_conditions: tuple[Condition, ...] = tuple(),
533547
timelock_info: ConditionValidTimes = ConditionValidTimes(),
534-
) -> dict[str, Any]:
535-
self.add_to_log("spend_clawback_coins", (coin_ids, fee, force, push, timelock_info))
536-
tx_hex_list = [get_bytes32(6).hex(), get_bytes32(7).hex(), get_bytes32(8).hex()]
537-
return {
538-
"transaction_ids": tx_hex_list,
539-
"transactions": [STD_TX.to_json_dict()],
540-
}
548+
) -> SpendClawbackCoinsResponse:
549+
self.add_to_log(
550+
"spend_clawback_coins", (request.coin_ids, request.fee, request.force, request.push, timelock_info)
551+
)
552+
tx_list = [get_bytes32(6), get_bytes32(7), get_bytes32(8)]
553+
return SpendClawbackCoinsResponse(
554+
transaction_ids=tx_list,
555+
transactions=[STD_TX],
556+
unsigned_transactions=[STD_UTX],
557+
)
541558

542559
inst_rpc_client = ClawbackWalletRpcClient()
543560
test_rpc_clients.wallet_rpc_client = inst_rpc_client
544561
tx_ids = [get_bytes32(3), get_bytes32(4), get_bytes32(5)]
545-
r_tx_ids_hex = [get_bytes32(6).hex(), get_bytes32(7).hex(), get_bytes32(8).hex()]
562+
r_tx_ids_hex = ["0x" + get_bytes32(6).hex(), "0x" + get_bytes32(7).hex(), "0x" + get_bytes32(8).hex()]
546563
command_args = [
547564
"wallet",
548565
"clawback",
@@ -556,7 +573,7 @@ async def spend_clawback_coins(
556573
"--expires-at",
557574
"150",
558575
]
559-
run_cli_command_and_assert(capsys, root_dir, command_args, ["transaction_ids", str(r_tx_ids_hex)])
576+
run_cli_command_and_assert(capsys, root_dir, command_args, ["transaction_ids", *r_tx_ids_hex])
560577
# these are various things that should be in the output
561578
expected_calls: logType = {
562579
"spend_clawback_coins": [(tx_ids, 500000000000, False, True, test_condition_valid_times)],
@@ -569,8 +586,8 @@ def test_del_unconfirmed_tx(capsys: object, get_test_cli_clients: tuple[TestRpcC
569586

570587
# set RPC Client
571588
class UnconfirmedTxRpcClient(TestWalletRpcClient):
572-
async def delete_unconfirmed_transactions(self, wallet_id: int) -> None:
573-
self.add_to_log("delete_unconfirmed_transactions", (wallet_id,))
589+
async def delete_unconfirmed_transactions(self, request: DeleteUnconfirmedTransactions) -> None:
590+
self.add_to_log("delete_unconfirmed_transactions", (request.wallet_id,))
574591

575592
inst_rpc_client = UnconfirmedTxRpcClient()
576593
test_rpc_clients.wallet_rpc_client = inst_rpc_client
@@ -594,9 +611,9 @@ def test_get_derivation_index(capsys: object, get_test_cli_clients: tuple[TestRp
594611

595612
# set RPC Client
596613
class GetDerivationIndexRpcClient(TestWalletRpcClient):
597-
async def get_current_derivation_index(self) -> str:
614+
async def get_current_derivation_index(self) -> GetCurrentDerivationIndexResponse:
598615
self.add_to_log("get_current_derivation_index", ())
599-
return str(520)
616+
return GetCurrentDerivationIndexResponse(uint32(520))
600617

601618
inst_rpc_client = GetDerivationIndexRpcClient()
602619
test_rpc_clients.wallet_rpc_client = inst_rpc_client
@@ -625,8 +642,9 @@ def test_sign_message(capsys: object, get_test_cli_clients: tuple[TestRpcClients
625642
# these are various things that should be in the output
626643
assert_list = [
627644
f"Message: {message.hex()}",
628-
f"Public Key: {bytes([3] * 48).hex()}",
629-
f"Signature: {bytes([6] * 576).hex()}",
645+
"Public Key: b5acf3599bc5fa5da1c00f6cc3d5bcf1560def67778b7f50a8c373a83f78761505b6250ab776e38a292e26628009aec4",
646+
"Signature: c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
647+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
630648
f"Signing Mode: {SigningMode.CHIP_0002.value}",
631649
]
632650
run_cli_command_and_assert(capsys, root_dir, [*command_args, f"-a{xch_addr}"], assert_list)
@@ -641,9 +659,9 @@ def test_update_derivation_index(capsys: object, get_test_cli_clients: tuple[Tes
641659

642660
# set RPC Client
643661
class UpdateDerivationIndexRpcClient(TestWalletRpcClient):
644-
async def extend_derivation_index(self, index: int) -> str:
645-
self.add_to_log("extend_derivation_index", (index,))
646-
return str(index)
662+
async def extend_derivation_index(self, request: ExtendDerivationIndex) -> ExtendDerivationIndexResponse:
663+
self.add_to_log("extend_derivation_index", (request.index,))
664+
return ExtendDerivationIndexResponse(request.index)
647665

648666
inst_rpc_client = UpdateDerivationIndexRpcClient()
649667
test_rpc_clients.wallet_rpc_client = inst_rpc_client

0 commit comments

Comments
 (0)