Repository: Chia-Network/chia-blockchain
File: chia/_tests/wallet/sync/test_wallet_sync.py (Python)

Code before:
    assert response.proofs == []
    assert len(response.coins) == 0


@pytest.mark.anyio
async def test_request_removals_too_many_coin_names(
    simulator_and_wallet: OldSimulatorsAndWallets, self_hostname: str
) -> None:
    full_nodes, wallets, _ = simulator_and_wallet
    wallet_node, wallet_server = wallets[0]
    wallet = wallet_node.wallet_state_manager.main_wallet
    async with wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
        ph = await action_scope.get_puzzle_hash(wallet.wallet_state_manager)

    full_node_api = full_nodes[0]
    await wallet_server.start_client(PeerInfo(self_hostname, full_node_api.full_node.server.get_port()), None)

    for _ in range(2):
        await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))

    await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)

    last_block = full_node_api.full_node.blockchain.get_peak()
    assert last_block is not None

    too_many = [std_hash(i.to_bytes(4, "big")) for i in range(MAX_COIN_HASHES_PER_REQUEST + 1)]
    res = await full_node_api.request_removals(RequestRemovals(last_block.height, last_block.header_hash, too_many))
    assert res is not None
    reject = RejectRemovalsRequest.from_bytes(res.data)
    assert reject.height == last_block.height
    assert reject.header_hash == last_block.header_hash


@pytest.mark.anyio
async def test_get_wp_fork_point(
    default_10000_blocks: list[FullBlock], blockchain_constants: ConsensusConstants
) -> None:
    blocks = default_10000_blocks
    header_cache, height_to_hash, sub_blocks, summaries = await load_blocks_dont_validate(blocks, blockchain_constants)
    wpf = WeightProofHandler(blockchain_constants, BlockchainMock(sub_blocks, header_cache, height_to_hash, summaries))
    wp1 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_000)]].header_hash)
    assert wp1 is not None
    wp2 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_030)]].header_hash)
    assert wp2 is not None
    wp3 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(7_500)]].header_hash)
    assert wp3 is not None
    wp4 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(8_700)]].header_hash)
    assert wp4 is not None
    wp5 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_700)]].header_hash)
    assert wp5 is not None
    wp6 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_010)]].header_hash)

Review comment (suggestion):
```suggestion
    too_many = [bytes32.random() for _ in range(MAX_COIN_HASHES_PER_REQUEST + 1)]
```

Code after:
    assert response.proofs == []
    assert len(response.coins) == 0


@pytest.mark.anyio
async def test_request_removals_too_many_coin_names(
    simulator_and_wallet: OldSimulatorsAndWallets, self_hostname: str
) -> None:
    full_nodes, wallets, _ = simulator_and_wallet
    wallet_node, wallet_server = wallets[0]
    wallet = wallet_node.wallet_state_manager.main_wallet
    async with wallet.wallet_state_manager.new_action_scope(DEFAULT_TX_CONFIG, push=True) as action_scope:
        ph = await action_scope.get_puzzle_hash(wallet.wallet_state_manager)

    full_node_api = full_nodes[0]
    await wallet_server.start_client(PeerInfo(self_hostname, full_node_api.full_node.server.get_port()), None)

    for _ in range(2):
        await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))

    await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)

    last_block = full_node_api.full_node.blockchain.get_peak()
    assert last_block is not None

    too_many = [bytes32.random() for _ in range(MAX_COIN_HASHES_PER_REQUEST + 1)]
    res = await full_node_api.request_removals(RequestRemovals(last_block.height, last_block.header_hash, too_many))
    assert res is not None
    reject = RejectRemovalsRequest.from_bytes(res.data)
    assert reject.height == last_block.height
    assert reject.header_hash == last_block.header_hash


@pytest.mark.anyio
async def test_get_wp_fork_point(
    default_10000_blocks: list[FullBlock], blockchain_constants: ConsensusConstants
) -> None:
    blocks = default_10000_blocks
    header_cache, height_to_hash, sub_blocks, summaries = await load_blocks_dont_validate(blocks, blockchain_constants)
    wpf = WeightProofHandler(blockchain_constants, BlockchainMock(sub_blocks, header_cache, height_to_hash, summaries))
    wp1 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_000)]].header_hash)
    assert wp1 is not None
    wp2 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_030)]].header_hash)
    assert wp2 is not None
    wp3 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(7_500)]].header_hash)
    assert wp3 is not None
    wp4 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(8_700)]].header_hash)
    assert wp4 is not None
    wp5 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_700)]].header_hash)
    assert wp5 is not None
    wp6 = await wpf.get_proof_of_weight(header_cache[height_to_hash[uint32(9_010)]].header_hash)