Skip to content

Commit e5cb31b

Browse files
committed
Port get_offer_summary to @marshal
1 parent 424b184 commit e5cb31b

File tree

15 files changed

+300
-231
lines changed

15 files changed

+300
-231
lines changed

chia/_tests/core/cmds/test_wallet.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def cat_name_resolver(request: CATAssetIDToName) -> CATAssetIDToNameRespon
2626

2727
@pytest.mark.anyio
2828
async def test_print_offer_summary_xch(capsys: Any) -> None:
29-
summary_dict = {"xch": 1_000_000_000_000}
29+
summary_dict = {"xch": str(1_000_000_000_000)}
3030

3131
await print_offer_summary(cat_name_resolver, summary_dict)
3232

@@ -38,7 +38,7 @@ async def test_print_offer_summary_xch(capsys: Any) -> None:
3838
@pytest.mark.anyio
3939
async def test_print_offer_summary_cat(capsys: Any) -> None:
4040
summary_dict = {
41-
TEST_DUCKSAUCE_ASSET_ID: 1_000,
41+
TEST_DUCKSAUCE_ASSET_ID: str(1_000),
4242
}
4343

4444
await print_offer_summary(cat_name_resolver, summary_dict)
@@ -51,8 +51,8 @@ async def test_print_offer_summary_cat(capsys: Any) -> None:
5151
@pytest.mark.anyio
5252
async def test_print_offer_summary_multiple_cats(capsys: Any) -> None:
5353
summary_dict = {
54-
TEST_DUCKSAUCE_ASSET_ID: 1_000,
55-
TEST_CRUNCHBERRIES_ASSET_ID: 2_000,
54+
TEST_DUCKSAUCE_ASSET_ID: str(1_000),
55+
TEST_CRUNCHBERRIES_ASSET_ID: str(2_000),
5656
}
5757

5858
await print_offer_summary(cat_name_resolver, summary_dict)
@@ -66,10 +66,10 @@ async def test_print_offer_summary_multiple_cats(capsys: Any) -> None:
6666
@pytest.mark.anyio
6767
async def test_print_offer_summary_xch_and_cats(capsys: Any) -> None:
6868
summary_dict = {
69-
"xch": 2_500_000_000_000,
70-
TEST_DUCKSAUCE_ASSET_ID: 1_111,
71-
TEST_CRUNCHBERRIES_ASSET_ID: 2_222,
72-
TEST_UNICORNTEARS_ASSET_ID: 3_333,
69+
"xch": str(2_500_000_000_000),
70+
TEST_DUCKSAUCE_ASSET_ID: str(1_111),
71+
TEST_CRUNCHBERRIES_ASSET_ID: str(2_222),
72+
TEST_UNICORNTEARS_ASSET_ID: str(3_333),
7373
}
7474

7575
await print_offer_summary(cat_name_resolver, summary_dict)
@@ -85,10 +85,10 @@ async def test_print_offer_summary_xch_and_cats(capsys: Any) -> None:
8585
@pytest.mark.anyio
8686
async def test_print_offer_summary_xch_and_cats_with_zero_values(capsys: Any) -> None:
8787
summary_dict = {
88-
"xch": 0,
89-
TEST_DUCKSAUCE_ASSET_ID: 0,
90-
TEST_CRUNCHBERRIES_ASSET_ID: 0,
91-
TEST_UNICORNTEARS_ASSET_ID: 0,
88+
"xch": str(0),
89+
TEST_DUCKSAUCE_ASSET_ID: str(0),
90+
TEST_CRUNCHBERRIES_ASSET_ID: str(0),
91+
TEST_UNICORNTEARS_ASSET_ID: str(0),
9292
}
9393

9494
await print_offer_summary(cat_name_resolver, summary_dict)
@@ -104,8 +104,8 @@ async def test_print_offer_summary_xch_and_cats_with_zero_values(capsys: Any) ->
104104
@pytest.mark.anyio
105105
async def test_print_offer_summary_cat_with_fee_and_change(capsys: Any) -> None:
106106
summary_dict = {
107-
TEST_DUCKSAUCE_ASSET_ID: 1_000,
108-
"unknown": 3_456,
107+
TEST_DUCKSAUCE_ASSET_ID: str(1_000),
108+
"unknown": str(3_456),
109109
}
110110

