4
4
from unittest .mock import MagicMock , patch
5
5
6
6
import pytest
7
- from chia_rs import ProofOfSpace
7
+ from chia_rs import FullBlock , ProofOfSpace
8
8
from chia_rs .sized_bytes import bytes32
9
9
from chia_rs .sized_ints import uint64
10
10
17
17
from chia .simulator .block_tools import BlockTools
18
18
19
19
20
- def signage_point_from_block (bt : BlockTools ) -> harvester_protocol .NewSignagePointHarvester :
21
- """Create a real NewSignagePointHarvester from actual blockchain blocks."""
22
- # generate real blocks using BlockTools
23
- blocks = bt .get_consecutive_blocks (
24
- num_blocks = 3 ,
25
- guarantee_transaction_block = True ,
26
- farmer_reward_puzzle_hash = bt .farmer_ph ,
27
- )
28
- block = blocks [- 1 ] # always use the last block
20
+ def signage_point_from_block (block : FullBlock , bt : BlockTools ) -> harvester_protocol .NewSignagePointHarvester :
21
+ """Create a real NewSignagePointHarvester from a blockchain block."""
29
22
# extract real signage point data from the block
30
23
sp_index = block .reward_chain_block .signage_point_index
31
24
challenge_hash = block .reward_chain_block .pos_ss_cc_challenge_hash
@@ -63,21 +56,23 @@ def create_plot_info() -> PlotInfo:
63
56
64
57
65
58
@pytest .mark .anyio
66
- async def test_new_signage_point_harvester (harvester_farmer_environment : HarvesterFarmerEnvironment ) -> None :
59
+ async def test_new_signage_point_harvester (
60
+ harvester_farmer_environment : HarvesterFarmerEnvironment , default_400_blocks : list [FullBlock ], tmp_path : Path
61
+ ) -> None :
67
62
"""Test successful signage point processing with real blockchain data."""
68
63
_ , _ , harvester_service , _ , bt = harvester_farmer_environment
69
64
harvester_api = harvester_service ._server .api
70
65
assert isinstance (harvester_api , HarvesterAPI )
71
66
# use real signage point data from actual block
72
- new_challenge = signage_point_from_block (bt )
67
+ block = default_400_blocks [2 ] # use a transaction block
68
+ new_challenge = signage_point_from_block (block , bt )
73
69
# harvester doesn't accept incoming connections, so use mock peer like other tests
74
70
mock_peer = MagicMock (spec = WSChiaConnection )
75
71
# create realistic plot info for testing
76
72
mock_plot_info = create_plot_info ()
77
- plot_path = Path ("/fake/plot.plot" )
78
73
79
74
with patch .object (harvester_api .harvester .plot_manager , "public_keys_available" , return_value = True ):
80
- with patch .object (harvester_api .harvester .plot_manager , "plots" , {plot_path : mock_plot_info }):
75
+ with patch .object (harvester_api .harvester .plot_manager , "plots" , {tmp_path : mock_plot_info }):
81
76
# let passes_plot_filter, calculate_pos_challenge, and calculate_sp_interval_iters use real implementations
82
77
with patch ("chia.harvester.harvester_api.calculate_iterations_quality" , return_value = uint64 (1000 )):
83
78
with patch .object (mock_plot_info .prover , "get_full_proof" ) as mock_get_proof :
@@ -88,7 +83,7 @@ async def test_new_signage_point_harvester(harvester_farmer_environment: Harvest
88
83
89
84
@pytest .mark .anyio
90
85
async def test_new_signage_point_harvester_pool_difficulty (
91
- harvester_farmer_environment : HarvesterFarmerEnvironment ,
86
+ harvester_farmer_environment : HarvesterFarmerEnvironment , default_400_blocks : list [ FullBlock ], tmp_path : Path
92
87
) -> None :
93
88
"""Test pool difficulty overrides with real blockchain signage points."""
94
89
_ , _ , harvester_service , _ , bt = harvester_farmer_environment
@@ -102,15 +97,15 @@ async def test_new_signage_point_harvester_pool_difficulty(
102
97
# create realistic plot info for testing
103
98
mock_plot_info = create_plot_info ()
104
99
mock_plot_info .pool_contract_puzzle_hash = pool_puzzle_hash
105
- plot_path = Path ("/fake/pool_plot.plot" )
106
100
pool_difficulty = PoolDifficulty (
107
101
pool_contract_puzzle_hash = pool_puzzle_hash ,
108
102
difficulty = uint64 (500 ), # lower than main difficulty
109
103
sub_slot_iters = uint64 (67108864 ), # different from main
110
104
)
111
105
112
106
# create signage point from real block with pool difficulty
113
- new_challenge = signage_point_from_block (bt )
107
+ block = default_400_blocks [2 ] # use a transaction block
108
+ new_challenge = signage_point_from_block (block , bt )
114
109
new_challenge = harvester_protocol .NewSignagePointHarvester (
115
110
challenge_hash = new_challenge .challenge_hash ,
116
111
difficulty = new_challenge .difficulty ,
@@ -123,7 +118,7 @@ async def test_new_signage_point_harvester_pool_difficulty(
123
118
)
124
119
125
120
with patch .object (harvester_api .harvester .plot_manager , "public_keys_available" , return_value = True ):
126
- with patch .object (harvester_api .harvester .plot_manager , "plots" , {plot_path : mock_plot_info }):
121
+ with patch .object (harvester_api .harvester .plot_manager , "plots" , {tmp_path : mock_plot_info }):
127
122
# mock passes_plot_filter to return True so we can test pool difficulty logic
128
123
with patch ("chia.harvester.harvester_api.passes_plot_filter" , return_value = True ):
129
124
with patch ("chia.harvester.harvester_api.calculate_iterations_quality" ) as mock_calc_iter :
@@ -140,24 +135,24 @@ async def test_new_signage_point_harvester_pool_difficulty(
140
135
141
136
@pytest .mark .anyio
142
137
async def test_new_signage_point_harvester_prover_error (
143
- harvester_farmer_environment : HarvesterFarmerEnvironment ,
138
+ harvester_farmer_environment : HarvesterFarmerEnvironment , default_400_blocks : list [ FullBlock ], tmp_path : Path
144
139
) -> None :
145
140
"""Test error handling when prover fails using real blockchain data."""
146
141
_ , _ , harvester_service , _ , bt = harvester_farmer_environment
147
142
harvester_api = harvester_service ._server .api
148
143
assert isinstance (harvester_api , HarvesterAPI )
149
144
150
145
# create signage point from real block
151
- new_challenge = signage_point_from_block (bt )
146
+ block = default_400_blocks [2 ] # use a transaction block
147
+ new_challenge = signage_point_from_block (block , bt )
152
148
153
149
mock_peer = MagicMock (spec = WSChiaConnection )
154
150
155
151
# create realistic plot info for testing
156
152
mock_plot_info = create_plot_info ()
157
- plot_path = Path ("/fake/plot.plot" )
158
153
159
154
with patch .object (harvester_api .harvester .plot_manager , "public_keys_available" , return_value = True ):
160
- with patch .object (harvester_api .harvester .plot_manager , "plots" , {plot_path : mock_plot_info }):
155
+ with patch .object (harvester_api .harvester .plot_manager , "plots" , {tmp_path : mock_plot_info }):
161
156
# let passes_plot_filter and calculate_pos_challenge use real implementations
162
157
# make the prover fail during quality check
163
158
with patch .object (
0 commit comments