rework around tx records and offer takes (#13603)

* mixed rework around tx records and offer takes

* more

* wait for wallets

* process_transaction_records() -> process_transactions()

* correct to use new bundles= parameter a couple spots

* .process_transaction_records()

* .process_spend_bundles()
This commit is contained in:
Kyle Altendorf 2022-11-15 19:42:45 -05:00 committed by GitHub
parent 7ae9f8f54b
commit a531580868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 132 additions and 306 deletions

View File

@ -1555,8 +1555,8 @@ class WalletRpcApi:
offer, peer, fee=fee, min_coin_amount=min_coin_amount, max_coin_amount=max_coin_amount, solver=solver
)
if not result[0]:
raise ValueError(result[2])
success, trade_record, error = result
raise ValueError(result[3])
success, trade_record, tx_records, error = result
return {"trade_record": trade_record.to_json_dict_convenience()}
async def get_offer(self, request: Dict) -> EndpointResult:

View File

@ -529,3 +529,10 @@ class FullNodeSimulator(FullNodeAPI):
await wait_for_coins_in_wallet(coins=coins_to_receive, wallet=wallet)
return coins_to_receive
def tx_id_in_mempool(self, tx_id: bytes32) -> bool:
spendbundle = self.full_node.mempool_manager.get_spendbundle(bundle_hash=tx_id)
return spendbundle is not None
def txs_in_mempool(self, txs: List[TransactionRecord]) -> bool:
return all(self.tx_id_in_mempool(tx_id=tx.spend_bundle.name()) for tx in txs if tx.spend_bundle is not None)

View File