111111
await print_offer_summary(cat_name_resolver, summary_dict, has_fee=True)
@@ -118,7 +118,7 @@ async def test_print_offer_summary_cat_with_fee_and_change(capsys: Any) -> None:
118118

119119
@pytest.mark.anyio
120120
async def test_print_offer_summary_xch_with_one_mojo(capsys: Any) -> None:
121-
summary_dict = {"xch": 1}
121+
summary_dict = {"xch": str(1)}
122122

123123
await print_offer_summary(cat_name_resolver, summary_dict)
124124

chia/_tests/wallet/cat_wallet/test_offer_lifecycle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
173173
{"type": AssetType.CAT.value, "tail": "0x" + str_to_tail_hash("blue").hex()}
174174
),
175175
}
176-
driver_dict_as_infos = {key.hex(): value.info for key, value in driver_dict.items()}
176+
driver_dict_as_summary = {key.hex(): value for key, value in driver_dict.items()}
177177

178178
# Create an XCH Offer for RED
179179
chia_requested_payments: dict[Optional[bytes32], list[CreateCoin]] = {
@@ -239,9 +239,9 @@ async def test_complex_offer(cost_logger: CostLogger) -> None:
239239
}
240240
assert new_offer.get_requested_amounts() == {None: 900, str_to_tail_hash("red"): 350}
241241
assert new_offer.summary() == (
242-
{"xch": 1000, str_to_tail_hash("red").hex(): 350, str_to_tail_hash("blue").hex(): 2000},
243-
{"xch": 900, str_to_tail_hash("red").hex(): 350},
244-
driver_dict_as_infos,
242+
{"xch": "1000", str_to_tail_hash("red").hex(): "350", str_to_tail_hash("blue").hex(): "2000"},
243+
{"xch": "900", str_to_tail_hash("red").hex(): "350"},
244+
driver_dict_as_summary,
245245
ConditionValidTimes(),
246246
)
247247
assert new_offer.get_pending_amounts() == {

chia/_tests/wallet/cat_wallet/test_trades.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from chia.wallet.puzzle_drivers import PuzzleInfo
2929
from chia.wallet.trade_manager import TradeManager
3030
from chia.wallet.trade_record import TradeRecord
31-
from chia.wallet.trading.offer import Offer, OfferSummary
31+
from chia.wallet.trading.offer import Offer, OfferSpecification
3232
from chia.wallet.trading.trade_status import TradeStatus
3333
from chia.wallet.transaction_record import TransactionRecord
3434
from chia.wallet.util.transaction_type import TransactionType
@@ -415,29 +415,29 @@ async def test_cat_trades(
415415
await env_maker.check_balances()
416416

417417
# Create the trade parameters
418-
chia_for_cat: OfferSummary = {
418+
chia_for_cat: OfferSpecification = {
419419
wallet_maker.id(): -1,
420420
bytes32.from_hexstr(new_cat_wallet_maker.get_asset_id()): 2, # This is the CAT that the taker made
421421
}
422-
cat_for_chia: OfferSummary = {
422+
cat_for_chia: OfferSpecification = {
423423
wallet_maker.id(): 3,
424424
cat_wallet_maker.id(): -4, # The taker has no knowledge of this CAT yet
425425
}
426-
cat_for_cat: OfferSummary = {
426+
cat_for_cat: OfferSpecification = {
427427
bytes32.from_hexstr(cat_wallet_maker.get_asset_id()): -5,
428428
new_cat_wallet_maker.id(): 6,
429429
}
430-
chia_for_multiple_cat: OfferSummary = {
430+
chia_for_multiple_cat: OfferSpecification = {
431431
wallet_maker.id(): -7,
432432
cat_wallet_maker.id(): 8,
433433
new_cat_wallet_maker.id(): 9,
434434
}
435-
multiple_cat_for_chia: OfferSummary = {
435+
multiple_cat_for_chia: OfferSpecification = {
436436
wallet_maker.id(): 10,
437437
cat_wallet_maker.id(): -11,
438438
new_cat_wallet_maker.id(): -12,
439439
}
440-
chia_and_cat_for_cat: OfferSummary = {
440+
chia_and_cat_for_cat: OfferSpecification = {
441441
wallet_maker.id(): -13,
442442
cat_wallet_maker.id(): -14,
443443
new_cat_wallet_maker.id(): 15,
@@ -1673,12 +1673,12 @@ async def test_trade_cancellation(wallet_environments: WalletTestFramework, wall
16731673
]
16741674
)
16751675

1676-
cat_for_chia: OfferSummary = {
1676+
cat_for_chia: OfferSpecification = {
16771677
env_maker.wallet_aliases["xch"]: 1,
16781678
env_maker.wallet_aliases["cat"]: -2,
16791679
}
16801680

1681-
chia_for_cat: OfferSummary = {
1681+
chia_for_cat: OfferSpecification = {
16821682
env_maker.wallet_aliases["xch"]: -3,
16831683
env_maker.wallet_aliases["cat"]: 4,
16841684
}
@@ -1846,7 +1846,7 @@ async def test_trade_cancellation(wallet_environments: WalletTestFramework, wall
18461846
await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
18471847

18481848
# Now let's test the case where two coins need to be spent in order to cancel
1849-
chia_and_cat_for_something: OfferSummary = {
1849+
chia_and_cat_for_something: OfferSpecification = {
18501850
env_maker.wallet_aliases["xch"]: -5,
18511851
env_maker.wallet_aliases["cat"]: -6,
18521852
bytes32.zeros: 1, # Doesn't matter
@@ -1991,7 +1991,7 @@ async def test_trade_conflict(wallet_environments: WalletTestFramework, wallet_t
19911991
]
19921992
)
19931993

1994-
cat_for_chia: OfferSummary = {
1994+
cat_for_chia: OfferSpecification = {
19951995
env_maker.wallet_aliases["xch"]: 1000,
19961996
env_maker.wallet_aliases["cat"]: -4,
19971997
}
@@ -2182,7 +2182,7 @@ async def test_trade_bad_spend(wallet_environments: WalletTestFramework, wallet_
21822182
]
21832183
)
21842184

2185-
cat_for_chia: OfferSummary = {
2185+
cat_for_chia: OfferSpecification = {
21862186
env_maker.wallet_aliases["xch"]: 1000,
21872187
env_maker.wallet_aliases["cat"]: -4,
21882188
}
@@ -2304,7 +2304,7 @@ async def test_trade_high_fee(wallet_environments: WalletTestFramework, wallet_t
23042304
]
23052305
)
23062306

2307-
cat_for_chia: OfferSummary = {
2307+
cat_for_chia: OfferSpecification = {
23082308
env_maker.wallet_aliases["xch"]: 1000,
23092309
env_maker.wallet_aliases["cat"]: -4,
23102310
}
@@ -2449,15 +2449,15 @@ async def test_aggregated_trade_state(wallet_environments: WalletTestFramework,
24492449
]
24502450
)
24512451

2452-
cat_for_chia: OfferSummary = {
2452+
cat_for_chia: OfferSpecification = {
24532453
env_maker.wallet_aliases["xch"]: 2,
24542454
env_maker.wallet_aliases["cat"]: -2,
24552455
}
2456-
chia_for_cat: OfferSummary = {
2456+
chia_for_cat: OfferSpecification = {
24572457
env_maker.wallet_aliases["xch"]: -1,
24582458
env_maker.wallet_aliases["cat"]: 1,
24592459
}
2460-
combined_summary: OfferSummary = {
2460+
combined_summary: OfferSpecification = {
24612461
env_maker.wallet_aliases["xch"]: cat_for_chia[env_maker.wallet_aliases["xch"]]
24622462
+ chia_for_cat[env_maker.wallet_aliases["xch"]],
24632463
env_maker.wallet_aliases["cat"]: cat_for_chia[env_maker.wallet_aliases["cat"]]

chia/_tests/wallet/db_wallet/test_dl_offers.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from chia._tests.environments.wallet import WalletStateTransition, WalletTestFramework
1010
from chia._tests.util.time_out_assert import time_out_assert
11-
from chia.data_layer.data_layer_wallet import DataLayerWallet
11+
from chia.data_layer.data_layer_wallet import DataLayerSummary, DataLayerWallet, SingletonDependencies, SingletonSummary
1212
from chia.wallet.puzzle_drivers import Solver
1313
from chia.wallet.trade_record import TradeRecord
1414
from chia.wallet.trading.offer import Offer
@@ -179,20 +179,20 @@ async def test_dl_offers(wallet_environments: WalletTestFramework) -> None:
179179
assert success is True
180180
assert offer_maker is not None
181181

182-
assert await trade_manager_taker.get_offer_summary(Offer.from_bytes(offer_maker.offer)) == {
183-
"offered": [
184-
{
185-
"launcher_id": launcher_id_maker.hex(),
186-
"new_root": maker_root.hex(),
187-
"dependencies": [
188-
{
189-
"launcher_id": launcher_id_taker.hex(),
190-
"values_to_prove": [taker_branch.hex()],
191-
}
182+
assert await trade_manager_taker.get_dl_offer_summary(Offer.from_bytes(offer_maker.offer)) == DataLayerSummary(
183+
offered=[
184+
SingletonSummary(
185+
launcher_id=launcher_id_maker,
186+
new_root=maker_root,
187+
dependencies=[
188+
SingletonDependencies(
189+
launcher_id=launcher_id_taker,
190+
values_to_prove=[taker_branch],
191+
)
192192
],
193-
}
193+
)
194194
]
195-
}
195+
)
196196

197197
[_maker_offer], signing_response = await wsm_maker.sign_offers([Offer.from_bytes(offer_maker.offer)])
198198
async with trade_manager_taker.wallet_state_manager.new_action_scope(
@@ -231,30 +231,30 @@ async def test_dl_offers(wallet_environments: WalletTestFramework) -> None:
231231
)
232232
assert offer_taker is not None
233233

234-
assert await trade_manager_maker.get_offer_summary(Offer.from_bytes(offer_taker.offer)) == {
235-
"offered": [
236-
{
237-
"launcher_id": launcher_id_maker.hex(),
238-
"new_root": maker_root.hex(),
239-
"dependencies": [
240-
{
241-
"launcher_id": launcher_id_taker.hex(),
242-
"values_to_prove": [taker_branch.hex()],
243-
}
234+
assert await trade_manager_maker.get_dl_offer_summary(Offer.from_bytes(offer_taker.offer)) == DataLayerSummary(
235+
offered=[
236+
SingletonSummary(
237+
launcher_id=launcher_id_maker,
238+
new_root=maker_root,
239+
dependencies=[
240+
SingletonDependencies(
241+
launcher_id=launcher_id_taker,
242+
values_to_prove=[taker_branch],
243+
)
244244
],
245-
},
246-
{
247-
"launcher_id": launcher_id_taker.hex(),
248-
"new_root": taker_root.hex(),
249-
"dependencies": [
250-
{
251-
"launcher_id": launcher_id_maker.hex(),
252-
"values_to_prove": [maker_branch.hex()],
253-
}
245+
),
246+
SingletonSummary(
247+
launcher_id=launcher_id_taker,
248+
new_root=taker_root,
249+
dependencies=[
250+
SingletonDependencies(
251+
launcher_id=launcher_id_maker,
252+
values_to_prove=[maker_branch],
253+
),
254254
],
255-
},
255+
),
256256
]
257-
}
257+
)
258258

259259
await wallet_environments.process_pending_states(
260260
[

chia/_tests/wallet/nft_wallet/test_nft_1_offers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from chia.wallet.nft_wallet.nft_wallet import NFTWallet
1818
from chia.wallet.outer_puzzles import create_asset_id, match_puzzle
1919
from chia.wallet.puzzle_drivers import PuzzleInfo
20-
from chia.wallet.trading.offer import Offer, OfferSummary
20+
from chia.wallet.trading.offer import Offer, OfferSpecification
2121
from chia.wallet.trading.trade_status import TradeStatus
2222
from chia.wallet.uncurried_puzzle import uncurry_puzzle
2323

@@ -163,7 +163,7 @@ async def test_nft_offer_sell_nft(wallet_environments: WalletTestFramework, zero
163163
xch_requested = 1000
164164
maker_fee = uint64(433)
165165

166-
offer_did_nft_for_xch: OfferSummary = {nft_to_offer_asset_id: -1, wallet_maker.id(): xch_requested}
166+
offer_did_nft_for_xch: OfferSpecification = {nft_to_offer_asset_id: -1, wallet_maker.id(): xch_requested}
167167

168168
async with trade_manager_maker.wallet_state_manager.new_action_scope(
169169
wallet_environments.tx_config, push=False
@@ -395,7 +395,7 @@ async def test_nft_offer_request_nft(wallet_environments: WalletTestFramework, z
395395
maker_fee = uint64(10)
396396
driver_dict = {nft_to_request_asset_id: nft_to_request_info}
397397

398-
offer_dict: OfferSummary = {nft_to_request_asset_id: 1, wallet_maker.id(): -xch_offered}
398+
offer_dict: OfferSpecification = {nft_to_request_asset_id: 1, wallet_maker.id(): -xch_offered}
399399

400400
async with trade_manager_maker.wallet_state_manager.new_action_scope(
401401
wallet_environments.tx_config, push=False
@@ -685,7 +685,7 @@ async def test_nft_offer_sell_did_to_did(wallet_environments: WalletTestFramewor
685685
xch_requested = 1000
686686
maker_fee = uint64(433)
687687

688-
offer_did_nft_for_xch: OfferSummary = {nft_to_offer_asset_id: -1, wallet_maker.id(): xch_requested}
688+
offer_did_nft_for_xch: OfferSpecification = {nft_to_offer_asset_id: -1, wallet_maker.id(): xch_requested}
689689

690690
async with trade_manager_maker.wallet_state_manager.new_action_scope(
691691
wallet_environments.tx_config, push=False
@@ -990,7 +990,7 @@ async def test_nft_offer_sell_nft_for_cat(
990990
cats_requested = 1000
991991
maker_fee = uint64(433)
992992

993-
offer_did_nft_for_xch: OfferSummary = {nft_to_offer_asset_id: -1, cat_wallet_maker.id(): cats_requested}
993+
offer_did_nft_for_xch: OfferSpecification = {nft_to_offer_asset_id: -1, cat_wallet_maker.id(): cats_requested}
994994

995995
async with trade_manager_maker.wallet_state_manager.new_action_scope(
996996
wallet_environments.tx_config, push=False
@@ -1347,7 +1347,7 @@ async def test_nft_offer_request_nft_for_cat(
13471347
maker_fee = uint64(433)
13481348
driver_dict = {nft_to_request_asset_id: nft_to_request_info}
13491349

1350-
offer_dict: OfferSummary = {nft_to_request_asset_id: 1, cat_wallet_maker.id(): -cats_requested}
1350+
offer_dict: OfferSpecification = {nft_to_request_asset_id: 1, cat_wallet_maker.id(): -cats_requested}
13511351

13521352
async with trade_manager_maker.wallet_state_manager.new_action_scope(
13531353
wallet_environments.tx_config, push=False
@@ -1583,7 +1583,7 @@ async def test_nft_offer_sell_cancel(wallet_environments: WalletTestFramework) -
15831583
xch_requested = 1000
15841584
maker_fee = uint64(433)
15851585

1586-
offer_did_nft_for_xch: OfferSummary = {nft_to_offer_asset_id: -1, wallet_maker.id(): xch_requested}
1586+
offer_did_nft_for_xch: OfferSpecification = {nft_to_offer_asset_id: -1, wallet_maker.id(): xch_requested}
15871587

15881588
async with trade_manager_maker.wallet_state_manager.new_action_scope(
15891589
wallet_environments.tx_config, push=False
@@ -1976,7 +1976,7 @@ async def test_complex_nft_offer(
19761976
CAT_REQUESTED = 100000
19771977
FEE = uint64(2000000000000)
19781978

1979-
complex_nft_offer: OfferSummary = {
1979+
complex_nft_offer: OfferSpecification = {
19801980
nft_to_offer_asset_id_maker: -1,
19811981
cat_wallet_maker.id(): CAT_REQUESTED * -1,
19821982
1: XCH_REQUESTED,

0 commit comments

Comments
 (0)