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

Code before:
    last_block: BlockRecord | None = full_node_api.full_node.blockchain.get_peak()
    assert last_block is not None

    # Invalid height (with header_hash specified)
    res = await full_node_api.request_additions(RequestAdditions(uint32(100), last_block.header_hash, [ph]))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == 100
    assert reject.header_hash == last_block.header_hash

    # Invalid height (no header_hash, returns zeros)
    res = await full_node_api.request_additions(RequestAdditions(uint32(100), None, [ph]))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == 100
    assert reject.header_hash == bytes32.zeros

    # Invalid header hash
    res = await full_node_api.request_additions(RequestAdditions(last_block.height, std_hash(b""), [ph]))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == last_block.height
    assert reject.header_hash == std_hash(b"")

    # Too many puzzle hashes
    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_additions(RequestAdditions(last_block.height, last_block.header_hash, too_many))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == last_block.height
    assert reject.header_hash == last_block.header_hash

    # Exactly at the limit is allowed
    at_limit = [std_hash(i.to_bytes(4, "big")) for i in range(MAX_COIN_HASHES_PER_REQUEST)]
    res = await full_node_api.request_additions(RequestAdditions(last_block.height, last_block.header_hash, at_limit))
    assert res is not None
    response = RespondAdditions.from_bytes(res.data)
    assert response.height == last_block.height

    # No results
    fake_coin = std_hash(b"")
    assert ph != fake_coin
    res1 = await full_node_api.request_additions(
        RequestAdditions(last_block.height, last_block.header_hash, [fake_coin])
    )
    assert res1 is not None
    response = RespondAdditions.from_bytes(res1.data)
    assert response.height == last_block.height
    assert response.header_hash == last_block.header_hash
    assert response.proofs is not None
    assert len(response.proofs) == 1

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

Code after:
    last_block: BlockRecord | None = full_node_api.full_node.blockchain.get_peak()
    assert last_block is not None

    # Invalid height (with header_hash specified)
    res = await full_node_api.request_additions(RequestAdditions(uint32(100), last_block.header_hash, [ph]))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == 100
    assert reject.header_hash == last_block.header_hash

    # Invalid height (no header_hash, returns zeros)
    res = await full_node_api.request_additions(RequestAdditions(uint32(100), None, [ph]))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == 100
    assert reject.header_hash == bytes32.zeros

    # Invalid header hash
    res = await full_node_api.request_additions(RequestAdditions(last_block.height, std_hash(b""), [ph]))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == last_block.height
    assert reject.header_hash == std_hash(b"")

    # Too many puzzle hashes
    too_many = [bytes32.random() for _ in range(MAX_COIN_HASHES_PER_REQUEST + 1)]
    res = await full_node_api.request_additions(RequestAdditions(last_block.height, last_block.header_hash, too_many))
    assert res is not None
    reject = RejectAdditionsRequest.from_bytes(res.data)
    assert reject.height == last_block.height
    assert reject.header_hash == last_block.header_hash

    # Exactly at the limit is allowed
    at_limit = [bytes32.random() for _i in range(MAX_COIN_HASHES_PER_REQUEST)]
    res = await full_node_api.request_additions(RequestAdditions(last_block.height, last_block.header_hash, at_limit))
    assert res is not None
    response = RespondAdditions.from_bytes(res.data)
    assert response.height == last_block.height

    # No results
    fake_coin = bytes32.random()
    assert ph != fake_coin
    res1 = await full_node_api.request_additions(
        RequestAdditions(last_block.height, last_block.header_hash, [fake_coin])
    )
    assert res1 is not None
    response = RespondAdditions.from_bytes(res1.data)
    assert response.height == last_block.height
    assert response.header_hash == last_block.header_hash
    assert response.proofs is not None
    assert len(response.proofs) == 1