4
4
from unittest .mock import MagicMock , patch
5
5
6
6
import pytest
7
- from chia_rs import FullBlock , ProofOfSpace
7
+ from chia_rs import ConsensusConstants , FullBlock , ProofOfSpace
8
8
from chia_rs .sized_bytes import bytes32
9
9
from chia_rs .sized_ints import uint64
10
10
14
14
from chia .protocols import harvester_protocol
15
15
from chia .protocols .harvester_protocol import PoolDifficulty
16
16
from chia .server .ws_connection import WSChiaConnection
17
- from chia .simulator .block_tools import BlockTools
18
17
19
18
20
- def signage_point_from_block (block : FullBlock , bt : BlockTools ) -> harvester_protocol .NewSignagePointHarvester :
19
+ def signage_point_from_block (
20
+ block : FullBlock , constants : ConsensusConstants
21
+ ) -> harvester_protocol .NewSignagePointHarvester :
21
22
"""Create a real NewSignagePointHarvester from a blockchain block."""
22
23
# extract real signage point data from the block
23
24
sp_index = block .reward_chain_block .signage_point_index
@@ -30,8 +31,8 @@ def signage_point_from_block(block: FullBlock, bt: BlockTools) -> harvester_prot
30
31
31
32
return harvester_protocol .NewSignagePointHarvester (
32
33
challenge_hash = challenge_hash ,
33
- difficulty = uint64 (bt . constants .DIFFICULTY_STARTING ),
34
- sub_slot_iters = uint64 (bt . constants .SUB_SLOT_ITERS_STARTING ),
34
+ difficulty = uint64 (constants .DIFFICULTY_STARTING ),
35
+ sub_slot_iters = uint64 (constants .SUB_SLOT_ITERS_STARTING ),
35
36
signage_point_index = sp_index ,
36
37
sp_hash = sp_hash ,
37
38
pool_difficulties = [],
@@ -57,15 +58,18 @@ def create_plot_info() -> PlotInfo:
57
58
58
59
@pytest .mark .anyio
59
60
async def test_new_signage_point_harvester (
60
- harvester_farmer_environment : HarvesterFarmerEnvironment , default_400_blocks : list [FullBlock ], tmp_path : Path
61
+ harvester_farmer_environment : HarvesterFarmerEnvironment ,
62
+ default_400_blocks : list [FullBlock ],
63
+ tmp_path : Path ,
64
+ testconstants : ConsensusConstants ,
61
65
) -> None :
62
66
"""Test successful signage point processing with real blockchain data."""
63
- _ , _ , harvester_service , _ , bt = harvester_farmer_environment
67
+ _ , _ , harvester_service , _ , _ = harvester_farmer_environment
64
68
harvester_api = harvester_service ._server .api
65
69
assert isinstance (harvester_api , HarvesterAPI )
66
70
# use real signage point data from actual block
67
71
block = default_400_blocks [2 ] # use a transaction block
68
- new_challenge = signage_point_from_block (block , bt )
72
+ new_challenge = signage_point_from_block (block , testconstants )
69
73
# harvester doesn't accept incoming connections, so use mock peer like other tests
70
74
mock_peer = MagicMock (spec = WSChiaConnection )
71
75
# create realistic plot info for testing
@@ -83,10 +87,13 @@ async def test_new_signage_point_harvester(
83
87
84
88
@pytest .mark .anyio
85
89
async def test_new_signage_point_harvester_pool_difficulty (
86
- harvester_farmer_environment : HarvesterFarmerEnvironment , default_400_blocks : list [FullBlock ], tmp_path : Path
90
+ harvester_farmer_environment : HarvesterFarmerEnvironment ,
91
+ default_400_blocks : list [FullBlock ],
92
+ tmp_path : Path ,
93
+ testconstants : ConsensusConstants ,
87
94
) -> None :
88
95
"""Test pool difficulty overrides with real blockchain signage points."""
89
- _ , _ , harvester_service , _ , bt = harvester_farmer_environment
96
+ _ , _ , harvester_service , _ , _ = harvester_farmer_environment
90
97
harvester_api = harvester_service ._server .api
91
98
assert isinstance (harvester_api , HarvesterAPI )
92
99
@@ -105,7 +112,7 @@ async def test_new_signage_point_harvester_pool_difficulty(
105
112
106
113
# create signage point from real block with pool difficulty
107
114
block = default_400_blocks [2 ] # use a transaction block
108
- new_challenge = signage_point_from_block (block , bt )
115
+ new_challenge = signage_point_from_block (block , testconstants )
109
116
new_challenge = harvester_protocol .NewSignagePointHarvester (
110
117
challenge_hash = new_challenge .challenge_hash ,
111
118
difficulty = new_challenge .difficulty ,
@@ -135,16 +142,19 @@ async def test_new_signage_point_harvester_pool_difficulty(
135
142
136
143
@pytest .mark .anyio
137
144
async def test_new_signage_point_harvester_prover_error (
138
- harvester_farmer_environment : HarvesterFarmerEnvironment , default_400_blocks : list [FullBlock ], tmp_path : Path
145
+ harvester_farmer_environment : HarvesterFarmerEnvironment ,
146
+ default_400_blocks : list [FullBlock ],
147
+ tmp_path : Path ,
148
+ testconstants : ConsensusConstants ,
139
149
) -> None :
140
150
"""Test error handling when prover fails using real blockchain data."""
141
- _ , _ , harvester_service , _ , bt = harvester_farmer_environment
151
+ _ , _ , harvester_service , _ , _ = harvester_farmer_environment
142
152
harvester_api = harvester_service ._server .api
143
153
assert isinstance (harvester_api , HarvesterAPI )
144
154
145
155
# create signage point from real block
146
156
block = default_400_blocks [2 ] # use a transaction block
147
- new_challenge = signage_point_from_block (block , bt )
157
+ new_challenge = signage_point_from_block (block , testconstants )
148
158
149
159
mock_peer = MagicMock (spec = WSChiaConnection )
150
160
0 commit comments