-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Plotmanager v2 #19832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Plotmanager v2 #19832
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7741337
prover protocol and v2Prover
almogdepaz 8c4f578
format name
almogdepaz 6aef294
format
almogdepaz 3f3b134
refactor filename
almogdepaz 6e28f8c
tests/raise unimplemented
almogdepaz 7811dbb
add get_filename_str to mock
almogdepaz 441aed5
rename methods
almogdepaz bffc732
rename
almogdepaz 17b0b34
refactor
almogdepaz 42f3348
improve coverage
almogdepaz e3a8cfc
test from bytes
almogdepaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from __future__ import annotations | ||
|
||
import tempfile | ||
from pathlib import Path | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
|
||
from chia.plotting.prover import PlotVersion, V1Prover, V2Prover, get_prover_from_bytes, get_prover_from_file | ||
|
||
|
||
class TestProver: | ||
def test_v2_prover_init_with_nonexistent_file(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
assert prover.get_version() == PlotVersion.V2 | ||
assert prover.get_filename() == "/nonexistent/path/test.plot2" | ||
|
||
def test_v2_prover_get_size_raises_error(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
prover.get_size() | ||
|
||
def test_v2_prover_get_memo_raises_error(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
prover.get_memo() | ||
|
||
def test_v2_prover_get_compression_level_raises_error(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
prover.get_compression_level() | ||
|
||
def test_v2_prover_get_id_raises_error(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
prover.get_id() | ||
|
||
def test_v2_prover_get_qualities_for_challenge_raises_error(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
prover.get_qualities_for_challenge(b"challenge") | ||
|
||
def test_v2_prover_get_full_proof_raises_error(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
prover.get_full_proof(b"challenge", 0) | ||
|
||
def test_v2_prover_bytes_raises_error(self) -> None: | ||
prover = V2Prover("/nonexistent/path/test.plot2") | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
bytes(prover) | ||
|
||
def test_v2_prover_from_bytes_raises_error(self) -> None: | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
V2Prover.from_bytes(b"test_data") | ||
|
||
def test_get_prover_from_file(self) -> None: | ||
prover = get_prover_from_file("/nonexistent/path/test.plot2") | ||
assert prover.get_version() == PlotVersion.V2 | ||
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"): | ||
prover.get_size() | ||
|
||
def test_get_prover_from_file_with_plot1_still_works(self) -> None: | ||
with tempfile.NamedTemporaryFile(suffix=".plot", delete=False) as f: | ||
temp_path = f.name | ||
try: | ||
with pytest.raises(Exception) as exc_info: | ||
get_prover_from_file(temp_path) | ||
assert not isinstance(exc_info.value, NotImplementedError) | ||
finally: | ||
Path(temp_path).unlink() | ||
|
||
def test_unsupported_file_extension_raises_value_error(self) -> None: | ||
with pytest.raises(ValueError, match="Unsupported plot file"): | ||
get_prover_from_file("/nonexistent/path/test.txt") | ||
|
||
|
||
class TestV1Prover: | ||
def test_v1_prover_get_version(self) -> None: | ||
"""Test that V1Prover.get_version() returns PlotVersion.V1""" | ||
mock_disk_prover = MagicMock() | ||
prover = V1Prover(mock_disk_prover) | ||
assert prover.get_version() == PlotVersion.V1 | ||
|
||
|
||
class TestGetProverFromBytes: | ||
def test_get_prover_from_bytes_v2_plot(self) -> None: | ||
with patch("chia.plotting.prover.V2Prover.from_bytes") as mock_v2_from_bytes: | ||
mock_prover = MagicMock() | ||
mock_v2_from_bytes.return_value = mock_prover | ||
result = get_prover_from_bytes("test.plot2", b"test_data") | ||
assert result == mock_prover | ||
|
||
def test_get_prover_from_bytes_v1_plot(self) -> None: | ||
with patch("chia.plotting.prover.DiskProver") as mock_disk_prover_class: | ||
mock_disk_prover = MagicMock() | ||
mock_disk_prover_class.from_bytes.return_value = mock_disk_prover | ||
result = get_prover_from_bytes("test.plot", b"test_data") | ||
assert isinstance(result, V1Prover) | ||
|
||
def test_get_prover_from_bytes_unsupported_extension(self) -> None: | ||
with pytest.raises(ValueError, match="Unsupported plot file"): | ||
get_prover_from_bytes("test.txt", b"test_data") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.