chia-blockchain 2.4.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1028) hide show
  1. chia/__init__.py +10 -0
  2. chia/__main__.py +5 -0
  3. chia/_tests/README.md +53 -0
  4. chia/_tests/__init__.py +0 -0
  5. chia/_tests/blockchain/__init__.py +0 -0
  6. chia/_tests/blockchain/blockchain_test_utils.py +197 -0
  7. chia/_tests/blockchain/config.py +4 -0
  8. chia/_tests/blockchain/test_augmented_chain.py +147 -0
  9. chia/_tests/blockchain/test_blockchain.py +4100 -0
  10. chia/_tests/blockchain/test_blockchain_transactions.py +1050 -0
  11. chia/_tests/blockchain/test_build_chains.py +61 -0
  12. chia/_tests/blockchain/test_get_block_generator.py +72 -0
  13. chia/_tests/blockchain/test_lookup_fork_chain.py +195 -0
  14. chia/_tests/build-init-files.py +93 -0
  15. chia/_tests/build-job-matrix.py +204 -0
  16. chia/_tests/check_pytest_monitor_output.py +34 -0
  17. chia/_tests/check_sql_statements.py +73 -0
  18. chia/_tests/chia-start-sim +42 -0
  19. chia/_tests/clvm/__init__.py +0 -0
  20. chia/_tests/clvm/benchmark_costs.py +23 -0
  21. chia/_tests/clvm/coin_store.py +147 -0
  22. chia/_tests/clvm/test_chialisp_deserialization.py +101 -0
  23. chia/_tests/clvm/test_clvm_step.py +37 -0
  24. chia/_tests/clvm/test_condition_codes.py +13 -0
  25. chia/_tests/clvm/test_curry_and_treehash.py +57 -0
  26. chia/_tests/clvm/test_program.py +150 -0
  27. chia/_tests/clvm/test_puzzle_compression.py +144 -0
  28. chia/_tests/clvm/test_puzzle_drivers.py +45 -0
  29. chia/_tests/clvm/test_puzzles.py +247 -0
  30. chia/_tests/clvm/test_singletons.py +540 -0
  31. chia/_tests/clvm/test_spend_sim.py +181 -0
  32. chia/_tests/cmds/__init__.py +0 -0
  33. chia/_tests/cmds/cmd_test_utils.py +472 -0
  34. chia/_tests/cmds/config.py +3 -0
  35. chia/_tests/cmds/conftest.py +23 -0
  36. chia/_tests/cmds/test_click_types.py +195 -0
  37. chia/_tests/cmds/test_cmd_framework.py +400 -0
  38. chia/_tests/cmds/test_cmds_util.py +97 -0
  39. chia/_tests/cmds/test_daemon.py +92 -0
  40. chia/_tests/cmds/test_farm_cmd.py +67 -0
  41. chia/_tests/cmds/test_show.py +116 -0
  42. chia/_tests/cmds/test_sim.py +207 -0
  43. chia/_tests/cmds/test_timelock_args.py +75 -0
  44. chia/_tests/cmds/test_tx_config_args.py +153 -0
  45. chia/_tests/cmds/testing_classes.py +59 -0
  46. chia/_tests/cmds/wallet/__init__.py +0 -0
  47. chia/_tests/cmds/wallet/test_coins.py +195 -0
  48. chia/_tests/cmds/wallet/test_consts.py +47 -0
  49. chia/_tests/cmds/wallet/test_dao.py +565 -0
  50. chia/_tests/cmds/wallet/test_did.py +403 -0
  51. chia/_tests/cmds/wallet/test_nft.py +470 -0
  52. chia/_tests/cmds/wallet/test_notifications.py +124 -0
  53. chia/_tests/cmds/wallet/test_offer.toffer +1 -0
  54. chia/_tests/cmds/wallet/test_tx_decorators.py +27 -0
  55. chia/_tests/cmds/wallet/test_vcs.py +376 -0
  56. chia/_tests/cmds/wallet/test_wallet.py +1126 -0
  57. chia/_tests/cmds/wallet/test_wallet_check.py +111 -0
  58. chia/_tests/conftest.py +1304 -0
  59. chia/_tests/connection_utils.py +124 -0
  60. chia/_tests/core/__init__.py +0 -0
  61. chia/_tests/core/cmds/__init__.py +0 -0
  62. chia/_tests/core/cmds/test_beta.py +382 -0
  63. chia/_tests/core/cmds/test_keys.py +1734 -0
  64. chia/_tests/core/cmds/test_wallet.py +126 -0
  65. chia/_tests/core/config.py +3 -0
  66. chia/_tests/core/consensus/__init__.py +0 -0
  67. chia/_tests/core/consensus/test_block_creation.py +56 -0
  68. chia/_tests/core/consensus/test_pot_iterations.py +117 -0
  69. chia/_tests/core/custom_types/__init__.py +0 -0
  70. chia/_tests/core/custom_types/test_coin.py +109 -0
  71. chia/_tests/core/custom_types/test_proof_of_space.py +144 -0
  72. chia/_tests/core/custom_types/test_spend_bundle.py +71 -0
  73. chia/_tests/core/daemon/__init__.py +0 -0
  74. chia/_tests/core/daemon/config.py +4 -0
  75. chia/_tests/core/daemon/test_daemon.py +2128 -0
  76. chia/_tests/core/daemon/test_daemon_register.py +109 -0
  77. chia/_tests/core/daemon/test_keychain_proxy.py +100 -0
  78. chia/_tests/core/data_layer/__init__.py +0 -0
  79. chia/_tests/core/data_layer/config.py +5 -0
  80. chia/_tests/core/data_layer/conftest.py +105 -0
  81. chia/_tests/core/data_layer/test_data_cli.py +57 -0
  82. chia/_tests/core/data_layer/test_data_layer.py +83 -0
  83. chia/_tests/core/data_layer/test_data_layer_util.py +219 -0
  84. chia/_tests/core/data_layer/test_data_rpc.py +3865 -0
  85. chia/_tests/core/data_layer/test_data_store.py +2423 -0
  86. chia/_tests/core/data_layer/test_data_store_schema.py +381 -0
  87. chia/_tests/core/data_layer/test_plugin.py +91 -0
  88. chia/_tests/core/data_layer/util.py +232 -0
  89. chia/_tests/core/farmer/__init__.py +0 -0
  90. chia/_tests/core/farmer/config.py +3 -0
  91. chia/_tests/core/farmer/test_farmer_api.py +101 -0
  92. chia/_tests/core/full_node/__init__.py +0 -0
  93. chia/_tests/core/full_node/config.py +4 -0
  94. chia/_tests/core/full_node/dos/__init__.py +0 -0
  95. chia/_tests/core/full_node/dos/config.py +3 -0
  96. chia/_tests/core/full_node/full_sync/__init__.py +0 -0
  97. chia/_tests/core/full_node/full_sync/config.py +4 -0
  98. chia/_tests/core/full_node/full_sync/test_full_sync.py +448 -0
  99. chia/_tests/core/full_node/ram_db.py +27 -0
  100. chia/_tests/core/full_node/stores/__init__.py +0 -0
  101. chia/_tests/core/full_node/stores/config.py +4 -0
  102. chia/_tests/core/full_node/stores/test_block_store.py +488 -0
  103. chia/_tests/core/full_node/stores/test_coin_store.py +888 -0
  104. chia/_tests/core/full_node/stores/test_full_node_store.py +1215 -0
  105. chia/_tests/core/full_node/stores/test_hint_store.py +230 -0
  106. chia/_tests/core/full_node/stores/test_sync_store.py +135 -0
  107. chia/_tests/core/full_node/test_address_manager.py +588 -0
  108. chia/_tests/core/full_node/test_block_height_map.py +556 -0
  109. chia/_tests/core/full_node/test_conditions.py +558 -0
  110. chia/_tests/core/full_node/test_full_node.py +2445 -0
  111. chia/_tests/core/full_node/test_generator_tools.py +82 -0
  112. chia/_tests/core/full_node/test_hint_management.py +104 -0
  113. chia/_tests/core/full_node/test_node_load.py +34 -0
  114. chia/_tests/core/full_node/test_performance.py +182 -0
  115. chia/_tests/core/full_node/test_subscriptions.py +492 -0
  116. chia/_tests/core/full_node/test_transactions.py +203 -0
  117. chia/_tests/core/full_node/test_tx_processing_queue.py +154 -0
  118. chia/_tests/core/large_block.py +2388 -0
  119. chia/_tests/core/make_block_generator.py +72 -0
  120. chia/_tests/core/mempool/__init__.py +0 -0
  121. chia/_tests/core/mempool/config.py +4 -0
  122. chia/_tests/core/mempool/test_mempool.py +3180 -0
  123. chia/_tests/core/mempool/test_mempool_fee_estimator.py +104 -0
  124. chia/_tests/core/mempool/test_mempool_fee_protocol.py +55 -0
  125. chia/_tests/core/mempool/test_mempool_item_queries.py +192 -0
  126. chia/_tests/core/mempool/test_mempool_manager.py +2054 -0
  127. chia/_tests/core/mempool/test_mempool_performance.py +65 -0
  128. chia/_tests/core/mempool/test_singleton_fast_forward.py +567 -0
  129. chia/_tests/core/node_height.py +28 -0
  130. chia/_tests/core/server/__init__.py +0 -0
  131. chia/_tests/core/server/config.py +3 -0
  132. chia/_tests/core/server/flood.py +82 -0
  133. chia/_tests/core/server/serve.py +132 -0
  134. chia/_tests/core/server/test_capabilities.py +68 -0
  135. chia/_tests/core/server/test_dos.py +320 -0
  136. chia/_tests/core/server/test_event_loop.py +109 -0
  137. chia/_tests/core/server/test_loop.py +290 -0
  138. chia/_tests/core/server/test_node_discovery.py +74 -0
  139. chia/_tests/core/server/test_rate_limits.py +370 -0
  140. chia/_tests/core/server/test_server.py +225 -0
  141. chia/_tests/core/server/test_upnp.py +8 -0
  142. chia/_tests/core/services/__init__.py +0 -0
  143. chia/_tests/core/services/config.py +3 -0
  144. chia/_tests/core/services/test_services.py +166 -0
  145. chia/_tests/core/ssl/__init__.py +0 -0
  146. chia/_tests/core/ssl/config.py +3 -0
  147. chia/_tests/core/ssl/test_ssl.py +198 -0
  148. chia/_tests/core/test_coins.py +33 -0
  149. chia/_tests/core/test_cost_calculation.py +314 -0
  150. chia/_tests/core/test_crawler.py +175 -0
  151. chia/_tests/core/test_crawler_rpc.py +53 -0
  152. chia/_tests/core/test_daemon_rpc.py +24 -0
  153. chia/_tests/core/test_db_conversion.py +129 -0
  154. chia/_tests/core/test_db_validation.py +161 -0
  155. chia/_tests/core/test_farmer_harvester_rpc.py +504 -0
  156. chia/_tests/core/test_filter.py +37 -0
  157. chia/_tests/core/test_full_node_rpc.py +794 -0
  158. chia/_tests/core/test_merkle_set.py +343 -0
  159. chia/_tests/core/test_program.py +49 -0
  160. chia/_tests/core/test_rpc_util.py +87 -0
  161. chia/_tests/core/test_seeder.py +308 -0
  162. chia/_tests/core/test_setproctitle.py +13 -0
  163. chia/_tests/core/util/__init__.py +0 -0
  164. chia/_tests/core/util/config.py +4 -0
  165. chia/_tests/core/util/test_block_cache.py +44 -0
  166. chia/_tests/core/util/test_cached_bls.py +57 -0
  167. chia/_tests/core/util/test_config.py +337 -0
  168. chia/_tests/core/util/test_file_keyring_synchronization.py +105 -0
  169. chia/_tests/core/util/test_files.py +391 -0
  170. chia/_tests/core/util/test_jsonify.py +146 -0
  171. chia/_tests/core/util/test_keychain.py +514 -0
  172. chia/_tests/core/util/test_keyring_wrapper.py +490 -0
  173. chia/_tests/core/util/test_lockfile.py +380 -0
  174. chia/_tests/core/util/test_log_exceptions.py +187 -0
  175. chia/_tests/core/util/test_lru_cache.py +56 -0
  176. chia/_tests/core/util/test_significant_bits.py +40 -0
  177. chia/_tests/core/util/test_streamable.py +883 -0
  178. chia/_tests/db/__init__.py +0 -0
  179. chia/_tests/db/test_db_wrapper.py +565 -0
  180. chia/_tests/environments/__init__.py +0 -0
  181. chia/_tests/environments/common.py +35 -0
  182. chia/_tests/environments/full_node.py +47 -0
  183. chia/_tests/environments/wallet.py +368 -0
  184. chia/_tests/ether.py +19 -0
  185. chia/_tests/farmer_harvester/__init__.py +0 -0
  186. chia/_tests/farmer_harvester/config.py +3 -0
  187. chia/_tests/farmer_harvester/test_farmer.py +1264 -0
  188. chia/_tests/farmer_harvester/test_farmer_harvester.py +292 -0
  189. chia/_tests/farmer_harvester/test_filter_prefix_bits.py +130 -0
  190. chia/_tests/farmer_harvester/test_third_party_harvesters.py +501 -0
  191. chia/_tests/farmer_harvester/test_third_party_harvesters_data.json +29 -0
  192. chia/_tests/fee_estimation/__init__.py +0 -0
  193. chia/_tests/fee_estimation/config.py +3 -0
  194. chia/_tests/fee_estimation/test_fee_estimation_integration.py +262 -0
  195. chia/_tests/fee_estimation/test_fee_estimation_rpc.py +287 -0
  196. chia/_tests/fee_estimation/test_fee_estimation_unit_tests.py +145 -0
  197. chia/_tests/fee_estimation/test_mempoolitem_height_added.py +146 -0
  198. chia/_tests/generator/__init__.py +0 -0
  199. chia/_tests/generator/puzzles/__init__.py +0 -0
  200. chia/_tests/generator/puzzles/test_generator_deserialize.clsp +3 -0
  201. chia/_tests/generator/puzzles/test_generator_deserialize.clsp.hex +1 -0
  202. chia/_tests/generator/puzzles/test_multiple_generator_input_arguments.clsp +19 -0
  203. chia/_tests/generator/puzzles/test_multiple_generator_input_arguments.clsp.hex +1 -0
  204. chia/_tests/generator/test_compression.py +218 -0
  205. chia/_tests/generator/test_generator_types.py +44 -0
  206. chia/_tests/generator/test_rom.py +182 -0
  207. chia/_tests/plot_sync/__init__.py +0 -0
  208. chia/_tests/plot_sync/config.py +3 -0
  209. chia/_tests/plot_sync/test_delta.py +102 -0
  210. chia/_tests/plot_sync/test_plot_sync.py +617 -0
  211. chia/_tests/plot_sync/test_receiver.py +451 -0
  212. chia/_tests/plot_sync/test_sender.py +116 -0
  213. chia/_tests/plot_sync/test_sync_simulated.py +450 -0
  214. chia/_tests/plot_sync/util.py +67 -0
  215. chia/_tests/plotting/__init__.py +0 -0
  216. chia/_tests/plotting/config.py +3 -0
  217. chia/_tests/plotting/test_plot_manager.py +738 -0
  218. chia/_tests/plotting/util.py +13 -0
  219. chia/_tests/pools/__init__.py +0 -0
  220. chia/_tests/pools/config.py +5 -0
  221. chia/_tests/pools/test_pool_cmdline.py +23 -0
  222. chia/_tests/pools/test_pool_config.py +44 -0
  223. chia/_tests/pools/test_pool_puzzles_lifecycle.py +398 -0
  224. chia/_tests/pools/test_pool_rpc.py +1010 -0
  225. chia/_tests/pools/test_pool_wallet.py +201 -0
  226. chia/_tests/pools/test_wallet_pool_store.py +161 -0
  227. chia/_tests/process_junit.py +349 -0
  228. chia/_tests/rpc/__init__.py +0 -0
  229. chia/_tests/rpc/test_rpc_client.py +81 -0
  230. chia/_tests/simulation/__init__.py +0 -0
  231. chia/_tests/simulation/config.py +6 -0
  232. chia/_tests/simulation/test_simulation.py +501 -0
  233. chia/_tests/simulation/test_simulator.py +234 -0
  234. chia/_tests/simulation/test_start_simulator.py +106 -0
  235. chia/_tests/testconfig.py +13 -0
  236. chia/_tests/timelord/__init__.py +0 -0
  237. chia/_tests/timelord/config.py +3 -0
  238. chia/_tests/timelord/test_new_peak.py +437 -0
  239. chia/_tests/timelord/test_timelord.py +11 -0
  240. chia/_tests/tools/1315537.json +170 -0
  241. chia/_tests/tools/1315544.json +160 -0
  242. chia/_tests/tools/1315630.json +150 -0
  243. chia/_tests/tools/300000.json +105 -0
  244. chia/_tests/tools/442734.json +140 -0
  245. chia/_tests/tools/466212.json +130 -0
  246. chia/_tests/tools/__init__.py +0 -0
  247. chia/_tests/tools/config.py +5 -0
  248. chia/_tests/tools/test-blockchain-db.sqlite +0 -0
  249. chia/_tests/tools/test_full_sync.py +30 -0
  250. chia/_tests/tools/test_legacy_keyring.py +82 -0
  251. chia/_tests/tools/test_run_block.py +129 -0
  252. chia/_tests/util/__init__.py +0 -0
  253. chia/_tests/util/benchmark_cost.py +170 -0
  254. chia/_tests/util/benchmarks.py +154 -0
  255. chia/_tests/util/bip39_test_vectors.json +148 -0
  256. chia/_tests/util/blockchain.py +133 -0
  257. chia/_tests/util/blockchain_mock.py +132 -0
  258. chia/_tests/util/build_network_protocol_files.py +302 -0
  259. chia/_tests/util/clvm_generator.bin +0 -0
  260. chia/_tests/util/config.py +3 -0
  261. chia/_tests/util/constants.py +20 -0
  262. chia/_tests/util/db_connection.py +36 -0
  263. chia/_tests/util/full_sync.py +245 -0
  264. chia/_tests/util/gen_ssl_certs.py +115 -0
  265. chia/_tests/util/generator_tools_testing.py +47 -0
  266. chia/_tests/util/key_tool.py +37 -0
  267. chia/_tests/util/misc.py +722 -0
  268. chia/_tests/util/network_protocol_data.py +1074 -0
  269. chia/_tests/util/protocol_messages_bytes-v1.0 +0 -0
  270. chia/_tests/util/protocol_messages_json.py +2700 -0
  271. chia/_tests/util/rpc.py +23 -0
  272. chia/_tests/util/run_block.py +163 -0
  273. chia/_tests/util/setup_nodes.py +479 -0
  274. chia/_tests/util/split_managers.py +99 -0
  275. chia/_tests/util/temp_file.py +14 -0
  276. chia/_tests/util/test_action_scope.py +143 -0
  277. chia/_tests/util/test_async_pool.py +366 -0
  278. chia/_tests/util/test_build_job_matrix.py +43 -0
  279. chia/_tests/util/test_build_network_protocol_files.py +7 -0
  280. chia/_tests/util/test_chia_version.py +50 -0
  281. chia/_tests/util/test_collection.py +11 -0
  282. chia/_tests/util/test_condition_tools.py +231 -0
  283. chia/_tests/util/test_config.py +426 -0
  284. chia/_tests/util/test_dump_keyring.py +60 -0
  285. chia/_tests/util/test_errors.py +10 -0
  286. chia/_tests/util/test_full_block_utils.py +271 -0
  287. chia/_tests/util/test_installed.py +20 -0
  288. chia/_tests/util/test_limited_semaphore.py +52 -0
  289. chia/_tests/util/test_logging_filter.py +43 -0
  290. chia/_tests/util/test_misc.py +444 -0
  291. chia/_tests/util/test_network.py +74 -0
  292. chia/_tests/util/test_network_protocol_files.py +579 -0
  293. chia/_tests/util/test_network_protocol_json.py +266 -0
  294. chia/_tests/util/test_network_protocol_test.py +257 -0
  295. chia/_tests/util/test_paginator.py +72 -0
  296. chia/_tests/util/test_pprint.py +17 -0
  297. chia/_tests/util/test_priority_mutex.py +487 -0
  298. chia/_tests/util/test_recursive_replace.py +116 -0
  299. chia/_tests/util/test_replace_str_to_bytes.py +137 -0
  300. chia/_tests/util/test_service_groups.py +15 -0
  301. chia/_tests/util/test_ssl_check.py +31 -0
  302. chia/_tests/util/test_testnet_overrides.py +19 -0
  303. chia/_tests/util/test_tests_misc.py +38 -0
  304. chia/_tests/util/test_timing.py +37 -0
  305. chia/_tests/util/test_trusted_peer.py +51 -0
  306. chia/_tests/util/time_out_assert.py +154 -0
  307. chia/_tests/wallet/__init__.py +0 -0
  308. chia/_tests/wallet/cat_wallet/__init__.py +0 -0
  309. chia/_tests/wallet/cat_wallet/config.py +4 -0
  310. chia/_tests/wallet/cat_wallet/test_cat_lifecycle.py +468 -0
  311. chia/_tests/wallet/cat_wallet/test_cat_outer_puzzle.py +69 -0
  312. chia/_tests/wallet/cat_wallet/test_cat_wallet.py +1738 -0
  313. chia/_tests/wallet/cat_wallet/test_offer_lifecycle.py +291 -0
  314. chia/_tests/wallet/cat_wallet/test_trades.py +2578 -0
  315. chia/_tests/wallet/clawback/__init__.py +0 -0
  316. chia/_tests/wallet/clawback/config.py +3 -0
  317. chia/_tests/wallet/clawback/test_clawback_decorator.py +80 -0
  318. chia/_tests/wallet/clawback/test_clawback_lifecycle.py +292 -0
  319. chia/_tests/wallet/clawback/test_clawback_metadata.py +51 -0
  320. chia/_tests/wallet/config.py +4 -0
  321. chia/_tests/wallet/conftest.py +217 -0
  322. chia/_tests/wallet/dao_wallet/__init__.py +0 -0
  323. chia/_tests/wallet/dao_wallet/config.py +3 -0
  324. chia/_tests/wallet/dao_wallet/test_dao_clvm.py +1322 -0
  325. chia/_tests/wallet/dao_wallet/test_dao_wallets.py +3488 -0
  326. chia/_tests/wallet/db_wallet/__init__.py +0 -0
  327. chia/_tests/wallet/db_wallet/config.py +3 -0
  328. chia/_tests/wallet/db_wallet/test_db_graftroot.py +143 -0
  329. chia/_tests/wallet/db_wallet/test_dl_offers.py +491 -0
  330. chia/_tests/wallet/db_wallet/test_dl_wallet.py +823 -0
  331. chia/_tests/wallet/did_wallet/__init__.py +0 -0
  332. chia/_tests/wallet/did_wallet/config.py +4 -0
  333. chia/_tests/wallet/did_wallet/test_did.py +1481 -0
  334. chia/_tests/wallet/nft_wallet/__init__.py +0 -0
  335. chia/_tests/wallet/nft_wallet/config.py +4 -0
  336. chia/_tests/wallet/nft_wallet/test_nft_1_offers.py +1492 -0
  337. chia/_tests/wallet/nft_wallet/test_nft_bulk_mint.py +1014 -0
  338. chia/_tests/wallet/nft_wallet/test_nft_lifecycle.py +376 -0
  339. chia/_tests/wallet/nft_wallet/test_nft_offers.py +1209 -0
  340. chia/_tests/wallet/nft_wallet/test_nft_puzzles.py +172 -0
  341. chia/_tests/wallet/nft_wallet/test_nft_wallet.py +2558 -0
  342. chia/_tests/wallet/nft_wallet/test_ownership_outer_puzzle.py +70 -0
  343. chia/_tests/wallet/rpc/__init__.py +0 -0
  344. chia/_tests/wallet/rpc/config.py +4 -0
  345. chia/_tests/wallet/rpc/test_dl_wallet_rpc.py +287 -0
  346. chia/_tests/wallet/rpc/test_wallet_rpc.py +3106 -0
  347. chia/_tests/wallet/simple_sync/__init__.py +0 -0
  348. chia/_tests/wallet/simple_sync/config.py +3 -0
  349. chia/_tests/wallet/simple_sync/test_simple_sync_protocol.py +719 -0
  350. chia/_tests/wallet/sync/__init__.py +0 -0
  351. chia/_tests/wallet/sync/config.py +4 -0
  352. chia/_tests/wallet/sync/test_wallet_sync.py +1529 -0
  353. chia/_tests/wallet/test_address_type.py +189 -0
  354. chia/_tests/wallet/test_bech32m.py +45 -0
  355. chia/_tests/wallet/test_clvm_streamable.py +244 -0
  356. chia/_tests/wallet/test_coin_selection.py +589 -0
  357. chia/_tests/wallet/test_conditions.py +388 -0
  358. chia/_tests/wallet/test_debug_spend_bundle.py +76 -0
  359. chia/_tests/wallet/test_new_wallet_protocol.py +1176 -0
  360. chia/_tests/wallet/test_nft_store.py +193 -0
  361. chia/_tests/wallet/test_notifications.py +196 -0
  362. chia/_tests/wallet/test_offer_parsing_performance.py +48 -0
  363. chia/_tests/wallet/test_puzzle_store.py +133 -0
  364. chia/_tests/wallet/test_sign_coin_spends.py +159 -0
  365. chia/_tests/wallet/test_signer_protocol.py +948 -0
  366. chia/_tests/wallet/test_singleton.py +122 -0
  367. chia/_tests/wallet/test_singleton_lifecycle_fast.py +772 -0
  368. chia/_tests/wallet/test_singleton_store.py +152 -0
  369. chia/_tests/wallet/test_taproot.py +19 -0
  370. chia/_tests/wallet/test_transaction_store.py +941 -0
  371. chia/_tests/wallet/test_util.py +181 -0
  372. chia/_tests/wallet/test_wallet.py +2139 -0
  373. chia/_tests/wallet/test_wallet_action_scope.py +85 -0
  374. chia/_tests/wallet/test_wallet_blockchain.py +113 -0
  375. chia/_tests/wallet/test_wallet_coin_store.py +1002 -0
  376. chia/_tests/wallet/test_wallet_interested_store.py +43 -0
  377. chia/_tests/wallet/test_wallet_key_val_store.py +40 -0
  378. chia/_tests/wallet/test_wallet_node.py +783 -0
  379. chia/_tests/wallet/test_wallet_retry.py +95 -0
  380. chia/_tests/wallet/test_wallet_state_manager.py +252 -0
  381. chia/_tests/wallet/test_wallet_test_framework.py +275 -0
  382. chia/_tests/wallet/test_wallet_trade_store.py +218 -0
  383. chia/_tests/wallet/test_wallet_user_store.py +34 -0
  384. chia/_tests/wallet/test_wallet_utils.py +155 -0
  385. chia/_tests/wallet/vc_wallet/__init__.py +0 -0
  386. chia/_tests/wallet/vc_wallet/config.py +3 -0
  387. chia/_tests/wallet/vc_wallet/test_cr_outer_puzzle.py +70 -0
  388. chia/_tests/wallet/vc_wallet/test_vc_lifecycle.py +883 -0
  389. chia/_tests/wallet/vc_wallet/test_vc_wallet.py +801 -0
  390. chia/_tests/wallet/wallet_block_tools.py +327 -0
  391. chia/_tests/weight_proof/__init__.py +0 -0
  392. chia/_tests/weight_proof/config.py +3 -0
  393. chia/_tests/weight_proof/test_weight_proof.py +528 -0
  394. chia/clvm/__init__.py +0 -0
  395. chia/clvm/spend_sim.py +488 -0
  396. chia/cmds/__init__.py +0 -0
  397. chia/cmds/beta.py +183 -0
  398. chia/cmds/beta_funcs.py +133 -0
  399. chia/cmds/check_wallet_db.py +418 -0
  400. chia/cmds/chia.py +143 -0
  401. chia/cmds/cmd_classes.py +315 -0
  402. chia/cmds/cmds_util.py +498 -0
  403. chia/cmds/coin_funcs.py +260 -0
  404. chia/cmds/coins.py +220 -0
  405. chia/cmds/completion.py +49 -0
  406. chia/cmds/configure.py +331 -0
  407. chia/cmds/dao.py +1008 -0
  408. chia/cmds/dao_funcs.py +576 -0
  409. chia/cmds/data.py +707 -0
  410. chia/cmds/data_funcs.py +380 -0
  411. chia/cmds/db.py +86 -0
  412. chia/cmds/db_backup_func.py +77 -0
  413. chia/cmds/db_upgrade_func.py +452 -0
  414. chia/cmds/db_validate_func.py +184 -0
  415. chia/cmds/dev.py +16 -0
  416. chia/cmds/farm.py +87 -0
  417. chia/cmds/farm_funcs.py +207 -0
  418. chia/cmds/init.py +70 -0
  419. chia/cmds/init_funcs.py +367 -0
  420. chia/cmds/installers.py +129 -0
  421. chia/cmds/keys.py +510 -0
  422. chia/cmds/keys_funcs.py +864 -0
  423. chia/cmds/netspace.py +47 -0
  424. chia/cmds/netspace_funcs.py +53 -0
  425. chia/cmds/options.py +32 -0
  426. chia/cmds/param_types.py +228 -0
  427. chia/cmds/passphrase.py +130 -0
  428. chia/cmds/passphrase_funcs.py +346 -0
  429. chia/cmds/peer.py +50 -0
  430. chia/cmds/peer_funcs.py +129 -0
  431. chia/cmds/plotnft.py +206 -0
  432. chia/cmds/plotnft_funcs.py +374 -0
  433. chia/cmds/plots.py +222 -0
  434. chia/cmds/plotters.py +17 -0
  435. chia/cmds/rpc.py +188 -0
  436. chia/cmds/show.py +71 -0
  437. chia/cmds/show_funcs.py +214 -0
  438. chia/cmds/signer.py +304 -0
  439. chia/cmds/sim.py +217 -0
  440. chia/cmds/sim_funcs.py +509 -0
  441. chia/cmds/start.py +24 -0
  442. chia/cmds/start_funcs.py +112 -0
  443. chia/cmds/stop.py +61 -0
  444. chia/cmds/units.py +11 -0
  445. chia/cmds/wallet.py +1745 -0
  446. chia/cmds/wallet_funcs.py +1800 -0
  447. chia/consensus/__init__.py +0 -0
  448. chia/consensus/block_body_validation.py +515 -0
  449. chia/consensus/block_creation.py +525 -0
  450. chia/consensus/block_header_validation.py +1064 -0
  451. chia/consensus/block_record.py +32 -0
  452. chia/consensus/block_rewards.py +53 -0
  453. chia/consensus/block_root_validation.py +46 -0
  454. chia/consensus/blockchain.py +1100 -0
  455. chia/consensus/blockchain_interface.py +56 -0
  456. chia/consensus/coinbase.py +30 -0
  457. chia/consensus/condition_costs.py +9 -0
  458. chia/consensus/constants.py +49 -0
  459. chia/consensus/cost_calculator.py +15 -0
  460. chia/consensus/default_constants.py +90 -0
  461. chia/consensus/deficit.py +55 -0
  462. chia/consensus/difficulty_adjustment.py +412 -0
  463. chia/consensus/find_fork_point.py +111 -0
  464. chia/consensus/full_block_to_block_record.py +167 -0
  465. chia/consensus/get_block_challenge.py +106 -0
  466. chia/consensus/get_block_generator.py +26 -0
  467. chia/consensus/make_sub_epoch_summary.py +210 -0
  468. chia/consensus/multiprocess_validation.py +365 -0
  469. chia/consensus/pos_quality.py +19 -0
  470. chia/consensus/pot_iterations.py +67 -0
  471. chia/consensus/puzzles/__init__.py +0 -0
  472. chia/consensus/puzzles/chialisp_deserialisation.clsp +69 -0
  473. chia/consensus/puzzles/chialisp_deserialisation.clsp.hex +1 -0
  474. chia/consensus/puzzles/rom_bootstrap_generator.clsp +37 -0
  475. chia/consensus/puzzles/rom_bootstrap_generator.clsp.hex +1 -0
  476. chia/consensus/vdf_info_computation.py +156 -0
  477. chia/daemon/__init__.py +0 -0
  478. chia/daemon/client.py +233 -0
  479. chia/daemon/keychain_proxy.py +501 -0
  480. chia/daemon/keychain_server.py +365 -0
  481. chia/daemon/server.py +1616 -0
  482. chia/daemon/windows_signal.py +56 -0
  483. chia/data_layer/__init__.py +0 -0
  484. chia/data_layer/data_layer.py +1303 -0
  485. chia/data_layer/data_layer_api.py +25 -0
  486. chia/data_layer/data_layer_errors.py +50 -0
  487. chia/data_layer/data_layer_server.py +170 -0
  488. chia/data_layer/data_layer_util.py +985 -0
  489. chia/data_layer/data_layer_wallet.py +1315 -0
  490. chia/data_layer/data_store.py +2267 -0
  491. chia/data_layer/dl_wallet_store.py +407 -0
  492. chia/data_layer/download_data.py +389 -0
  493. chia/data_layer/puzzles/__init__.py +0 -0
  494. chia/data_layer/puzzles/graftroot_dl_offers.clsp +100 -0
  495. chia/data_layer/puzzles/graftroot_dl_offers.clsp.hex +1 -0
  496. chia/data_layer/s3_plugin_config.yml +33 -0
  497. chia/data_layer/s3_plugin_service.py +468 -0
  498. chia/data_layer/util/__init__.py +0 -0
  499. chia/data_layer/util/benchmark.py +108 -0
  500. chia/data_layer/util/plugin.py +41 -0
  501. chia/farmer/__init__.py +0 -0
  502. chia/farmer/farmer.py +920 -0
  503. chia/farmer/farmer_api.py +814 -0
  504. chia/full_node/__init__.py +0 -0
  505. chia/full_node/bitcoin_fee_estimator.py +85 -0
  506. chia/full_node/block_height_map.py +271 -0
  507. chia/full_node/block_store.py +570 -0
  508. chia/full_node/bundle_tools.py +19 -0
  509. chia/full_node/coin_store.py +646 -0
  510. chia/full_node/fee_estimate.py +54 -0
  511. chia/full_node/fee_estimate_store.py +24 -0
  512. chia/full_node/fee_estimation.py +93 -0
  513. chia/full_node/fee_estimator.py +90 -0
  514. chia/full_node/fee_estimator_constants.py +38 -0
  515. chia/full_node/fee_estimator_interface.py +42 -0
  516. chia/full_node/fee_history.py +26 -0
  517. chia/full_node/fee_tracker.py +564 -0
  518. chia/full_node/full_node.py +3052 -0
  519. chia/full_node/full_node_api.py +1974 -0
  520. chia/full_node/full_node_store.py +1033 -0
  521. chia/full_node/hint_management.py +56 -0
  522. chia/full_node/hint_store.py +94 -0
  523. chia/full_node/mempool.py +583 -0
  524. chia/full_node/mempool_check_conditions.py +177 -0
  525. chia/full_node/mempool_manager.py +858 -0
  526. chia/full_node/pending_tx_cache.py +112 -0
  527. chia/full_node/puzzles/__init__.py +0 -0
  528. chia/full_node/puzzles/block_program_zero.clsp +14 -0
  529. chia/full_node/puzzles/block_program_zero.clsp.hex +1 -0
  530. chia/full_node/puzzles/decompress_coin_spend_entry.clsp +5 -0
  531. chia/full_node/puzzles/decompress_coin_spend_entry.clsp.hex +1 -0
  532. chia/full_node/puzzles/decompress_coin_spend_entry_with_prefix.clsp +7 -0
  533. chia/full_node/puzzles/decompress_coin_spend_entry_with_prefix.clsp.hex +1 -0
  534. chia/full_node/puzzles/decompress_puzzle.clsp +6 -0
  535. chia/full_node/puzzles/decompress_puzzle.clsp.hex +1 -0
  536. chia/full_node/signage_point.py +16 -0
  537. chia/full_node/subscriptions.py +248 -0
  538. chia/full_node/sync_store.py +145 -0
  539. chia/full_node/tx_processing_queue.py +78 -0
  540. chia/full_node/weight_proof.py +1719 -0
  541. chia/harvester/__init__.py +0 -0
  542. chia/harvester/harvester.py +271 -0
  543. chia/harvester/harvester_api.py +374 -0
  544. chia/introducer/__init__.py +0 -0
  545. chia/introducer/introducer.py +120 -0
  546. chia/introducer/introducer_api.py +64 -0
  547. chia/legacy/__init__.py +0 -0
  548. chia/legacy/keyring.py +154 -0
  549. chia/plot_sync/__init__.py +0 -0
  550. chia/plot_sync/delta.py +61 -0
  551. chia/plot_sync/exceptions.py +56 -0
  552. chia/plot_sync/receiver.py +385 -0
  553. chia/plot_sync/sender.py +337 -0
  554. chia/plot_sync/util.py +43 -0
  555. chia/plotters/__init__.py +0 -0
  556. chia/plotters/bladebit.py +388 -0
  557. chia/plotters/chiapos.py +63 -0
  558. chia/plotters/madmax.py +224 -0
  559. chia/plotters/plotters.py +577 -0
  560. chia/plotters/plotters_util.py +131 -0
  561. chia/plotting/__init__.py +0 -0
  562. chia/plotting/cache.py +212 -0
  563. chia/plotting/check_plots.py +283 -0
  564. chia/plotting/create_plots.py +278 -0
  565. chia/plotting/manager.py +436 -0
  566. chia/plotting/util.py +324 -0
  567. chia/pools/__init__.py +0 -0
  568. chia/pools/pool_config.py +110 -0
  569. chia/pools/pool_puzzles.py +459 -0
  570. chia/pools/pool_wallet.py +926 -0
  571. chia/pools/pool_wallet_info.py +118 -0
  572. chia/pools/puzzles/__init__.py +0 -0
  573. chia/pools/puzzles/pool_member_innerpuz.clsp +70 -0
  574. chia/pools/puzzles/pool_member_innerpuz.clsp.hex +1 -0
  575. chia/pools/puzzles/pool_waitingroom_innerpuz.clsp +69 -0
  576. chia/pools/puzzles/pool_waitingroom_innerpuz.clsp.hex +1 -0
  577. chia/protocols/__init__.py +0 -0
  578. chia/protocols/farmer_protocol.py +102 -0
  579. chia/protocols/full_node_protocol.py +219 -0
  580. chia/protocols/harvester_protocol.py +216 -0
  581. chia/protocols/introducer_protocol.py +26 -0
  582. chia/protocols/pool_protocol.py +177 -0
  583. chia/protocols/protocol_message_types.py +139 -0
  584. chia/protocols/protocol_state_machine.py +87 -0
  585. chia/protocols/protocol_timing.py +7 -0
  586. chia/protocols/shared_protocol.py +86 -0
  587. chia/protocols/timelord_protocol.py +93 -0
  588. chia/protocols/wallet_protocol.py +401 -0
  589. chia/py.typed +0 -0
  590. chia/rpc/__init__.py +0 -0
  591. chia/rpc/crawler_rpc_api.py +75 -0
  592. chia/rpc/data_layer_rpc_api.py +639 -0
  593. chia/rpc/data_layer_rpc_client.py +188 -0
  594. chia/rpc/data_layer_rpc_util.py +62 -0
  595. chia/rpc/farmer_rpc_api.py +360 -0
  596. chia/rpc/farmer_rpc_client.py +86 -0
  597. chia/rpc/full_node_rpc_api.py +954 -0
  598. chia/rpc/full_node_rpc_client.py +292 -0
  599. chia/rpc/harvester_rpc_api.py +136 -0
  600. chia/rpc/harvester_rpc_client.py +54 -0
  601. chia/rpc/rpc_client.py +144 -0
  602. chia/rpc/rpc_server.py +447 -0
  603. chia/rpc/timelord_rpc_api.py +27 -0
  604. chia/rpc/util.py +293 -0
  605. chia/rpc/wallet_request_types.py +688 -0
  606. chia/rpc/wallet_rpc_api.py +4779 -0
  607. chia/rpc/wallet_rpc_client.py +1844 -0
  608. chia/seeder/__init__.py +0 -0
  609. chia/seeder/crawl_store.py +427 -0
  610. chia/seeder/crawler.py +423 -0
  611. chia/seeder/crawler_api.py +129 -0
  612. chia/seeder/dns_server.py +544 -0
  613. chia/seeder/peer_record.py +146 -0
  614. chia/seeder/start_crawler.py +88 -0
  615. chia/server/__init__.py +0 -0
  616. chia/server/address_manager.py +658 -0
  617. chia/server/address_manager_store.py +237 -0
  618. chia/server/api_protocol.py +11 -0
  619. chia/server/capabilities.py +24 -0
  620. chia/server/chia_policy.py +345 -0
  621. chia/server/introducer_peers.py +76 -0
  622. chia/server/node_discovery.py +718 -0
  623. chia/server/outbound_message.py +33 -0
  624. chia/server/rate_limit_numbers.py +204 -0
  625. chia/server/rate_limits.py +113 -0
  626. chia/server/server.py +720 -0
  627. chia/server/signal_handlers.py +117 -0
  628. chia/server/ssl_context.py +32 -0
  629. chia/server/start_data_layer.py +137 -0
  630. chia/server/start_farmer.py +86 -0
  631. chia/server/start_full_node.py +106 -0
  632. chia/server/start_harvester.py +80 -0
  633. chia/server/start_introducer.py +69 -0
  634. chia/server/start_service.py +328 -0
  635. chia/server/start_timelord.py +82 -0
  636. chia/server/start_wallet.py +109 -0
  637. chia/server/upnp.py +117 -0
  638. chia/server/ws_connection.py +752 -0
  639. chia/simulator/__init__.py +0 -0
  640. chia/simulator/block_tools.py +2053 -0
  641. chia/simulator/full_node_simulator.py +802 -0
  642. chia/simulator/keyring.py +128 -0
  643. chia/simulator/setup_services.py +505 -0
  644. chia/simulator/simulator_constants.py +13 -0
  645. chia/simulator/simulator_full_node_rpc_api.py +101 -0
  646. chia/simulator/simulator_full_node_rpc_client.py +62 -0
  647. chia/simulator/simulator_protocol.py +29 -0
  648. chia/simulator/simulator_test_tools.py +163 -0
  649. chia/simulator/socket.py +27 -0
  650. chia/simulator/ssl_certs.py +114 -0
  651. chia/simulator/ssl_certs_1.py +699 -0
  652. chia/simulator/ssl_certs_10.py +699 -0
  653. chia/simulator/ssl_certs_2.py +699 -0
  654. chia/simulator/ssl_certs_3.py +699 -0
  655. chia/simulator/ssl_certs_4.py +699 -0
  656. chia/simulator/ssl_certs_5.py +699 -0
  657. chia/simulator/ssl_certs_6.py +699 -0
  658. chia/simulator/ssl_certs_7.py +699 -0
  659. chia/simulator/ssl_certs_8.py +699 -0
  660. chia/simulator/ssl_certs_9.py +699 -0
  661. chia/simulator/start_simulator.py +135 -0
  662. chia/simulator/wallet_tools.py +245 -0
  663. chia/ssl/__init__.py +0 -0
  664. chia/ssl/chia_ca.crt +19 -0
  665. chia/ssl/chia_ca.key +28 -0
  666. chia/ssl/create_ssl.py +249 -0
  667. chia/ssl/dst_root_ca.pem +20 -0
  668. chia/timelord/__init__.py +0 -0
  669. chia/timelord/iters_from_block.py +50 -0
  670. chia/timelord/timelord.py +1202 -0
  671. chia/timelord/timelord_api.py +132 -0
  672. chia/timelord/timelord_launcher.py +188 -0
  673. chia/timelord/timelord_state.py +244 -0
  674. chia/timelord/types.py +22 -0
  675. chia/types/__init__.py +0 -0
  676. chia/types/aliases.py +35 -0
  677. chia/types/block_protocol.py +20 -0
  678. chia/types/blockchain_format/__init__.py +0 -0
  679. chia/types/blockchain_format/classgroup.py +5 -0
  680. chia/types/blockchain_format/coin.py +28 -0
  681. chia/types/blockchain_format/foliage.py +8 -0
  682. chia/types/blockchain_format/pool_target.py +5 -0
  683. chia/types/blockchain_format/program.py +270 -0
  684. chia/types/blockchain_format/proof_of_space.py +135 -0
  685. chia/types/blockchain_format/reward_chain_block.py +6 -0
  686. chia/types/blockchain_format/serialized_program.py +5 -0
  687. chia/types/blockchain_format/sized_bytes.py +11 -0
  688. chia/types/blockchain_format/slots.py +9 -0
  689. chia/types/blockchain_format/sub_epoch_summary.py +5 -0
  690. chia/types/blockchain_format/tree_hash.py +72 -0
  691. chia/types/blockchain_format/vdf.py +86 -0
  692. chia/types/clvm_cost.py +13 -0
  693. chia/types/coin_record.py +43 -0
  694. chia/types/coin_spend.py +115 -0
  695. chia/types/condition_opcodes.py +73 -0
  696. chia/types/condition_with_args.py +17 -0
  697. chia/types/eligible_coin_spends.py +364 -0
  698. chia/types/end_of_slot_bundle.py +5 -0
  699. chia/types/fee_rate.py +38 -0
  700. chia/types/full_block.py +5 -0
  701. chia/types/generator_types.py +14 -0
  702. chia/types/header_block.py +5 -0
  703. chia/types/internal_mempool_item.py +19 -0
  704. chia/types/mempool_inclusion_status.py +9 -0
  705. chia/types/mempool_item.py +85 -0
  706. chia/types/mempool_submission_status.py +30 -0
  707. chia/types/mojos.py +7 -0
  708. chia/types/peer_info.py +64 -0
  709. chia/types/signing_mode.py +29 -0
  710. chia/types/spend_bundle.py +31 -0
  711. chia/types/spend_bundle_conditions.py +7 -0
  712. chia/types/transaction_queue_entry.py +55 -0
  713. chia/types/unfinished_block.py +5 -0
  714. chia/types/unfinished_header_block.py +37 -0
  715. chia/types/weight_proof.py +50 -0
  716. chia/util/__init__.py +0 -0
  717. chia/util/action_scope.py +168 -0
  718. chia/util/api_decorators.py +89 -0
  719. chia/util/async_pool.py +224 -0
  720. chia/util/augmented_chain.py +130 -0
  721. chia/util/batches.py +39 -0
  722. chia/util/bech32m.py +123 -0
  723. chia/util/beta_metrics.py +118 -0
  724. chia/util/block_cache.py +56 -0
  725. chia/util/byte_types.py +10 -0
  726. chia/util/check_fork_next_block.py +32 -0
  727. chia/util/chia_logging.py +124 -0
  728. chia/util/chia_version.py +33 -0
  729. chia/util/collection.py +17 -0
  730. chia/util/condition_tools.py +201 -0
  731. chia/util/config.py +366 -0
  732. chia/util/cpu.py +20 -0
  733. chia/util/db_synchronous.py +21 -0
  734. chia/util/db_version.py +30 -0
  735. chia/util/db_wrapper.py +427 -0
  736. chia/util/default_root.py +10 -0
  737. chia/util/dump_keyring.py +93 -0
  738. chia/util/english.txt +2048 -0
  739. chia/util/errors.py +351 -0
  740. chia/util/file_keyring.py +480 -0
  741. chia/util/files.py +95 -0
  742. chia/util/full_block_utils.py +321 -0
  743. chia/util/generator_tools.py +62 -0
  744. chia/util/hash.py +29 -0
  745. chia/util/initial-config.yaml +675 -0
  746. chia/util/inline_executor.py +24 -0
  747. chia/util/ints.py +19 -0
  748. chia/util/json_util.py +41 -0
  749. chia/util/keychain.py +673 -0
  750. chia/util/keyring_wrapper.py +266 -0
  751. chia/util/limited_semaphore.py +39 -0
  752. chia/util/lock.py +47 -0
  753. chia/util/log_exceptions.py +29 -0
  754. chia/util/logging.py +34 -0
  755. chia/util/lru_cache.py +29 -0
  756. chia/util/math.py +20 -0
  757. chia/util/network.py +240 -0
  758. chia/util/paginator.py +46 -0
  759. chia/util/path.py +29 -0
  760. chia/util/permissions.py +19 -0
  761. chia/util/pprint.py +40 -0
  762. chia/util/prev_transaction_block.py +23 -0
  763. chia/util/priority_mutex.py +92 -0
  764. chia/util/profiler.py +194 -0
  765. chia/util/recursive_replace.py +22 -0
  766. chia/util/safe_cancel_task.py +14 -0
  767. chia/util/service_groups.py +47 -0
  768. chia/util/setproctitle.py +20 -0
  769. chia/util/significant_bits.py +30 -0
  770. chia/util/ssl_check.py +213 -0
  771. chia/util/streamable.py +654 -0
  772. chia/util/task_timing.py +378 -0
  773. chia/util/timing.py +64 -0
  774. chia/util/vdf_prover.py +31 -0
  775. chia/util/ws_message.py +66 -0
  776. chia/wallet/__init__.py +0 -0
  777. chia/wallet/cat_wallet/__init__.py +0 -0
  778. chia/wallet/cat_wallet/cat_constants.py +75 -0
  779. chia/wallet/cat_wallet/cat_info.py +47 -0
  780. chia/wallet/cat_wallet/cat_outer_puzzle.py +120 -0
  781. chia/wallet/cat_wallet/cat_utils.py +163 -0
  782. chia/wallet/cat_wallet/cat_wallet.py +869 -0
  783. chia/wallet/cat_wallet/dao_cat_info.py +28 -0
  784. chia/wallet/cat_wallet/dao_cat_wallet.py +669 -0
  785. chia/wallet/cat_wallet/lineage_store.py +74 -0
  786. chia/wallet/cat_wallet/puzzles/__init__.py +0 -0
  787. chia/wallet/cat_wallet/puzzles/cat_truths.clib +31 -0
  788. chia/wallet/cat_wallet/puzzles/cat_v2.clsp +397 -0
  789. chia/wallet/cat_wallet/puzzles/cat_v2.clsp.hex +1 -0
  790. chia/wallet/cat_wallet/puzzles/delegated_tail.clsp +25 -0
  791. chia/wallet/cat_wallet/puzzles/delegated_tail.clsp.hex +1 -0
  792. chia/wallet/cat_wallet/puzzles/everything_with_signature.clsp +15 -0
  793. chia/wallet/cat_wallet/puzzles/everything_with_signature.clsp.hex +1 -0
  794. chia/wallet/cat_wallet/puzzles/genesis_by_coin_id.clsp +26 -0
  795. chia/wallet/cat_wallet/puzzles/genesis_by_coin_id.clsp.hex +1 -0
  796. chia/wallet/cat_wallet/puzzles/genesis_by_coin_id_or_singleton.clsp +42 -0
  797. chia/wallet/cat_wallet/puzzles/genesis_by_coin_id_or_singleton.clsp.hex +1 -0
  798. chia/wallet/cat_wallet/puzzles/genesis_by_puzzle_hash.clsp +24 -0
  799. chia/wallet/cat_wallet/puzzles/genesis_by_puzzle_hash.clsp.hex +1 -0
  800. chia/wallet/coin_selection.py +188 -0
  801. chia/wallet/conditions.py +1326 -0
  802. chia/wallet/dao_wallet/__init__.py +0 -0
  803. chia/wallet/dao_wallet/dao_info.py +61 -0
  804. chia/wallet/dao_wallet/dao_utils.py +810 -0
  805. chia/wallet/dao_wallet/dao_wallet.py +2121 -0
  806. chia/wallet/db_wallet/__init__.py +0 -0
  807. chia/wallet/db_wallet/db_wallet_puzzles.py +107 -0
  808. chia/wallet/derivation_record.py +30 -0
  809. chia/wallet/derive_keys.py +146 -0
  810. chia/wallet/did_wallet/__init__.py +0 -0
  811. chia/wallet/did_wallet/did_info.py +39 -0
  812. chia/wallet/did_wallet/did_wallet.py +1485 -0
  813. chia/wallet/did_wallet/did_wallet_puzzles.py +220 -0
  814. chia/wallet/did_wallet/puzzles/__init__.py +0 -0
  815. chia/wallet/did_wallet/puzzles/did_innerpuz.clsp +135 -0
  816. chia/wallet/did_wallet/puzzles/did_innerpuz.clsp.hex +1 -0
  817. chia/wallet/driver_protocol.py +26 -0
  818. chia/wallet/key_val_store.py +55 -0
  819. chia/wallet/lineage_proof.py +58 -0
  820. chia/wallet/nft_wallet/__init__.py +0 -0
  821. chia/wallet/nft_wallet/metadata_outer_puzzle.py +92 -0
  822. chia/wallet/nft_wallet/nft_info.py +120 -0
  823. chia/wallet/nft_wallet/nft_puzzles.py +305 -0
  824. chia/wallet/nft_wallet/nft_wallet.py +1686 -0
  825. chia/wallet/nft_wallet/ownership_outer_puzzle.py +101 -0
  826. chia/wallet/nft_wallet/puzzles/__init__.py +0 -0
  827. chia/wallet/nft_wallet/puzzles/create_nft_launcher_from_did.clsp +6 -0
  828. chia/wallet/nft_wallet/puzzles/create_nft_launcher_from_did.clsp.hex +1 -0
  829. chia/wallet/nft_wallet/puzzles/nft_intermediate_launcher.clsp +6 -0
  830. chia/wallet/nft_wallet/puzzles/nft_intermediate_launcher.clsp.hex +1 -0
  831. chia/wallet/nft_wallet/puzzles/nft_metadata_updater_default.clsp +30 -0
  832. chia/wallet/nft_wallet/puzzles/nft_metadata_updater_default.clsp.hex +1 -0
  833. chia/wallet/nft_wallet/puzzles/nft_metadata_updater_updateable.clsp +28 -0
  834. chia/wallet/nft_wallet/puzzles/nft_metadata_updater_updateable.clsp.hex +1 -0
  835. chia/wallet/nft_wallet/puzzles/nft_ownership_layer.clsp +100 -0
  836. chia/wallet/nft_wallet/puzzles/nft_ownership_layer.clsp.hex +1 -0
  837. chia/wallet/nft_wallet/puzzles/nft_ownership_transfer_program_one_way_claim_with_royalties.clsp +78 -0
  838. chia/wallet/nft_wallet/puzzles/nft_ownership_transfer_program_one_way_claim_with_royalties.clsp.hex +1 -0
  839. chia/wallet/nft_wallet/puzzles/nft_state_layer.clsp +74 -0
  840. chia/wallet/nft_wallet/puzzles/nft_state_layer.clsp.hex +1 -0
  841. chia/wallet/nft_wallet/singleton_outer_puzzle.py +101 -0
  842. chia/wallet/nft_wallet/transfer_program_puzzle.py +82 -0
  843. chia/wallet/nft_wallet/uncurry_nft.py +217 -0
  844. chia/wallet/notification_manager.py +117 -0
  845. chia/wallet/notification_store.py +178 -0
  846. chia/wallet/outer_puzzles.py +84 -0
  847. chia/wallet/payment.py +34 -0
  848. chia/wallet/puzzle_drivers.py +118 -0
  849. chia/wallet/puzzles/__init__.py +0 -0
  850. chia/wallet/puzzles/augmented_condition.clsp +13 -0
  851. chia/wallet/puzzles/augmented_condition.clsp.hex +1 -0
  852. chia/wallet/puzzles/clawback/__init__.py +0 -0
  853. chia/wallet/puzzles/clawback/drivers.py +188 -0
  854. chia/wallet/puzzles/clawback/metadata.py +38 -0
  855. chia/wallet/puzzles/clawback/puzzle_decorator.py +67 -0
  856. chia/wallet/puzzles/condition_codes.clib +77 -0
  857. chia/wallet/puzzles/curry-and-treehash.clib +102 -0
  858. chia/wallet/puzzles/curry.clib +135 -0
  859. chia/wallet/puzzles/curry_by_index.clib +16 -0
  860. chia/wallet/puzzles/dao_cat_eve.clsp +17 -0
  861. chia/wallet/puzzles/dao_cat_eve.clsp.hex +1 -0
  862. chia/wallet/puzzles/dao_cat_launcher.clsp +36 -0
  863. chia/wallet/puzzles/dao_cat_launcher.clsp.hex +1 -0
  864. chia/wallet/puzzles/dao_finished_state.clsp +35 -0
  865. chia/wallet/puzzles/dao_finished_state.clsp.hex +1 -0
  866. chia/wallet/puzzles/dao_finished_state.clsp.hex.sha256tree +1 -0
  867. chia/wallet/puzzles/dao_lockup.clsp +288 -0
  868. chia/wallet/puzzles/dao_lockup.clsp.hex +1 -0
  869. chia/wallet/puzzles/dao_lockup.clsp.hex.sha256tree +1 -0
  870. chia/wallet/puzzles/dao_proposal.clsp +377 -0
  871. chia/wallet/puzzles/dao_proposal.clsp.hex +1 -0
  872. chia/wallet/puzzles/dao_proposal.clsp.hex.sha256tree +1 -0
  873. chia/wallet/puzzles/dao_proposal_timer.clsp +78 -0
  874. chia/wallet/puzzles/dao_proposal_timer.clsp.hex +1 -0
  875. chia/wallet/puzzles/dao_proposal_timer.clsp.hex.sha256tree +1 -0
  876. chia/wallet/puzzles/dao_proposal_validator.clsp +87 -0
  877. chia/wallet/puzzles/dao_proposal_validator.clsp.hex +1 -0
  878. chia/wallet/puzzles/dao_proposal_validator.clsp.hex.sha256tree +1 -0
  879. chia/wallet/puzzles/dao_spend_p2_singleton_v2.clsp +240 -0
  880. chia/wallet/puzzles/dao_spend_p2_singleton_v2.clsp.hex +1 -0
  881. chia/wallet/puzzles/dao_spend_p2_singleton_v2.clsp.hex.sha256tree +1 -0
  882. chia/wallet/puzzles/dao_treasury.clsp +115 -0
  883. chia/wallet/puzzles/dao_treasury.clsp.hex +1 -0
  884. chia/wallet/puzzles/dao_update_proposal.clsp +44 -0
  885. chia/wallet/puzzles/dao_update_proposal.clsp.hex +1 -0
  886. chia/wallet/puzzles/deployed_puzzle_hashes.json +67 -0
  887. chia/wallet/puzzles/json.clib +25 -0
  888. chia/wallet/puzzles/load_clvm.py +162 -0
  889. chia/wallet/puzzles/merkle_utils.clib +18 -0
  890. chia/wallet/puzzles/notification.clsp +7 -0
  891. chia/wallet/puzzles/notification.clsp.hex +1 -0
  892. chia/wallet/puzzles/p2_1_of_n.clsp +22 -0
  893. chia/wallet/puzzles/p2_1_of_n.clsp.hex +1 -0
  894. chia/wallet/puzzles/p2_conditions.clsp +3 -0
  895. chia/wallet/puzzles/p2_conditions.clsp.hex +1 -0
  896. chia/wallet/puzzles/p2_conditions.py +27 -0
  897. chia/wallet/puzzles/p2_delegated_conditions.clsp +18 -0
  898. chia/wallet/puzzles/p2_delegated_conditions.clsp.hex +1 -0
  899. chia/wallet/puzzles/p2_delegated_conditions.py +22 -0
  900. chia/wallet/puzzles/p2_delegated_puzzle.clsp +19 -0
  901. chia/wallet/puzzles/p2_delegated_puzzle.clsp.hex +1 -0
  902. chia/wallet/puzzles/p2_delegated_puzzle.py +35 -0
  903. chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.clsp +91 -0
  904. chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.clsp.hex +1 -0
  905. chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py +161 -0
  906. chia/wallet/puzzles/p2_m_of_n_delegate_direct.clsp +108 -0
  907. chia/wallet/puzzles/p2_m_of_n_delegate_direct.clsp.hex +1 -0
  908. chia/wallet/puzzles/p2_m_of_n_delegate_direct.py +22 -0
  909. chia/wallet/puzzles/p2_parent.clsp +19 -0
  910. chia/wallet/puzzles/p2_parent.clsp.hex +1 -0
  911. chia/wallet/puzzles/p2_puzzle_hash.clsp +18 -0
  912. chia/wallet/puzzles/p2_puzzle_hash.clsp.hex +1 -0
  913. chia/wallet/puzzles/p2_puzzle_hash.py +28 -0
  914. chia/wallet/puzzles/p2_singleton.clsp +30 -0
  915. chia/wallet/puzzles/p2_singleton.clsp.hex +1 -0
  916. chia/wallet/puzzles/p2_singleton_aggregator.clsp +81 -0
  917. chia/wallet/puzzles/p2_singleton_aggregator.clsp.hex +1 -0
  918. chia/wallet/puzzles/p2_singleton_or_delayed_puzhash.clsp +50 -0
  919. chia/wallet/puzzles/p2_singleton_or_delayed_puzhash.clsp.hex +1 -0
  920. chia/wallet/puzzles/p2_singleton_via_delegated_puzzle.clsp +47 -0
  921. chia/wallet/puzzles/p2_singleton_via_delegated_puzzle.clsp.hex +1 -0
  922. chia/wallet/puzzles/puzzle_utils.py +34 -0
  923. chia/wallet/puzzles/settlement_payments.clsp +49 -0
  924. chia/wallet/puzzles/settlement_payments.clsp.hex +1 -0
  925. chia/wallet/puzzles/sha256tree.clib +11 -0
  926. chia/wallet/puzzles/singleton_launcher.clsp +16 -0
  927. chia/wallet/puzzles/singleton_launcher.clsp.hex +1 -0
  928. chia/wallet/puzzles/singleton_top_layer.clsp +177 -0
  929. chia/wallet/puzzles/singleton_top_layer.clsp.hex +1 -0
  930. chia/wallet/puzzles/singleton_top_layer.py +295 -0
  931. chia/wallet/puzzles/singleton_top_layer_v1_1.clsp +107 -0
  932. chia/wallet/puzzles/singleton_top_layer_v1_1.clsp.hex +1 -0
  933. chia/wallet/puzzles/singleton_top_layer_v1_1.py +344 -0
  934. chia/wallet/puzzles/singleton_truths.clib +21 -0
  935. chia/wallet/puzzles/tails.py +344 -0
  936. chia/wallet/puzzles/utility_macros.clib +48 -0
  937. chia/wallet/signer_protocol.py +126 -0
  938. chia/wallet/singleton.py +106 -0
  939. chia/wallet/singleton_record.py +30 -0
  940. chia/wallet/trade_manager.py +1088 -0
  941. chia/wallet/trade_record.py +67 -0
  942. chia/wallet/trading/__init__.py +0 -0
  943. chia/wallet/trading/offer.py +703 -0
  944. chia/wallet/trading/trade_status.py +13 -0
  945. chia/wallet/trading/trade_store.py +526 -0
  946. chia/wallet/transaction_record.py +143 -0
  947. chia/wallet/transaction_sorting.py +14 -0
  948. chia/wallet/uncurried_puzzle.py +17 -0
  949. chia/wallet/util/__init__.py +0 -0
  950. chia/wallet/util/address_type.py +55 -0
  951. chia/wallet/util/blind_signer_tl.py +168 -0
  952. chia/wallet/util/clvm_streamable.py +203 -0
  953. chia/wallet/util/compute_hints.py +66 -0
  954. chia/wallet/util/compute_memos.py +45 -0
  955. chia/wallet/util/curry_and_treehash.py +90 -0
  956. chia/wallet/util/debug_spend_bundle.py +234 -0
  957. chia/wallet/util/merkle_tree.py +100 -0
  958. chia/wallet/util/merkle_utils.py +102 -0
  959. chia/wallet/util/new_peak_queue.py +82 -0
  960. chia/wallet/util/notifications.py +12 -0
  961. chia/wallet/util/peer_request_cache.py +174 -0
  962. chia/wallet/util/puzzle_compression.py +96 -0
  963. chia/wallet/util/puzzle_decorator.py +100 -0
  964. chia/wallet/util/puzzle_decorator_type.py +7 -0
  965. chia/wallet/util/query_filter.py +60 -0
  966. chia/wallet/util/transaction_type.py +23 -0
  967. chia/wallet/util/tx_config.py +158 -0
  968. chia/wallet/util/wallet_sync_utils.py +348 -0
  969. chia/wallet/util/wallet_types.py +65 -0
  970. chia/wallet/vc_wallet/__init__.py +0 -0
  971. chia/wallet/vc_wallet/cr_cat_drivers.py +663 -0
  972. chia/wallet/vc_wallet/cr_cat_wallet.py +875 -0
  973. chia/wallet/vc_wallet/cr_outer_puzzle.py +102 -0
  974. chia/wallet/vc_wallet/cr_puzzles/__init__.py +0 -0
  975. chia/wallet/vc_wallet/cr_puzzles/conditions_w_fee_announce.clsp +3 -0
  976. chia/wallet/vc_wallet/cr_puzzles/conditions_w_fee_announce.clsp.hex +1 -0
  977. chia/wallet/vc_wallet/cr_puzzles/credential_restriction.clsp +304 -0
  978. chia/wallet/vc_wallet/cr_puzzles/credential_restriction.clsp.hex +1 -0
  979. chia/wallet/vc_wallet/cr_puzzles/flag_proofs_checker.clsp +45 -0
  980. chia/wallet/vc_wallet/cr_puzzles/flag_proofs_checker.clsp.hex +1 -0
  981. chia/wallet/vc_wallet/vc_drivers.py +838 -0
  982. chia/wallet/vc_wallet/vc_puzzles/__init__.py +0 -0
  983. chia/wallet/vc_wallet/vc_puzzles/covenant_layer.clsp +30 -0
  984. chia/wallet/vc_wallet/vc_puzzles/covenant_layer.clsp.hex +1 -0
  985. chia/wallet/vc_wallet/vc_puzzles/eml_covenant_morpher.clsp +75 -0
  986. chia/wallet/vc_wallet/vc_puzzles/eml_covenant_morpher.clsp.hex +1 -0
  987. chia/wallet/vc_wallet/vc_puzzles/eml_transfer_program_covenant_adapter.clsp +32 -0
  988. chia/wallet/vc_wallet/vc_puzzles/eml_transfer_program_covenant_adapter.clsp.hex +1 -0
  989. chia/wallet/vc_wallet/vc_puzzles/eml_update_metadata_with_DID.clsp +80 -0
  990. chia/wallet/vc_wallet/vc_puzzles/eml_update_metadata_with_DID.clsp.hex +1 -0
  991. chia/wallet/vc_wallet/vc_puzzles/exigent_metadata_layer.clsp +163 -0
  992. chia/wallet/vc_wallet/vc_puzzles/exigent_metadata_layer.clsp.hex +1 -0
  993. chia/wallet/vc_wallet/vc_puzzles/p2_announced_delegated_puzzle.clsp +16 -0
  994. chia/wallet/vc_wallet/vc_puzzles/p2_announced_delegated_puzzle.clsp.hex +1 -0
  995. chia/wallet/vc_wallet/vc_puzzles/standard_vc_backdoor_puzzle.clsp +74 -0
  996. chia/wallet/vc_wallet/vc_puzzles/standard_vc_backdoor_puzzle.clsp.hex +1 -0
  997. chia/wallet/vc_wallet/vc_puzzles/std_parent_morpher.clsp +23 -0
  998. chia/wallet/vc_wallet/vc_puzzles/std_parent_morpher.clsp.hex +1 -0
  999. chia/wallet/vc_wallet/vc_puzzles/viral_backdoor.clsp +64 -0
  1000. chia/wallet/vc_wallet/vc_puzzles/viral_backdoor.clsp.hex +1 -0
  1001. chia/wallet/vc_wallet/vc_store.py +263 -0
  1002. chia/wallet/vc_wallet/vc_wallet.py +638 -0
  1003. chia/wallet/wallet.py +698 -0
  1004. chia/wallet/wallet_action_scope.py +95 -0
  1005. chia/wallet/wallet_blockchain.py +244 -0
  1006. chia/wallet/wallet_coin_record.py +72 -0
  1007. chia/wallet/wallet_coin_store.py +351 -0
  1008. chia/wallet/wallet_info.py +36 -0
  1009. chia/wallet/wallet_interested_store.py +188 -0
  1010. chia/wallet/wallet_nft_store.py +279 -0
  1011. chia/wallet/wallet_node.py +1769 -0
  1012. chia/wallet/wallet_node_api.py +201 -0
  1013. chia/wallet/wallet_pool_store.py +120 -0
  1014. chia/wallet/wallet_protocol.py +90 -0
  1015. chia/wallet/wallet_puzzle_store.py +365 -0
  1016. chia/wallet/wallet_retry_store.py +70 -0
  1017. chia/wallet/wallet_singleton_store.py +258 -0
  1018. chia/wallet/wallet_spend_bundle.py +41 -0
  1019. chia/wallet/wallet_state_manager.py +2820 -0
  1020. chia/wallet/wallet_transaction_store.py +470 -0
  1021. chia/wallet/wallet_user_store.py +110 -0
  1022. chia/wallet/wallet_weight_proof_handler.py +126 -0
  1023. chia_blockchain-2.4.4.dist-info/LICENSE +201 -0
  1024. chia_blockchain-2.4.4.dist-info/METADATA +161 -0
  1025. chia_blockchain-2.4.4.dist-info/RECORD +1028 -0
  1026. chia_blockchain-2.4.4.dist-info/WHEEL +4 -0
  1027. chia_blockchain-2.4.4.dist-info/entry_points.txt +17 -0
  1028. mozilla-ca/cacert.pem +3666 -0