@ -703,7 +703,9 @@ class TradeManager:
fee: uint64 = uint64(0),
min_coin_amount: Optional[uint64] = None,
max_coin_amount: Optional[uint64] = None,
) -> Union[Tuple[Literal[True], TradeRecord, None], Tuple[Literal[False], None, str]]:
) -> Union[
Tuple[Literal[True], TradeRecord, List[TransactionRecord], None], Tuple[Literal[False], None, None, str]
]:
if solver is None:
solver = Solver({})
take_offer_dict: Dict[Union[bytes32, int], int] = {}
@ -717,7 +719,7 @@ class TradeManager:
# ATTENTION: new wallets
wallet = await self.wallet_state_manager.get_wallet_for_asset_id(asset_id.hex())
if wallet is None and amount < 0:
return False, None, f"Do not have a wallet for asset ID: {asset_id} to fulfill offer"
return False, None, None, f"Do not have a wallet for asset ID: {asset_id} to fulfill offer"
elif wallet is None or wallet.type() in [WalletType.NFT, WalletType.DATA_LAYER]:
key = asset_id
else:
@ -727,7 +729,7 @@ class TradeManager:
# First we validate that all of the coins in this offer exist
valid: bool = await self.check_offer_validity(offer, peer)
if not valid:
return False, None, "This offer is no longer valid"
return False, None, None, "This offer is no longer valid"
result = await self._create_offer_for_ids(
take_offer_dict,
offer.driver_dict,
@ -737,7 +739,7 @@ class TradeManager:
max_coin_amount=max_coin_amount,
)
if not result[0] or result[1] is None:
return False, None, result[2]
return False, None, None, result[2]
success, take_offer, error = result
@ -788,7 +790,7 @@ class TradeManager:
for tx in tx_records:
await self.wallet_state_manager.add_transaction(tx)
return True, trade_record, None
return True, trade_record, [push_tx, *tx_records], None
async def check_for_special_offer_making(
self,

View File

@ -4,10 +4,8 @@ from typing import List
import pytest
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
from chia.full_node.mempool_manager import MempoolManager
from chia.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.peer_info import PeerInfo
from chia.util.ints import uint16, uint32, uint64
from chia.wallet.cat_wallet.cat_constants import DEFAULT_CATS
@ -21,13 +19,6 @@ from chia.simulator.time_out_assert import time_out_assert
from tests.util.wallet_is_synced import wallet_is_synced
async def tx_in_pool(mempool: MempoolManager, tx_id: bytes32):
tx = mempool.get_spendbundle(tx_id)
if tx is None:
return False
return True
class TestCATWallet:
@pytest.mark.parametrize(
"trusted",
@ -73,12 +64,7 @@ class TestCATWallet:
tx_queue: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
tx_record = tx_queue[0]
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
await full_node_api.process_transaction_records(records=[tx_record])
await time_out_assert(20, cat_wallet.get_confirmed_balance, 100)
await time_out_assert(20, cat_wallet.get_spendable_balance, 100)
@ -188,12 +174,7 @@ class TestCATWallet:
)
tx_queue: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
tx_record = tx_queue[0]
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
await full_node_api.process_transaction_records(records=[tx_record])
await time_out_assert(20, cat_wallet.get_confirmed_balance, 100)
await time_out_assert(20, cat_wallet.get_unconfirmed_balance, 100)
@ -211,13 +192,11 @@ class TestCATWallet:
tx_records = await cat_wallet.generate_signed_transaction([uint64(60)], [cat_2_hash], fee=uint64(1))
for tx_record in tx_records:
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
if tx_record.spend_bundle is not None:
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
if tx_record.wallet_id is cat_wallet.id():
assert tx_record.to_puzzle_hash == cat_2_hash
await time_out_assert(15, full_node_api.txs_in_mempool, True, tx_records)
await time_out_assert(20, cat_wallet.get_pending_change_balance, 40)
for i in range(1, num_blocks):
@ -235,9 +214,8 @@ class TestCATWallet:
tx_records = await cat_wallet_2.generate_signed_transaction([uint64(15)], [cat_hash])
for tx_record in tx_records:
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
await time_out_assert(15, full_node_api.txs_in_mempool, True, tx_records)
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
@ -343,13 +321,8 @@ class TestCATWallet:
cat_wallet: CATWallet = await CATWallet.create_new_cat_wallet(
wallet_node.wallet_state_manager, wallet, {"identifier": "genesis_by_id"}, uint64(100)
)
tx_queue: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
tx_record = tx_queue[0]
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
tx_records: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet.get_confirmed_balance, 100)
await time_out_assert(20, cat_wallet.get_unconfirmed_balance, 100)
@ -367,12 +340,7 @@ class TestCATWallet:
tx_records = await cat_wallet.generate_signed_transaction([uint64(60)], [cat_2_hash], fee=uint64(1))
for tx_record in tx_records:
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
if tx_record.spend_bundle is not None:
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(30, wallet.get_confirmed_balance, funds - 101)
await time_out_assert(30, wallet.get_unconfirmed_balance, funds - 101)
@ -386,11 +354,7 @@ class TestCATWallet:
cc2_ph = await cat_wallet_2.get_new_cat_puzzle_hash()
tx_record = await wallet.wallet_state_manager.main_wallet.generate_signed_transaction(10, cc2_ph, 0)
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
await full_node_api.process_transaction_records(records=[tx_record])
id = cat_wallet_2.id()
wsm = cat_wallet_2.wallet_state_manager
@ -447,13 +411,8 @@ class TestCATWallet:
cat_wallet_0: CATWallet = await CATWallet.create_new_cat_wallet(
wallet_node_0.wallet_state_manager, wallet_0, {"identifier": "genesis_by_id"}, uint64(100)
)
tx_queue: List[TransactionRecord] = await wallet_node_0.wallet_state_manager.tx_store.get_not_sent()
tx_record = tx_queue[0]
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
tx_records: List[TransactionRecord] = await wallet_node_0.wallet_state_manager.tx_store.get_not_sent()
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet_0.get_confirmed_balance, 100)
await time_out_assert(20, cat_wallet_0.get_unconfirmed_balance, 100)
@ -478,11 +437,7 @@ class TestCATWallet:
tx_records = await cat_wallet_0.generate_signed_transaction([uint64(60), uint64(20)], [cat_1_hash, cat_2_hash])
for tx_record in tx_records:
await wallet_0.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet_0.get_confirmed_balance, 20)
await time_out_assert(20, cat_wallet_0.get_unconfirmed_balance, 20)
@ -498,19 +453,12 @@ class TestCATWallet:
tx_records = await cat_wallet_1.generate_signed_transaction([uint64(15)], [cat_hash])
for tx_record in tx_records:
await wallet_1.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
tx_records_2 = await cat_wallet_2.generate_signed_transaction([uint64(20)], [cat_hash])
for tx_record in tx_records_2:
await wallet_2.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
await full_node_api.process_transaction_records(records=[*tx_records, *tx_records_2])
await time_out_assert(20, cat_wallet_0.get_confirmed_balance, 55)
await time_out_assert(20, cat_wallet_0.get_unconfirmed_balance, 55)
@ -534,9 +482,7 @@ class TestCATWallet:
for tx_record in tx_records_3:
await wallet_1.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
await time_out_assert(15, full_node_api.txs_in_mempool, True, tx_records_3)
txs = await wallet_1.wallet_state_manager.tx_store.get_transactions_between(cat_wallet_1.id(), 0, 100000)
for tx in txs:
if tx.amount == 30:
@ -586,13 +532,8 @@ class TestCATWallet:
cat_wallet: CATWallet = await CATWallet.create_new_cat_wallet(
wallet_node.wallet_state_manager, wallet, {"identifier": "genesis_by_id"}, uint64(100000)
)
tx_queue: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
tx_record = tx_queue[0]
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
tx_records: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet.get_confirmed_balance, 100000)
await time_out_assert(20, cat_wallet.get_unconfirmed_balance, 100000)
@ -610,12 +551,7 @@ class TestCATWallet:
tx_records = await cat_wallet.generate_signed_transaction(amounts, puzzle_hashes, coins={spent_coint})
for tx_record in tx_records:
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await full_node_api.process_transaction_records(records=tx_records)
await asyncio.sleep(2)
@ -708,13 +644,8 @@ class TestCATWallet:
cat_wallet: CATWallet = await CATWallet.create_new_cat_wallet(
wallet_node.wallet_state_manager, wallet, {"identifier": "genesis_by_id"}, uint64(100)
)
tx_queue: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
tx_record = tx_queue[0]
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
tx_records: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet.get_confirmed_balance, 100)
await time_out_assert(20, cat_wallet.get_unconfirmed_balance, 100)
@ -726,12 +657,7 @@ class TestCATWallet:
for tx_record in tx_records:
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet.get_confirmed_balance, 40)
await time_out_assert(20, cat_wallet.get_unconfirmed_balance, 40)
@ -761,12 +687,7 @@ class TestCATWallet:
for tx_record in tx_records:
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet.get_confirmed_balance, 30)
await time_out_assert(20, cat_wallet.get_unconfirmed_balance, 30)
@ -784,12 +705,7 @@ class TestCATWallet:
for tx_record in tx_records:
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, cat_wallet.get_confirmed_balance, 35)
await time_out_assert(20, cat_wallet.get_unconfirmed_balance, 35)

