Skip to content

Commit 0d8d182

Browse files
committed
cleanup
1 parent 1626309 commit 0d8d182

File tree

12 files changed

+75
-81
lines changed

12 files changed

+75
-81
lines changed

chia/_tests/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@
6565
setup_full_node,
6666
setup_introducer,
6767
setup_seeder,
68-
setup_solver,
6968
setup_timelord,
7069
)
7170
from chia.simulator.start_simulator import SimulatorFullNodeService
7271
from chia.simulator.wallet_tools import WalletTool
73-
from chia.solver.solver_service import SolverService
7472
from chia.timelord.timelord_service import TimelordService
7573
from chia.types.peer_info import PeerInfo
7674
from chia.util.config import create_default_chia_config, lock_and_load_config
@@ -1114,12 +1112,6 @@ async def seeder_service(root_path_populated_with_config: Path, database_uri: st
11141112
yield seeder
11151113

11161114

1117-
@pytest.fixture(scope="function")
1118-
async def solver_service(bt: BlockTools) -> AsyncIterator[SolverService]:
1119-
async with setup_solver(bt.root_path, bt.constants) as _:
1120-
yield _
1121-
1122-
11231115
@pytest.fixture(scope="function")
11241116
def tmp_chia_root(tmp_path):
11251117
"""

chia/_tests/core/custom_types/test_proof_of_space.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_calculate_plot_difficulty(height: uint32, difficulty: uint8) -> None:
223223

224224
class TestProofOfSpace:
225225
@pytest.mark.parametrize("prefix_bits", [DEFAULT_CONSTANTS.NUMBER_ZERO_BITS_PLOT_FILTER_V1, 8, 7, 6, 5, 1, 0])
226-
def test_can_create_proof(self, prefix_bits: uint8, seeded_random: random.Random) -> None:
226+
def test_can_create_proof(self, prefix_bits: int, seeded_random: random.Random) -> None:
227227
"""
228228
Tests that the change of getting a correct proof is exactly 1/target_filter.
229229
"""

chia/_tests/harvester/__init__.py

Whitespace-only changes.

chia/_tests/harvester/test_harvester_api.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from unittest.mock import MagicMock, patch
55

66
import pytest
7-
from chia_rs import ProofOfSpace
7+
from chia_rs import FullBlock, ProofOfSpace
88
from chia_rs.sized_bytes import bytes32
99
from chia_rs.sized_ints import uint64
1010

@@ -17,15 +17,8 @@
1717
from chia.simulator.block_tools import BlockTools
1818

1919

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."""
2922
# extract real signage point data from the block
3023
sp_index = block.reward_chain_block.signage_point_index
3124
challenge_hash = block.reward_chain_block.pos_ss_cc_challenge_hash
@@ -63,21 +56,23 @@ def create_plot_info() -> PlotInfo:
6356

6457

6558
@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:
6762
"""Test successful signage point processing with real blockchain data."""
6863
_, _, harvester_service, _, bt = harvester_farmer_environment
6964
harvester_api = harvester_service._server.api
7065
assert isinstance(harvester_api, HarvesterAPI)
7166
# 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)
7369
# harvester doesn't accept incoming connections, so use mock peer like other tests
7470
mock_peer = MagicMock(spec=WSChiaConnection)
7571
# create realistic plot info for testing
7672
mock_plot_info = create_plot_info()
77-
plot_path = Path("/fake/plot.plot")
7873

7974
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}):
8176
# let passes_plot_filter, calculate_pos_challenge, and calculate_sp_interval_iters use real implementations
8277
with patch("chia.harvester.harvester_api.calculate_iterations_quality", return_value=uint64(1000)):
8378
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
8883

8984
@pytest.mark.anyio
9085
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
9287
) -> None:
9388
"""Test pool difficulty overrides with real blockchain signage points."""
9489
_, _, harvester_service, _, bt = harvester_farmer_environment
@@ -102,15 +97,15 @@ async def test_new_signage_point_harvester_pool_difficulty(
10297
# create realistic plot info for testing
10398
mock_plot_info = create_plot_info()
10499
mock_plot_info.pool_contract_puzzle_hash = pool_puzzle_hash
105-
plot_path = Path("/fake/pool_plot.plot")
106100
pool_difficulty = PoolDifficulty(
107101
pool_contract_puzzle_hash=pool_puzzle_hash,
108102
difficulty=uint64(500), # lower than main difficulty
109103
sub_slot_iters=uint64(67108864), # different from main
110104
)
111105

112106
# 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)
114109
new_challenge = harvester_protocol.NewSignagePointHarvester(
115110
challenge_hash=new_challenge.challenge_hash,
116111
difficulty=new_challenge.difficulty,
@@ -123,7 +118,7 @@ async def test_new_signage_point_harvester_pool_difficulty(
123118
)
124119

125120
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}):
127122
# mock passes_plot_filter to return True so we can test pool difficulty logic
128123
with patch("chia.harvester.harvester_api.passes_plot_filter", return_value=True):
129124
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(
140135

141136
@pytest.mark.anyio
142137
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
144139
) -> None:
145140
"""Test error handling when prover fails using real blockchain data."""
146141
_, _, harvester_service, _, bt = harvester_farmer_environment
147142
harvester_api = harvester_service._server.api
148143
assert isinstance(harvester_api, HarvesterAPI)
149144

