Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions chia/_tests/core/custom_types/test_proof_of_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from chia.types.blockchain_format.proof_of_space import (
calculate_plot_difficulty,
calculate_prefix_bits,
check_plot_size,
passes_plot_filter,
verify_and_get_quality_string,
)
Expand Down Expand Up @@ -221,6 +222,34 @@ def test_calculate_plot_difficulty(height: uint32, difficulty: uint8) -> None:
assert calculate_plot_difficulty(DEFAULT_CONSTANTS, height) == difficulty


@pytest.mark.parametrize(
"size, valid",
[
(PlotSize.make_v1(31), False), # too small
(PlotSize.make_v1(32), True),
(PlotSize.make_v1(33), True),
(PlotSize.make_v1(34), True),
(PlotSize.make_v1(35), True),
(PlotSize.make_v1(36), True),
(PlotSize.make_v1(37), True),
(PlotSize.make_v1(49), True),
(PlotSize.make_v1(50), True),
(PlotSize.make_v1(51), False), # too large
(PlotSize.make_v2(26), False), # too small
(PlotSize.make_v2(27), False), # too small (and odd)
(PlotSize.make_v2(28), True),
(PlotSize.make_v2(29), False), # odd
(PlotSize.make_v2(30), True),
(PlotSize.make_v2(31), False), # odd
(PlotSize.make_v2(32), True),
(PlotSize.make_v2(33), False), # too large (and odd)
(PlotSize.make_v2(34), False), # too large
],
)
def test_check_plot_size(size: PlotSize, valid: bool) -> None:
assert check_plot_size(DEFAULT_CONSTANTS, size) == valid


class TestProofOfSpace:
@pytest.mark.parametrize("prefix_bits", [DEFAULT_CONSTANTS.NUMBER_ZERO_BITS_PLOT_FILTER_V1, 8, 7, 6, 5, 1, 0])
def test_can_create_proof(self, prefix_bits: int, seeded_random: random.Random) -> None:
Expand Down
3 changes: 3 additions & 0 deletions chia/types/blockchain_format/proof_of_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def check_plot_size(constants: ConsensusConstants, ps: PlotSize) -> bool:
if size_v2 > constants.MAX_PLOT_SIZE_V2:
log.error("Plot size is higher than the maximum")
return False
if (size_v2 & 1) == 1:
log.error("Plot size is odd")
return False
return True


Expand Down
Loading