9
9
10
10
from chia ._tests .environments .wallet import WalletStateTransition , WalletTestFramework
11
11
from chia ._tests .util .time_out_assert import time_out_assert
12
+ from chia ._tests .wallet .cat_wallet .test_cat_wallet import mint_cat
12
13
from chia .types .blockchain_format .program import Program
13
14
from chia .wallet .cat_wallet .cat_wallet import CATWallet
15
+ from chia .wallet .cat_wallet .r_cat_wallet import RCATWallet
14
16
from chia .wallet .did_wallet .did_wallet import DIDWallet
15
17
from chia .wallet .nft_wallet .nft_wallet import NFTWallet
16
18
from chia .wallet .outer_puzzles import create_asset_id , match_puzzle
@@ -777,8 +779,11 @@ async def test_nft_offer_sell_did_to_did(wallet_environments: WalletTestFramewor
777
779
@pytest .mark .limit_consensus_modes
778
780
@pytest .mark .parametrize ("wallet_environments" , [{"num_environments" : 2 , "blocks_needed" : [1 , 1 ]}], indirect = True )
779
781
@pytest .mark .parametrize ("zero_royalties" , [True , False ])
782
+ @pytest .mark .parametrize ("wallet_type" , [CATWallet , RCATWallet ])
780
783
@pytest .mark .anyio
781
- async def test_nft_offer_sell_nft_for_cat (wallet_environments : WalletTestFramework , zero_royalties : bool ) -> None :
784
+ async def test_nft_offer_sell_nft_for_cat (
785
+ wallet_environments : WalletTestFramework , zero_royalties : bool , wallet_type : type [CATWallet ]
786
+ ) -> None :
782
787
env_maker = wallet_environments .environments [0 ]
783
788
env_taker = wallet_environments .environments [1 ]
784
789
wallet_maker = env_maker .xch_wallet
@@ -910,46 +915,24 @@ async def test_nft_offer_sell_nft_for_cat(wallet_environments: WalletTestFramewo
910
915
911
916
# Create new CAT and wallets for maker and taker
912
917
# Trade them between maker and taker to ensure multiple coins for each cat
913
- cats_to_mint = 100000
918
+ cats_to_mint = uint64 ( 100000 )
914
919
cats_to_trade = uint64 (10000 )
915
- async with wallet_maker .wallet_state_manager .new_action_scope (
916
- wallet_environments .tx_config , push = True
917
- ) as action_scope :
918
- cat_wallet_maker = await CATWallet .create_new_cat_wallet (
919
- env_maker .wallet_state_manager ,
920
- wallet_maker ,
921
- {"identifier" : "genesis_by_id" },
922
- uint64 (cats_to_mint ),
923
- action_scope ,
924
- )
925
-
926
- await wallet_environments .process_pending_states (
927
- [
928
- WalletStateTransition (
929
- pre_block_balance_updates = {
930
- "xch" : {
931
- "set_remainder" : True ,
932
- },
933
- "cat" : {
934
- "init" : True ,
935
- "set_remainder" : True ,
936
- },
937
- },
938
- post_block_balance_updates = {
939
- "xch" : {
940
- "set_remainder" : True ,
941
- },
942
- "cat" : {
943
- "set_remainder" : True ,
944
- },
945
- },
946
- ),
947
- WalletStateTransition (),
948
- ]
920
+ cat_wallet_maker = await mint_cat (
921
+ wallet_environments ,
922
+ env_maker ,
923
+ "xch" ,
924
+ "cat" ,
925
+ cats_to_mint ,
926
+ wallet_type ,
927
+ "cat" ,
949
928
)
950
929
951
- cat_wallet_taker : CATWallet = await CATWallet .get_or_create_wallet_for_cat (
952
- env_taker .wallet_state_manager , wallet_taker , cat_wallet_maker .get_asset_id ()
930
+ if wallet_type is RCATWallet :
931
+ extra_args : Any = (bytes32 .zeros ,)
932
+ else :
933
+ extra_args = tuple ()
934
+ cat_wallet_taker : CATWallet = await wallet_type .get_or_create_wallet_for_cat (
935
+ env_taker .wallet_state_manager , wallet_taker , cat_wallet_maker .get_asset_id (), * extra_args
953
936
)
954
937
955
938
await env_taker .change_balances ({"cat" : {"init" : True }})
@@ -1120,8 +1103,11 @@ async def test_nft_offer_sell_nft_for_cat(wallet_environments: WalletTestFramewo
1120
1103
@pytest .mark .limit_consensus_modes
1121
1104
@pytest .mark .parametrize ("wallet_environments" , [{"num_environments" : 2 , "blocks_needed" : [1 , 1 ]}], indirect = True )
1122
1105
@pytest .mark .parametrize ("test_change" , [True , False ])
1106
+ @pytest .mark .parametrize ("wallet_type" , [CATWallet , RCATWallet ])
1123
1107
@pytest .mark .anyio
1124
- async def test_nft_offer_request_nft_for_cat (wallet_environments : WalletTestFramework , test_change : bool ) -> None :
1108
+ async def test_nft_offer_request_nft_for_cat (
1109
+ wallet_environments : WalletTestFramework , test_change : bool , wallet_type : type [CATWallet ]
1110
+ ) -> None :
1125
1111
env_maker = wallet_environments .environments [0 ]
1126
1112
env_taker = wallet_environments .environments [1 ]
1127
1113
wallet_maker = env_maker .xch_wallet
@@ -1255,46 +1241,24 @@ async def test_nft_offer_request_nft_for_cat(wallet_environments: WalletTestFram
1255
1241
1256
1242
# Create new CAT and wallets for maker and taker
1257
1243
# Trade them between maker and taker to ensure multiple coins for each cat
1258
- cats_to_mint = 100000
1244
+ cats_to_mint = uint64 ( 100000 )
1259
1245
cats_to_trade = uint64 (20000 )
1260
- async with wallet_maker .wallet_state_manager .new_action_scope (
1261
- wallet_environments .tx_config , push = True
1262
- ) as action_scope :
1263
- cat_wallet_maker = await CATWallet .create_new_cat_wallet (
1264
- env_maker .wallet_state_manager ,
1265
- wallet_maker ,
1266
- {"identifier" : "genesis_by_id" },
1267
- uint64 (cats_to_mint ),
1268
- action_scope ,
1269
- )
1270
-
1271
- await wallet_environments .process_pending_states (
1272
- [
1273
- WalletStateTransition (
1274
- pre_block_balance_updates = {
1275
- "xch" : {
1276
- "set_remainder" : True ,
1277
- },
1278
- "cat" : {
1279
- "init" : True ,
1280
- "set_remainder" : True ,
1281
- },
1282
- },
1283
- post_block_balance_updates = {
1284
- "xch" : {
1285
- "set_remainder" : True ,
1286
- },
1287
- "cat" : {
1288
- "set_remainder" : True ,
1289
- },
1290
- },
1291
- ),
1292
- WalletStateTransition (),
1293
- ]
1246
+ cat_wallet_maker = await mint_cat (
1247
+ wallet_environments ,
1248
+ env_maker ,
1249
+ "xch" ,
1250
+ "cat" ,
1251
+ cats_to_mint ,
1252
+ wallet_type ,
1253
+ "cat" ,
1294
1254
)
1295
1255
1296
- await CATWallet .get_or_create_wallet_for_cat (
1297
- env_taker .wallet_state_manager , wallet_taker , cat_wallet_maker .get_asset_id ()
1256
+ if wallet_type is RCATWallet :
1257
+ extra_args : Any = (bytes32 .zeros ,)
1258
+ else :
1259
+ extra_args = tuple ()
1260
+ await wallet_type .get_or_create_wallet_for_cat (
1261
+ env_taker .wallet_state_manager , wallet_taker , cat_wallet_maker .get_asset_id (), * extra_args
1298
1262
)
1299
1263
1300
1264
await env_taker .change_balances ({"cat" : {"init" : True }})
@@ -1690,8 +1654,11 @@ async def get_trade_and_status(trade_manager: Any, trade: Any) -> TradeStatus:
1690
1654
[{"num_environments" : 2 , "blocks_needed" : [3 , 3 ], "config_overrides" : {"automatically_add_unknown_cats" : True }}],
1691
1655
indirect = True ,
1692
1656
)
1657
+ @pytest .mark .parametrize ("wallet_type" , [CATWallet , RCATWallet ])
1693
1658
@pytest .mark .anyio
1694
- async def test_complex_nft_offer (wallet_environments : WalletTestFramework , royalty_pts : tuple [int , int , int ]) -> None :
1659
+ async def test_complex_nft_offer (
1660
+ wallet_environments : WalletTestFramework , royalty_pts : tuple [int , int , int ], wallet_type : type [CATWallet ]
1661
+ ) -> None :
1695
1662
"""
1696
1663
This test is going to create an offer where the maker offers 1 NFT and 1 CAT for 2 NFTs, an XCH and a CAT
1697
1664
"""
@@ -1729,20 +1696,24 @@ async def test_complex_nft_offer(wallet_environments: WalletTestFramework, royal
1729
1696
ph_taker = await action_scope .get_puzzle_hash (wallet_taker .wallet_state_manager )
1730
1697
1731
1698
CAT_AMOUNT = uint64 (100000000 )
1732
- async with wallet_maker .wallet_state_manager .new_action_scope (
1733
- wallet_environments .tx_config , push = True
1734
- ) as action_scope :
1735
- cat_wallet_maker = await CATWallet .create_new_cat_wallet (
1736
- wsm_maker , wallet_maker , {"identifier" : "genesis_by_id" }, CAT_AMOUNT , action_scope
1737
- )
1738
- async with wallet_taker .wallet_state_manager .new_action_scope (
1739
- wallet_environments .tx_config , push = True
1740
- ) as action_scope :
1741
- cat_wallet_taker = await CATWallet .create_new_cat_wallet (
1742
- wsm_taker , wallet_taker , {"identifier" : "genesis_by_id" }, CAT_AMOUNT , action_scope
1743
- )
1744
- await env_maker .change_balances ({"cat_maker" : {"init" : True }})
1745
- await env_taker .change_balances ({"cat_taker" : {"init" : True }})
1699
+ cat_wallet_maker = await mint_cat (
1700
+ wallet_environments ,
1701
+ env_maker ,
1702
+ "xch" ,
1703
+ "cat_maker" ,
1704
+ CAT_AMOUNT ,
1705
+ wallet_type ,
1706
+ "cat_maker" ,
1707
+ )
1708
+ cat_wallet_taker = await mint_cat (
1709
+ wallet_environments ,
1710
+ env_taker ,
1711
+ "xch" ,
1712
+ "cat_taker" ,
1713
+ CAT_AMOUNT ,
1714
+ wallet_type ,
1715
+ "cat_taker" ,
1716
+ )
1746
1717
1747
1718
# We'll need these later
1748
1719
basic_nft_wallet_maker = await NFTWallet .create_new_nft_wallet (wsm_maker , wallet_maker , name = "NFT WALLET MAKER" )
@@ -2025,6 +1996,11 @@ async def test_complex_nft_offer(wallet_environments: WalletTestFramework, royal
2025
1996
{
2026
1997
"type" : "CAT" ,
2027
1998
"tail" : "0x" + cat_wallet_taker .get_asset_id (),
1999
+ ** (
2000
+ {}
2001
+ if wallet_type is CATWallet
2002
+ else {"also" : {"type" : "revocation layer" , "hidden_puzzle_hash" : "0x" + bytes32 .zeros .hex ()}}
2003
+ ),
2028
2004
}
2029
2005
),
2030
2006
}
@@ -2090,7 +2066,8 @@ async def test_complex_nft_offer(wallet_environments: WalletTestFramework, royal
2090
2066
+ taker_royalty_summary [nft_to_offer_asset_id_taker_2 ][0 ]["amount" ]
2091
2067
)
2092
2068
2093
- xch_coins = int (XCH_REQUESTED / 1_750_000_000_000 ) + 2
2069
+ # in the zero royalty case, exact change ends up being selected which complicates things a bit
2070
+ xch_coins = int (XCH_REQUESTED / 1_750_000_000_000 ) + 2 - (1 if royalty_basis_pts_maker == 0 else 0 )
2094
2071
fee_coins = int (FEE / 1_750_000_000_000 ) + 1 if FEE > 1_750_000_000_000 else 1
2095
2072
await wallet_environments .process_pending_states (
2096
2073
[
@@ -2151,7 +2128,7 @@ async def test_complex_nft_offer(wallet_environments: WalletTestFramework, royal
2151
2128
"unconfirmed_wallet_balance" : - XCH_REQUESTED - maker_xch_royalties_expected - FEE ,
2152
2129
"<=#spendable_balance" : - XCH_REQUESTED - maker_xch_royalties_expected - FEE ,
2153
2130
"<=#max_send_amount" : - XCH_REQUESTED - maker_xch_royalties_expected - FEE ,
2154
- ">=#pending_change" : 1 ,
2131
+ ">=#pending_change" : 0 ,
2155
2132
"pending_coin_removal_count" : xch_coins + fee_coins ,
2156
2133
},
2157
2134
"cat_taker" : {
@@ -2173,9 +2150,9 @@ async def test_complex_nft_offer(wallet_environments: WalletTestFramework, royal
2173
2150
post_block_balance_updates = {
2174
2151
"xch" : {
2175
2152
"confirmed_wallet_balance" : - XCH_REQUESTED - maker_xch_royalties_expected - FEE ,
2176
- ">=#spendable_balance" : 1 ,
2177
- ">=#max_send_amount" : 1 ,
2178
- "<=#pending_change" : - 1 ,
2153
+ ">=#spendable_balance" : 0 ,
2154
+ ">=#max_send_amount" : 0 ,
2155
+ "<=#pending_change" : 0 ,
2179
2156
"pending_coin_removal_count" : - fee_coins - xch_coins ,
2180
2157
# Parametrizations make unspent_coin_count too complicated
2181
2158
"set_remainder" : True ,
0 commit comments