@@ -0,0 +1,2578 @@
1
+ from __future__ import annotations
2
+
3
+ import dataclasses
4
+ from typing import Any, Dict, List, Union
5
+
6
+ import pytest
7
+ from chia_rs import G2Element
8
+
9
+ from chia._tests.conftest import SOFTFORK_HEIGHTS
10
+ from chia._tests.environments.wallet import WalletStateTransition, WalletTestFramework
11
+ from chia._tests.util.time_out_assert import time_out_assert
12
+ from chia._tests.wallet.vc_wallet.test_vc_wallet import mint_cr_cat
13
+ from chia.consensus.cost_calculator import NPCResult
14
+ from chia.consensus.default_constants import DEFAULT_CONSTANTS
15
+ from chia.full_node.bundle_tools import simple_solution_generator
16
+ from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions
17
+ from chia.types.blockchain_format.program import INFINITE_COST, Program
18
+ from chia.types.blockchain_format.sized_bytes import bytes32
19
+ from chia.types.spend_bundle import SpendBundle
20
+ from chia.util.hash import std_hash
21
+ from chia.util.ints import uint32, uint64
22
+ from chia.wallet.cat_wallet.cat_wallet import CATWallet
23
+ from chia.wallet.conditions import CreateCoinAnnouncement, parse_conditions_non_consensus
24
+ from chia.wallet.did_wallet.did_wallet import DIDWallet
25
+ from chia.wallet.outer_puzzles import AssetType
26
+ from chia.wallet.puzzle_drivers import PuzzleInfo
27
+ from chia.wallet.trade_manager import TradeManager
28
+ from chia.wallet.trade_record import TradeRecord
29
+ from chia.wallet.trading.offer import Offer
30
+ from chia.wallet.trading.trade_status import TradeStatus
31
+ from chia.wallet.transaction_record import TransactionRecord
32
+ from chia.wallet.util.transaction_type import TransactionType
33
+ from chia.wallet.vc_wallet.cr_cat_drivers import ProofsChecker
34
+ from chia.wallet.vc_wallet.cr_cat_wallet import CRCATWallet
35
+ from chia.wallet.vc_wallet.vc_store import VCProofs
36
+ from chia.wallet.wallet_node import WalletNode
37
+ from chia.wallet.wallet_spend_bundle import WalletSpendBundle
38
+
39
+ OfferSummary = Dict[Union[int, bytes32], int]
40
+
41
+
42
+ async def get_trade_and_status(trade_manager: TradeManager, trade: TradeRecord) -> TradeStatus:
43
+ trade_rec = await trade_manager.get_trade_by_id(trade.trade_id)
44
+ if trade_rec is not None:
45
+ return TradeStatus(trade_rec.status)
46
+ raise ValueError("Couldn't find the trade record")
47
+
48
+
49
+ # This deliberate parameterization may at first look like we're neglecting quite a few cases.
50
+ # However, active_softfork_height is only used is the case where we test aggregation.
51
+ # We do not test aggregation in a number of cases because it's not correlated with a lot of these parameters.
52
+ # So to avoid the overhead of start up for identical tests, we only change the softfork param for the tests that use it.
53
+ # To pin down the behavior that we intend to eventually deprecate, it only gets one test case.
54
+ @pytest.mark.anyio
55
+ @pytest.mark.parametrize(
56
+ "wallet_environments,credential_restricted,active_softfork_height",
57
+ [
58
+ (
59
+ {"num_environments": 2, "trusted": True, "blocks_needed": [1, 1], "reuse_puzhash": True},
60
+ True,
61
+ SOFTFORK_HEIGHTS[0],
62
+ ),
63
+ (
64
+ {"num_environments": 2, "trusted": True, "blocks_needed": [1, 1], "reuse_puzhash": True},
65
+ False,
66
+ SOFTFORK_HEIGHTS[0],
67
+ ),
68
+ (
69
+ {"num_environments": 2, "trusted": True, "blocks_needed": [1, 1], "reuse_puzhash": False},
70
+ True,
71
+ SOFTFORK_HEIGHTS[0],
72
+ ),
73
+ (
74
+ {"num_environments": 2, "trusted": False, "blocks_needed": [1, 1], "reuse_puzhash": True},
75
+ True,
76
+ SOFTFORK_HEIGHTS[0],
77
+ ),
78
+ (
79
+ {"num_environments": 2, "trusted": False, "blocks_needed": [1, 1], "reuse_puzhash": False},
80
+ False,
81
+ SOFTFORK_HEIGHTS[0],
82
+ ),
83
+ (
84
+ {"num_environments": 2, "trusted": False, "blocks_needed": [1, 1], "reuse_puzhash": True},
85
+ False,
86
+ SOFTFORK_HEIGHTS[0],
87
+ ),
88
+ (
89
+ {"num_environments": 2, "trusted": False, "blocks_needed": [1, 1], "reuse_puzhash": False},
90
+ True,
91
+ SOFTFORK_HEIGHTS[0],
92
+ ),
93
+ *(
94
+ ({"num_environments": 2, "trusted": True, "blocks_needed": [1, 1], "reuse_puzhash": False}, False, height)
95
+ for height in SOFTFORK_HEIGHTS
96
+ ),
97
+ ],
98
+ indirect=["wallet_environments"],
99
+ )
100
+ @pytest.mark.limit_consensus_modes(reason="irrelevant")
101
+ async def test_cat_trades(
102
+ wallet_environments: WalletTestFramework,
103
+ credential_restricted: bool,
104
+ active_softfork_height: uint32,
105
+ ) -> None:
106
+ # Setup
107
+ env_maker = wallet_environments.environments[0]
108
+ env_taker = wallet_environments.environments[1]
109
+ wallet_node_maker = env_maker.node
110
+ wallet_node_taker = env_taker.node
111
+ client_maker = env_maker.rpc_client
112
+ client_taker = env_taker.rpc_client
113
+ wallet_maker = env_maker.xch_wallet
114
+ wallet_taker = env_taker.xch_wallet
115
+ full_node = wallet_environments.full_node
116
+
117
+ trusted = len(wallet_node_maker.config["trusted_peers"]) > 0
118
+
119
+ # Because making/taking CR-CATs is asymetrical, approving the hacked together aggregation test will fail
120
+ # The taker is "making" offers that it is approving with a VC which multiple actual makers would never do
121
+ # This is really a test of CATOuterPuzzle anyways and is not correlated with any of our params
122
+ test_aggregation = not credential_restricted and not wallet_environments.tx_config.reuse_puzhash and trusted
123
+
124
+ # Create two new CATs, one in each wallet
125
+ if credential_restricted:
126
+ # Aliasing
127
+ env_maker.wallet_aliases = {
128
+ "xch": 1,
129
+ "did": 2,
130
+ "cat": 3,
131
+ "vc": 4,
132
+ "new cat": 5,
133
+ }
134
+ env_taker.wallet_aliases = {
135
+ "xch": 1,
136
+ "did": 2,
137
+ "new cat": 3,
138
+ "vc": 4,
139
+ "cat": 5,
140
+ }
141
+
142
+ # Mint some DIDs
143
+ async with wallet_maker.wallet_state_manager.new_action_scope(
144
+ wallet_environments.tx_config, push=True
145
+ ) as action_scope:
146
+ did_wallet_maker: DIDWallet = await DIDWallet.create_new_did_wallet(
147
+ wallet_node_maker.wallet_state_manager,
148
+ wallet_maker,
149
+ uint64(1),
150
+ action_scope,
151
+ )
152
+ async with wallet_taker.wallet_state_manager.new_action_scope(
153
+ wallet_environments.tx_config, push=True
154
+ ) as action_scope:
155
+ did_wallet_taker: DIDWallet = await DIDWallet.create_new_did_wallet(
156
+ wallet_node_taker.wallet_state_manager,
157
+ wallet_taker,
158
+ uint64(1),
159
+ action_scope,
160
+ )
161
+ did_id_maker = bytes32.from_hexstr(did_wallet_maker.get_my_DID())
162
+ did_id_taker = bytes32.from_hexstr(did_wallet_taker.get_my_DID())
163
+
164
+ # Mint some CR-CATs
165
+ tail_maker = Program.to([3, (1, "maker"), None, None])
166
+ tail_taker = Program.to([3, (1, "taker"), None, None])
167
+ proofs_checker_maker = ProofsChecker(["foo", "bar"])
168
+ proofs_checker_taker = ProofsChecker(["bar", "zap"])
169
+ authorized_providers: List[bytes32] = [did_id_maker, did_id_taker]
170
+ cat_wallet_maker: CATWallet = await CRCATWallet.get_or_create_wallet_for_cat(
171
+ wallet_node_maker.wallet_state_manager,
172
+ wallet_maker,
173
+ tail_maker.get_tree_hash().hex(),
174
+ None,
175
+ authorized_providers,
176
+ proofs_checker_maker,
177
+ )
178
+ new_cat_wallet_taker: CATWallet = await CRCATWallet.get_or_create_wallet_for_cat(
179
+ wallet_node_taker.wallet_state_manager,
180
+ wallet_taker,
181
+ tail_taker.get_tree_hash().hex(),
182
+ None,
183
+ authorized_providers,
184
+ proofs_checker_taker,
185
+ )
186
+ await mint_cr_cat(
187
+ 1,
188
+ wallet_maker,
189
+ wallet_node_maker,
190
+ client_maker,
191
+ full_node,
192
+ authorized_providers,
193
+ tail_maker,
194
+ proofs_checker_maker,
195
+ )
196
+ await mint_cr_cat(
197
+ 1,
198
+ wallet_taker,
199
+ wallet_node_taker,
200
+ client_taker,
201
+ full_node,
202
+ authorized_providers,
203
+ tail_taker,
204
+ proofs_checker_taker,
205
+ )
206
+
207
+ await wallet_environments.process_pending_states(
208
+ [
209
+ # Balance checking for this scenario is covered in tests/wallet/vc_wallet/test_vc_lifecycle
210
+ WalletStateTransition(
211
+ pre_block_balance_updates={
212
+ "xch": {"set_remainder": True},
213
+ "did": {"init": True, "set_remainder": True},
214
+ "cat": {"init": True, "set_remainder": True},
215
+ },
216
+ post_block_balance_updates={
217
+ "xch": {"set_remainder": True},
218
+ "did": {"set_remainder": True},
219
+ "cat": {"set_remainder": True},
220
+ },
221
+ ),
222
+ WalletStateTransition(
223
+ pre_block_balance_updates={
224
+ "xch": {"set_remainder": True},
225
+ "did": {"init": True, "set_remainder": True},
226
+ "new cat": {"init": True, "set_remainder": True},
227
+ },
228
+ post_block_balance_updates={
229
+ "xch": {"set_remainder": True},
230
+ "did": {"set_remainder": True},
231
+ "new cat": {"set_remainder": True},
232
+ },
233
+ ),
234
+ ]
235
+ )
236
+
237
+ # Mint some VCs that can spend the CR-CATs
238
+ vc_record_maker = (
239
+ await client_maker.vc_mint(
240
+ did_id_maker, wallet_environments.tx_config, target_address=await wallet_maker.get_new_puzzlehash()
241
+ )
242
+ ).vc_record
243
+ vc_record_taker = (
244
+ await client_taker.vc_mint(
245
+ did_id_taker, wallet_environments.tx_config, target_address=await wallet_taker.get_new_puzzlehash()
246
+ )
247
+ ).vc_record
248
+ await wallet_environments.process_pending_states(
249
+ [
250
+ # Balance checking for this scenario is covered in tests/wallet/vc_wallet/test_vc_lifecycle
251
+ WalletStateTransition(
252
+ pre_block_balance_updates={
253
+ "xch": {"set_remainder": True},
254
+ "vc": {"init": True, "set_remainder": True},
255
+ },
256
+ post_block_balance_updates={
257
+ "xch": {"set_remainder": True},
258
+ "vc": {"set_remainder": True},
259
+ },
260
+ ),
261
+ WalletStateTransition(
262
+ pre_block_balance_updates={
263
+ "xch": {"set_remainder": True},
264
+ "vc": {"init": True, "set_remainder": True},
265
+ },
266
+ post_block_balance_updates={
267
+ "xch": {"set_remainder": True},
268
+ "vc": {"set_remainder": True},
269
+ },
270
+ ),
271
+ ]
272
+ )
273
+
274
+ proofs_maker = VCProofs({"foo": "1", "bar": "1", "zap": "1"})
275
+ proof_root_maker: bytes32 = proofs_maker.root()
276
+ await client_maker.vc_spend(
277
+ vc_record_maker.vc.launcher_id,
278
+ wallet_environments.tx_config,
279
+ new_proof_hash=proof_root_maker,
280
+ )
281
+
282
+ proofs_taker = VCProofs({"foo": "1", "bar": "1", "zap": "1"})
283
+ proof_root_taker: bytes32 = proofs_taker.root()
284
+ await client_taker.vc_spend(
285
+ vc_record_taker.vc.launcher_id,
286
+ wallet_environments.tx_config,
287
+ new_proof_hash=proof_root_taker,
288
+ )
289
+ await wallet_environments.process_pending_states(
290
+ [
291
+ # Balance checking for this scenario is covered in tests/wallet/vc_wallet/test_vc_lifecycle
292
+ WalletStateTransition(
293
+ pre_block_balance_updates={
294
+ "did": {"set_remainder": True},
295
+ "vc": {"set_remainder": True},
296
+ },
297
+ post_block_balance_updates={
298
+ "did": {"set_remainder": True},
299
+ "vc": {"set_remainder": True},
300
+ },
301
+ ),
302
+ WalletStateTransition(
303
+ pre_block_balance_updates={
304
+ "did": {"set_remainder": True},
305
+ "vc": {"set_remainder": True},
306
+ },
307
+ post_block_balance_updates={
308
+ "did": {"set_remainder": True},
309
+ "vc": {"set_remainder": True},
310
+ },
311
+ ),
312
+ ]
313
+ )
314
+ else:
315
+ # Aliasing
316
+ env_maker.wallet_aliases = {
317
+ "xch": 1,
318
+ "cat": 2,
319
+ "new cat": 3,
320
+ }
321
+ env_taker.wallet_aliases = {
322
+ "xch": 1,
323
+ "new cat": 2,
324
+ "cat": 3,
325
+ }
326
+
327
+ # Mint some standard CATs
328
+ async with wallet_maker.wallet_state_manager.new_action_scope(
329
+ wallet_environments.tx_config, push=True
330
+ ) as action_scope:
331
+ cat_wallet_maker = await CATWallet.create_new_cat_wallet(
332
+ wallet_node_maker.wallet_state_manager,
333
+ wallet_maker,
334
+ {"identifier": "genesis_by_id"},
335
+ uint64(100),
336
+ action_scope,
337
+ )
338
+
339
+ async with wallet_taker.wallet_state_manager.new_action_scope(
340
+ wallet_environments.tx_config, push=True
341
+ ) as action_scope:
342
+ new_cat_wallet_taker = await CATWallet.create_new_cat_wallet(
343
+ wallet_node_taker.wallet_state_manager,
344
+ wallet_taker,
345
+ {"identifier": "genesis_by_id"},
346
+ uint64(100),
347
+ action_scope,
348
+ )
349
+
350
+ await wallet_environments.process_pending_states(
351
+ [
352
+ # Balance checking for this scenario is covered in test_cat_wallet
353
+ WalletStateTransition(
354
+ pre_block_balance_updates={
355
+ "xch": {"set_remainder": True},
356
+ "cat": {"init": True, "set_remainder": True},
357
+ },
358
+ post_block_balance_updates={
359
+ "xch": {"set_remainder": True},
360
+ "cat": {"set_remainder": True},
361
+ },
362
+ ),
363
+ WalletStateTransition(
364
+ pre_block_balance_updates={
365
+ "xch": {"set_remainder": True},
366
+ "new cat": {"init": True, "set_remainder": True},
367
+ },
368
+ post_block_balance_updates={
369
+ "xch": {"set_remainder": True},
370
+ "new cat": {"set_remainder": True},
371
+ },
372
+ ),
373
+ ]
374
+ )
375
+
376
+ if credential_restricted:
377
+ await client_maker.vc_add_proofs(proofs_maker.key_value_pairs)
378
+ assert await client_maker.vc_get_proofs_for_root(proof_root_maker) == proofs_maker.key_value_pairs
379
+ vc_records, fetched_proofs = await client_maker.vc_get_list()
380
+ assert len(vc_records) == 1
381
+ assert fetched_proofs[proof_root_maker.hex()] == proofs_maker.key_value_pairs
382
+
383
+ await client_taker.vc_add_proofs(proofs_taker.key_value_pairs)
384
+ assert await client_taker.vc_get_proofs_for_root(proof_root_taker) == proofs_taker.key_value_pairs
385
+ vc_records, fetched_proofs = await client_taker.vc_get_list()
386
+ assert len(vc_records) == 1
387
+ assert fetched_proofs[proof_root_taker.hex()] == proofs_taker.key_value_pairs
388
+
389
+ # Add the taker's CAT to the maker's wallet
390
+ if credential_restricted:
391
+ new_cat_wallet_maker: CATWallet = await CRCATWallet.get_or_create_wallet_for_cat(
392
+ wallet_node_maker.wallet_state_manager,
393
+ wallet_maker,
394
+ new_cat_wallet_taker.get_asset_id(),
395
+ None,
396
+ authorized_providers,
397
+ proofs_checker_taker,
398
+ )
399
+ else:
400
+ new_cat_wallet_maker = await CATWallet.get_or_create_wallet_for_cat(
401
+ wallet_node_maker.wallet_state_manager, wallet_maker, new_cat_wallet_taker.get_asset_id()
402
+ )
403
+
404
+ await env_maker.change_balances(
405
+ {
406
+ "new cat": {
407
+ "init": True,
408
+ "confirmed_wallet_balance": 0,
409
+ "unconfirmed_wallet_balance": 0,
410
+ "spendable_balance": 0,
411
+ "pending_coin_removal_count": 0,
412
+ "pending_change": 0,
413
+ "max_send_amount": 0,
414
+ }
415
+ }
416
+ )
417
+ await env_maker.check_balances()
418
+
419
+ # Create the trade parameters
420
+ chia_for_cat: OfferSummary = {
421
+ wallet_maker.id(): -1,
422
+ bytes32.from_hexstr(new_cat_wallet_maker.get_asset_id()): 2, # This is the CAT that the taker made
423
+ }
424
+ cat_for_chia: OfferSummary = {
425
+ wallet_maker.id(): 3,
426
+ cat_wallet_maker.id(): -4, # The taker has no knowledge of this CAT yet
427
+ }
428
+ cat_for_cat: OfferSummary = {
429
+ bytes32.from_hexstr(cat_wallet_maker.get_asset_id()): -5,
430
+ new_cat_wallet_maker.id(): 6,
431
+ }
432
+ chia_for_multiple_cat: OfferSummary = {
433
+ wallet_maker.id(): -7,
434
+ cat_wallet_maker.id(): 8,
435
+ new_cat_wallet_maker.id(): 9,
436
+ }
437
+ multiple_cat_for_chia: OfferSummary = {
438
+ wallet_maker.id(): 10,
439
+ cat_wallet_maker.id(): -11,
440
+ new_cat_wallet_maker.id(): -12,
441
+ }
442
+ chia_and_cat_for_cat: OfferSummary = {
443
+ wallet_maker.id(): -13,
444
+ cat_wallet_maker.id(): -14,
445
+ new_cat_wallet_maker.id(): 15,
446
+ }
447
+
448
+ driver_dict: Dict[bytes32, PuzzleInfo] = {}
449
+ for wallet in (cat_wallet_maker, new_cat_wallet_maker):
450
+ asset_id: str = wallet.get_asset_id()
451
+ driver_item: Dict[str, Any] = {
452
+ "type": AssetType.CAT.value,
453
+ "tail": "0x" + asset_id,
454
+ }
455
+ if credential_restricted:
456
+ driver_item["also"] = {
457
+ "type": AssetType.CR.value,
458
+ "authorized_providers": ["0x" + provider.hex() for provider in authorized_providers],
459
+ "proofs_checker": (
460
+ proofs_checker_maker.as_program()
461
+ if wallet == cat_wallet_maker
462
+ else proofs_checker_taker.as_program()
463
+ ),
464
+ }
465
+ driver_dict[bytes32.from_hexstr(asset_id)] = PuzzleInfo(driver_item)
466
+
467
+ trade_manager_maker = env_maker.wallet_state_manager.trade_manager
468
+ trade_manager_taker = env_taker.wallet_state_manager.trade_manager
469
+ maker_unused_dr = await wallet_maker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
470
+ uint32(1)
471
+ )
472
+ assert maker_unused_dr is not None
473
+ maker_unused_index = maker_unused_dr.index
474
+ taker_unused_dr = await wallet_taker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
475
+ uint32(1)
476
+ )
477
+ assert taker_unused_dr is not None
478
+ taker_unused_index = taker_unused_dr.index
479
+ # Execute all of the trades
480
+ # chia_for_cat
481
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
482
+ wallet_environments.tx_config, push=False
483
+ ) as action_scope:
484
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(
485
+ chia_for_cat, action_scope, fee=uint64(1)
486
+ )
487
+ assert error is None
488
+ assert success is True
489
+ assert trade_make is not None
490
+
491
+ peer = wallet_node_taker.get_full_node_peer()
492
+ [maker_offer], signing_response = await wallet_node_maker.wallet_state_manager.sign_offers(
493
+ [Offer.from_bytes(trade_make.offer)]
494
+ )
495
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
496
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
497
+ ) as action_scope:
498
+ trade_take = await trade_manager_taker.respond_to_offer(
499
+ maker_offer,
500
+ peer,
501
+ action_scope,
502
+ fee=uint64(1),
503
+ )
504
+
505
+ if test_aggregation:
506
+ first_offer = Offer.from_bytes(trade_take.offer)
507
+
508
+ await wallet_environments.process_pending_states(
509
+ [
510
+ WalletStateTransition(
511
+ pre_block_balance_updates={
512
+ "xch": {
513
+ "pending_coin_removal_count": 1,
514
+ "<=#spendable_balance": -2,
515
+ "<=#max_send_amount": -2,
516
+ # Unconfirmed balance doesn't change because offer may not complete
517
+ "unconfirmed_wallet_balance": 0,
518
+ },
519
+ },
520
+ post_block_balance_updates={
521
+ "xch": {
522
+ "pending_coin_removal_count": -1,
523
+ "confirmed_wallet_balance": -2, # One for offered XCH, one for fee
524
+ "unconfirmed_wallet_balance": -2, # One for offered XCH, one for fee
525
+ ">#spendable_balance": 0,
526
+ ">#max_send_amount": 0,
527
+ },
528
+ "new cat": (
529
+ {
530
+ # No change if credential_restricted because pending approval balance needs to be claimed
531
+ "confirmed_wallet_balance": 0,
532
+ "unconfirmed_wallet_balance": 0,
533
+ "spendable_balance": 0,
534
+ "max_send_amount": 0,
535
+ "pending_change": 0,
536
+ "unspent_coin_count": 0,
537
+ }
538
+ if credential_restricted
539
+ else {
540
+ "confirmed_wallet_balance": 2,
541
+ "unconfirmed_wallet_balance": 2,
542
+ "spendable_balance": 2,
543
+ "max_send_amount": 2,
544
+ "unspent_coin_count": 1,
545
+ }
546
+ ),
547
+ },
548
+ post_block_additional_balance_info=(
549
+ {
550
+ "new cat": {
551
+ "pending_approval_balance": 2,
552
+ }
553
+ }
554
+ if credential_restricted
555
+ else {}
556
+ ),
557
+ ),
558
+ WalletStateTransition(
559
+ pre_block_balance_updates={
560
+ "xch": {
561
+ "pending_coin_removal_count": 1,
562
+ "<=#spendable_balance": -2,
563
+ "<=#max_send_amount": -2,
564
+ # Unconfirmed balance doesn't change because receiveing 1 XCH and spending 1 in fee
565
+ "unconfirmed_wallet_balance": 0,
566
+ ">=#pending_change": 1, # any amount increase
567
+ },
568
+ "new cat": {
569
+ "unconfirmed_wallet_balance": -2,
570
+ "pending_coin_removal_count": 1,
571
+ "pending_change": 98,
572
+ "<=#spendable_balance": -2,
573
+ "<=#max_send_amount": -2,
574
+ },
575
+ **(
576
+ {
577
+ "vc": {
578
+ "pending_coin_removal_count": 1,
579
+ }
580
+ }
581
+ if credential_restricted
582
+ else {}
583
+ ),
584
+ },
585
+ post_block_balance_updates={
586
+ "xch": {
587
+ "pending_coin_removal_count": -1,
588
+ "unspent_coin_count": 1,
589
+ ">#spendable_balance": 0,
590
+ ">#max_send_amount": 0,
591
+ # Confirmed balance doesn't change because receiveing 1 XCH and spending 1 in fee
592
+ "confirmed_wallet_balance": 0,
593
+ "<=#pending_change": 1, # any amount decrease
594
+ },
595
+ "new cat": {
596
+ "confirmed_wallet_balance": -2,
597
+ "pending_coin_removal_count": -1,
598
+ "pending_change": -98,
599
+ ">#spendable_balance": 0,
600
+ ">#max_send_amount": 0,
601
+ },
602
+ **(
603
+ {
604
+ "vc": {
605
+ "pending_coin_removal_count": -1,
606
+ }
607
+ }
608
+ if credential_restricted
609
+ else {}
610
+ ),
611
+ },
612
+ ),
613
+ ]
614
+ )
615
+
616
+ if credential_restricted:
617
+ await client_maker.crcat_approve_pending(
618
+ new_cat_wallet_maker.id(),
619
+ uint64(2),
620
+ wallet_environments.tx_config,
621
+ )
622
+
623
+ await wallet_environments.process_pending_states(
624
+ [
625
+ WalletStateTransition(
626
+ pre_block_balance_updates={
627
+ "new cat": {
628
+ "unconfirmed_wallet_balance": 2,
629
+ "pending_coin_removal_count": 1,
630
+ "pending_change": 2, # This is a little weird but fits the current definition
631
+ },
632
+ "vc": {
633
+ "pending_coin_removal_count": 1,
634
+ },
635
+ },
636
+ pre_block_additional_balance_info={
637
+ "new cat": {
638
+ "pending_approval_balance": 2,
639
+ }
640
+ },
641
+ post_block_balance_updates={
642
+ "new cat": {
643
+ "confirmed_wallet_balance": 2,
644
+ "spendable_balance": 2,
645
+ "max_send_amount": 2,
646
+ "pending_change": -2,
647
+ "unspent_coin_count": 1,
648
+ "pending_coin_removal_count": -1,
649
+ },
650
+ "vc": {
651
+ "pending_coin_removal_count": -1,
652
+ },
653
+ },
654
+ post_block_additional_balance_info={
655
+ "new cat": {
656
+ "pending_approval_balance": 0,
657
+ }
658
+ },
659
+ ),
660
+ WalletStateTransition(),
661
+ ]
662
+ )
663
+
664
+ if wallet_environments.tx_config.reuse_puzhash:
665
+ # Check if unused index changed
666
+ maker_unused_dr = await wallet_maker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
667
+ uint32(1)
668
+ )
669
+ assert maker_unused_dr is not None
670
+ assert maker_unused_index == maker_unused_dr.index
671
+ taker_unused_dr = await wallet_taker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
672
+ uint32(1)
673
+ )
674
+ assert taker_unused_dr is not None
675
+ assert taker_unused_index == taker_unused_dr.index
676
+ else:
677
+ maker_unused_dr = await wallet_maker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
678
+ uint32(1)
679
+ )
680
+ assert maker_unused_dr is not None
681
+ assert maker_unused_index < maker_unused_dr.index
682
+ taker_unused_dr = await wallet_taker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
683
+ uint32(1)
684
+ )
685
+ assert taker_unused_dr is not None
686
+ assert taker_unused_index < taker_unused_dr.index
687
+
688
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
689
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, trade_take)
690
+
691
+ async def assert_trade_tx_number(wallet_node: WalletNode, trade_id: bytes32, number: int) -> bool:
692
+ txs = await wallet_node.wallet_state_manager.tx_store.get_transactions_by_trade_id(trade_id)
693
+ return len(txs) == number
694
+
695
+ await time_out_assert(15, assert_trade_tx_number, True, wallet_node_maker, trade_make.trade_id, 1)
696
+ # CR-CATs will also have a TX record for the VC
697
+ await time_out_assert(
698
+ 15, assert_trade_tx_number, True, wallet_node_taker, trade_take.trade_id, 4 if credential_restricted else 3
699
+ )
700
+
701
+ # cat_for_chia
702
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
703
+ wallet_environments.tx_config, push=False
704
+ ) as action_scope:
705
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(cat_for_chia, action_scope)
706
+ assert error is None
707
+ assert success is True
708
+ assert trade_make is not None
709
+
710
+ [maker_offer], signing_response = await wallet_node_maker.wallet_state_manager.sign_offers(
711
+ [Offer.from_bytes(trade_make.offer)]
712
+ )
713
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
714
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
715
+ ) as action_scope:
716
+ trade_take = await trade_manager_taker.respond_to_offer(
717
+ Offer.from_bytes(trade_make.offer),
718
+ peer,
719
+ action_scope,
720
+ fee=uint64(1),
721
+ )
722
+
723
+ # Testing a precious display bug real quick
724
+ xch_tx: TransactionRecord = next(tx for tx in action_scope.side_effects.transactions if tx.wallet_id == 1)
725
+ assert xch_tx.amount == 3
726
+ assert xch_tx.fee_amount == 1
727
+
728
+ await wallet_environments.process_pending_states(
729
+ [
730
+ WalletStateTransition(
731
+ pre_block_balance_updates={
732
+ "cat": {
733
+ "pending_coin_removal_count": 1,
734
+ "<=#spendable_balance": -4,
735
+ "<=#max_send_amount": -4,
736
+ # Unconfirmed balance doesn't change because offer may not complete
737
+ "unconfirmed_wallet_balance": 0,
738
+ },
739
+ },
740
+ post_block_balance_updates={
741
+ "xch": {
742
+ "confirmed_wallet_balance": 3,
743
+ "unconfirmed_wallet_balance": 3,
744
+ "spendable_balance": 3,
745
+ "max_send_amount": 3,
746
+ "unspent_coin_count": 1,
747
+ },
748
+ "cat": {
749
+ "confirmed_wallet_balance": -4,
750
+ "unconfirmed_wallet_balance": -4,
751
+ ">#spendable_balance": 0,
752
+ ">#max_send_amount": 0,
753
+ "pending_coin_removal_count": -1,
754
+ },
755
+ },
756
+ ),
757
+ WalletStateTransition(
758
+ pre_block_balance_updates={
759
+ "xch": {
760
+ "unconfirmed_wallet_balance": -4, # -3 for offer, -1 for fee
761
+ "<=#spendable_balance": -4,
762
+ "<=#max_send_amount": -4,
763
+ "pending_coin_removal_count": 1,
764
+ ">=#pending_change": 1, # any amount increase
765
+ },
766
+ "cat": {
767
+ "init": True,
768
+ "confirmed_wallet_balance": 0,
769
+ "unconfirmed_wallet_balance": 4,
770
+ "spendable_balance": 0,
771
+ "pending_change": 0,
772
+ "max_send_amount": 0,
773
+ "unspent_coin_count": 0,
774
+ "pending_coin_removal_count": 0,
775
+ },
776
+ **(
777
+ {
778
+ "vc": {
779
+ "pending_coin_removal_count": 1,
780
+ }
781
+ }
782
+ if credential_restricted
783
+ else {}
784
+ ),
785
+ },
786
+ post_block_balance_updates={
787
+ "xch": {
788
+ "confirmed_wallet_balance": -4,
789
+ ">#spendable_balance": 0,
790
+ ">#max_send_amount": 0,
791
+ "pending_coin_removal_count": -1,
792
+ "<=#pending_change": 1, # any amount decrease
793
+ },
794
+ "cat": {
795
+ "unspent_coin_count": 1,
796
+ "spendable_balance": 4,
797
+ "max_send_amount": 4,
798
+ "confirmed_wallet_balance": 4,
799
+ },
800
+ **(
801
+ {
802
+ "vc": {
803
+ "pending_coin_removal_count": -1,
804
+ }
805
+ }
806
+ if credential_restricted
807
+ else {}
808
+ ),
809
+ },
810
+ ),
811
+ ]
812
+ )
813
+
814
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
815
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, trade_take)
816
+ await time_out_assert(15, assert_trade_tx_number, True, wallet_node_maker, trade_make.trade_id, 1)
817
+ await time_out_assert(
818
+ 15, assert_trade_tx_number, True, wallet_node_taker, trade_take.trade_id, 3 if credential_restricted else 2
819
+ )
820
+
821
+ # cat_for_cat
822
+ maker_unused_dr = await wallet_maker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
823
+ uint32(1)
824
+ )
825
+ assert maker_unused_dr is not None
826
+ maker_unused_index = maker_unused_dr.index
827
+ taker_unused_dr = await wallet_taker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
828
+ uint32(1)
829
+ )
830
+ assert taker_unused_dr is not None
831
+ taker_unused_index = taker_unused_dr.index
832
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
833
+ wallet_environments.tx_config, push=False
834
+ ) as action_scope:
835
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(cat_for_cat, action_scope)
836
+ assert error is None
837
+ assert success is True
838
+ assert trade_make is not None
839
+ [maker_offer], signing_response = await wallet_node_maker.wallet_state_manager.sign_offers(
840
+ [Offer.from_bytes(trade_make.offer)]
841
+ )
842
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
843
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
844
+ ) as action_scope:
845
+ trade_take = await trade_manager_taker.respond_to_offer(
846
+ Offer.from_bytes(trade_make.offer),
847
+ peer,
848
+ action_scope,
849
+ )
850
+
851
+ if test_aggregation:
852
+ second_offer = Offer.from_bytes(trade_take.offer)
853
+
854
+ await wallet_environments.process_pending_states(
855
+ [
856
+ WalletStateTransition(
857
+ pre_block_balance_updates={
858
+ "cat": {
859
+ "pending_coin_removal_count": 1,
860
+ "<=#spendable_balance": -5,
861
+ "<=#max_send_amount": -5,
862
+ # Unconfirmed balance doesn't change because offer may not complete
863
+ "unconfirmed_wallet_balance": 0,
864
+ },
865
+ },
866
+ post_block_balance_updates={
867
+ "new cat": (
868
+ {
869
+ # No change if credential_restricted because pending approval balance needs to be claimed
870
+ "confirmed_wallet_balance": 0,
871
+ "unconfirmed_wallet_balance": 0,
872
+ "spendable_balance": 0,
873
+ "max_send_amount": 0,
874
+ "unspent_coin_count": 0,
875
+ }
876
+ if credential_restricted
877
+ else {
878
+ "confirmed_wallet_balance": 6,
879
+ "unconfirmed_wallet_balance": 6,
880
+ "spendable_balance": 6,
881
+ "max_send_amount": 6,
882
+ "unspent_coin_count": 1,
883
+ }
884
+ ),
885
+ "cat": {
886
+ "confirmed_wallet_balance": -5,
887
+ "unconfirmed_wallet_balance": -5,
888
+ ">#spendable_balance": 0,
889
+ ">#max_send_amount": 0,
890
+ "pending_coin_removal_count": -1,
891
+ },
892
+ },
893
+ post_block_additional_balance_info=(
894
+ {
895
+ "new cat": {
896
+ "pending_approval_balance": 6,
897
+ }
898
+ }
899
+ if credential_restricted
900
+ else {}
901
+ ),
902
+ ),
903
+ WalletStateTransition(
904
+ pre_block_balance_updates={
905
+ "cat": {
906
+ "unconfirmed_wallet_balance": 5,
907
+ },
908
+ "new cat": {
909
+ "unconfirmed_wallet_balance": -6,
910
+ "pending_change": 92,
911
+ "<=#spendable_balance": -6,
912
+ "<=#max_send_amount": -6,
913
+ "pending_coin_removal_count": 1,
914
+ },
915
+ **(
916
+ {
917
+ "vc": {
918
+ "pending_coin_removal_count": 1,
919
+ }
920
+ }
921
+ if credential_restricted
922
+ else {}
923
+ ),
924
+ },
925
+ post_block_balance_updates={
926
+ "cat": {
927
+ "unspent_coin_count": 1,
928
+ "spendable_balance": 5,
929
+ "max_send_amount": 5,
930
+ "confirmed_wallet_balance": 5,
931
+ },
932
+ "new cat": {
933
+ "confirmed_wallet_balance": -6,
934
+ "pending_change": -92,
935
+ ">#spendable_balance": 0,
936
+ ">#max_send_amount": 0,
937
+ "pending_coin_removal_count": -1,
938
+ },
939
+ **(
940
+ {
941
+ "vc": {
942
+ "pending_coin_removal_count": -1,
943
+ }
944
+ }
945
+ if credential_restricted
946
+ else {}
947
+ ),
948
+ },
949
+ ),
950
+ ]
951
+ )
952
+
953
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
954
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, trade_take)
955
+
956
+ if credential_restricted:
957
+ await client_maker.crcat_approve_pending(
958
+ new_cat_wallet_maker.id(),
959
+ uint64(6),
960
+ wallet_environments.tx_config,
961
+ )
962
+
963
+ await wallet_environments.process_pending_states(
964
+ [
965
+ WalletStateTransition(
966
+ pre_block_balance_updates={
967
+ "new cat": {
968
+ "unconfirmed_wallet_balance": 6,
969
+ "pending_coin_removal_count": 1,
970
+ "pending_change": 6, # This is a little weird but fits the current definition
971
+ },
972
+ "vc": {
973
+ "pending_coin_removal_count": 1,
974
+ },
975
+ },
976
+ pre_block_additional_balance_info={
977
+ "new cat": {
978
+ "pending_approval_balance": 6,
979
+ }
980
+ },
981
+ post_block_balance_updates={
982
+ "new cat": {
983
+ "confirmed_wallet_balance": 6,
984
+ "spendable_balance": 6,
985
+ "max_send_amount": 6,
986
+ "pending_change": -6,
987
+ "unspent_coin_count": 1,
988
+ "pending_coin_removal_count": -1,
989
+ },
990
+ "vc": {
991
+ "pending_coin_removal_count": -1,
992
+ },
993
+ },
994
+ post_block_additional_balance_info={
995
+ "new cat": {
996
+ "pending_approval_balance": 0,
997
+ }
998
+ },
999
+ ),
1000
+ WalletStateTransition(),
1001
+ ]
1002
+ )
1003
+
1004
+ if wallet_environments.tx_config.reuse_puzhash:
1005
+ # Check if unused index changed
1006
+ maker_unused_dr = await wallet_maker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
1007
+ uint32(1)
1008
+ )
1009
+ assert maker_unused_dr is not None
1010
+ assert maker_unused_index == maker_unused_dr.index
1011
+ taker_unused_dr = await wallet_taker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
1012
+ uint32(1)
1013
+ )
1014
+ assert taker_unused_dr is not None
1015
+ assert taker_unused_index == taker_unused_dr.index
1016
+ else:
1017
+ maker_unused_dr = await wallet_maker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
1018
+ uint32(1)
1019
+ )
1020
+ assert maker_unused_dr is not None
1021
+ assert maker_unused_index < maker_unused_dr.index
1022
+ taker_unused_dr = await wallet_taker.wallet_state_manager.puzzle_store.get_current_derivation_record_for_wallet(
1023
+ uint32(1)
1024
+ )
1025
+ assert taker_unused_dr is not None
1026
+ assert taker_unused_index < taker_unused_dr.index
1027
+
1028
+ # chia_for_multiple_cat
1029
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
1030
+ wallet_environments.tx_config, push=False
1031
+ ) as action_scope:
1032
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(
1033
+ chia_for_multiple_cat,
1034
+ action_scope,
1035
+ driver_dict=driver_dict,
1036
+ )
1037
+ assert error is None
1038
+ assert success is True
1039
+ assert trade_make is not None
1040
+
1041
+ [maker_offer], signing_response = await wallet_node_maker.wallet_state_manager.sign_offers(
1042
+ [Offer.from_bytes(trade_make.offer)]
1043
+ )
1044
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
1045
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
1046
+ ) as action_scope:
1047
+ trade_take = await trade_manager_taker.respond_to_offer(
1048
+ Offer.from_bytes(trade_make.offer),
1049
+ peer,
1050
+ action_scope,
1051
+ )
1052
+
1053
+ if test_aggregation:
1054
+ third_offer = Offer.from_bytes(trade_take.offer)
1055
+
1056
+ await wallet_environments.process_pending_states(
1057
+ [
1058
+ WalletStateTransition(
1059
+ pre_block_balance_updates={
1060
+ "xch": {
1061
+ "pending_coin_removal_count": 1,
1062
+ "<=#spendable_balance": -7,
1063
+ "<=#max_send_amount": -7,
1064
+ # Unconfirmed balance doesn't change because offer may not complete
1065
+ "unconfirmed_wallet_balance": 0,
1066
+ },
1067
+ },
1068
+ post_block_balance_updates={
1069
+ "xch": {
1070
+ "pending_coin_removal_count": -1,
1071
+ ">#spendable_balance": 0,
1072
+ ">#max_send_amount": 0,
1073
+ "unconfirmed_wallet_balance": -7,
1074
+ "confirmed_wallet_balance": -7,
1075
+ },
1076
+ "cat": (
1077
+ {
1078
+ # No change if credential_restricted because pending approval balance needs to be claimed
1079
+ "confirmed_wallet_balance": 0,
1080
+ "unconfirmed_wallet_balance": 0,
1081
+ "spendable_balance": 0,
1082
+ "max_send_amount": 0,
1083
+ "unspent_coin_count": 0,
1084
+ }
1085
+ if credential_restricted
1086
+ else {
1087
+ "confirmed_wallet_balance": 8,
1088
+ "unconfirmed_wallet_balance": 8,
1089
+ "spendable_balance": 8,
1090
+ "max_send_amount": 8,
1091
+ "unspent_coin_count": 1,
1092
+ }
1093
+ ),
1094
+ "new cat": (
1095
+ {
1096
+ # No change if credential_restricted because pending approval balance needs to be claimed
1097
+ "confirmed_wallet_balance": 0,
1098
+ "unconfirmed_wallet_balance": 0,
1099
+ "spendable_balance": 0,
1100
+ "max_send_amount": 0,
1101
+ "unspent_coin_count": 0,
1102
+ }
1103
+ if credential_restricted
1104
+ else {
1105
+ "confirmed_wallet_balance": 9,
1106
+ "unconfirmed_wallet_balance": 9,
1107
+ "spendable_balance": 9,
1108
+ "max_send_amount": 9,
1109
+ "unspent_coin_count": 1,
1110
+ }
1111
+ ),
1112
+ },
1113
+ post_block_additional_balance_info=(
1114
+ {
1115
+ "cat": {
1116
+ "pending_approval_balance": 8,
1117
+ },
1118
+ "new cat": {
1119
+ "pending_approval_balance": 9,
1120
+ },
1121
+ }
1122
+ if credential_restricted
1123
+ else {}
1124
+ ),
1125
+ ),
1126
+ WalletStateTransition(
1127
+ pre_block_balance_updates={
1128
+ "xch": {
1129
+ "unconfirmed_wallet_balance": 7,
1130
+ },
1131
+ "cat": {
1132
+ "unconfirmed_wallet_balance": -8,
1133
+ "pending_change": 1,
1134
+ "<=#spendable_balance": -8,
1135
+ "<=#max_send_amount": -8,
1136
+ "pending_coin_removal_count": 2, # For the first time, we're using two coins in an offer
1137
+ },
1138
+ "new cat": {
1139
+ "unconfirmed_wallet_balance": -9,
1140
+ "pending_change": 83,
1141
+ "<=#spendable_balance": -9,
1142
+ "<=#max_send_amount": -9,
1143
+ "pending_coin_removal_count": 1,
1144
+ },
1145
+ **(
1146
+ {
1147
+ "vc": {
1148
+ "pending_coin_removal_count": 1,
1149
+ }
1150
+ }
1151
+ if credential_restricted
1152
+ else {}
1153
+ ),
1154
+ },
1155
+ post_block_balance_updates={
1156
+ "xch": {
1157
+ "confirmed_wallet_balance": 7,
1158
+ "spendable_balance": 7,
1159
+ "max_send_amount": 7,
1160
+ "unspent_coin_count": 1,
1161
+ },
1162
+ "cat": {
1163
+ "confirmed_wallet_balance": -8,
1164
+ "pending_change": -1,
1165
+ ">#spendable_balance": 0,
1166
+ ">#max_send_amount": 0,
1167
+ "pending_coin_removal_count": -2,
1168
+ "unspent_coin_count": -1,
1169
+ },
1170
+ "new cat": {
1171
+ "confirmed_wallet_balance": -9,
1172
+ "pending_change": -83,
1173
+ ">#spendable_balance": 0,
1174
+ ">#max_send_amount": 0,
1175
+ "pending_coin_removal_count": -1,
1176
+ },
1177
+ **(
1178
+ {
1179
+ "vc": {
1180
+ "pending_coin_removal_count": -1,
1181
+ }
1182
+ }
1183
+ if credential_restricted
1184
+ else {}
1185
+ ),
1186
+ },
1187
+ ),
1188
+ ]
1189
+ )
1190
+
1191
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
1192
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, trade_take)
1193
+
1194
+ if credential_restricted:
1195
+ await client_maker.crcat_approve_pending(
1196
+ cat_wallet_maker.id(),
1197
+ uint64(8),
1198
+ wallet_environments.tx_config,
1199
+ )
1200
+
1201
+ await wallet_environments.process_pending_states(
1202
+ [
1203
+ WalletStateTransition(
1204
+ pre_block_balance_updates={
1205
+ "cat": {
1206
+ "unconfirmed_wallet_balance": 8,
1207
+ "pending_coin_removal_count": 1,
1208
+ "pending_change": 8, # This is a little weird but fits the current definition
1209
+ },
1210
+ "vc": {
1211
+ "pending_coin_removal_count": 1,
1212
+ },
1213
+ },
1214
+ pre_block_additional_balance_info={
1215
+ "cat": {
1216
+ "pending_approval_balance": 8,
1217
+ },
1218
+ },
1219
+ post_block_balance_updates={
1220
+ "cat": {
1221
+ "confirmed_wallet_balance": 8,
1222
+ "spendable_balance": 8,
1223
+ "max_send_amount": 8,
1224
+ "pending_change": -8,
1225
+ "unspent_coin_count": 1,
1226
+ "pending_coin_removal_count": -1,
1227
+ },
1228
+ "vc": {
1229
+ "pending_coin_removal_count": -1,
1230
+ },
1231
+ },
1232
+ post_block_additional_balance_info={
1233
+ "cat": {
1234
+ "pending_approval_balance": 0,
1235
+ },
1236
+ },
1237
+ ),
1238
+ WalletStateTransition(),
1239
+ ]
1240
+ )
1241
+
1242
+ await client_maker.crcat_approve_pending(
1243
+ new_cat_wallet_maker.id(),
1244
+ uint64(9),
1245
+ wallet_environments.tx_config,
1246
+ )
1247
+
1248
+ await wallet_environments.process_pending_states(
1249
+ [
1250
+ WalletStateTransition(
1251
+ pre_block_balance_updates={
1252
+ "new cat": {
1253
+ "unconfirmed_wallet_balance": 9,
1254
+ "pending_coin_removal_count": 1,
1255
+ "pending_change": 9, # This is a little weird but fits the current definition
1256
+ },
1257
+ "vc": {
1258
+ "pending_coin_removal_count": 1,
1259
+ },
1260
+ },
1261
+ pre_block_additional_balance_info={
1262
+ "new cat": {
1263
+ "pending_approval_balance": 9,
1264
+ }
1265
+ },
1266
+ post_block_balance_updates={
1267
+ "new cat": {
1268
+ "confirmed_wallet_balance": 9,
1269
+ "spendable_balance": 9,
1270
+ "max_send_amount": 9,
1271
+ "pending_change": -9,
1272
+ "unspent_coin_count": 1,
1273
+ "pending_coin_removal_count": -1,
1274
+ },
1275
+ "vc": {
1276
+ "pending_coin_removal_count": -1,
1277
+ },
1278
+ },
1279
+ post_block_additional_balance_info={
1280
+ "new cat": {
1281
+ "pending_approval_balance": 0,
1282
+ }
1283
+ },
1284
+ ),
1285
+ WalletStateTransition(),
1286
+ ]
1287
+ )
1288
+
1289
+ # multiple_cat_for_chia
1290
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
1291
+ wallet_environments.tx_config, push=False
1292
+ ) as action_scope:
1293
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(
1294
+ multiple_cat_for_chia,
1295
+ action_scope,
1296
+ )
1297
+ assert error is None
1298
+ assert success is True
1299
+ assert trade_make is not None
1300
+ [maker_offer], signing_response = await wallet_node_maker.wallet_state_manager.sign_offers(
1301
+ [Offer.from_bytes(trade_make.offer)]
1302
+ )
1303
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
1304
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
1305
+ ) as action_scope:
1306
+ trade_take = await trade_manager_taker.respond_to_offer(
1307
+ Offer.from_bytes(trade_make.offer),
1308
+ peer,
1309
+ action_scope,
1310
+ )
1311
+
1312
+ if test_aggregation:
1313
+ fourth_offer = Offer.from_bytes(trade_take.offer)
1314
+
1315
+ await wallet_environments.process_pending_states(
1316
+ [
1317
+ WalletStateTransition(
1318
+ pre_block_balance_updates={
1319
+ "cat": {
1320
+ "pending_coin_removal_count": 1,
1321
+ "<=#spendable_balance": -11,
1322
+ "<=#max_send_amount": -11,
1323
+ # Unconfirmed balance doesn't change because offer may not complete
1324
+ "unconfirmed_wallet_balance": 0,
1325
+ },
1326
+ "new cat": {
1327
+ "pending_coin_removal_count": 2,
1328
+ "<=#spendable_balance": -12,
1329
+ "<=#max_send_amount": -12,
1330
+ # Unconfirmed balance doesn't change because offer may not complete
1331
+ "unconfirmed_wallet_balance": 0,
1332
+ },
1333
+ },
1334
+ post_block_balance_updates={
1335
+ "xch": {
1336
+ "confirmed_wallet_balance": 10,
1337
+ "unconfirmed_wallet_balance": 10,
1338
+ "spendable_balance": 10,
1339
+ "max_send_amount": 10,
1340
+ "unspent_coin_count": 1,
1341
+ },
1342
+ "cat": {
1343
+ "pending_coin_removal_count": -1,
1344
+ ">#spendable_balance": 0,
1345
+ ">#max_send_amount": 0,
1346
+ "unconfirmed_wallet_balance": -11,
1347
+ "confirmed_wallet_balance": -11,
1348
+ },
1349
+ "new cat": {
1350
+ "pending_coin_removal_count": -2,
1351
+ ">#spendable_balance": 0,
1352
+ ">#max_send_amount": 0,
1353
+ "unconfirmed_wallet_balance": -12,
1354
+ "confirmed_wallet_balance": -12,
1355
+ "unspent_coin_count": -1,
1356
+ },
1357
+ },
1358
+ ),
1359
+ WalletStateTransition(
1360
+ pre_block_balance_updates={
1361
+ "xch": {
1362
+ "unconfirmed_wallet_balance": -10,
1363
+ "<=#spendable_balance": -10,
1364
+ "<=#max_send_amount": -10,
1365
+ "pending_coin_removal_count": 1,
1366
+ ">=#pending_change": 1, # any amount increase
1367
+ },
1368
+ "cat": {
1369
+ "unconfirmed_wallet_balance": 11,
1370
+ },
1371
+ "new cat": {
1372
+ "unconfirmed_wallet_balance": 12,
1373
+ },
1374
+ **(
1375
+ {
1376
+ "vc": {
1377
+ "pending_coin_removal_count": 1,
1378
+ }
1379
+ }
1380
+ if credential_restricted
1381
+ else {}
1382
+ ),
1383
+ },
1384
+ post_block_balance_updates={
1385
+ "xch": {
1386
+ "confirmed_wallet_balance": -10,
1387
+ ">#spendable_balance": 0,
1388
+ ">#max_send_amount": 0,
1389
+ "pending_coin_removal_count": -1,
1390
+ "<=#pending_change": 1, # any amount increase
1391
+ },
1392
+ "cat": {
1393
+ "confirmed_wallet_balance": 11,
1394
+ "spendable_balance": 11,
1395
+ "max_send_amount": 11,
1396
+ "unspent_coin_count": 1,
1397
+ },
1398
+ "new cat": {
1399
+ "confirmed_wallet_balance": 12,
1400
+ "spendable_balance": 12,
1401
+ "max_send_amount": 12,
1402
+ "unspent_coin_count": 1,
1403
+ },
1404
+ **(
1405
+ {
1406
+ "vc": {
1407
+ "pending_coin_removal_count": -1,
1408
+ }
1409
+ }
1410
+ if credential_restricted
1411
+ else {}
1412
+ ),
1413
+ },
1414
+ ),
1415
+ ]
1416
+ )
1417
+
1418
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
1419
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, trade_take)
1420
+
1421
+ # chia_and_cat_for_cat
1422
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
1423
+ wallet_environments.tx_config, push=False
1424
+ ) as action_scope:
1425
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(
1426
+ chia_and_cat_for_cat,
1427
+ action_scope,
1428
+ )
1429
+ assert error is None
1430
+ assert success is True
1431
+ assert trade_make is not None
1432
+
1433
+ [maker_offer], signing_response = await wallet_node_maker.wallet_state_manager.sign_offers(
1434
+ [Offer.from_bytes(trade_make.offer)]
1435
+ )
1436
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
1437
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
1438
+ ) as action_scope:
1439
+ trade_take = await trade_manager_taker.respond_to_offer(
1440
+ Offer.from_bytes(trade_make.offer),
1441
+ peer,
1442
+ action_scope,
1443
+ )
1444
+
1445
+ if test_aggregation:
1446
+ fifth_offer = Offer.from_bytes(trade_take.offer)
1447
+
1448
+ await wallet_environments.process_pending_states(
1449
+ [
1450
+ WalletStateTransition(
1451
+ pre_block_balance_updates={
1452
+ "xch": {
1453
+ "pending_coin_removal_count": 2,
1454
+ "<=#spendable_balance": -13,
1455
+ "<=#max_send_amount": -13,
1456
+ # Unconfirmed balance doesn't change because offer may not complete
1457
+ "unconfirmed_wallet_balance": 0,
1458
+ },
1459
+ "cat": {
1460
+ "pending_coin_removal_count": 1,
1461
+ "<=#spendable_balance": -14,
1462
+ "<=#max_send_amount": -14,
1463
+ # Unconfirmed balance doesn't change because offer may not complete
1464
+ "unconfirmed_wallet_balance": 0,
1465
+ },
1466
+ },
1467
+ post_block_balance_updates={
1468
+ "xch": {
1469
+ "confirmed_wallet_balance": -13,
1470
+ "unconfirmed_wallet_balance": -13,
1471
+ ">=#spendable_balance": 0,
1472
+ ">=#max_send_amount": 0,
1473
+ "unspent_coin_count": -2,
1474
+ "pending_coin_removal_count": -2,
1475
+ },
1476
+ "cat": {
1477
+ "pending_coin_removal_count": -1,
1478
+ ">=#spendable_balance": 0,
1479
+ ">=#max_send_amount": 0,
1480
+ "unconfirmed_wallet_balance": -14,
1481
+ "confirmed_wallet_balance": -14,
1482
+ },
1483
+ "new cat": (
1484
+ {
1485
+ "spendable_balance": 0,
1486
+ "max_send_amount": 0,
1487
+ "unconfirmed_wallet_balance": 0,
1488
+ "confirmed_wallet_balance": 0,
1489
+ "unspent_coin_count": 0,
1490
+ }
1491
+ if credential_restricted
1492
+ else {
1493
+ "spendable_balance": 15,
1494
+ "max_send_amount": 15,
1495
+ "unconfirmed_wallet_balance": 15,
1496
+ "confirmed_wallet_balance": 15,
1497
+ "unspent_coin_count": 1,
1498
+ }
1499
+ ),
1500
+ },
1501
+ ),
1502
+ WalletStateTransition(
1503
+ pre_block_balance_updates={
1504
+ "xch": {
1505
+ "unconfirmed_wallet_balance": 13,
1506
+ },
1507
+ "cat": {
1508
+ "unconfirmed_wallet_balance": 14,
1509
+ },
1510
+ "new cat": {
1511
+ "unconfirmed_wallet_balance": -15,
1512
+ "pending_change": 68,
1513
+ "<=#spendable_balance": -15,
1514
+ "<=#max_send_amount": -15,
1515
+ "pending_coin_removal_count": 1,
1516
+ },
1517
+ **(
1518
+ {
1519
+ "vc": {
1520
+ "pending_coin_removal_count": 1,
1521
+ }
1522
+ }
1523
+ if credential_restricted
1524
+ else {}
1525
+ ),
1526
+ },
1527
+ post_block_balance_updates={
1528
+ "xch": {
1529
+ "confirmed_wallet_balance": 13,
1530
+ "spendable_balance": 13,
1531
+ "max_send_amount": 13,
1532
+ "unspent_coin_count": 1,
1533
+ },
1534
+ "cat": {
1535
+ "confirmed_wallet_balance": 14,
1536
+ "spendable_balance": 14,
1537
+ "max_send_amount": 14,
1538
+ "unspent_coin_count": 1,
1539
+ },
1540
+ "new cat": {
1541
+ "confirmed_wallet_balance": -15,
1542
+ "pending_change": -68,
1543
+ ">#spendable_balance": 0,
1544
+ ">#max_send_amount": 0,
1545
+ "pending_coin_removal_count": -1,
1546
+ },
1547
+ **(
1548
+ {
1549
+ "vc": {
1550
+ "pending_coin_removal_count": -1,
1551
+ }
1552
+ }
1553
+ if credential_restricted
1554
+ else {}
1555
+ ),
1556
+ },
1557
+ ),
1558
+ ]
1559
+ )
1560
+
1561
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
1562
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, trade_take)
1563
+
1564
+ if credential_restricted:
1565
+ await client_maker.crcat_approve_pending(
1566
+ new_cat_wallet_maker.id(),
1567
+ uint64(15),
1568
+ wallet_environments.tx_config,
1569
+ )
1570
+
1571
+ await wallet_environments.process_pending_states(
1572
+ [
1573
+ WalletStateTransition(
1574
+ pre_block_balance_updates={
1575
+ "new cat": {
1576
+ "unconfirmed_wallet_balance": 15,
1577
+ "pending_coin_removal_count": 1,
1578
+ "pending_change": 15, # This is a little weird but fits the current definition
1579
+ },
1580
+ "vc": {
1581
+ "pending_coin_removal_count": 1,
1582
+ },
1583
+ },
1584
+ pre_block_additional_balance_info={
1585
+ "new cat": {
1586
+ "pending_approval_balance": 15,
1587
+ }
1588
+ },
1589
+ post_block_balance_updates={
1590
+ "new cat": {
1591
+ "confirmed_wallet_balance": 15,
1592
+ "spendable_balance": 15,
1593
+ "max_send_amount": 15,
1594
+ "pending_change": -15,
1595
+ "unspent_coin_count": 1,
1596
+ "pending_coin_removal_count": -1,
1597
+ },
1598
+ "vc": {
1599
+ "pending_coin_removal_count": -1,
1600
+ },
1601
+ },
1602
+ post_block_additional_balance_info={
1603
+ "new cat": {
1604
+ "pending_approval_balance": 0,
1605
+ }
1606
+ },
1607
+ ),
1608
+ WalletStateTransition(),
1609
+ ]
1610
+ )
1611
+
1612
+ if test_aggregation:
1613
+ # This tests an edge case where aggregated offers the include > 2 of the same kind of CAT
1614
+ # (and therefore are solved as a complete ring)
1615
+ bundle = Offer.aggregate([first_offer, second_offer, third_offer, fourth_offer, fifth_offer]).to_valid_spend()
1616
+ program = simple_solution_generator(bundle)
1617
+ result: NPCResult = get_name_puzzle_conditions(
1618
+ program, INFINITE_COST, mempool_mode=True, height=active_softfork_height, constants=DEFAULT_CONSTANTS
1619
+ )
1620
+ assert result.error is None
1621
+
1622
+
1623
+ @pytest.mark.parametrize(
1624
+ "wallet_environments",
1625
+ [
1626
+ {
1627
+ "num_environments": 2,
1628
+ "blocks_needed": [2, 1],
1629
+ }
1630
+ ],
1631
+ indirect=True,
1632
+ )
1633
+ @pytest.mark.limit_consensus_modes(reason="irrelevant")
1634
+ @pytest.mark.anyio
1635
+ async def test_trade_cancellation(wallet_environments: WalletTestFramework) -> None:
1636
+ env_maker = wallet_environments.environments[0]
1637
+ env_taker = wallet_environments.environments[1]
1638
+
1639
+ env_maker.wallet_aliases = {
1640
+ "xch": 1,
1641
+ "cat": 2,
1642
+ }
1643
+ env_taker.wallet_aliases = {
1644
+ "xch": 1,
1645
+ "cat": 2,
1646
+ }
1647
+
1648
+ xch_to_cat_amount = uint64(100)
1649
+
1650
+ async with env_maker.wallet_state_manager.new_action_scope(
1651
+ wallet_environments.tx_config, push=True
1652
+ ) as action_scope:
1653
+ cat_wallet_maker = await CATWallet.create_new_cat_wallet(
1654
+ env_maker.wallet_state_manager,
1655
+ env_maker.xch_wallet,
1656
+ {"identifier": "genesis_by_id"},
1657
+ xch_to_cat_amount,
1658
+ action_scope,
1659
+ )
1660
+
1661
+ await wallet_environments.process_pending_states(
1662
+ [
1663
+ # tests in test_cat_wallet.py
1664
+ WalletStateTransition(
1665
+ pre_block_balance_updates={
1666
+ "xch": {"set_remainder": True},
1667
+ "cat": {"init": True, "set_remainder": True},
1668
+ },
1669
+ post_block_balance_updates={
1670
+ "xch": {"set_remainder": True},
1671
+ "cat": {"set_remainder": True},
1672
+ },
1673
+ ),
1674
+ WalletStateTransition(),
1675
+ ]
1676
+ )
1677
+
1678
+ cat_for_chia: OfferSummary = {
1679
+ env_maker.wallet_aliases["xch"]: 1,
1680
+ env_maker.wallet_aliases["cat"]: -2,
1681
+ }
1682
+
1683
+ chia_for_cat: OfferSummary = {
1684
+ env_maker.wallet_aliases["xch"]: -3,
1685
+ env_maker.wallet_aliases["cat"]: 4,
1686
+ }
1687
+
1688
+ trade_manager_maker = env_maker.wallet_state_manager.trade_manager
1689
+ trade_manager_taker = env_taker.wallet_state_manager.trade_manager
1690
+
1691
+ async with env_maker.wallet_state_manager.new_action_scope(
1692
+ wallet_environments.tx_config, push=False
1693
+ ) as action_scope:
1694
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(cat_for_chia, action_scope)
1695
+ assert error is None
1696
+ assert success is True
1697
+ assert trade_make is not None
1698
+
1699
+ # Cancelling the trade and trying an ID that doesn't exist just in case
1700
+ async with env_maker.wallet_state_manager.new_action_scope(
1701
+ wallet_environments.tx_config, push=False
1702
+ ) as action_scope:
1703
+ await trade_manager_maker.cancel_pending_offers(
1704
+ [trade_make.trade_id, bytes32([0] * 32)], action_scope, secure=False
1705
+ )
1706
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
1707
+
1708
+ # Due to current mempool rules, trying to force a take out of the mempool with a cancel will not work.
1709
+ # Uncomment this when/if it does
1710
+
1711
+ # [maker_offer], signing_response = await wallet_node_maker.wallet_state_manager.sign_offers(
1712
+ # [Offer.from_bytes(trade_make.offer)]
1713
+ # )
1714
+ # trade_take = await trade_manager_taker.respond_to_offer(
1715
+ # maker_offer,
1716
+ # )
1717
+ # tx_records = await wallet_taker.wallet_state_manager.add_pending_transactions(
1718
+ # action_scope.side_effects.transactions,
1719
+ # additional_signing_responses=signing_response,
1720
+ # )
1721
+ # await time_out_assert(15, full_node.txs_in_mempool, True, tx_records)
1722
+ # assert trade_take is not None
1723
+ # assert tx_records is not None
1724
+ # await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CONFIRM, trade_manager_taker, trade_take)
1725
+ # await time_out_assert(
1726
+ # 15,
1727
+ # full_node.tx_id_in_mempool,
1728
+ # True,
1729
+ # Offer.from_bytes(trade_take.offer).to_valid_spend().name(),
1730
+ # )
1731
+
1732
+ fee = uint64(2_000_000_000_000)
1733
+
1734
+ async with env_maker.wallet_state_manager.new_action_scope(
1735
+ wallet_environments.tx_config, push=True
1736
+ ) as action_scope:
1737
+ await trade_manager_maker.cancel_pending_offers([trade_make.trade_id], action_scope, fee=fee, secure=True)
1738
+ await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
1739
+
1740
+ await wallet_environments.process_pending_states(
1741
+ [
1742
+ WalletStateTransition(
1743
+ pre_block_balance_updates={
1744
+ "xch": {
1745
+ "unconfirmed_wallet_balance": -fee,
1746
+ "<=#spendable_balance": -fee,
1747
+ "<=#max_send_amount": -fee,
1748
+ ">=#pending_change": 0,
1749
+ ">=#pending_coin_removal_count": 2,
1750
+ },
1751
+ "cat": {
1752
+ "spendable_balance": -xch_to_cat_amount,
1753
+ "pending_change": xch_to_cat_amount,
1754
+ "max_send_amount": -xch_to_cat_amount,
1755
+ "pending_coin_removal_count": 1,
1756
+ },
1757
+ },
1758
+ post_block_balance_updates={
1759
+ "xch": {
1760
+ "confirmed_wallet_balance": -fee,
1761
+ ">=#spendable_balance": 0,
1762
+ ">=#max_send_amount": 0,
1763
+ "<=#pending_change": 0,
1764
+ "<=#pending_coin_removal_count": 1,
1765
+ "<=#unspent_coin_count": 0,
1766
+ },
1767
+ "cat": {
1768
+ "spendable_balance": xch_to_cat_amount,
1769
+ "pending_change": -xch_to_cat_amount,
1770
+ "max_send_amount": xch_to_cat_amount,
1771
+ "pending_coin_removal_count": -1,
1772
+ },
1773
+ },
1774
+ ),
1775
+ WalletStateTransition(),
1776
+ ]
1777
+ )
1778
+
1779
+ sum_of_outgoing = uint64(0)
1780
+ sum_of_incoming = uint64(0)
1781
+ for tx in action_scope.side_effects.transactions:
1782
+ if tx.type == TransactionType.OUTGOING_TX.value:
1783
+ sum_of_outgoing = uint64(sum_of_outgoing + tx.amount)
1784
+ elif tx.type == TransactionType.INCOMING_TX.value:
1785
+ sum_of_incoming = uint64(sum_of_incoming + tx.amount)
1786
+ assert (sum_of_outgoing - sum_of_incoming) == 0
1787
+
1788
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
1789
+ # await time_out_assert(15, get_trade_and_status, TradeStatus.FAILED, trade_manager_taker, trade_take)
1790
+
1791
+ peer = env_taker.node.get_full_node_peer()
1792
+ with pytest.raises(ValueError, match="This offer is no longer valid"):
1793
+ async with env_taker.wallet_state_manager.new_action_scope(
1794
+ wallet_environments.tx_config, push=False
1795
+ ) as action_scope:
1796
+ await trade_manager_taker.respond_to_offer(Offer.from_bytes(trade_make.offer), peer, action_scope)
1797
+
1798
+ # Now we're going to create the other way around for test coverage sake
1799
+ async with env_maker.wallet_state_manager.new_action_scope(
1800
+ wallet_environments.tx_config, push=False
1801
+ ) as action_scope:
1802
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(chia_for_cat, action_scope)
1803
+ assert error is None
1804
+ assert success is True
1805
+ assert trade_make is not None
1806
+
1807
+ # This take should fail since we have no CATs to fulfill it with
1808
+ with pytest.raises(
1809
+ ValueError,
1810
+ match=f"Do not have a wallet for asset ID: {cat_wallet_maker.get_asset_id()} to fulfill offer",
1811
+ ):
1812
+ async with env_taker.wallet_state_manager.new_action_scope(
1813
+ wallet_environments.tx_config, push=False
1814
+ ) as action_scope:
1815
+ await trade_manager_taker.respond_to_offer(Offer.from_bytes(trade_make.offer), peer, action_scope)
1816
+
1817
+ async with env_maker.wallet_state_manager.new_action_scope(
1818
+ wallet_environments.tx_config, push=True
1819
+ ) as action_scope:
1820
+ await trade_manager_maker.cancel_pending_offers([trade_make.trade_id], action_scope, fee=uint64(0), secure=True)
1821
+ await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
1822
+
1823
+ await wallet_environments.process_pending_states(
1824
+ [
1825
+ WalletStateTransition(
1826
+ pre_block_balance_updates={
1827
+ "xch": {
1828
+ "<=#spendable_balance": chia_for_cat[env_maker.wallet_aliases["xch"]],
1829
+ "<=#max_send_amount": chia_for_cat[env_maker.wallet_aliases["xch"]],
1830
+ ">=#pending_change": 1,
1831
+ "pending_coin_removal_count": 1,
1832
+ },
1833
+ "cat": {},
1834
+ },
1835
+ post_block_balance_updates={
1836
+ "xch": {
1837
+ ">=#spendable_balance": 1,
1838
+ ">=#max_send_amount": 1,
1839
+ "<=#pending_change": -1,
1840
+ "pending_coin_removal_count": -1,
1841
+ },
1842
+ "cat": {},
1843
+ },
1844
+ )
1845
+ ]
1846
+ )
1847
+
1848
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
1849
+
1850
+ # Now let's test the case where two coins need to be spent in order to cancel
1851
+ chia_and_cat_for_something: OfferSummary = {
1852
+ env_maker.wallet_aliases["xch"]: -5,
1853
+ env_maker.wallet_aliases["cat"]: -6,
1854
+ bytes32([0] * 32): 1, # Doesn't matter
1855
+ }
1856
+
1857
+ # Now we're going to create the other way around for test coverage sake
1858
+ async with env_maker.wallet_state_manager.new_action_scope(
1859
+ wallet_environments.tx_config, push=False
1860
+ ) as action_scope:
1861
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(
1862
+ chia_and_cat_for_something,
1863
+ action_scope,
1864
+ driver_dict={bytes32([0] * 32): PuzzleInfo({"type": AssetType.CAT.value, "tail": "0x" + bytes(32).hex()})},
1865
+ )
1866
+ assert error is None
1867
+ assert success is True
1868
+ assert trade_make is not None
1869
+
1870
+ async with env_maker.wallet_state_manager.new_action_scope(
1871
+ wallet_environments.tx_config, push=True
1872
+ ) as action_scope:
1873
+ await trade_manager_maker.cancel_pending_offers([trade_make.trade_id], action_scope, fee=uint64(0), secure=True)
1874
+
1875
+ # Check an announcement ring has been created
1876
+ total_spend = SpendBundle.aggregate(
1877
+ [tx.spend_bundle for tx in action_scope.side_effects.transactions if tx.spend_bundle is not None]
1878
+ )
1879
+ all_conditions: List[Program] = []
1880
+ creations: List[CreateCoinAnnouncement] = []
1881
+ announcement_nonce = std_hash(trade_make.trade_id)
1882
+ for spend in total_spend.coin_spends:
1883
+ all_conditions.extend(
1884
+ [
1885
+ c.to_program()
1886
+ for c in parse_conditions_non_consensus(
1887
+ spend.puzzle_reveal.to_program().run(spend.solution.to_program()).as_iter(), abstractions=False
1888
+ )
1889
+ ]
1890
+ )
1891
+ creations.append(CreateCoinAnnouncement(msg=announcement_nonce, coin_id=spend.coin.name()))
1892
+ for creation in creations:
1893
+ assert creation.corresponding_assertion().to_program() in all_conditions
1894
+
1895
+ await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
1896
+
1897
+ await wallet_environments.process_pending_states(
1898
+ [
1899
+ WalletStateTransition(
1900
+ pre_block_balance_updates={
1901
+ "xch": {
1902
+ "<=#spendable_balance": chia_and_cat_for_something[env_maker.wallet_aliases["xch"]],
1903
+ "<=#max_send_amount": chia_and_cat_for_something[env_maker.wallet_aliases["xch"]],
1904
+ ">=#pending_change": 1,
1905
+ "pending_coin_removal_count": 1,
1906
+ },
1907
+ "cat": {
1908
+ "spendable_balance": -xch_to_cat_amount,
1909
+ "pending_change": xch_to_cat_amount,
1910
+ "max_send_amount": -xch_to_cat_amount,
1911
+ "pending_coin_removal_count": 1,
1912
+ },
1913
+ },
1914
+ post_block_balance_updates={
1915
+ "xch": {
1916
+ ">=#spendable_balance": 1,
1917
+ ">=#max_send_amount": 1,
1918
+ "<=#pending_change": -1,
1919
+ "pending_coin_removal_count": -1,
1920
+ },
1921
+ "cat": {
1922
+ "spendable_balance": xch_to_cat_amount,
1923
+ "pending_change": -xch_to_cat_amount,
1924
+ "max_send_amount": xch_to_cat_amount,
1925
+ "pending_coin_removal_count": -1,
1926
+ },
1927
+ },
1928
+ )
1929
+ ]
1930
+ )
1931
+
1932
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
1933
+
1934
+
1935
+ @pytest.mark.parametrize(
1936
+ "wallet_environments",
1937
+ [
1938
+ {
1939
+ "num_environments": 3,
1940
+ "blocks_needed": [2, 1, 1],
1941
+ }
1942
+ ],
1943
+ indirect=True,
1944
+ )
1945
+ @pytest.mark.limit_consensus_modes(reason="irrelevant")
1946
+ @pytest.mark.anyio
1947
+ async def test_trade_conflict(wallet_environments: WalletTestFramework) -> None:
1948
+ env_maker = wallet_environments.environments[0]
1949
+ env_taker = wallet_environments.environments[1]
1950
+ env_trader = wallet_environments.environments[2]
1951
+
1952
+ env_maker.wallet_aliases = {
1953
+ "xch": 1,
1954
+ "cat": 2,
1955
+ }
1956
+ env_taker.wallet_aliases = {
1957
+ "xch": 1,
1958
+ "cat": 2,
1959
+ }
1960
+ env_trader.wallet_aliases = {
1961
+ "xch": 1,
1962
+ "cat": 2,
1963
+ }
1964
+
1965
+ xch_to_cat_amount = uint64(100)
1966
+ fee = uint64(10)
1967
+
1968
+ async with env_maker.wallet_state_manager.new_action_scope(
1969
+ wallet_environments.tx_config, push=True
1970
+ ) as action_scope:
1971
+ await CATWallet.create_new_cat_wallet(
1972
+ env_maker.wallet_state_manager,
1973
+ env_maker.xch_wallet,
1974
+ {"identifier": "genesis_by_id"},
1975
+ xch_to_cat_amount,
1976
+ action_scope,
1977
+ )
1978
+
1979
+ await wallet_environments.process_pending_states(
1980
+ [
1981
+ # tests in test_cat_wallet.py
1982
+ WalletStateTransition(
1983
+ pre_block_balance_updates={
1984
+ "xch": {"set_remainder": True},
1985
+ "cat": {"init": True, "set_remainder": True},
1986
+ },
1987
+ post_block_balance_updates={
1988
+ "xch": {"set_remainder": True},
1989
+ "cat": {"set_remainder": True},
1990
+ },
1991
+ ),
1992
+ WalletStateTransition(),
1993
+ ]
1994
+ )
1995
+
1996
+ cat_for_chia: OfferSummary = {
1997
+ env_maker.wallet_aliases["xch"]: 1000,
1998
+ env_maker.wallet_aliases["cat"]: -4,
1999
+ }
2000
+
2001
+ trade_manager_maker = env_maker.node.wallet_state_manager.trade_manager
2002
+ trade_manager_taker = env_taker.wallet_state_manager.trade_manager
2003
+ trade_manager_trader = env_trader.wallet_state_manager.trade_manager
2004
+
2005
+ async with env_maker.wallet_state_manager.new_action_scope(
2006
+ wallet_environments.tx_config, push=False
2007
+ ) as action_scope:
2008
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(cat_for_chia, action_scope)
2009
+ await time_out_assert(10, get_trade_and_status, TradeStatus.PENDING_ACCEPT, trade_manager_maker, trade_make)
2010
+ assert error is None
2011
+ assert success is True
2012
+ assert trade_make is not None
2013
+ peer = env_taker.node.get_full_node_peer()
2014
+ offer = Offer.from_bytes(trade_make.offer)
2015
+ [offer], signing_response = await env_maker.wallet_state_manager.sign_offers([offer])
2016
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
2017
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
2018
+ ) as action_scope:
2019
+ tr1 = await trade_manager_taker.respond_to_offer(offer, peer, action_scope, fee=fee)
2020
+
2021
+ await wallet_environments.full_node.wait_transaction_records_entered_mempool(
2022
+ records=action_scope.side_effects.transactions
2023
+ )
2024
+
2025
+ # we shouldn't be able to respond to a duplicate offer
2026
+ with pytest.raises(ValueError):
2027
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
2028
+ wallet_environments.tx_config, push=False
2029
+ ) as action_scope:
2030
+ await trade_manager_taker.respond_to_offer(offer, peer, action_scope, fee=fee)
2031
+ await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CONFIRM, trade_manager_taker, tr1)
2032
+ # pushing into mempool while already in it should fail
2033
+ [offer], signing_response = await env_maker.wallet_state_manager.sign_offers([offer])
2034
+ async with trade_manager_trader.wallet_state_manager.new_action_scope(
2035
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
2036
+ ) as action_scope:
2037
+ tr2 = await trade_manager_trader.respond_to_offer(offer, peer, action_scope, fee=fee)
2038
+ assert await trade_manager_trader.get_coins_of_interest()
2039
+ await wallet_environments.process_pending_states(
2040
+ [
2041
+ WalletStateTransition(
2042
+ pre_block_balance_updates={
2043
+ "cat": {
2044
+ "<=#spendable_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2045
+ "<=#max_send_amount": cat_for_chia[env_maker.wallet_aliases["cat"]],
2046
+ "pending_change": 0,
2047
+ "pending_coin_removal_count": 1,
2048
+ }
2049
+ },
2050
+ post_block_balance_updates={
2051
+ "xch": {
2052
+ "unconfirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["xch"]],
2053
+ "confirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["xch"]],
2054
+ ">=#spendable_balance": 1,
2055
+ ">=#max_send_amount": 1,
2056
+ "pending_change": 0,
2057
+ "unspent_coin_count": 1,
2058
+ },
2059
+ "cat": {
2060
+ "unconfirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2061
+ "confirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2062
+ ">=#spendable_balance": 1,
2063
+ ">=#max_send_amount": 1,
2064
+ "pending_change": 0,
2065
+ "pending_coin_removal_count": -1,
2066
+ },
2067
+ },
2068
+ ),
2069
+ WalletStateTransition(
2070
+ pre_block_balance_updates={
2071
+ "xch": {
2072
+ "unconfirmed_wallet_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2073
+ "<=#spendable_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2074
+ "<=#max_send_amount": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2075
+ ">=#pending_change": 1,
2076
+ "pending_coin_removal_count": 1,
2077
+ },
2078
+ "cat": {
2079
+ "init": True,
2080
+ "unconfirmed_wallet_balance": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2081
+ },
2082
+ },
2083
+ post_block_balance_updates={
2084
+ "xch": {
2085
+ "confirmed_wallet_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2086
+ ">=#spendable_balance": 1,
2087
+ ">=#max_send_amount": 1,
2088
+ "<=#pending_change": -1,
2089
+ "pending_coin_removal_count": -1,
2090
+ },
2091
+ "cat": {
2092
+ "confirmed_wallet_balance": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2093
+ "spendable_balance": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2094
+ "max_send_amount": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2095
+ "unspent_coin_count": 1,
2096
+ },
2097
+ },
2098
+ ),
2099
+ WalletStateTransition(
2100
+ pre_block_balance_updates={
2101
+ "xch": {
2102
+ "unconfirmed_wallet_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2103
+ "<=#spendable_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2104
+ "<=#max_send_amount": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2105
+ ">=#pending_change": 1,
2106
+ "pending_coin_removal_count": 1,
2107
+ },
2108
+ "cat": {
2109
+ "init": True,
2110
+ "unconfirmed_wallet_balance": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2111
+ },
2112
+ },
2113
+ post_block_balance_updates={
2114
+ "xch": {
2115
+ "unconfirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["xch"]] + fee,
2116
+ ">=#spendable_balance": cat_for_chia[env_maker.wallet_aliases["xch"]] + fee,
2117
+ ">=#max_send_amount": cat_for_chia[env_maker.wallet_aliases["xch"]] + fee,
2118
+ "<=#pending_change": -1,
2119
+ "pending_coin_removal_count": -1,
2120
+ },
2121
+ "cat": {
2122
+ "unconfirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2123
+ },
2124
+ },
2125
+ ),
2126
+ ],
2127
+ invalid_transactions=[tx.name for tx in action_scope.side_effects.transactions],
2128
+ )
2129
+ await time_out_assert(15, get_trade_and_status, TradeStatus.FAILED, trade_manager_trader, tr2)
2130
+
2131
+
2132
+ @pytest.mark.parametrize(
2133
+ "wallet_environments",
2134
+ [
2135
+ {
2136
+ "num_environments": 2,
2137
+ "blocks_needed": [1, 1],
2138
+ }
2139
+ ],
2140
+ indirect=True,
2141
+ )
2142
+ @pytest.mark.limit_consensus_modes(reason="irrelevant")
2143
+ @pytest.mark.anyio
2144
+ async def test_trade_bad_spend(wallet_environments: WalletTestFramework) -> None:
2145
+ env_maker = wallet_environments.environments[0]
2146
+ env_taker = wallet_environments.environments[1]
2147
+
2148
+ env_maker.wallet_aliases = {
2149
+ "xch": 1,
2150
+ "cat": 2,
2151
+ }
2152
+ env_taker.wallet_aliases = {
2153
+ "xch": 1,
2154
+ "cat": 2,
2155
+ }
2156
+
2157
+ xch_to_cat_amount = uint64(100)
2158
+
2159
+ async with env_maker.wallet_state_manager.new_action_scope(
2160
+ wallet_environments.tx_config, push=True
2161
+ ) as action_scope:
2162
+ await CATWallet.create_new_cat_wallet(
2163
+ env_maker.wallet_state_manager,
2164
+ env_maker.xch_wallet,
2165
+ {"identifier": "genesis_by_id"},
2166
+ xch_to_cat_amount,
2167
+ action_scope,
2168
+ )
2169
+
2170
+ await wallet_environments.process_pending_states(
2171
+ [
2172
+ # tests in test_cat_wallet.py
2173
+ WalletStateTransition(
2174
+ pre_block_balance_updates={
2175
+ "xch": {"set_remainder": True},
2176
+ "cat": {"init": True, "set_remainder": True},
2177
+ },
2178
+ post_block_balance_updates={
2179
+ "xch": {"set_remainder": True},
2180
+ "cat": {"set_remainder": True},
2181
+ },
2182
+ ),
2183
+ WalletStateTransition(),
2184
+ ]
2185
+ )
2186
+
2187
+ cat_for_chia: OfferSummary = {
2188
+ env_maker.wallet_aliases["xch"]: 1000,
2189
+ env_maker.wallet_aliases["cat"]: -4,
2190
+ }
2191
+
2192
+ trade_manager_maker = env_maker.wallet_state_manager.trade_manager
2193
+ trade_manager_taker = env_taker.wallet_state_manager.trade_manager
2194
+
2195
+ async with env_maker.wallet_state_manager.new_action_scope(
2196
+ wallet_environments.tx_config, push=False
2197
+ ) as action_scope:
2198
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(cat_for_chia, action_scope)
2199
+ await time_out_assert(30, get_trade_and_status, TradeStatus.PENDING_ACCEPT, trade_manager_maker, trade_make)
2200
+ assert error is None
2201
+ assert success is True
2202
+ assert trade_make is not None
2203
+ peer = env_taker.node.get_full_node_peer()
2204
+ offer = Offer.from_bytes(trade_make.offer)
2205
+ bundle = WalletSpendBundle(coin_spends=offer._bundle.coin_spends, aggregated_signature=G2Element())
2206
+ offer = dataclasses.replace(offer, _bundle=bundle)
2207
+ fee = uint64(10)
2208
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
2209
+ wallet_environments.tx_config, push=True, sign=False
2210
+ ) as action_scope:
2211
+ tr1 = await trade_manager_taker.respond_to_offer(offer, peer, action_scope, fee=fee)
2212
+ env_taker.node.wallet_tx_resend_timeout_secs = 0 # don't wait for resend
2213
+
2214
+ def check_wallet_cache_empty() -> bool:
2215
+ return env_taker.node._tx_messages_in_progress == {}
2216
+
2217
+ for _ in range(10):
2218
+ await env_taker.node._resend_queue()
2219
+ await time_out_assert(5, check_wallet_cache_empty, True)
2220
+
2221
+ await wallet_environments.process_pending_states(
2222
+ [
2223
+ # We're ignoring initial balance checking here because of the peculiarity
2224
+ # of the forced resend behavior we're doing above. Not entirely sure that we should be
2225
+ # but the balances are weird in such a way that it suggests to me a test issue and not
2226
+ # an issue with production code - quex
2227
+ WalletStateTransition(
2228
+ pre_block_balance_updates={
2229
+ "xch": {"set_remainder": True},
2230
+ "cat": {"set_remainder": True},
2231
+ },
2232
+ post_block_balance_updates={
2233
+ "xch": {},
2234
+ "cat": {},
2235
+ },
2236
+ ),
2237
+ WalletStateTransition(
2238
+ pre_block_balance_updates={
2239
+ "xch": {"set_remainder": True},
2240
+ "cat": {"init": True, "set_remainder": True},
2241
+ },
2242
+ post_block_balance_updates={
2243
+ "xch": {},
2244
+ "cat": {},
2245
+ },
2246
+ ),
2247
+ ],
2248
+ invalid_transactions=[tx.name for tx in action_scope.side_effects.transactions],
2249
+ )
2250
+
2251
+ await time_out_assert(30, get_trade_and_status, TradeStatus.FAILED, trade_manager_taker, tr1)
2252
+
2253
+
2254
+ @pytest.mark.parametrize(
2255
+ "wallet_environments",
2256
+ [
2257
+ {
2258
+ "num_environments": 2,
2259
+ "blocks_needed": [1, 1],
2260
+ }
2261
+ ],
2262
+ indirect=True,
2263
+ )
2264
+ @pytest.mark.limit_consensus_modes(reason="irrelevant")
2265
+ @pytest.mark.anyio
2266
+ async def test_trade_high_fee(wallet_environments: WalletTestFramework) -> None:
2267
+ env_maker = wallet_environments.environments[0]
2268
+ env_taker = wallet_environments.environments[1]
2269
+
2270
+ env_maker.wallet_aliases = {
2271
+ "xch": 1,
2272
+ "cat": 2,
2273
+ }
2274
+ env_taker.wallet_aliases = {
2275
+ "xch": 1,
2276
+ "cat": 2,
2277
+ }
2278
+
2279
+ xch_to_cat_amount = uint64(100)
2280
+
2281
+ async with env_maker.wallet_state_manager.new_action_scope(
2282
+ wallet_environments.tx_config, push=True
2283
+ ) as action_scope:
2284
+ await CATWallet.create_new_cat_wallet(
2285
+ env_maker.wallet_state_manager,
2286
+ env_maker.xch_wallet,
2287
+ {"identifier": "genesis_by_id"},
2288
+ xch_to_cat_amount,
2289
+ action_scope,
2290
+ )
2291
+
2292
+ await wallet_environments.process_pending_states(
2293
+ [
2294
+ # tests in test_cat_wallet.py
2295
+ WalletStateTransition(
2296
+ pre_block_balance_updates={
2297
+ "xch": {"set_remainder": True},
2298
+ "cat": {"init": True, "set_remainder": True},
2299
+ },
2300
+ post_block_balance_updates={
2301
+ "xch": {"set_remainder": True},
2302
+ "cat": {"set_remainder": True},
2303
+ },
2304
+ ),
2305
+ WalletStateTransition(),
2306
+ ]
2307
+ )
2308
+
2309
+ cat_for_chia: OfferSummary = {
2310
+ env_maker.wallet_aliases["xch"]: 1000,
2311
+ env_maker.wallet_aliases["cat"]: -4,
2312
+ }
2313
+
2314
+ trade_manager_maker = env_maker.wallet_state_manager.trade_manager
2315
+ trade_manager_taker = env_taker.wallet_state_manager.trade_manager
2316
+
2317
+ async with env_maker.wallet_state_manager.new_action_scope(
2318
+ wallet_environments.tx_config, push=False
2319
+ ) as action_scope:
2320
+ success, trade_make, error = await trade_manager_maker.create_offer_for_ids(cat_for_chia, action_scope)
2321
+ await time_out_assert(10, get_trade_and_status, TradeStatus.PENDING_ACCEPT, trade_manager_maker, trade_make)
2322
+ assert error is None
2323
+ assert success is True
2324
+ assert trade_make is not None
2325
+ peer = env_taker.node.get_full_node_peer()
2326
+ [offer], signing_response = await env_maker.wallet_state_manager.sign_offers([Offer.from_bytes(trade_make.offer)])
2327
+ fee = uint64(1_000_000_000_000)
2328
+ async with trade_manager_taker.wallet_state_manager.new_action_scope(
2329
+ wallet_environments.tx_config, push=True, additional_signing_responses=signing_response
2330
+ ) as action_scope:
2331
+ tr1 = await trade_manager_taker.respond_to_offer(offer, peer, action_scope, fee=fee)
2332
+
2333
+ await wallet_environments.process_pending_states(
2334
+ [
2335
+ WalletStateTransition(
2336
+ pre_block_balance_updates={
2337
+ "cat": {
2338
+ "<=#spendable_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2339
+ "<=#max_send_amount": cat_for_chia[env_maker.wallet_aliases["cat"]],
2340
+ "pending_change": 0,
2341
+ "pending_coin_removal_count": 1,
2342
+ }
2343
+ },
2344
+ post_block_balance_updates={
2345
+ "xch": {
2346
+ "unconfirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["xch"]],
2347
+ "confirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["xch"]],
2348
+ ">=#spendable_balance": 1,
2349
+ ">=#max_send_amount": 1,
2350
+ "pending_change": 0,
2351
+ "unspent_coin_count": 1,
2352
+ },
2353
+ "cat": {
2354
+ "unconfirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2355
+ "confirmed_wallet_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2356
+ ">=#spendable_balance": 1,
2357
+ ">=#max_send_amount": 1,
2358
+ "pending_change": 0,
2359
+ "pending_coin_removal_count": -1,
2360
+ },
2361
+ },
2362
+ ),
2363
+ WalletStateTransition(
2364
+ pre_block_balance_updates={
2365
+ "xch": {
2366
+ "unconfirmed_wallet_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2367
+ "<=#spendable_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2368
+ "<=#max_send_amount": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2369
+ ">=#pending_change": 1,
2370
+ "pending_coin_removal_count": 1,
2371
+ },
2372
+ "cat": {
2373
+ "init": True,
2374
+ "unconfirmed_wallet_balance": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2375
+ },
2376
+ },
2377
+ post_block_balance_updates={
2378
+ "xch": {
2379
+ "confirmed_wallet_balance": -cat_for_chia[env_maker.wallet_aliases["xch"]] - fee,
2380
+ ">=#spendable_balance": 1,
2381
+ ">=#max_send_amount": 1,
2382
+ "<=#pending_change": -1,
2383
+ "pending_coin_removal_count": -1,
2384
+ },
2385
+ "cat": {
2386
+ "confirmed_wallet_balance": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2387
+ "spendable_balance": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2388
+ "max_send_amount": -1 * cat_for_chia[env_maker.wallet_aliases["cat"]],
2389
+ "unspent_coin_count": 1,
2390
+ },
2391
+ },
2392
+ ),
2393
+ ]
2394
+ )
2395
+
2396
+ await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, tr1)
2397
+
2398
+
2399
+ @pytest.mark.parametrize(
2400
+ "wallet_environments",
2401
+ [
2402
+ {
2403
+ "num_environments": 2,
2404
+ "blocks_needed": [1, 1],
2405
+ }
2406
+ ],
2407
+ indirect=True,
2408
+ )
2409
+ @pytest.mark.limit_consensus_modes(reason="irrelevant")
2410
+ @pytest.mark.anyio
2411
+ async def test_aggregated_trade_state(wallet_environments: WalletTestFramework) -> None:
2412
+ env_maker = wallet_environments.environments[0]
2413
+ env_taker = wallet_environments.environments[1]
2414
+
2415
+ env_maker.wallet_aliases = {
2416
+ "xch": 1,
2417
+ "cat": 2,
2418
+ }
2419
+ env_taker.wallet_aliases = {
2420
+ "xch": 1,
2421
+ "cat": 2,
2422
+ }
2423
+
2424
+ xch_to_cat_amount = uint64(100)
2425
+
2426
+ async with env_maker.wallet_state_manager.new_action_scope(
2427
+ wallet_environments.tx_config, push=True
2428
+ ) as action_scope:
2429
+ await CATWallet.create_new_cat_wallet(
2430
+ env_maker.wallet_state_manager,
2431
+ env_maker.xch_wallet,
2432
+ {"identifier": "genesis_by_id"},
2433
+ xch_to_cat_amount,
2434
+ action_scope,
2435
+ )
2436
+
2437
+ await wallet_environments.process_pending_states(
2438
+ [
2439
+ # tests in test_cat_wallet.py
2440
+ WalletStateTransition(
2441
+ pre_block_balance_updates={
2442
+ "xch": {"set_remainder": True},
2443
+ "cat": {"init": True, "set_remainder": True},
2444
+ },
2445
+ post_block_balance_updates={
2446
+ "xch": {"set_remainder": True},
2447
+ "cat": {"set_remainder": True},
2448
+ },
2449
+ ),
2450
+ WalletStateTransition(),
2451
+ ]
2452
+ )
2453
+
2454
+ cat_for_chia: OfferSummary = {
2455
+ env_maker.wallet_aliases["xch"]: 2,
2456
+ env_maker.wallet_aliases["cat"]: -2,
2457
+ }
2458
+ chia_for_cat: OfferSummary = {
2459
+ env_maker.wallet_aliases["xch"]: -1,
2460
+ env_maker.wallet_aliases["cat"]: 1,
2461
+ }
2462
+ combined_summary: OfferSummary = {
2463
+ env_maker.wallet_aliases["xch"]: cat_for_chia[env_maker.wallet_aliases["xch"]]
2464
+ + chia_for_cat[env_maker.wallet_aliases["xch"]],
2465
+ env_maker.wallet_aliases["cat"]: cat_for_chia[env_maker.wallet_aliases["cat"]]
2466
+ + chia_for_cat[env_maker.wallet_aliases["cat"]],
2467
+ }
2468
+
2469
+ trade_manager_maker = env_maker.wallet_state_manager.trade_manager
2470
+ trade_manager_taker = env_taker.wallet_state_manager.trade_manager
2471
+
2472
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
2473
+ wallet_environments.tx_config, push=False
2474
+ ) as action_scope:
2475
+ success, trade_make_1, error = await trade_manager_maker.create_offer_for_ids(chia_for_cat, action_scope)
2476
+ await time_out_assert(10, get_trade_and_status, TradeStatus.PENDING_ACCEPT, trade_manager_maker, trade_make_1)
2477
+ assert error is None
2478
+ assert success is True
2479
+ assert trade_make_1 is not None
2480
+ async with trade_manager_maker.wallet_state_manager.new_action_scope(
2481
+ wallet_environments.tx_config, push=False
2482
+ ) as action_scope:
2483
+ success, trade_make_2, error = await trade_manager_maker.create_offer_for_ids(cat_for_chia, action_scope)
2484
+ await time_out_assert(10, get_trade_and_status, TradeStatus.PENDING_ACCEPT, trade_manager_maker, trade_make_2)
2485
+ assert error is None
2486
+ assert success is True
2487
+ assert trade_make_2 is not None
2488
+
2489
+ [offer_1], signing_response_1 = await env_maker.node.wallet_state_manager.sign_offers(
2490
+ [Offer.from_bytes(trade_make_1.offer)]
2491
+ )
2492
+ [offer_2], signing_response_2 = await env_maker.node.wallet_state_manager.sign_offers(
2493
+ [Offer.from_bytes(trade_make_2.offer)]
2494
+ )
2495
+ agg_offer = Offer.aggregate([offer_1, offer_2])
2496
+
2497
+ peer = env_taker.node.get_full_node_peer()
2498
+ async with env_taker.wallet_state_manager.new_action_scope(
2499
+ wallet_environments.tx_config,
2500
+ push=True,
2501
+ additional_signing_responses=[*signing_response_1, *signing_response_2],
2502
+ ) as action_scope:
2503
+ await trade_manager_taker.respond_to_offer(
2504
+ agg_offer,
2505
+ peer,
2506
+ action_scope,
2507
+ )
2508
+
2509
+ await wallet_environments.process_pending_states(
2510
+ [
2511
+ WalletStateTransition(
2512
+ pre_block_balance_updates={
2513
+ "xch": {
2514
+ "<=#spendable_balance": chia_for_cat[env_maker.wallet_aliases["xch"]],
2515
+ "<=#max_send_amount": chia_for_cat[env_maker.wallet_aliases["xch"]],
2516
+ "pending_change": 0,
2517
+ "pending_coin_removal_count": 1,
2518
+ },
2519
+ "cat": {
2520
+ "<=#spendable_balance": cat_for_chia[env_maker.wallet_aliases["cat"]],
2521
+ "<=#max_send_amount": cat_for_chia[env_maker.wallet_aliases["cat"]],
2522
+ "pending_change": 0,
2523
+ "pending_coin_removal_count": 1,
2524
+ },
2525
+ },
2526
+ post_block_balance_updates={
2527
+ "xch": {
2528
+ "unconfirmed_wallet_balance": combined_summary[env_maker.wallet_aliases["xch"]],
2529
+ "confirmed_wallet_balance": combined_summary[env_maker.wallet_aliases["xch"]],
2530
+ ">=#spendable_balance": 1,
2531
+ ">=#max_send_amount": 1,
2532
+ "pending_change": 0,
2533
+ "unspent_coin_count": 1,
2534
+ "pending_coin_removal_count": -1,
2535
+ },
2536
+ "cat": {
2537
+ "unconfirmed_wallet_balance": combined_summary[env_maker.wallet_aliases["cat"]],
2538
+ "confirmed_wallet_balance": combined_summary[env_maker.wallet_aliases["cat"]],
2539
+ ">=#spendable_balance": 1,
2540
+ ">=#max_send_amount": 1,
2541
+ "pending_change": 0,
2542
+ "unspent_coin_count": 1,
2543
+ "pending_coin_removal_count": -1,
2544
+ },
2545
+ },
2546
+ ),
2547
+ WalletStateTransition(
2548
+ pre_block_balance_updates={
2549
+ "xch": {
2550
+ "unconfirmed_wallet_balance": -combined_summary[env_maker.wallet_aliases["xch"]],
2551
+ "<=#spendable_balance": -combined_summary[env_maker.wallet_aliases["xch"]],
2552
+ "<=#max_send_amount": -combined_summary[env_maker.wallet_aliases["xch"]],
2553
+ ">=#pending_change": 1,
2554
+ "pending_coin_removal_count": 1,
2555
+ },
2556
+ "cat": {
2557
+ "init": True,
2558
+ "unconfirmed_wallet_balance": -1 * combined_summary[env_maker.wallet_aliases["cat"]],
2559
+ },
2560
+ },
2561
+ post_block_balance_updates={
2562
+ "xch": {
2563
+ "confirmed_wallet_balance": -combined_summary[env_maker.wallet_aliases["xch"]],
2564
+ ">=#spendable_balance": 1,
2565
+ ">=#max_send_amount": 1,
2566
+ "<=#pending_change": -1,
2567
+ "pending_coin_removal_count": -1,
2568
+ },
2569
+ "cat": {
2570
+ "confirmed_wallet_balance": -1 * combined_summary[env_maker.wallet_aliases["cat"]],
2571
+ "spendable_balance": -1 * combined_summary[env_maker.wallet_aliases["cat"]],
2572
+ "max_send_amount": -1 * combined_summary[env_maker.wallet_aliases["cat"]],
2573
+ "unspent_coin_count": 1,
2574
+ },
2575
+ },
2576
+ ),
2577
+ ]
2578
+ )