Skip to content

Commit fd5c036

Browse files
committed
Merge remote-tracking branch 'origin/main' into quex.port_send_transaction_s_to_marshal
2 parents 5872b9c + 8463909 commit fd5c036

19 files changed

+558
-381
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: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@
4646
CATSpendResponse,
4747
ClawbackPuzzleDecoratorOverride,
4848
CreateOfferForIDsResponse,
49+
DeleteUnconfirmedTransactions,
50+
ExtendDerivationIndex,
51+
ExtendDerivationIndexResponse,
4952
FungibleAsset,
53+
GetCurrentDerivationIndexResponse,
5054
GetHeightInfoResponse,
55+
GetNextAddress,
56+
GetNextAddressResponse,
5157
GetTransaction,
5258
GetTransactions,
5359
GetTransactionsResponse,
@@ -500,11 +506,11 @@ def test_get_address(capsys: object, get_test_cli_clients: tuple[TestRpcClients,
500506

501507
# set RPC Client
502508
class GetAddressWalletRpcClient(TestWalletRpcClient):
503-
async def get_next_address(self, wallet_id: int, new_address: bool) -> str:
504-
self.add_to_log("get_next_address", (wallet_id, new_address))
505-
if new_address:
506-
return encode_puzzle_hash(get_bytes32(3), "xch")
507-
return encode_puzzle_hash(get_bytes32(4), "xch")
509+
async def get_next_address(self, request: GetNextAddress) -> GetNextAddressResponse:
510+
self.add_to_log("get_next_address", (request.wallet_id, request.new_address))
511+
if request.new_address:
512+
return GetNextAddressResponse(request.wallet_id, encode_puzzle_hash(get_bytes32(3), "xch"))
513+
return GetNextAddressResponse(request.wallet_id, encode_puzzle_hash(get_bytes32(4), "xch"))
508514

509515
inst_rpc_client = GetAddressWalletRpcClient()
510516
test_rpc_clients.wallet_rpc_client = inst_rpc_client
@@ -576,8 +582,8 @@ def test_del_unconfirmed_tx(capsys: object, get_test_cli_clients: tuple[TestRpcC
576582

577583
# set RPC Client
578584
class UnconfirmedTxRpcClient(TestWalletRpcClient):
579-
async def delete_unconfirmed_transactions(self, wallet_id: int) -> None:
580-
self.add_to_log("delete_unconfirmed_transactions", (wallet_id,))
585+
async def delete_unconfirmed_transactions(self, request: DeleteUnconfirmedTransactions) -> None:
586+
self.add_to_log("delete_unconfirmed_transactions", (request.wallet_id,))
581587

582588
inst_rpc_client = UnconfirmedTxRpcClient()
583589
test_rpc_clients.wallet_rpc_client = inst_rpc_client
@@ -601,9 +607,9 @@ def test_get_derivation_index(capsys: object, get_test_cli_clients: tuple[TestRp
601607

602608
# set RPC Client
603609
class GetDerivationIndexRpcClient(TestWalletRpcClient):
604-
async def get_current_derivation_index(self) -> str:
610+
async def get_current_derivation_index(self) -> GetCurrentDerivationIndexResponse:
605611
self.add_to_log("get_current_derivation_index", ())
606-
return str(520)
612+
return GetCurrentDerivationIndexResponse(uint32(520))
607613

608614
inst_rpc_client = GetDerivationIndexRpcClient()
609615
test_rpc_clients.wallet_rpc_client = inst_rpc_client
@@ -632,8 +638,9 @@ def test_sign_message(capsys: object, get_test_cli_clients: tuple[TestRpcClients
632638
# these are various things that should be in the output
633639
assert_list = [
634640
f"Message: {message.hex()}",
635-
f"Public Key: {bytes([3] * 48).hex()}",
636-
f"Signature: {bytes([6] * 576).hex()}",
641+
"Public Key: b5acf3599bc5fa5da1c00f6cc3d5bcf1560def67778b7f50a8c373a83f78761505b6250ab776e38a292e26628009aec4",
642+
"Signature: c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
643+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
637644
f"Signing Mode: {SigningMode.CHIP_0002.value}",
638645
]
639646
run_cli_command_and_assert(capsys, root_dir, [*command_args, f"-a{xch_addr}"], assert_list)
@@ -648,9 +655,9 @@ def test_update_derivation_index(capsys: object, get_test_cli_clients: tuple[Tes
648655

649656
# set RPC Client
650657
class UpdateDerivationIndexRpcClient(TestWalletRpcClient):
651-
async def extend_derivation_index(self, index: int) -> str:
652-
self.add_to_log("extend_derivation_index", (index,))
653-
return str(index)
658+
async def extend_derivation_index(self, request: ExtendDerivationIndex) -> ExtendDerivationIndexResponse:
659+
self.add_to_log("extend_derivation_index", (request.index,))
660+
return ExtendDerivationIndexResponse(request.index)
654661

655662
inst_rpc_client = UpdateDerivationIndexRpcClient()
656663
test_rpc_clients.wallet_rpc_client = inst_rpc_client

0 commit comments

Comments
 (0)