View File

@ -9,7 +9,6 @@ import pytest
from chia.consensus.cost_calculator import NPCResult
from chia.full_node.bundle_tools import simple_solution_generator
from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions
from chia.full_node.mempool_manager import MempoolManager
from chia.simulator.simulator_protocol import FarmNewBlockProtocol
from chia.simulator.time_out_assert import time_out_assert
from chia.types.blockchain_format.program import INFINITE_COST
@ -21,14 +20,7 @@ from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.transaction_type import TransactionType
async def tx_in_pool(mempool: MempoolManager, tx_id):
tx = mempool.get_spendbundle(tx_id)
if tx is None:
return False
return True
from tests.util.wallet_is_synced import wallets_are_synced
buffer_blocks = 4
@ -136,13 +128,13 @@ class TestCATTrades:
peer = wallet_node_taker.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=uint64(1)
)
await asyncio.sleep(1)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
first_offer = Offer.from_bytes(trade_take.offer)
@ -154,8 +146,8 @@ class TestCATTrades:
await time_out_assert(15, wallet_taker.get_unconfirmed_balance, TAKER_CHIA_BALANCE)
await time_out_assert(15, new_cat_wallet_taker.get_unconfirmed_balance, TAKER_NEW_CAT_BALANCE)
for i in range(0, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=tx_records)
await time_out_assert(15, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node)
await time_out_assert(15, wallet_maker.get_confirmed_balance, MAKER_CHIA_BALANCE)
await time_out_assert(15, wallet_maker.get_unconfirmed_balance, MAKER_CHIA_BALANCE)
@ -182,18 +174,17 @@ class TestCATTrades:
# cat_for_chia
success, trade_make, error = await trade_manager_maker.create_offer_for_ids(cat_for_chia)
await asyncio.sleep(1)
assert error is None
assert success is True
assert trade_make is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer
)
await asyncio.sleep(1)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
MAKER_CAT_BALANCE -= 4
MAKER_CHIA_BALANCE += 3
@ -207,8 +198,8 @@ class TestCATTrades:
await time_out_assert(15, wallet_taker.get_unconfirmed_balance, TAKER_CHIA_BALANCE)
await time_out_assert(15, cat_wallet_taker.get_unconfirmed_balance, TAKER_CAT_BALANCE)
for i in range(0, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=tx_records)
await time_out_assert(15, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node)
await time_out_assert(15, wallet_maker.get_confirmed_balance, MAKER_CHIA_BALANCE)
await time_out_assert(15, wallet_maker.get_unconfirmed_balance, MAKER_CHIA_BALANCE)
@ -229,13 +220,14 @@ class TestCATTrades:
assert error is None
assert success is True
assert trade_make is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer
)
await asyncio.sleep(1)
await time_out_assert(15, full_node.txs_in_mempool, True, tx_records)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
second_offer = Offer.from_bytes(trade_take.offer)
@ -247,8 +239,8 @@ class TestCATTrades:
await time_out_assert(15, new_cat_wallet_taker.get_unconfirmed_balance, TAKER_NEW_CAT_BALANCE)
await time_out_assert(15, cat_wallet_taker.get_unconfirmed_balance, TAKER_CAT_BALANCE)
for i in range(0, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=tx_records)
await time_out_assert(15, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node)
await time_out_assert(15, new_cat_wallet_maker.get_confirmed_balance, MAKER_NEW_CAT_BALANCE)
await time_out_assert(15, new_cat_wallet_maker.get_unconfirmed_balance, MAKER_NEW_CAT_BALANCE)
@ -269,13 +261,14 @@ class TestCATTrades:
assert error is None
assert success is True
assert trade_make is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer
)
await asyncio.sleep(1)
await time_out_assert(15, full_node.txs_in_mempool, True, tx_records)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
third_offer = Offer.from_bytes(trade_take.offer)
@ -289,8 +282,8 @@ class TestCATTrades:
await time_out_assert(15, new_cat_wallet_taker.get_unconfirmed_balance, TAKER_NEW_CAT_BALANCE)
await time_out_assert(15, cat_wallet_taker.get_unconfirmed_balance, TAKER_CAT_BALANCE)
for i in range(0, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=tx_records)
await time_out_assert(15, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node)
await time_out_assert(15, new_cat_wallet_maker.get_confirmed_balance, MAKER_NEW_CAT_BALANCE)
await time_out_assert(15, new_cat_wallet_maker.get_unconfirmed_balance, MAKER_NEW_CAT_BALANCE)
@ -309,13 +302,14 @@ class TestCATTrades:
assert error is None
assert success is True
assert trade_make is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer
)
await asyncio.sleep(1)
await time_out_assert(15, full_node.txs_in_mempool, True, tx_records)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
fourth_offer = Offer.from_bytes(trade_take.offer)
@ -329,8 +323,8 @@ class TestCATTrades:
await time_out_assert(15, new_cat_wallet_taker.get_unconfirmed_balance, TAKER_NEW_CAT_BALANCE)
await time_out_assert(15, cat_wallet_taker.get_unconfirmed_balance, TAKER_CAT_BALANCE)
for i in range(0, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=tx_records)
await time_out_assert(15, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node)
await time_out_assert(15, new_cat_wallet_maker.get_confirmed_balance, MAKER_NEW_CAT_BALANCE)
await time_out_assert(15, new_cat_wallet_maker.get_unconfirmed_balance, MAKER_NEW_CAT_BALANCE)
@ -349,13 +343,14 @@ class TestCATTrades:
assert error is None
assert success is True
assert trade_make is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer
)
await asyncio.sleep(1)
await time_out_assert(15, full_node.txs_in_mempool, True, tx_records)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
fifth_offer = Offer.from_bytes(trade_take.offer)
@ -369,8 +364,8 @@ class TestCATTrades:
await time_out_assert(15, new_cat_wallet_taker.get_unconfirmed_balance, TAKER_NEW_CAT_BALANCE)
await time_out_assert(15, cat_wallet_taker.get_unconfirmed_balance, TAKER_CAT_BALANCE)
for i in range(0, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=tx_records)
await time_out_assert(15, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node)
await time_out_assert(15, new_cat_wallet_maker.get_confirmed_balance, MAKER_NEW_CAT_BALANCE)
await time_out_assert(15, new_cat_wallet_maker.get_unconfirmed_balance, MAKER_NEW_CAT_BALANCE)
@ -407,13 +402,9 @@ class TestCATTrades:
wallet_node_maker.wallet_state_manager, wallet_maker, {"identifier": "genesis_by_id"}, xch_to_cat_amount
)
tx_queue: List[TransactionRecord] = await wallet_node_maker.wallet_state_manager.tx_store.get_not_sent()
await time_out_assert(
15, tx_in_pool, True, full_node.full_node.mempool_manager, tx_queue[0].spend_bundle.name()
)
tx_records: List[TransactionRecord] = await wallet_node_maker.wallet_state_manager.tx_store.get_not_sent()
for i in range(1, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=tx_records)
await time_out_assert(15, cat_wallet_maker.get_confirmed_balance, xch_to_cat_amount)
await time_out_assert(15, cat_wallet_maker.get_unconfirmed_balance, xch_to_cat_amount)
@ -449,17 +440,19 @@ class TestCATTrades:
# Due to current mempool rules, trying to force a take out of the mempool with a cancel will not work.
# Uncomment this when/if it does
# success, trade_take, error = await trade_manager_taker.respond_to_offer(Offer.from_bytes(trade_make.offer))
# await asyncio.sleep(1)
# success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
# Offer.from_bytes(trade_make.offer),
# )
# await time_out_assert(15, full_node.txs_in_mempool, True, tx_records)
# assert error is None
# assert success is True
# assert trade_take is not None
# assert tx_records is not None
# await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CONFIRM, trade_manager_taker, trade_take)
# await time_out_assert(
# 15,
# tx_in_pool,
# full_node.tx_id_in_mempool,
# True,
# full_node.full_node.mempool_manager,
# Offer.from_bytes(trade_take.offer).to_valid_spend().name(),
# )
@ -467,9 +460,7 @@ class TestCATTrades:
txs = await trade_manager_maker.cancel_pending_offer_safely(trade_make.trade_id, fee=fee)
await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
for tx in txs:
if tx.spend_bundle is not None:
await time_out_assert(15, tx_in_pool, True, full_node.full_node.mempool_manager, tx.spend_bundle.name())
await full_node.process_transaction_records(records=txs)
sum_of_outgoing = uint64(0)
sum_of_incoming = uint64(0)
@ -480,9 +471,6 @@ class TestCATTrades:
sum_of_incoming = uint64(sum_of_incoming + tx.amount)
assert (sum_of_outgoing - sum_of_incoming) == 0
for i in range(1, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
# await time_out_assert(15, get_trade_and_status, TradeStatus.FAILED, trade_manager_taker, trade_take)
@ -493,37 +481,31 @@ class TestCATTrades:
peer = wallet_node_taker.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer
)
await asyncio.sleep(1)
assert error is not None
assert success is False
assert trade_take is None
assert tx_records is None
# Now we're going to create the other way around for test coverage sake
success, trade_make, error = await trade_manager_maker.create_offer_for_ids(chia_for_cat)
await asyncio.sleep(1)
assert error is None
assert success is True
assert trade_make is not None
# This take should fail since we have no CATs to fulfill it with
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer
)
await asyncio.sleep(1)
assert error is not None
assert success is False
assert trade_take is None
assert tx_records is None
txs = await trade_manager_maker.cancel_pending_offer_safely(trade_make.trade_id, fee=uint64(0))
await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
for tx in txs:
if tx.spend_bundle is not None:
await time_out_assert(15, tx_in_pool, True, full_node.full_node.mempool_manager, tx.spend_bundle.name())
for i in range(1, buffer_blocks):
await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
await full_node.process_transaction_records(records=txs)
await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)

