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
27 changes: 17 additions & 10 deletions chia/_tests/cmds/wallet/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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 ConditionValidTimes
from chia.wallet.conditions import Condition, ConditionValidTimes
from chia.wallet.trade_record import TradeRecord
from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
Expand All @@ -44,6 +44,7 @@
BalanceResponse,
CancelOfferResponse,
CATSpendResponse,
ClawbackPuzzleDecoratorOverride,
CreateOfferForIDsResponse,
DeleteUnconfirmedTransactions,
ExtendDerivationIndex,
Expand All @@ -64,6 +65,7 @@
NFTGetWalletDID,
NFTGetWalletDIDResponse,
RoyaltyAsset,
SendTransaction,
SendTransactionResponse,
TakeOfferResponse,
TransactionRecordWithMetadata,
Expand Down Expand Up @@ -333,19 +335,24 @@ def test_send(capsys: object, get_test_cli_clients: tuple[TestRpcClients, Path])
class SendWalletRpcClient(TestWalletRpcClient):
async def send_transaction(
self,
wallet_id: int,
amount: uint64,
address: str,
request: SendTransaction,
tx_config: TXConfig,
fee: uint64 = uint64(0),
memos: Optional[list[str]] = None,
puzzle_decorator_override: Optional[list[dict[str, Union[str, int, bool]]]] = None,
push: bool = True,
extra_conditions: tuple[Condition, ...] = tuple(),
timelock_info: ConditionValidTimes = ConditionValidTimes(),
) -> SendTransactionResponse:
self.add_to_log(
"send_transaction",
(wallet_id, amount, address, tx_config, fee, memos, puzzle_decorator_override, push, timelock_info),
(
request.wallet_id,
request.amount,
request.address,
tx_config,
request.fee,
request.memos,
request.puzzle_decorator,
request.push,
timelock_info,
),
)
name = get_bytes32(2)
tx_rec = TransactionRecord(
Expand Down Expand Up @@ -463,7 +470,7 @@ async def cat_spend(
),
500000000000,
["0x6262626262626262626262626262626262626262626262626262626262626262"],
[{"decorator": "CLAWBACK", "clawback_timelock": 60}],
[ClawbackPuzzleDecoratorOverride(decorator="CLAWBACK", clawback_timelock=uint64(60))],
True,
test_condition_valid_times,
)
Expand Down
9 changes: 8 additions & 1 deletion chia/_tests/pools/test_pool_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
PWJoinPool,
PWSelfPool,
PWStatus,
SendTransaction,
)
from chia.wallet.wallet_rpc_client import WalletRpcClient
from chia.wallet.wallet_service import WalletService
Expand Down Expand Up @@ -591,7 +592,13 @@ async def test_absorb_self(

tr: TransactionRecord = (
await client.send_transaction(
1, uint64(100), encode_puzzle_hash(status.p2_singleton_puzzle_hash, "txch"), DEFAULT_TX_CONFIG
SendTransaction(
wallet_id=uint32(1),
amount=uint64(100),
address=encode_puzzle_hash(status.p2_singleton_puzzle_hash, "txch"),
push=True,
),
DEFAULT_TX_CONFIG,
)
).transaction

Expand Down
9 changes: 7 additions & 2 deletions chia/_tests/wallet/cat_wallet/test_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from chia.wallet.wallet_info import WalletInfo
from chia.wallet.wallet_interested_store import WalletInterestedStore
from chia.wallet.wallet_node import WalletNode
from chia.wallet.wallet_request_types import GetTransactionMemo, PushTX
from chia.wallet.wallet_request_types import GetTransactionMemo, PushTX, SendTransaction
from chia.wallet.wallet_state_manager import WalletStateManager


Expand Down Expand Up @@ -1429,7 +1429,12 @@ async def test_cat_change_detection(wallet_environments: WalletTestFramework, wa
cat_amount_0 = uint64(100)
cat_amount_1 = uint64(5)

tx = (await env.rpc_client.send_transaction(1, cat_amount_0, addr, wallet_environments.tx_config)).transaction
tx = (
await env.rpc_client.send_transaction(
SendTransaction(wallet_id=uint32(1), amount=cat_amount_0, address=addr, push=True),
wallet_environments.tx_config,
)
).transaction
spend_bundle = tx.spend_bundle
assert spend_bundle is not None

Expand Down
91 changes: 63 additions & 28 deletions chia/_tests/wallet/rpc/test_wallet_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
from chia.wallet.wallet_request_types import (
AddKey,
CheckDeleteKey,
ClawbackPuzzleDecoratorOverride,
CombineCoins,
DefaultCAT,
DeleteKey,
Expand Down Expand Up @@ -140,6 +141,7 @@
PushTransactions,
PushTX,
RoyaltyAsset,
SendTransaction,
SetWalletResyncOnStartup,
SplitCoins,
VerifySignature,
Expand Down Expand Up @@ -382,24 +384,25 @@ async def test_send_transaction(wallet_rpc_environment: WalletRpcTestEnvironment
addr = encode_puzzle_hash(await action_scope.get_puzzle_hash(wallet_2.wallet_state_manager), "txch")
tx_amount = uint64(15600000)
with pytest.raises(ValueError):
await client.send_transaction(1, uint64(100000000000000001), addr, DEFAULT_TX_CONFIG)
await client.send_transaction(
SendTransaction(wallet_id=uint32(1), amount=uint64(100000000000000001), address=addr, push=True),
DEFAULT_TX_CONFIG,
)

# Tests sending a basic transaction
extra_conditions = (Remark(Program.to(("test", None))),)
non_existent_coin = Coin(bytes32.zeros, bytes32.zeros, uint64(0))
tx_no_push = (
await client.send_transaction(
1,
tx_amount,
addr,
memos=["this is a basic tx"],
SendTransaction(
wallet_id=uint32(1), amount=tx_amount, address=addr, memos=["this is a basic tx"], push=False
),
tx_config=DEFAULT_TX_CONFIG.override(
excluded_coin_amounts=[uint64(250000000000)],
excluded_coin_ids=[non_existent_coin.name()],
reuse_puzhash=True,
),
extra_conditions=extra_conditions,
push=False,
)
).transaction
response = await client.fetch(
Expand Down Expand Up @@ -841,12 +844,14 @@ async def test_spend_clawback_coins(wallet_rpc_environment: WalletRpcTestEnviron
wallet_2_puzhash = await action_scope.get_puzzle_hash(wallet_2.wallet_state_manager)
tx = (
await wallet_1_rpc.send_transaction(
wallet_id=1,
amount=uint64(500),
address=encode_puzzle_hash(wallet_2_puzhash, "txch"),
SendTransaction(
wallet_id=uint32(1),
amount=uint64(500),
address=encode_puzzle_hash(wallet_2_puzhash, "txch"),
puzzle_decorator=[ClawbackPuzzleDecoratorOverride(decorator="CLAWBACK", clawback_timelock=uint64(5))],
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
fee=uint64(0),
puzzle_decorator_override=[{"decorator": "CLAWBACK", "clawback_timelock": 5}],
)
).transaction
clawback_coin_id_1 = tx.additions[0].name()
Expand All @@ -855,12 +860,14 @@ async def test_spend_clawback_coins(wallet_rpc_environment: WalletRpcTestEnviron
await full_node_api.wait_for_wallet_synced(wallet_node=wallet_2_node, timeout=20)
tx = (
await wallet_2_rpc.send_transaction(
wallet_id=1,
amount=uint64(500),
address=encode_puzzle_hash(wallet_1_puzhash, "txch"),
SendTransaction(
wallet_id=uint32(1),
amount=uint64(500),
address=encode_puzzle_hash(wallet_1_puzhash, "txch"),
puzzle_decorator=[ClawbackPuzzleDecoratorOverride(decorator="CLAWBACK", clawback_timelock=uint64(5))],
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
fee=uint64(0),
puzzle_decorator_override=[{"decorator": "CLAWBACK", "clawback_timelock": 5}],
)
).transaction
assert tx.spend_bundle is not None
Expand Down Expand Up @@ -1023,7 +1030,8 @@ async def test_get_transactions(wallet_rpc_environment: WalletRpcTestEnvironment
puzhash = await action_scope.get_puzzle_hash(wallet.wallet_state_manager)
await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)
await client.send_transaction(
1, uint64(1), encode_puzzle_hash(puzhash, "txch"), DEFAULT_TX_CONFIG
SendTransaction(wallet_id=uint32(1), amount=uint64(1), address=encode_puzzle_hash(puzhash, "txch"), push=True),
DEFAULT_TX_CONFIG,
) # Create a pending tx

with pytest.raises(ValueError, match="There is no known sort foo"):
Expand All @@ -1049,7 +1057,12 @@ async def test_get_transactions(wallet_rpc_environment: WalletRpcTestEnvironment
async with wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
ph_by_addr = await action_scope.get_puzzle_hash(wallet.wallet_state_manager)
await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)
await client.send_transaction(1, uint64(1), encode_puzzle_hash(ph_by_addr, "txch"), DEFAULT_TX_CONFIG)
await client.send_transaction(
SendTransaction(
wallet_id=uint32(1), amount=uint64(1), address=encode_puzzle_hash(ph_by_addr, "txch"), push=True
),
DEFAULT_TX_CONFIG,
)
await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)
tx_for_address = (
await client.get_transactions(GetTransactions(uint32(1), to_address=encode_puzzle_hash(ph_by_addr, "txch")))
Expand Down Expand Up @@ -1801,7 +1814,12 @@ async def test_get_coin_records_by_names(wallet_rpc_environment: WalletRpcTestEn
await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)

# Spend half of it back to the same wallet get some spent coins in the wallet
tx = (await client.send_transaction(1, uint64(generated_funds / 2), address, DEFAULT_TX_CONFIG)).transaction
tx = (
await client.send_transaction(
SendTransaction(wallet_id=uint32(1), amount=uint64(generated_funds / 2), address=address, push=True),
DEFAULT_TX_CONFIG,
)
).transaction
assert tx.spend_bundle is not None
await time_out_assert(20, tx_in_mempool, True, client, tx.name)
await farm_transaction(full_node_api, wallet_node, tx.spend_bundle)
Expand Down Expand Up @@ -2167,7 +2185,11 @@ async def test_key_and_address_endpoints(wallet_rpc_environment: WalletRpcTestEn
addr = encode_puzzle_hash(ph, "txch")
tx_amount = uint64(15600000)
await env.full_node.api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)
created_tx = (await client.send_transaction(1, tx_amount, addr, DEFAULT_TX_CONFIG)).transaction
created_tx = (
await client.send_transaction(
SendTransaction(wallet_id=uint32(1), amount=tx_amount, address=addr, push=True), DEFAULT_TX_CONFIG
)
).transaction

await time_out_assert(20, tx_in_mempool, True, client, created_tx.name)
assert len(await wallet.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(1)) == 1
Expand Down Expand Up @@ -2230,7 +2252,10 @@ async def test_key_and_address_endpoints(wallet_rpc_environment: WalletRpcTestEn
assert await get_unconfirmed_balance(client, int(wallets[0].id)) == 0

with pytest.raises(ValueError):
await client.send_transaction(wallets[0].id, uint64(100), addr, DEFAULT_TX_CONFIG)
await client.send_transaction(
SendTransaction(wallet_id=uint32(wallets[0].id), amount=uint64(100), address=addr, push=True),
DEFAULT_TX_CONFIG,
)

# Delete all keys
await client.delete_all_keys()
Expand All @@ -2256,7 +2281,11 @@ async def test_select_coins_rpc(wallet_rpc_environment: WalletRpcTestEnvironment
for tx_amount in tx_amounts:
funds -= tx_amount
# create coins for tests
tx = (await client.send_transaction(1, tx_amount, addr, DEFAULT_TX_CONFIG)).transaction
tx = (
await client.send_transaction(
SendTransaction(wallet_id=uint32(1), amount=tx_amount, address=addr, push=True), DEFAULT_TX_CONFIG
)
).transaction
spend_bundle = tx.spend_bundle
assert spend_bundle is not None
for coin in spend_bundle.additions():
Expand Down Expand Up @@ -2817,12 +2846,14 @@ async def test_set_wallet_resync_on_startup(wallet_rpc_environment: WalletRpcTes
# Test Clawback resync
tx = (
await wc.send_transaction(
wallet_id=1,
amount=uint64(500),
address=address,
SendTransaction(
wallet_id=uint32(1),
amount=uint64(500),
address=address,
puzzle_decorator=[ClawbackPuzzleDecoratorOverride(decorator="CLAWBACK", clawback_timelock=uint64(5))],
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
fee=uint64(0),
puzzle_decorator_override=[{"decorator": "CLAWBACK", "clawback_timelock": 5}],
)
).transaction
clawback_coin_id = tx.additions[0].name()
Expand Down Expand Up @@ -2965,7 +2996,11 @@ async def test_cat_spend_run_tail(wallet_rpc_environment: WalletRpcTestEnvironme
)
tx_amount = uint64(100)

tx = (await client.send_transaction(1, tx_amount, addr, DEFAULT_TX_CONFIG)).transaction
tx = (
await client.send_transaction(
SendTransaction(wallet_id=uint32(1), amount=tx_amount, address=addr, push=True), DEFAULT_TX_CONFIG
)
).transaction
transaction_id = tx.name
spend_bundle = tx.spend_bundle
assert spend_bundle is not None
Expand Down
34 changes: 21 additions & 13 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from chia.wallet.wallet_coin_store import GetCoinRecords
from chia.wallet.wallet_request_types import (
CATSpendResponse,
ClawbackPuzzleDecoratorOverride,
DeleteNotifications,
DeleteUnconfirmedTransactions,
DIDFindLostDID,
Expand Down Expand Up @@ -72,6 +73,7 @@
NFTSetNFTDID,
NFTTransferNFT,
RoyaltyAsset,
SendTransaction,
SendTransactionResponse,
SignMessageByAddress,
SignMessageByAddressResponse,
Expand Down Expand Up @@ -335,7 +337,7 @@ async def send(
) -> list[TransactionRecord]:
async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config):
if memo is None:
memos = None
memos = []
else:
memos = [memo]

Expand Down Expand Up @@ -364,23 +366,29 @@ async def send(
if typ == WalletType.STANDARD_WALLET:
print("Submitting transaction...")
res: Union[CATSpendResponse, SendTransactionResponse] = await wallet_client.send_transaction(
wallet_id,
final_amount,
address.original_address,
CMDTXConfigLoader(
SendTransaction(
wallet_id=uint32(wallet_id),
amount=final_amount,
address=address.original_address,
fee=fee,
memos=memos,
push=push,
puzzle_decorator=(
[
ClawbackPuzzleDecoratorOverride(
PuzzleDecoratorType.CLAWBACK.name, clawback_timelock=uint64(clawback_time_lock)
)
]
if clawback_time_lock > 0
else None
),
),
tx_config=CMDTXConfigLoader(
min_coin_amount=min_coin_amount,
max_coin_amount=max_coin_amount,
excluded_coin_ids=list(excluded_coin_ids),
reuse_puzhash=reuse_puzhash,
).to_tx_config(mojo_per_unit, config, fingerprint),
fee,
memos,
puzzle_decorator_override=(
[{"decorator": PuzzleDecoratorType.CLAWBACK.name, "clawback_timelock": clawback_time_lock}]
if clawback_time_lock > 0
else None
),
push=push,
timelock_info=condition_valid_times,
)
elif typ in {WalletType.CAT, WalletType.CRCAT, WalletType.RCAT}:
Expand Down
Loading
Loading