more reorg

This commit is contained in:
Yostra 2021-01-07 17:03:55 -05:00 committed by Yostra
parent 46e1caf126
commit 67a85ea289

View File

@ -123,7 +123,45 @@ class TestWalletSync:
num_blocks = 30
blocks_reorg = bt.get_consecutive_blocks(num_blocks, block_list_input=default_400_blocks[:-5])
for block in blocks_reorg:
for block in blocks_reorg[-30:]:
await full_node_api.full_node.respond_sub_block(full_node_protocol.RespondSubBlock(block))
await time_out_assert(5, wallet.get_confirmed_balance, 0)
@pytest.mark.asyncio
async def test_wallet_reorg_get_coinbase(self, wallet_node_simulator, default_400_blocks):
full_nodes, wallets = wallet_node_simulator
full_node_api = full_nodes[0]
wallet_node, server_2 = wallets[0]
fn_server = full_node_api.full_node.server
wallet = wallet_node.wallet_state_manager.main_wallet
ph = await wallet.get_new_puzzlehash()
await server_2.start_client(PeerInfo("localhost", uint16(fn_server._port)), None)
# Insert 400 blocks
for block in default_400_blocks:
await full_node_api.full_node.respond_sub_block(full_node_protocol.RespondSubBlock(block))
# Reorg blocks that carry reward
num_blocks_reorg = 30
blocks_reorg = bt.get_consecutive_blocks(num_blocks_reorg, block_list_input=default_400_blocks[:-5])
for block in blocks_reorg[:-5]:
await full_node_api.full_node.respond_sub_block(full_node_protocol.RespondSubBlock(block))
num_blocks_reorg_1 = 40
blocks_reorg_1 = bt.get_consecutive_blocks(
1, pool_reward_puzzle_hash=ph, farmer_reward_puzzle_hash=ph, block_list_input=blocks_reorg[:-30]
)
blocks_reorg_2 = bt.get_consecutive_blocks(num_blocks_reorg_1, block_list_input=blocks_reorg_1)
for block in blocks_reorg_2[-41:]:
await full_node_api.full_node.respond_sub_block(full_node_protocol.RespondSubBlock(block))
# Confirm we have the funds
funds = calculate_pool_reward(uint32(len(blocks_reorg_1))) + calculate_base_farmer_reward(
uint32(len(blocks_reorg_1))
)
await time_out_assert(5, wallet.get_confirmed_balance, funds)