Fix several flaky tests (#11576)

* Increase some of the timeouts to reduce flakiness

* Experiment with CI for flakiness

* Force more runs

* Add argument name

* Fix flaky mempool test

* Attempt to fix another flaky test

* Fix wallet retry test

* Missing arg

* Lint

* Increase benchmark test time

* Debug

* Debug

* Simplify retry test

* Lint

* More lint

* Return false instead of assert

* No need to check disconnect twice (since we don't break, this was flaky)

* Remove useless changes

* Accidental changes revert

* Accidental changes revert 2

* Accidental changes revert 3

* Revert fixture
This commit is contained in:
Mariano Sorgente 2022-05-23 10:54:38 -04:00 committed by GitHub
parent 71a8ac2e69
commit 766e1c21f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 158 deletions

View File

@ -834,7 +834,6 @@ class TestFullNodeProtocol:
await full_node_1.new_transaction(new_transaction, fake_peer)
await time_out_assert(10, new_transaction_not_requested, True, incoming_queue, new_transaction)
print(f"FULL NODE HEIGHT: {start_height + 1} {full_node_1.full_node.blockchain.get_peak_height()}")
await time_out_assert(10, node_height_at_least, True, full_node_1, start_height + 1)
await time_out_assert(10, node_height_at_least, True, full_node_2, start_height + 1)
@ -845,6 +844,7 @@ class TestFullNodeProtocol:
# Fill mempool
receiver_puzzlehash = wallet_receiver.get_new_puzzlehash()
random.seed(b"123465")
group_size = 3 # We will generate transaction bundles of this size (* standard transaction of around 3-4M cost)
for i in range(1, len(puzzle_hashes), group_size):
phs_to_use = [puzzle_hashes[i + j] for j in range(group_size) if (i + j) < len(puzzle_hashes)]
@ -897,7 +897,7 @@ class TestFullNodeProtocol:
assert full_node_1.full_node.mempool_manager.mempool.at_full_capacity(10000000 * group_size)
assert included_tx > 0
assert not_included_tx > 0
assert not_included_tx == 3
assert seen_bigger_transaction_has_high_fee
# Mempool is full

View File

@ -2458,7 +2458,7 @@ class TestMaliciousGenerators:
spend = npc_result.conds.spends[0]
assert len(spend.create_coin) == 6094
print(f"run time:{run_time}")
assert run_time < 0.2
assert run_time < 0.3
@pytest.mark.asyncio
async def test_invalid_coin_spend_coin(self, bt, one_node_one_block, wallet_a):

View File

@ -149,7 +149,6 @@ class TestRateLimits:
if not response:
saw_disconnect = True
assert saw_disconnect
assert not r.process_msg_and_check(new_tx_message)
await asyncio.sleep(6)
assert r.process_msg_and_check(new_tx_message)

View File

@ -181,12 +181,12 @@ class TestPoolWalletRpc:
PeerInfo(self_hostname, uint16(full_node_api.full_node.server._port)), None
)
total_block_rewards = await get_total_block_rewards(PREFARMED_BLOCKS)
await time_out_assert(10, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(10, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(20, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(20, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
our_ph = await wallet_0.get_new_puzzlehash()
assert len(await client.get_wallets(WalletType.POOLING_WALLET)) == 0
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
creation_tx: TransactionRecord = await client.create_new_pool_wallet(
our_ph, "", 0, f"{self_hostname}:5000", "new", "SELF_POOLING", fee
)
@ -200,7 +200,7 @@ class TestPoolWalletRpc:
await farm_blocks(full_node_api, our_ph, 6)
assert full_node_api.full_node.mempool_manager.get_spendbundle(creation_tx.name) is None
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
summaries_response = await client.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1
wallet_id: int = summaries_response[0]["id"]
@ -251,11 +251,11 @@ class TestPoolWalletRpc:
PeerInfo(self_hostname, uint16(full_node_api.full_node.server._port)), None
)
total_block_rewards = await get_total_block_rewards(PREFARMED_BLOCKS)
await time_out_assert(10, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(20, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(10, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(20, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
our_ph = await wallet_0.get_new_puzzlehash()
assert len(await client.get_wallets(WalletType.POOLING_WALLET)) == 0
@ -273,7 +273,7 @@ class TestPoolWalletRpc:
await farm_blocks(full_node_api, our_ph, 6)
assert full_node_api.full_node.mempool_manager.get_spendbundle(creation_tx.name) is None
await time_out_assert(5, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
summaries_response = await client.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1
wallet_id: int = summaries_response[0]["id"]
@ -324,9 +324,9 @@ class TestPoolWalletRpc:
)
total_block_rewards = await get_total_block_rewards(PREFARMED_BLOCKS)
wallet_0 = wallet_node_0.wallet_state_manager.main_wallet
await time_out_assert(10, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(10, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(20, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
our_ph_1 = await wallet_0.get_new_puzzlehash()
our_ph_2 = await wallet_0.get_new_puzzlehash()
@ -402,7 +402,7 @@ class TestPoolWalletRpc:
# run this code more than once, since it's slow.
if not trusted:
for i in range(22):
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
creation_tx_3: TransactionRecord = await client.create_new_pool_wallet(
our_ph_1, self_hostname, 5, f"{self_hostname}:5000", "new", "FARMING_TO_POOL", fee
)
@ -451,13 +451,13 @@ class TestPoolWalletRpc:
)
wallet_0 = wallet_node_0.wallet_state_manager.main_wallet
total_block_rewards = await get_total_block_rewards(PREFARMED_BLOCKS)
await time_out_assert(10, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(10, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(20, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(20, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
our_ph = await wallet_0.get_new_puzzlehash()
assert len(await client.get_wallets(WalletType.POOLING_WALLET)) == 0
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
creation_tx: TransactionRecord = await client.create_new_pool_wallet(
our_ph, "", 0, f"{self_hostname}:5000", "new", "SELF_POOLING", fee
)
@ -545,7 +545,7 @@ class TestPoolWalletRpc:
tx1 = await client.get_transactions(1)
assert (250000000000 + fee) in [tx.amount for tx in tx1]
# await time_out_assert(10, wallet_0.get_confirmed_balance, total_block_rewards)
# await time_out_assert(20, wallet_0.get_confirmed_balance, total_block_rewards)
@pytest.mark.asyncio
@pytest.mark.parametrize("trusted_and_fee", [(True, FEE_AMOUNT * 2)])
@ -564,13 +564,13 @@ class TestPoolWalletRpc:
)
wallet_0 = wallet_node_0.wallet_state_manager.main_wallet
total_block_rewards = await get_total_block_rewards(PREFARMED_BLOCKS)
await time_out_assert(10, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(10, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(20, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(20, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
our_ph = await wallet_0.get_new_puzzlehash()
assert len(await client.get_wallets(WalletType.POOLING_WALLET)) == 0
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
creation_tx: TransactionRecord = await client.create_new_pool_wallet(
our_ph, "", 0, f"{self_hostname}:5000", "new", "SELF_POOLING", fee
)
@ -591,7 +591,7 @@ class TestPoolWalletRpc:
except ValueError:
return False
await time_out_assert(10, pool_wallet_created)
await time_out_assert(20, pool_wallet_created)
status: PoolWalletInfo = (await client.pw_status(2))[0]
async with TemporaryPoolPlot(bt, status.p2_singleton_puzzle_hash) as pool_plot:
@ -653,10 +653,10 @@ class TestPoolWalletRpc:
)
wallet_0 = wallet_node_0.wallet_state_manager.main_wallet
total_block_rewards = await get_total_block_rewards(PREFARMED_BLOCKS)
await time_out_assert(10, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(10, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(20, wallet_0.get_confirmed_balance, total_block_rewards)
await time_out_assert(20, wallet_node_0.wallet_state_manager.blockchain.get_peak_height, PREFARMED_BLOCKS)
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
our_ph = await wallet_0.get_new_puzzlehash()
assert len(await client.get_wallets(WalletType.POOLING_WALLET)) == 0
# Balance stars at 6 XCH
@ -782,7 +782,7 @@ class TestPoolWalletRpc:
assert (250000000000 + fee) in [tx.amount for tx in tx1]
@pytest.mark.asyncio
@pytest.mark.parametrize("trusted_and_fee", [(True, 0), (False, 0)])
@pytest.mark.parametrize("trusted_and_fee", [(False, 0)])
async def test_self_pooling_to_pooling(self, setup, trusted_and_fee, self_hostname):
"""
This tests self-pooling -> pooling
@ -813,10 +813,10 @@ class TestPoolWalletRpc:
total_blocks += await farm_blocks(full_node_api, our_ph, num_blocks)
total_block_rewards = await get_total_block_rewards(total_blocks)
await time_out_assert(10, wallets[0].get_unconfirmed_balance, total_block_rewards)
await time_out_assert(10, wallets[0].get_confirmed_balance, total_block_rewards)
await time_out_assert(10, wallets[0].get_spendable_balance, total_block_rewards)
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallets[0].get_unconfirmed_balance, total_block_rewards)
await time_out_assert(20, wallets[0].get_confirmed_balance, total_block_rewards)
await time_out_assert(20, wallets[0].get_spendable_balance, total_block_rewards)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
assert total_block_rewards > 0
assert len(await client.get_wallets(WalletType.POOLING_WALLET)) == 0
@ -824,16 +824,15 @@ class TestPoolWalletRpc:
creation_tx: TransactionRecord = await client.create_new_pool_wallet(
our_ph, "", 0, f"{self_hostname}:5000", "new", "SELF_POOLING", fee
)
creation_tx_2: TransactionRecord = await client.create_new_pool_wallet(
our_ph, "", 0, f"{self_hostname}:5000", "new", "SELF_POOLING", fee
)
await time_out_assert(
10,
full_node_api.full_node.mempool_manager.get_spendbundle,
creation_tx.spend_bundle,
creation_tx.name,
)
creation_tx_2: TransactionRecord = await client.create_new_pool_wallet(
our_ph, "", 0, f"{self_hostname}:5001", "new", "SELF_POOLING", fee
)
await time_out_assert(
10,
full_node_api.full_node.mempool_manager.get_spendbundle,
@ -841,15 +840,17 @@ class TestPoolWalletRpc:
creation_tx_2.name,
)
await farm_blocks(full_node_api, our_ph, 6)
for r in creation_tx.removals:
assert r not in creation_tx_2.removals
await farm_blocks(full_node_api, our_ph, 1)
assert full_node_api.full_node.mempool_manager.get_spendbundle(creation_tx.name) is None
await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api)
summaries_response = await client.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 2
wallet_id: int = summaries_response[0]["id"]
wallet_id_2: int = summaries_response[1]["id"]
await asyncio.sleep(1)
status: PoolWalletInfo = (await client.pw_status(wallet_id))[0]
status_2: PoolWalletInfo = (await client.pw_status(wallet_id_2))[0]
@ -858,36 +859,32 @@ class TestPoolWalletRpc:
assert status.target is None
assert status_2.target is None
join_pool_tx: TransactionRecord = (
await client.pw_join_pool(
wallet_id,
pool_ph,
"https://pool.example.com",
10,
fee,
)
)["transaction"]
join_pool_tx_2: TransactionRecord = (
await client.pw_join_pool(
wallet_id_2,
pool_ph,
"https://pool.example.com",
10,
fee,
)
)["transaction"]
assert join_pool_tx is not None
assert join_pool_tx_2 is not None
status: PoolWalletInfo = (await client.pw_status(wallet_id))[0]
status_2: PoolWalletInfo = (await client.pw_status(wallet_id_2))[0]
async def tx_is_in_mempool(wid, tx: TransactionRecord):
fetched: Optional[TransactionRecord] = await client.get_transaction(wid, tx.name)
return fetched is not None and fetched.is_in_mempool()
await time_out_assert(10, tx_is_in_mempool, True, wallet_id, join_pool_tx)
await time_out_assert(10, tx_is_in_mempool, True, wallet_id_2, join_pool_tx_2)
join_pool: Dict = await client.pw_join_pool(
wallet_id,
pool_ph,
"https://pool.example.com",
10,
fee,
)
assert join_pool["success"]
join_pool_tx: TransactionRecord = join_pool["transaction"]
assert join_pool_tx is not None
await time_out_assert(5, tx_is_in_mempool, True, wallet_id, join_pool_tx)
join_pool_2: Dict = await client.pw_join_pool(wallet_id_2, pool_ph, "https://pool.example.com", 10, fee)
assert join_pool_2["success"]
join_pool_tx_2: TransactionRecord = join_pool_2["transaction"]
for r in join_pool_tx.removals:
assert r not in join_pool_tx_2.removals
assert join_pool_tx_2 is not None
await time_out_assert(5, tx_is_in_mempool, True, wallet_id_2, join_pool_tx_2)
status: PoolWalletInfo = (await client.pw_status(wallet_id))[0]
status_2: PoolWalletInfo = (await client.pw_status(wallet_id_2))[0]
assert status.current.state == PoolSingletonState.SELF_POOLING.value
assert status.target is not None
@ -896,9 +893,7 @@ class TestPoolWalletRpc:
assert status_2.target is not None
assert status_2.target.state == PoolSingletonState.FARMING_TO_POOL.value
await farm_blocks(full_node_api, our_ph, 6)
total_blocks += await farm_blocks(full_node_api, our_ph, num_blocks)
await farm_blocks(full_node_api, our_ph, 1)
async def status_is_farming_to_pool(w_id: int):
pw_status: PoolWalletInfo = (await client.pw_status(w_id))[0]
@ -942,7 +937,7 @@ class TestPoolWalletRpc:
return (await wallets[0].get_confirmed_balance()) > 0
await time_out_assert(timeout=MAX_WAIT_SECS, function=have_chia)
await time_out_assert(10, wallet_is_synced, True, wallet_nodes[0], full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_nodes[0], full_node_api)
creation_tx: TransactionRecord = await client.create_new_pool_wallet(
our_ph, "", 0, f"{self_hostname}:5000", "new", "SELF_POOLING", fee
@ -958,7 +953,7 @@ class TestPoolWalletRpc:
await farm_blocks(full_node_api, our_ph, 6)
assert full_node_api.full_node.mempool_manager.get_spendbundle(creation_tx.name) is None
await time_out_assert(10, wallet_is_synced, True, wallet_nodes[0], full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_nodes[0], full_node_api)
summaries_response = await client.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1
@ -1000,7 +995,7 @@ class TestPoolWalletRpc:
await time_out_assert(timeout=MAX_WAIT_SECS, function=status_is_farming_to_pool)
await time_out_assert(10, wallet_is_synced, True, wallet_nodes[0], full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_nodes[0], full_node_api)
status: PoolWalletInfo = (await client.pw_status(wallet_id))[0]
@ -1061,7 +1056,7 @@ class TestPoolWalletRpc:
return (await wallets[0].get_confirmed_balance()) > 0
await time_out_assert(timeout=WAIT_SECS, function=have_chia)
await time_out_assert(10, wallet_is_synced, True, wallet_nodes[0], full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_nodes[0], full_node_api)
creation_tx: TransactionRecord = await client.create_new_pool_wallet(
pool_a_ph, "https://pool-a.org", 5, f"{self_hostname}:5000", "new", "FARMING_TO_POOL", fee
@ -1077,7 +1072,7 @@ class TestPoolWalletRpc:
await farm_blocks(full_node_api, our_ph, 6)
assert full_node_api.full_node.mempool_manager.get_spendbundle(creation_tx.name) is None
await time_out_assert(10, wallet_is_synced, True, wallet_nodes[0], full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_nodes[0], full_node_api)
summaries_response = await client.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1
@ -1160,7 +1155,7 @@ class TestPoolWalletRpc:
return (await wallets[0].get_confirmed_balance()) > 0
await time_out_assert(timeout=WAIT_SECS, function=have_chia)
await time_out_assert(10, wallet_is_synced, True, wallet_nodes[0], full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_nodes[0], full_node_api)
creation_tx: TransactionRecord = await client.create_new_pool_wallet(
pool_a_ph, "https://pool-a.org", 5, f"{self_hostname}:5000", "new", "FARMING_TO_POOL", fee
@ -1176,7 +1171,7 @@ class TestPoolWalletRpc:
await farm_blocks(full_node_api, our_ph, 6)
assert full_node_api.full_node.mempool_manager.get_spendbundle(creation_tx.name) is None
await time_out_assert(5, wallet_is_synced, True, wallet_nodes[0], full_node_api)
await time_out_assert(20, wallet_is_synced, True, wallet_nodes[0], full_node_api)
summaries_response = await client.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1

View File

@ -20,6 +20,7 @@ from chia.wallet.util.transaction_type import TransactionType
from chia.wallet.util.wallet_types import AmountWithPuzzlehash
from chia.wallet.wallet_node import WalletNode
from chia.wallet.wallet_state_manager import WalletStateManager
from tests.pools.test_pool_rpc import wallet_is_synced
from tests.time_out_assert import time_out_assert, time_out_assert_not_none
from tests.wallet.cat_wallet.test_cat_wallet import tx_in_pool
@ -316,9 +317,9 @@ class TestWalletSimulator:
funds = sum(
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
)
await time_out_assert(5, wallet_0.get_confirmed_balance, funds)
await time_out_assert(5, wallet_0.get_unconfirmed_balance, funds)
await time_out_assert(20, wallet_is_synced, True, wallet_node_0, full_node_api_0)
await time_out_assert(20, wallet_0.get_confirmed_balance, funds)
await time_out_assert(20, wallet_0.get_unconfirmed_balance, funds)
assert await wallet_0.get_confirmed_balance() == funds
assert await wallet_0.get_unconfirmed_balance() == funds
@ -331,10 +332,10 @@ class TestWalletSimulator:
await wallet_0.push_transaction(tx)
await time_out_assert(5, full_node_0.mempool_manager.get_spendbundle, tx.spend_bundle, tx.name)
await time_out_assert(20, full_node_0.mempool_manager.get_spendbundle, tx.spend_bundle, tx.name)
# Full node height 11, wallet height 9
await time_out_assert(5, wallet_0.get_confirmed_balance, funds)
await time_out_assert(5, wallet_0.get_unconfirmed_balance, funds - 10)
await time_out_assert(20, wallet_0.get_confirmed_balance, funds)
await time_out_assert(20, wallet_0.get_unconfirmed_balance, funds - 10)
for i in range(0, 4):
await full_node_api_0.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
@ -348,13 +349,13 @@ class TestWalletSimulator:
)
# Full node height 17, wallet height 15
await time_out_assert(5, wallet_0.get_confirmed_balance, new_funds - 10)
await time_out_assert(5, wallet_0.get_unconfirmed_balance, new_funds - 10)
await time_out_assert(5, wallet_1.get_confirmed_balance, 10)
await time_out_assert(20, wallet_0.get_confirmed_balance, new_funds - 10)
await time_out_assert(20, wallet_0.get_unconfirmed_balance, new_funds - 10)
await time_out_assert(20, wallet_1.get_confirmed_balance, 10)
tx = await wallet_1.generate_signed_transaction(uint64(5), await wallet_0.get_new_puzzlehash(), uint64(0))
await wallet_1.push_transaction(tx)
await time_out_assert(5, full_node_0.mempool_manager.get_spendbundle, tx.spend_bundle, tx.name)
await time_out_assert(20, full_node_0.mempool_manager.get_spendbundle, tx.spend_bundle, tx.name)
for i in range(0, 4):
await full_node_api_0.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
@ -363,9 +364,9 @@ class TestWalletSimulator:
await wallet_0.get_unconfirmed_balance()
await wallet_1.get_confirmed_balance()
await time_out_assert(5, wallet_0.get_confirmed_balance, new_funds - 5)
await time_out_assert(5, wallet_0.get_unconfirmed_balance, new_funds - 5)
await time_out_assert(5, wallet_1.get_confirmed_balance, 5)
await time_out_assert(20, wallet_0.get_confirmed_balance, new_funds - 5)
await time_out_assert(20, wallet_0.get_unconfirmed_balance, new_funds - 5)
await time_out_assert(20, wallet_1.get_confirmed_balance, 5)
# @pytest.mark.asyncio
# async def test_wallet_finds_full_node(self):

View File

@ -1,29 +1,18 @@
import time
from typing import Any, List, Tuple
import asyncio
from typing import Any, List, Optional, Tuple
import pytest
from chia.full_node.full_node_api import FullNodeAPI
from chia.protocols import full_node_protocol
from chia.simulator.full_node_simulator import FullNodeSimulator
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.peer_info import PeerInfo
from chia.types.spend_bundle import SpendBundle
from chia.util.ints import uint16, uint32, uint64
from chia.util.ints import uint16, uint64
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.transaction_type import TransactionType
from chia.wallet.wallet_node import WalletNode
from tests.block_tools import BlockTools
from tests.core.full_node.test_mempool import generate_test_spend_bundle
from tests.core.node_height import node_height_at_least
from tests.pools.test_pool_rpc import farm_blocks, wallet_is_synced
from tests.time_out_assert import time_out_assert, time_out_assert_custom_interval
from tests.wallet_tools import WalletTool
@pytest.fixture(scope="module")
def wallet_a(bt: BlockTools) -> WalletTool:
return bt.get_pool_wallet_tool()
def assert_sb_in_pool(node: FullNodeAPI, sb: SpendBundle) -> None:
@ -45,86 +34,47 @@ def evict_from_pool(node: FullNodeAPI, sb: SpendBundle) -> None:
async def test_wallet_tx_retry(
bt: BlockTools,
setup_two_nodes_and_wallet_fast_retry: Tuple[List[FullNodeSimulator], List[Tuple[Any, Any]]],
wallet_a: WalletTool,
self_hostname: str,
) -> None:
wait_secs = 1000
reward_ph = wallet_a.get_new_puzzlehash()
wait_secs = 20
nodes, wallets = setup_two_nodes_and_wallet_fast_retry
server_1 = nodes[0].full_node.server
full_node_1: FullNodeSimulator = nodes[0]
wallet_node_1: WalletNode = wallets[0][0]
wallet_node_1.config["tx_resend_timeout_secs"] = 5
wallet_server_1 = wallets[0][1]
assert wallet_node_1.wallet_state_manager is not None
wallet_1 = wallet_node_1.wallet_state_manager.main_wallet
reward_ph = await wallet_1.get_new_puzzlehash()
await wallet_server_1.start_client(PeerInfo(self_hostname, uint16(server_1._port)), None)
blocks = await full_node_1.get_all_full_blocks()
start_height = blocks[-1].height if len(blocks) > 0 else -1
blocks = bt.get_consecutive_blocks(
3,
block_list_input=blocks,
guarantee_transaction_block=True,
farmer_reward_puzzle_hash=reward_ph,
pool_reward_puzzle_hash=reward_ph,
)
await farm_blocks(full_node_1, reward_ph, 2)
await time_out_assert(wait_secs, wallet_is_synced, True, wallet_node_1, full_node_1)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
current_height = 3
coins = iter(blocks[-1].get_included_reward_coins())
coin1 = next(coins)
sb1 = generate_test_spend_bundle(wallet_a, coin1, new_puzzle_hash=bytes32(b"A" * 32))
amount_out = sum(_.amount for _ in sb1.additions())
tx = TransactionRecord(
confirmed_at_height=uint32(0),
created_at_time=uint64(int(time.time())),
to_puzzle_hash=bytes32(b"A" * 32),
amount=uint64(amount_out),
fee_amount=uint64(sb1.fees()),
confirmed=False,
sent=uint32(0),
spend_bundle=sb1,
additions=sb1.additions(),
removals=sb1.removals(),
wallet_id=wallet_node_1.wallet_state_manager.main_wallet.id(),
sent_to=[],
memos=[],
trade_id=None,
type=uint32(TransactionType.OUTGOING_TX.value),
name=sb1.name(),
)
await wallet_node_1.wallet_state_manager.add_pending_transaction(tx)
transaction: TransactionRecord = await wallet_1.generate_signed_transaction(uint64(100), reward_ph)
sb1: Optional[SpendBundle] = transaction.spend_bundle
assert sb1 is not None
await wallet_1.push_transaction(transaction)
async def sb_in_mempool() -> bool:
return full_node_1.full_node.mempool_manager.get_spendbundle(sb1.name()) == sb1
return full_node_1.full_node.mempool_manager.get_spendbundle(transaction.name) == transaction.spend_bundle
# SpendBundle is accepted by peer
await time_out_assert(wait_secs, sb_in_mempool)
async def wallet_synced() -> bool:
return await wallet_is_synced(wallet_node_1, full_node_1)
# Wait for wallet to catch up
await time_out_assert(wait_secs, wallet_synced)
# Evict SpendBundle from peer
evict_from_pool(full_node_1, sb1)
assert_sb_not_in_pool(full_node_1, sb1)
print(f"mempool spends: {full_node_1.full_node.mempool_manager.mempool.spends}")
# Wait some time so wallet will retry
await asyncio.sleep(2)
our_ph = await wallet_1.get_new_puzzlehash()
current_height += await farm_blocks(full_node_1, our_ph, 3)
await time_out_assert(wait_secs, wallet_synced)
await farm_blocks(full_node_1, our_ph, 2)
# Wait for wallet to catch up
await time_out_assert(wait_secs, wallet_is_synced, True, wallet_node_1, full_node_1)
async def check_transaction_in_mempool_or_confirmed(transaction: TransactionRecord) -> bool:
assert wallet_node_1.wallet_state_manager is not None
@ -133,8 +83,10 @@ async def test_wallet_tx_retry(
sb = txn.spend_bundle
assert sb is not None
full_node_sb = full_node_1.full_node.mempool_manager.get_spendbundle(sb.name())
in_mempool: bool = full_node_sb == sb
if full_node_sb is None:
return False
in_mempool: bool = full_node_sb.name() == sb.name()
return txn.confirmed or in_mempool
# Check that wallet resent the unconfirmed SpendBundle
await time_out_assert_custom_interval(wait_secs, 1, check_transaction_in_mempool_or_confirmed, True, tx)
await time_out_assert_custom_interval(wait_secs, 1, check_transaction_in_mempool_or_confirmed, True, transaction)