150145
# 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)
152148

153149
mock_peer = MagicMock(spec=WSChiaConnection)
154150

155151
# create realistic plot info for testing
156152
mock_plot_info = create_plot_info()
157-
plot_path = Path("/fake/plot.plot")
158153

159154
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}):
161156
# let passes_plot_filter and calculate_pos_challenge use real implementations
162157
# make the prover fail during quality check
163158
with patch.object(

chia/_tests/solver/test_solver_service.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
34
from typing import Optional
45
from unittest.mock import patch
56

67
import pytest
8+
from chia_rs import FullBlock
79
from chia_rs.sized_bytes import bytes32
810
from chia_rs.sized_ints import uint8, uint64
911

@@ -19,11 +21,9 @@
1921

2022

2123
@pytest.mark.anyio
22-
async def test_solver_api_methods(bt: BlockTools) -> None:
24+
async def test_solver_api_methods(bt: BlockTools, tmp_path: Path) -> None:
2325
"""Test solver api protocol methods with real requests."""
24-
solver_temp_dir = bt.root_path / "solver_farmer_test"
25-
solver_temp_dir.mkdir(exist_ok=True)
26-
async with setup_solver(solver_temp_dir, bt.constants) as solver_service:
26+
async with setup_solver(tmp_path, bt.constants) as solver_service:
2727
solver = solver_service._node
2828
solver_api = solver_service._api
2929

@@ -56,26 +56,22 @@ async def test_solver_api_methods(bt: BlockTools) -> None:
5656

5757

5858
@pytest.mark.anyio
59-
async def test_non_overflow_genesis(empty_blockchain: Blockchain, bt: BlockTools) -> None:
60-
blocks = bt.get_consecutive_blocks(
61-
num_blocks=3,
62-
guarantee_transaction_block=True,
63-
farmer_reward_puzzle_hash=bt.farmer_ph,
64-
)
59+
async def test_non_overflow_genesis(empty_blockchain: Blockchain, default_400_blocks: list[FullBlock]) -> None:
60+
blocks = default_400_blocks[:3]
6561
for block in blocks:
6662
await _validate_and_add_block(empty_blockchain, block)
6763

6864

6965
@pytest.mark.anyio
7066
async def test_solver_with_real_blocks_and_signage_points(
71-
bt: BlockTools, empty_blockchain: Blockchain, self_hostname: str
67+
bt: BlockTools,
68+
default_400_blocks: list[FullBlock],
69+
empty_blockchain: Blockchain,
70+
self_hostname: str,
71+
tmp_path: Path,
7272
) -> None:
7373
blockchain = empty_blockchain
74-
blocks = bt.get_consecutive_blocks(
75-
num_blocks=3,
76-
guarantee_transaction_block=True,
77-
farmer_reward_puzzle_hash=bt.farmer_ph,
78-
)
74+
blocks = default_400_blocks[:3]
7975
for block in blocks:
8076
await _validate_and_add_block(empty_blockchain, block)
8177
block = blocks[-1] # always use the last block
@@ -104,9 +100,7 @@ async def test_solver_with_real_blocks_and_signage_points(
104100
plot_size = pos.size()
105101
k_size = plot_size.size_v1 if plot_size.size_v1 is not None else plot_size.size_v2
106102
assert k_size is not None
107-
solver_temp_dir = bt.root_path / "solver_farmer_test"
108-
solver_temp_dir.mkdir(exist_ok=True)
109-
async with setup_solver(solver_temp_dir, bt.constants) as solver_service:
103+
async with setup_solver(tmp_path, bt.constants) as solver_service:
110104
assert solver_service.rpc_server is not None
111105
solver_rpc_client = await SolverRpcClient.create(
112106
self_hostname, solver_service.rpc_server.listen_port, solver_service.root_path, solver_service.config
@@ -119,11 +113,9 @@ async def test_solver_with_real_blocks_and_signage_points(
119113

120114

121115
@pytest.mark.anyio
122-
async def test_solver_error_handling_and_edge_cases(bt: BlockTools, self_hostname: str) -> None:
116+
async def test_solver_error_handling_and_edge_cases(bt: BlockTools, self_hostname: str, tmp_path: Path) -> None:
123117
"""Test solver error handling with invalid requests and edge cases."""
124-
solver_temp_dir = bt.root_path / "solver_farmer_test"
125-
solver_temp_dir.mkdir(exist_ok=True)
126-
async with setup_solver(solver_temp_dir, bt.constants) as solver_service:
118+
async with setup_solver(tmp_path, bt.constants) as solver_service:
127119
assert solver_service.rpc_server is not None
128120
solver_rpc_client = await SolverRpcClient.create(
129121
self_hostname, solver_service.rpc_server.listen_port, solver_service.root_path, solver_service.config

chia/_tests/util/setup_nodes.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
)
4444
from chia.simulator.socket import find_available_listen_port
4545
from chia.simulator.start_simulator import SimulatorFullNodeService
46+
from chia.solver.solver_service import SolverService
4647
from chia.timelord.timelord_service import TimelordService
4748
from chia.types.peer_info import UnresolvedPeerInfo
4849
from chia.util.hash import std_hash
@@ -65,6 +66,7 @@ class FullSystem:
6566
introducer: IntroducerAPI
6667
timelord: TimelordService
6768
timelord_bluebox: TimelordService
69+
solver: SolverService
6870
daemon: WebSocketServer
6971

7072

@@ -474,14 +476,13 @@ async def setup_full_system_inner(
474476

475477
await asyncio.sleep(backoff)
476478

477-
setup_solver(
478-
shared_b_tools.root_path / "harvester",
479-
consensus_constants,
480-
True,
479+
solver_service = await async_exit_stack.enter_async_context(
480+
setup_solver(
481+
shared_b_tools.root_path / "solver",
482+
consensus_constants,
483+
True,
484+
)
481485
)
482-
# solver_service = await async_exit_stack.enter_async_context(
483-
484-
# )
485486

486487
full_system = FullSystem(
487488
node_1=node_1,
@@ -491,6 +492,7 @@ async def setup_full_system_inner(
491492
introducer=introducer,
492493
timelord=timelord,
493494
timelord_bluebox=timelord_bluebox_service,
495+
solver=solver_service,
494496
daemon=daemon_ws,
495497
)
496498
yield full_system

chia/_tests/util/test_network_protocol_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
pool_protocol,
1313
protocol_message_types,
1414
shared_protocol,
15+
solver_protocol,
1516
timelord_protocol,
1617
wallet_protocol,
1718
)
@@ -136,6 +137,7 @@ def test_missing_messages() -> None:
136137
"NewSignagePoint",
137138
"RequestSignedValues",
138139
"SignedValues",
140+
"SolutionResponse",
139141
}
140142

141143
full_node_msgs = {
@@ -188,6 +190,7 @@ def test_missing_messages() -> None:
188190
"RequestSignatures",
189191
"RespondPlots",
190192
"RespondSignatures",
193+
"V2Qualities",
191194
}
192195

193196
introducer_msgs = {"RequestPeersIntroducer", "RespondPeersIntroducer"}
@@ -219,6 +222,8 @@ def test_missing_messages() -> None:
219222
"RespondCompactProofOfTime",
220223
}
221224

225+
solver_msgs = {"SolverInfo"}
226+
222227
shared_msgs = {"Handshake", "Capability", "Error"}
223228

224229
# if these asserts fail, make sure to add the new network protocol messages
@@ -252,6 +257,10 @@ def test_missing_messages() -> None:
252257
f"message types were added or removed from timelord_protocol. {STANDARD_ADVICE}"
253258
)
254259

260+
assert types_in_module(solver_protocol) == solver_msgs, (
261+
f"message types were added or removed from shared_protocol. {STANDARD_ADVICE}"
262+
)
263+
255264
assert types_in_module(shared_protocol) == shared_msgs, (
256265
f"message types were added or removed from shared_protocol. {STANDARD_ADVICE}"
257266
)

chia/cmds/rpc.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@
1313
from chia.cmds.cmd_classes import ChiaCliContext
1414
from chia.util.config import load_config
1515

16-
services: list[str] = ["crawler", "daemon", "farmer", "full_node", "harvester", "timelord", "wallet", "data_layer", "solver"]
16+
services: list[str] = [
17+
"crawler",
18+
"daemon",
19+
"farmer",
20+
"full_node",
21+
"harvester",
22+
"timelord",
23+
"wallet",
24+
"data_layer",
25+
"solver",
26+
]
1727

1828

1929
async def call_endpoint(

chia/cmds/solver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_state_cmd(
2727
solver_rpc_port: Optional[int],
2828
) -> None:
2929
import asyncio
30-
30+
3131
from chia.cmds.solver_funcs import get_state
3232

3333
asyncio.run(get_state(ChiaCliContext.set_default(ctx), solver_rpc_port))
@@ -36,7 +36,7 @@ def get_state_cmd(
3636
@solver_cmd.command("solve", help="Solve a quality string")
3737
@click.option(
3838
"-sp",
39-
"--solver-rpc-port",
39+
"--solver-rpc-port",
4040
help="Set the port where the Solver is hosting the RPC interface. See the rpc_port under solver in config.yaml",
4141
type=int,
4242
default=None,
@@ -74,7 +74,7 @@ def solve_cmd(
7474
difficulty: int,
7575
) -> None:
7676
import asyncio
77-
77+
7878
from chia.cmds.solver_funcs import solve_quality
7979

80-
asyncio.run(solve_quality(ChiaCliContext.set_default(ctx), solver_rpc_port, quality, plot_size, difficulty))
80+
asyncio.run(solve_quality(ChiaCliContext.set_default(ctx), solver_rpc_port, quality, plot_size, difficulty))

0 commit comments

Comments
 (0)