View File

@ -1,6 +1,5 @@
from __future__ import annotations
import dataclasses
from typing import Any, List, Tuple
import pytest
@ -143,7 +142,7 @@ async def test_dl_offers(wallets_prefarm: Any, trusted: bool) -> None:
]
}
success, offer_taker, error = await trade_manager_taker.respond_to_offer(
success, offer_taker, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(offer_maker.offer),
peer,
solver=Solver(
@ -176,6 +175,7 @@ async def test_dl_offers(wallets_prefarm: Any, trusted: bool) -> None:
assert error is None
assert success is True
assert offer_taker is not None
assert tx_records is not None
assert await trade_manager_maker.get_offer_summary(Offer.from_bytes(offer_taker.offer)) == {
"offered": [
@ -205,9 +205,7 @@ async def test_dl_offers(wallets_prefarm: Any, trusted: bool) -> None:
await time_out_assert(15, wallet_maker.get_unconfirmed_balance, maker_funds)
await time_out_assert(15, wallet_taker.get_unconfirmed_balance, taker_funds - fee)
# Let's hack a way to await this offer's confirmation
offer_record = dataclasses.replace(dl_record, spend_bundle=Offer.from_bytes(offer_taker.offer).bundle)
await full_node_api.process_transaction_records(records=[offer_record])
await full_node_api.process_transaction_records(records=tx_records)
maker_funds -= fee
taker_funds -= fee
@ -423,7 +421,7 @@ async def test_multiple_dl_offers(wallets_prefarm: Any, trusted: bool) -> None:
assert success is True
assert offer_maker is not None
success, offer_taker, error = await trade_manager_taker.respond_to_offer(
success, offer_taker, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(offer_maker.offer),
peer,
solver=Solver(
@ -469,13 +467,12 @@ async def test_multiple_dl_offers(wallets_prefarm: Any, trusted: bool) -> None:
assert error is None
assert success is True
assert offer_taker is not None
assert tx_records is not None
await time_out_assert(15, wallet_maker.get_unconfirmed_balance, maker_funds)
await time_out_assert(15, wallet_taker.get_unconfirmed_balance, taker_funds - fee)
# Let's hack a way to await this offer's confirmation
offer_record = dataclasses.replace(dl_record, spend_bundle=Offer.from_bytes(offer_taker.offer).bundle)
await full_node_api.process_transaction_records(records=[offer_record])
await full_node_api.process_transaction_records(records=tx_records)
maker_funds -= fee
taker_funds -= fee

View File

@ -8,7 +8,6 @@ from typing import Any, Callable, Coroutine, Optional
import pytest
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
from chia.full_node.mempool_manager import MempoolManager
from chia.simulator.full_node_simulator import FullNodeSimulator
from chia.simulator.simulator_protocol import FarmNewBlockProtocol
from chia.simulator.time_out_assert import time_out_assert, time_out_assert_not_none
@ -32,13 +31,6 @@ from tests.util.wallet_is_synced import wallets_are_synced
logging.getLogger("aiosqlite").setLevel(logging.INFO) # Too much logging on debug level
async def tx_in_pool(mempool: MempoolManager, tx_id: bytes32) -> bool:
tx = mempool.get_spendbundle(tx_id)
if tx is None:
return False
return True
def mempool_not_empty(fnapi: FullNodeSimulator) -> bool:
return len(fnapi.full_node.mempool_manager.mempool.spends) > 0
@ -188,7 +180,7 @@ async def test_nft_offer_sell_nft(two_wallet_nodes: Any, trusted: Any) -> None:
peer = wallet_node_taker.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=uint64(taker_fee)
)
@ -197,6 +189,7 @@ async def test_nft_offer_sell_nft(two_wallet_nodes: Any, trusted: Any) -> None:
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
async def maker_0_taker_1() -> bool:
return (
@ -347,7 +340,7 @@ async def test_nft_offer_request_nft(two_wallet_nodes: Any, trusted: Any) -> Non
peer = wallet_node_taker.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=uint64(taker_fee)
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
@ -355,7 +348,7 @@ async def test_nft_offer_request_nft(two_wallet_nodes: Any, trusted: Any) -> Non
assert success is True
assert trade_take is not None
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph_token))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node_api)
async def maker_1_taker_0() -> bool:
@ -523,13 +516,14 @@ async def test_nft_offer_sell_did_to_did(two_wallet_nodes: Any, trusted: Any) ->
peer = wallet_node_taker.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=uint64(taker_fee)
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
async def maker_0_taker_1() -> bool:
return (
@ -692,11 +686,7 @@ async def test_nft_offer_sell_nft_for_cat(two_wallet_nodes: Any, trusted: Any) -
)
for tx_record in cat_tx_records:
await wallet_maker.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name() # type: ignore
)
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph_token))
await full_node_api.process_transaction_records(records=cat_tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node_api)
maker_cat_balance = cats_to_mint - (2 * cats_to_trade)
taker_cat_balance = 2 * cats_to_trade
@ -722,13 +712,14 @@ async def test_nft_offer_sell_nft_for_cat(two_wallet_nodes: Any, trusted: Any) -
peer = wallet_node_taker.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=uint64(taker_fee)
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
async def maker_0_taker_1() -> bool:
return (
@ -891,11 +882,7 @@ async def test_nft_offer_request_nft_for_cat(two_wallet_nodes: Any, trusted: boo
cat_tx_records = await cat_wallet_maker.generate_signed_transaction(amounts, puzzle_hashes)
for tx_record in cat_tx_records:
await wallet_maker.wallet_state_manager.add_pending_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name() # type: ignore
)
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph_token))
await full_node_api.process_transaction_records(records=cat_tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_maker, wallet_node_taker], full_node_api)
if test_change:
taker_cat_balance = cats_to_mint - (2 * cats_to_trade)
@ -925,13 +912,14 @@ async def test_nft_offer_request_nft_for_cat(two_wallet_nodes: Any, trusted: boo
peer = wallet_node_taker.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=uint64(taker_fee)
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
assert error is None
assert success is True
assert trade_take is not None
assert tx_records is not None
async def maker_1_taker_0() -> bool:
return (
@ -1062,11 +1050,7 @@ async def test_nft_offer_sell_cancel(two_wallet_nodes: Any, trusted: Any) -> Non
return TradeStatus(trade_rec.status)
await time_out_assert(20, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
for tx in txs:
if tx.spend_bundle is not None:
await time_out_assert(20, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx.spend_bundle.name())
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32([0] * 32)))
await full_node_api.process_transaction_records(records=txs)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_maker], full_node_api)
await time_out_assert(15, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
@ -1183,9 +1167,7 @@ async def test_nft_offer_sell_cancel_in_batch(two_wallet_nodes: Any, trusted: An
return TradeStatus(trade_rec.status)
await time_out_assert(15, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
for tx in txs:
if tx.spend_bundle is not None:
await time_out_assert(15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx.spend_bundle.name())
await full_node_api.process_transaction_records(records=txs)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32([0] * 32)))
@ -1414,7 +1396,7 @@ async def test_complex_nft_offer(two_wallet_nodes: Any, trusted: Any) -> None:
assert success
assert trade_make is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer),
wallet_node_taker.get_full_node_peer(),
fee=FEE,
@ -1422,9 +1404,8 @@ async def test_complex_nft_offer(two_wallet_nodes: Any, trusted: Any) -> None:
assert error is None
assert success
assert trade_take is not None
await time_out_assert(20, mempool_not_empty, True, full_node_api)
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph_token))
assert tx_records is not None
await full_node_api.process_transaction_records(records=tx_records)
# Now let's make sure the final wallet state is correct
maker_royalty_summary = NFTWallet.royalty_calculation(

View File

@ -6,7 +6,6 @@ from typing import Any, Dict, Optional
import pytest
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
from chia.full_node.mempool_manager import MempoolManager
from chia.simulator.full_node_simulator import FullNodeSimulator
from chia.simulator.simulator_protocol import FarmNewBlockProtocol
from chia.simulator.time_out_assert import time_out_assert, time_out_assert_not_none
@ -25,13 +24,6 @@ from tests.util.wallet_is_synced import wallets_are_synced
from tests.wallet.nft_wallet.test_nft_1_offers import mempool_not_empty
async def tx_in_pool(mempool: MempoolManager, tx_id: bytes32) -> bool:
tx = mempool.get_spendbundle(tx_id)
if tx is None:
return False
return True
async def get_trade_and_status(trade_manager, trade) -> TradeStatus: # type: ignore
trade_rec = await trade_manager.get_trade_by_id(trade.trade_id)
return TradeStatus(trade_rec.status)
@ -136,18 +128,16 @@ async def test_nft_offer_with_fee(two_wallet_nodes: Any, trusted: Any) -> None:
peer = wallet_node_1.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=taker_fee
)
sb_id = Offer.from_bytes(trade_take.offer).to_valid_spend().name()
await time_out_assert_not_none(20, full_node_api.full_node.mempool_manager.get_spendbundle, sb_id)
assert success
assert error is None
assert trade_take is not None
assert tx_records is not None
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_0, wallet_node_1], full_node_api)
await time_out_assert(20, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
@ -182,18 +172,16 @@ async def test_nft_offer_with_fee(two_wallet_nodes: Any, trusted: Any) -> None:
taker_fee = uint64(1)
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=taker_fee
)
sb_id = Offer.from_bytes(trade_take.offer).to_valid_spend().name()
await time_out_assert_not_none(20, full_node_api.full_node.mempool_manager.get_spendbundle, sb_id)
assert success
assert error is None
assert trade_take is not None
assert tx_records is not None
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_0, wallet_node_1], full_node_api)
await time_out_assert(20, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
@ -309,11 +297,7 @@ async def test_nft_offer_cancellations(two_wallet_nodes: Any, trusted: Any) -> N
txs = await trade_manager_maker.cancel_pending_offer_safely(trade_make.trade_id, fee=cancel_fee)
await time_out_assert(20, get_trade_and_status, TradeStatus.PENDING_CANCEL, trade_manager_maker, trade_make)
for tx in txs:
if tx.spend_bundle is not None:
await time_out_assert(20, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx.spend_bundle.name())
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_ph))
await full_node_api.process_transaction_records(records=txs)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_0, wallet_node_1], full_node_api)
await time_out_assert(20, get_trade_and_status, TradeStatus.CANCELLED, trade_manager_maker, trade_make)
@ -444,16 +428,16 @@ async def test_nft_offer_with_metadata_update(two_wallet_nodes: Any, trusted: An
peer = wallet_node_1.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=taker_fee
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
assert success
assert error is None
assert trade_take is not None
assert tx_records is not None
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_0, wallet_node_1], full_node_api)
await time_out_assert(20, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
@ -601,16 +585,16 @@ async def test_nft_offer_nft_for_cat(two_wallet_nodes: Any, trusted: Any) -> Non
peer = wallet_node_1.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=taker_fee
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
assert success
assert error is None
assert trade_take is not None
assert tx_records is not None
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_0, wallet_node_1], full_node_api)
await time_out_assert(20, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
@ -657,17 +641,17 @@ async def test_nft_offer_nft_for_cat(two_wallet_nodes: Any, trusted: Any) -> Non
taker_fee = uint64(1)
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=taker_fee
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
assert success
assert error is None
assert trade_take is not None
assert tx_records is not None
await full_node_api.process_transaction_records(records=tx_records)
# check balances: taker wallet down an NFT, up cats
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_ph))
await time_out_assert(20, wallets_are_synced, True, [wallet_node_0, wallet_node_1], full_node_api)
await time_out_assert(20, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)
@ -802,16 +786,16 @@ async def test_nft_offer_nft_for_nft(two_wallet_nodes: Any, trusted: Any) -> Non
peer = wallet_node_1.get_full_node_peer()
assert peer is not None
success, trade_take, error = await trade_manager_taker.respond_to_offer(
success, trade_take, tx_records, error = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer), peer, fee=taker_fee
)
await time_out_assert(20, mempool_not_empty, True, full_node_api)
assert success
assert error is None
assert trade_take is not None
assert tx_records is not None
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_ph))
await full_node_api.process_transaction_records(records=tx_records)
await time_out_assert(20, wallets_are_synced, True, [wallet_node_0, wallet_node_1], full_node_api)
await time_out_assert(20, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_maker, trade_make)

