Skip to content

Commit

Permalink
Fix CMD tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Quexington committed Oct 30, 2024
1 parent 69d8fd3 commit 3da6dc8
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 79 deletions.
48 changes: 28 additions & 20 deletions chia/_tests/cmds/cmd_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
from chia.rpc.rpc_client import RpcClient
from chia.rpc.wallet_request_types import (
GetSyncStatusResponse,
GetTransaction,
GetTransactionResponse,
GetWallets,
GetWalletsResponse,
SendTransactionMultiResponse,
UserFriendlyMemos,
UserFriendlyTransactionRecord,
WalletInfoResponse,
)
from chia.rpc.wallet_rpc_client import WalletRpcClient
Expand Down Expand Up @@ -112,26 +116,30 @@ async def get_wallets(self, request: GetWallets) -> GetWalletsResponse:
raise ValueError(f"Invalid fingerprint: {self.fingerprint}")
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,))
return TransactionRecord(
confirmed_at_height=uint32(1),
created_at_time=uint64(1234),
to_puzzle_hash=bytes32([1] * 32),
amount=uint64(12345678),
fee_amount=uint64(1234567),
confirmed=False,
sent=uint32(0),
spend_bundle=WalletSpendBundle([], G2Element()),
additions=[Coin(bytes32([1] * 32), bytes32([2] * 32), uint64(12345678))],
removals=[Coin(bytes32([2] * 32), bytes32([4] * 32), uint64(12345678))],
wallet_id=uint32(1),
sent_to=[("aaaaa", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.OUTGOING_TX.value),
name=bytes32([2] * 32),
memos=[(bytes32([3] * 32), [bytes([4] * 32)])],
valid_times=ConditionValidTimes(),
async def get_transaction(self, request: GetTransaction) -> GetTransactionResponse:
self.add_to_log("get_transaction", (request,))
return GetTransactionResponse(
UserFriendlyTransactionRecord(
confirmed_at_height=uint32(1),
created_at_time=uint64(1234),
to_puzzle_hash=bytes32([1] * 32),
amount=uint64(12345678),
fee_amount=uint64(1234567),
confirmed=False,
sent=uint32(0),
spend_bundle=WalletSpendBundle([], G2Element()),
additions=[Coin(bytes32([1] * 32), bytes32([2] * 32), uint64(12345678))],
removals=[Coin(bytes32([2] * 32), bytes32([4] * 32), uint64(12345678))],
wallet_id=uint32(1),
sent_to=[("aaaaa", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.OUTGOING_TX.value),
name=bytes32([2] * 32),
memos=UserFriendlyMemos([(bytes32([3] * 32), [bytes([4] * 32)])]),
valid_times=ConditionValidTimes(),
to_address="",
),
bytes32([2] * 32),
)

async def get_cat_name(self, wallet_id: int) -> str:
Expand Down
131 changes: 73 additions & 58 deletions chia/_tests/cmds/wallet/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
DAOFreeCoinsFromFinishedProposalsResponse,
DAOSendToLockupResponse,
DAOVoteOnProposalResponse,
GetTransaction,
GetTransactionResponse,
GetWallets,
GetWalletsResponse,
UserFriendlyMemos,
UserFriendlyTransactionRecord,
WalletInfoResponse,
)
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.bech32m import encode_puzzle_hash
from chia.util.ints import uint8, uint32, uint64
from chia.wallet.conditions import ConditionValidTimes, parse_timelock_info
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.transaction_type import TransactionType
from chia.wallet.util.tx_config import TXConfig
from chia.wallet.util.wallet_types import WalletType
Expand Down Expand Up @@ -157,25 +160,29 @@ async def dao_get_rules(
return {"rules": {"proposal_minimum": 100}}

@override
async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
return TransactionRecord(
confirmed_at_height=uint32(0),
created_at_time=uint64(int(time.time())),
to_puzzle_hash=bytes32(b"2" * 32),
amount=uint64(10),
fee_amount=uint64(1),
confirmed=True,
sent=uint32(10),
spend_bundle=None,
additions=[],
removals=[],
wallet_id=uint32(1),
sent_to=[("peer1", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.INCOMING_TX.value),
name=bytes32(token_bytes()),
memos=[],
valid_times=parse_timelock_info(tuple()),
async def get_transaction(self, request: GetTransaction) -> GetTransactionResponse:
return GetTransactionResponse(
UserFriendlyTransactionRecord(
confirmed_at_height=uint32(0),
created_at_time=uint64(int(time.time())),
to_puzzle_hash=bytes32(b"2" * 32),
amount=uint64(10),
fee_amount=uint64(1),
confirmed=True,
sent=uint32(10),
spend_bundle=None,
additions=[],
removals=[],
wallet_id=uint32(1),
sent_to=[("peer1", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.INCOMING_TX.value),
name=bytes32(token_bytes()),
memos=UserFriendlyMemos([]),
valid_times=parse_timelock_info(tuple()),
to_address="",
),
bytes32(token_bytes()),
)

inst_rpc_client = DAOCreateRpcClient()
Expand Down Expand Up @@ -331,25 +338,29 @@ async def get_wallets(self, request: GetWallets) -> GetWalletsResponse:
)

@override
async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
return TransactionRecord(
confirmed_at_height=uint32(0),
created_at_time=uint64(int(time.time())),
to_puzzle_hash=bytes32(b"2" * 32),
amount=uint64(10),
fee_amount=uint64(1),
confirmed=True,
sent=uint32(10),
spend_bundle=None,
additions=[],
removals=[],
wallet_id=uint32(1),
sent_to=[("peer1", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.INCOMING_TX.value),
name=bytes32(b"x" * 32),
memos=[],
valid_times=parse_timelock_info(tuple()),
async def get_transaction(self, request: GetTransaction) -> GetTransactionResponse:
return GetTransactionResponse(
UserFriendlyTransactionRecord(
confirmed_at_height=uint32(0),
created_at_time=uint64(int(time.time())),
to_puzzle_hash=bytes32(b"2" * 32),
amount=uint64(10),
fee_amount=uint64(1),
confirmed=True,
sent=uint32(10),
spend_bundle=None,
additions=[],
removals=[],
wallet_id=uint32(1),
sent_to=[("peer1", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.INCOMING_TX.value),
name=bytes32(token_bytes()),
memos=UserFriendlyMemos([]),
valid_times=parse_timelock_info(tuple()),
to_address="",
),
bytes32(token_bytes()),
)

# List all proposals
Expand Down Expand Up @@ -536,25 +547,29 @@ async def dao_exit_lockup(
return DAOExitLockupResponse([STD_UTX], [STD_TX], STD_TX.name, STD_TX)

@override
async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
return TransactionRecord(
confirmed_at_height=uint32(0),
created_at_time=uint64(int(time.time())),
to_puzzle_hash=bytes32(b"2" * 32),
amount=uint64(10),
fee_amount=uint64(1),
confirmed=True,
sent=uint32(10),
spend_bundle=None,
additions=[],
removals=[],
wallet_id=uint32(1),
sent_to=[("peer1", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.INCOMING_TX.value),
name=bytes32(b"x" * 32),
memos=[],
valid_times=parse_timelock_info(tuple()),
async def get_transaction(self, request: GetTransaction) -> GetTransactionResponse:
return GetTransactionResponse(
UserFriendlyTransactionRecord(
confirmed_at_height=uint32(0),
created_at_time=uint64(int(time.time())),
to_puzzle_hash=bytes32(b"2" * 32),
amount=uint64(10),
fee_amount=uint64(1),
confirmed=True,
sent=uint32(10),
spend_bundle=None,
additions=[],
removals=[],
wallet_id=uint32(1),
sent_to=[("peer1", uint8(1), None)],
trade_id=None,
type=uint32(TransactionType.INCOMING_TX.value),
name=bytes32(token_bytes()),
memos=UserFriendlyMemos([]),
valid_times=parse_timelock_info(tuple()),
to_address="",
),
bytes32(token_bytes()),
)

inst_rpc_client = DAOCreateRpcClient()
Expand Down
3 changes: 2 additions & 1 deletion chia/_tests/cmds/wallet/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
CATSpendResponse,
CreateOfferForIDsResponse,
GetHeightInfoResponse,
GetTransaction,
GetWalletBalance,
GetWalletBalanceResponse,
GetWallets,
Expand Down Expand Up @@ -484,7 +485,7 @@ async def cat_spend(
test_condition_valid_times,
)
],
"get_transaction": [(get_bytes32(2),), (get_bytes32(2),)],
"get_transaction": [(GetTransaction(get_bytes32(2)),), (GetTransaction(get_bytes32(2)),)],
}
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)

Expand Down

0 comments on commit 3da6dc8

Please sign in to comment.