|
6 | 6 | import json |
7 | 7 | import logging |
8 | 8 | import random |
| 9 | +import re |
9 | 10 | from collections.abc import AsyncIterator |
10 | 11 | from operator import attrgetter |
11 | 12 | from typing import Any, Optional |
|
108 | 109 | CATGetAssetID, |
109 | 110 | CATGetName, |
110 | 111 | CATSetName, |
| 112 | + CATSpend, |
111 | 113 | CheckDeleteKey, |
112 | 114 | CheckOfferValidity, |
113 | 115 | ClawbackPuzzleDecoratorOverride, |
@@ -1255,18 +1257,69 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty |
1255 | 1257 | # Test CAT spend without a fee |
1256 | 1258 | with pytest.raises(ValueError): |
1257 | 1259 | await env_0.rpc_client.cat_spend( |
1258 | | - cat_0_id, |
1259 | | - DEFAULT_TX_CONFIG.override( |
| 1260 | + CATSpend( |
| 1261 | + wallet_id=cat_0_id, |
| 1262 | + amount=uint64(4), |
| 1263 | + inner_address=addr_1, |
| 1264 | + fee=uint64(0), |
| 1265 | + memos=["the cat memo"], |
| 1266 | + push=False, |
| 1267 | + ), |
| 1268 | + tx_config=wallet_environments.tx_config.override( |
1260 | 1269 | excluded_coin_amounts=[uint64(100)], |
1261 | 1270 | excluded_coin_ids=[bytes32.zeros], |
1262 | 1271 | ), |
1263 | | - uint64(4), |
1264 | | - addr_1, |
1265 | | - uint64(0), |
1266 | | - ["the cat memo"], |
1267 | 1272 | ) |
| 1273 | + |
| 1274 | + # Test some validation errors |
| 1275 | + with pytest.raises( |
| 1276 | + ValueError, |
| 1277 | + match=re.escape('Must specify "additions" or "amount"+"inner_address"+"memos", but not both.'), |
| 1278 | + ): |
| 1279 | + await env_0.rpc_client.cat_spend( |
| 1280 | + CATSpend( |
| 1281 | + wallet_id=cat_0_id, |
| 1282 | + amount=uint64(4), |
| 1283 | + inner_address=addr_1, |
| 1284 | + memos=["the cat memo"], |
| 1285 | + additions=[], |
| 1286 | + ), |
| 1287 | + tx_config=wallet_environments.tx_config, |
| 1288 | + ) |
| 1289 | + |
| 1290 | + with pytest.raises(ValueError, match=re.escape('Must specify "amount" and "inner_address" together.')): |
| 1291 | + await env_0.rpc_client.cat_spend( |
| 1292 | + CATSpend( |
| 1293 | + wallet_id=cat_0_id, |
| 1294 | + amount=uint64(4), |
| 1295 | + inner_address=None, |
| 1296 | + ), |
| 1297 | + tx_config=wallet_environments.tx_config, |
| 1298 | + ) |
| 1299 | + |
| 1300 | + with pytest.raises( |
| 1301 | + ValueError, |
| 1302 | + match=re.escape('Must specify \\"extra_delta\\", \\"tail_reveal\\" and \\"tail_solution\\" together.'), |
| 1303 | + ): |
| 1304 | + await env_0.rpc_client.cat_spend( |
| 1305 | + CATSpend( |
| 1306 | + wallet_id=cat_0_id, |
| 1307 | + additions=[], |
| 1308 | + extra_delta="1", |
| 1309 | + ), |
| 1310 | + tx_config=wallet_environments.tx_config, |
| 1311 | + ) |
| 1312 | + |
1268 | 1313 | tx_res = await env_0.rpc_client.cat_spend( |
1269 | | - cat_0_id, wallet_environments.tx_config, uint64(4), addr_1, uint64(0), ["the cat memo"] |
| 1314 | + CATSpend( |
| 1315 | + wallet_id=cat_0_id, |
| 1316 | + amount=uint64(4), |
| 1317 | + inner_address=addr_1, |
| 1318 | + fee=uint64(0), |
| 1319 | + memos=["the cat memo"], |
| 1320 | + push=True, |
| 1321 | + ), |
| 1322 | + tx_config=wallet_environments.tx_config, |
1270 | 1323 | ) |
1271 | 1324 |
|
1272 | 1325 | spend_bundle = tx_res.transaction.spend_bundle |
@@ -1312,7 +1365,15 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty |
1312 | 1365 |
|
1313 | 1366 | # Test CAT spend with a fee |
1314 | 1367 | tx_res = await env_0.rpc_client.cat_spend( |
1315 | | - cat_0_id, wallet_environments.tx_config, uint64(1), addr_1, uint64(5_000_000), ["the cat memo"] |
| 1368 | + CATSpend( |
| 1369 | + wallet_id=cat_0_id, |
| 1370 | + amount=uint64(1), |
| 1371 | + inner_address=addr_1, |
| 1372 | + fee=uint64(5_000_000), |
| 1373 | + memos=["the cat memo"], |
| 1374 | + push=True, |
| 1375 | + ), |
| 1376 | + wallet_environments.tx_config, |
1316 | 1377 | ) |
1317 | 1378 |
|
1318 | 1379 | spend_bundle = tx_res.transaction.spend_bundle |
@@ -1379,13 +1440,16 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty |
1379 | 1440 | ) |
1380 | 1441 | ) |
1381 | 1442 | tx_res = await env_0.rpc_client.cat_spend( |
1382 | | - cat_0_id, |
| 1443 | + CATSpend( |
| 1444 | + wallet_id=cat_0_id, |
| 1445 | + amount=uint64(1), |
| 1446 | + inner_address=addr_1, |
| 1447 | + fee=uint64(5_000_000), |
| 1448 | + memos=["the cat memo"], |
| 1449 | + coins=select_coins_response.coins, |
| 1450 | + push=True, |
| 1451 | + ), |
1383 | 1452 | wallet_environments.tx_config, |
1384 | | - uint64(1), |
1385 | | - addr_1, |
1386 | | - uint64(5_000_000), |
1387 | | - ["the cat memo"], |
1388 | | - removals=select_coins_response.coins, |
1389 | 1453 | ) |
1390 | 1454 |
|
1391 | 1455 | spend_bundle = tx_res.transaction.spend_bundle |
@@ -3109,11 +3173,16 @@ async def test_cat_spend_run_tail(wallet_rpc_environment: WalletRpcTestEnvironme |
3109 | 3173 | # Attempt to melt it fully |
3110 | 3174 | tx = ( |
3111 | 3175 | await client.cat_spend( |
3112 | | - cat_wallet_id, |
3113 | | - amount=uint64(0), |
| 3176 | + CATSpend( |
| 3177 | + wallet_id=cat_wallet_id, |
| 3178 | + amount=uint64(0), |
| 3179 | + inner_address=encode_puzzle_hash(our_ph, "txch"), |
| 3180 | + extra_delta=str(tx_amount * -1), |
| 3181 | + tail_reveal=b"\x80", |
| 3182 | + tail_solution=b"\x80", |
| 3183 | + push=True, |
| 3184 | + ), |
3114 | 3185 | tx_config=DEFAULT_TX_CONFIG, |
3115 | | - inner_address=encode_puzzle_hash(our_ph, "txch"), |
3116 | | - cat_discrepancy=(tx_amount * -1, Program.to(None), Program.to(None)), |
3117 | 3186 | ) |
3118 | 3187 | ).transaction |
3119 | 3188 | transaction_id = tx.name |
|
0 commit comments