View File

@ -9,7 +9,6 @@ from blspy import AugSchemeMPL, G1Element, G2Element
from clvm_tools.binutils import disassemble
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
from chia.full_node.mempool_manager import MempoolManager
from chia.rpc.wallet_rpc_api import WalletRpcApi
from chia.simulator.full_node_simulator import FullNodeSimulator
from chia.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol
@ -30,13 +29,6 @@ from chia.wallet.wallet_state_manager import WalletStateManager
from tests.util.wallet_is_synced import wallet_is_synced
async def tx_in_pool(mempool: MempoolManager, tx_id: bytes32) -> bool:
tx = mempool.get_spendbundle(tx_id)
if tx is None:
return False
return True
async def get_nft_count(wallet: NFTWallet) -> int:
return await wallet.get_nft_count()

View File

@ -25,7 +25,6 @@ from chia.wallet.wallet_state_manager import WalletStateManager
from tests.util.wallet_is_synced import wallet_is_synced
from tests.connection_utils import add_dummy_connection
from chia.simulator.time_out_assert import time_out_assert
from tests.wallet.cat_wallet.test_cat_wallet import tx_in_pool
from chia.simulator.wallet_tools import WalletTool
@ -188,12 +187,7 @@ class TestSimpleSyncProtocol:
await wallet.push_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hash))
await full_node_api.process_transaction_records(records=[tx_record])
# Let's make sure the wallet can handle a non ephemeral launcher
from chia.wallet.puzzles.singleton_top_layer import SINGLETON_LAUNCHER_HASH
@ -202,12 +196,7 @@ class TestSimpleSyncProtocol:
tx_record = await wallet.generate_signed_transaction(uint64(10), SINGLETON_LAUNCHER_HASH, uint64(0))
await wallet.push_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(SINGLETON_LAUNCHER_HASH))
await full_node_api.process_transaction_records(records=[tx_record])
await time_out_assert(20, wallet_is_synced, True, wallet_node, full_node_api)
@ -215,12 +204,7 @@ class TestSimpleSyncProtocol:
tx_record = await wallet.generate_signed_transaction(uint64(10), junk_ph, uint64(0))
await wallet.push_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hash))
await full_node_api.process_transaction_records(records=[tx_record])
all_messages = await get_all_messages_in_queue(incoming_queue)
@ -280,13 +264,7 @@ class TestSimpleSyncProtocol:
tx_record = await standard_wallet.generate_signed_transaction(uint64(10), puzzle_hash, uint64(0), coins=coins)
await standard_wallet.push_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
# Farm transaction
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hash))
await full_node_api.process_transaction_records(records=[tx_record])
all_messages = await get_all_messages_in_queue(incoming_queue)
@ -322,12 +300,7 @@ class TestSimpleSyncProtocol:
await standard_wallet.push_transaction(tx_record)
await time_out_assert(
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
)
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hash))
await full_node_api.process_transaction_records(records=[tx_record])
all_messages = await get_all_messages_in_queue(incoming_queue)
@ -532,10 +505,7 @@ class TestSimpleSyncProtocol:
)
await full_node_api.respond_transaction(RespondTransaction(tx), fake_wallet_peer)
await time_out_assert(20, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx.name())
for i in range(0, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await full_node_api.process_spend_bundles(bundles=[tx])
all_messages = await get_all_messages_in_queue(incoming_queue)
@ -615,7 +585,7 @@ class TestSimpleSyncProtocol:
)
await full_node_api.respond_transaction(RespondTransaction(tx), fake_wallet_peer)
await time_out_assert(20, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx.name())
await full_node_api.process_spend_bundles(bundles=[tx])
# Create more blocks than recent "short_sync_blocks_behind_threshold" so that node enters batch
for i in range(0, 100):

View File

@ -26,7 +26,6 @@ from chia.wallet.wallet_state_manager import WalletStateManager
from chia.simulator.block_tools import BlockTools
from chia.simulator.time_out_assert import time_out_assert, time_out_assert_not_none
from tests.util.wallet_is_synced import wallet_is_synced
from tests.wallet.cat_wallet.test_cat_wallet import tx_in_pool
class TestWalletSimulator:
@ -525,11 +524,7 @@ class TestWalletSimulator:
assert tx_split_coins.spend_bundle is not None
await wallet.push_transaction(tx_split_coins)
await time_out_assert(
15, tx_in_pool, True, full_node_1.full_node.mempool_manager, tx_split_coins.spend_bundle.name()
)
for i in range(0, num_blocks):
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
await full_node_1.process_transaction_records(records=[tx_split_coins])
funds = sum(
[