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

Code before:
    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
    assert len(response.coins) == 1
    full_block = await full_node_api.full_node.block_store.get_full_block(last_block.header_hash)
    assert full_block is not None
    assert full_block.foliage_transaction_block is not None
    root = full_block.foliage_transaction_block.additions_root
    assert confirm_not_included_already_hashed(root, response.proofs[0][0], response.proofs[0][1])
    # proofs is a tuple of (puzzlehash, proof, proof_2)
    # proof is a proof of inclusion (or exclusion) of that puzzlehash

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

Code after:
    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
    assert len(response.coins) == 1
    full_block = await full_node_api.full_node.block_store.get_full_block(last_block.header_hash)
    assert full_block is not None
    assert full_block.foliage_transaction_block is not None
    root = full_block.foliage_transaction_block.additions_root
    assert confirm_not_included_already_hashed(root, response.proofs[0][0], response.proofs[0][1])
    # proofs is a tuple of (puzzlehash, proof, proof_2)
    # proof is a proof of inclusion (or exclusion) of that puzzlehash