5
5
from typing import Optional
6
6
7
7
import pytest
8
- from chia_rs import G1Element , PlotSize , ProofOfSpace
8
+ from chia_rs import G1Element , PlotSize
9
9
from chia_rs .sized_bytes import bytes32 , bytes48
10
10
from chia_rs .sized_ints import uint8 , uint32
11
11
15
15
calculate_plot_difficulty ,
16
16
calculate_prefix_bits ,
17
17
check_plot_size ,
18
+ make_pos ,
18
19
passes_plot_filter ,
19
20
verify_and_get_quality_string ,
20
21
)
24
25
class ProofOfSpaceCase :
25
26
id : str
26
27
pos_challenge : bytes32
27
- plot_size : uint8
28
+ plot_size : PlotSize
28
29
plot_public_key : G1Element
29
30
pool_public_key : Optional [G1Element ] = None
30
31
pool_contract_puzzle_hash : Optional [bytes32 ] = None
@@ -46,14 +47,14 @@ def b32(key: str) -> bytes32:
46
47
ProofOfSpaceCase (
47
48
id = "Neither pool public key nor pool contract puzzle hash" ,
48
49
pos_challenge = bytes32 (b"1" * 32 ),
49
- plot_size = uint8 (0 ),
50
+ plot_size = PlotSize . make_v1 (0 ),
50
51
plot_public_key = G1Element (),
51
52
expected_error = "Expected pool public key or pool contract puzzle hash but got neither" ,
52
53
),
53
54
ProofOfSpaceCase (
54
55
id = "Both pool public key and pool contract puzzle hash" ,
55
56
pos_challenge = bytes32 (b"1" * 32 ),
56
- plot_size = uint8 (0 ),
57
+ plot_size = PlotSize . make_v1 (0 ),
57
58
plot_public_key = G1Element (),
58
59
pool_public_key = G1Element (),
59
60
pool_contract_puzzle_hash = bytes32 (b"1" * 32 ),
@@ -62,31 +63,31 @@ def b32(key: str) -> bytes32:
62
63
ProofOfSpaceCase (
63
64
id = "Lower than minimum plot size" ,
64
65
pos_challenge = bytes32 (b"1" * 32 ),
65
- plot_size = uint8 (31 ),
66
+ plot_size = PlotSize . make_v1 (31 ),
66
67
plot_public_key = G1Element (),
67
68
pool_public_key = G1Element (),
68
69
expected_error = "Plot size is lower than the minimum" ,
69
70
),
70
71
ProofOfSpaceCase (
71
72
id = "Higher than maximum plot size" ,
72
73
pos_challenge = bytes32 (b"1" * 32 ),
73
- plot_size = uint8 (51 ),
74
+ plot_size = PlotSize . make_v1 (51 ),
74
75
plot_public_key = G1Element (),
75
76
pool_public_key = G1Element (),
76
77
expected_error = "Plot size is higher than the maximum" ,
77
78
),
78
79
ProofOfSpaceCase (
79
80
id = "Different challenge" ,
80
81
pos_challenge = bytes32 (b"1" * 32 ),
81
- plot_size = uint8 (42 ),
82
+ plot_size = PlotSize . make_v1 (42 ),
82
83
pool_public_key = G1Element (),
83
84
plot_public_key = G1Element (),
84
85
expected_error = "Calculated pos challenge doesn't match the provided one" ,
85
86
),
86
87
ProofOfSpaceCase (
87
88
id = "Not passing the plot filter with size 9" ,
88
89
pos_challenge = b32 ("08b23cc2844dfb92d2eedaa705a1ce665d571ee753bd81cbb67b92caa6d34722" ),
89
- plot_size = uint8 (42 ),
90
+ plot_size = PlotSize . make_v1 (42 ),
90
91
pool_public_key = g1 (
91
92
"b6449c2c68df97c19e884427e42ee7350982d4020571ead08732615ff39bd216bfd630b6460784982bec98b49fea79d0"
92
93
),
@@ -99,7 +100,7 @@ def b32(key: str) -> bytes32:
99
100
ProofOfSpaceCase (
100
101
id = "Passing the plot filter with size 8" ,
101
102
pos_challenge = b32 ("08b23cc2844dfb92d2eedaa705a1ce665d571ee753bd81cbb67b92caa6d34722" ),
102
- plot_size = uint8 (42 ),
103
+ plot_size = PlotSize . make_v1 (42 ),
103
104
pool_public_key = g1 (
104
105
"b6449c2c68df97c19e884427e42ee7350982d4020571ead08732615ff39bd216bfd630b6460784982bec98b49fea79d0"
105
106
),
@@ -111,23 +112,23 @@ def b32(key: str) -> bytes32:
111
112
ProofOfSpaceCase (
112
113
id = "v2 plot size 0" ,
113
114
pos_challenge = bytes32 (b"1" * 32 ),
114
- plot_size = uint8 ( 0x80 ),
115
+ plot_size = PlotSize . make_v2 ( 0 ),
115
116
plot_public_key = G1Element (),
116
117
pool_public_key = G1Element (),
117
118
expected_error = "Plot size is lower than the minimum" ,
118
119
),
119
120
ProofOfSpaceCase (
120
121
id = "v2 plot size 34" ,
121
122
pos_challenge = bytes32 (b"1" * 32 ),
122
- plot_size = uint8 ( 0x80 | 34 ),
123
+ plot_size = PlotSize . make_v2 ( 34 ),
123
124
plot_public_key = G1Element (),
124
125
pool_public_key = G1Element (),
125
126
expected_error = "Plot size is higher than the maximum" ,
126
127
),
127
128
ProofOfSpaceCase (
128
129
id = "Not passing the plot filter v2" ,
129
130
pos_challenge = b32 ("3d29ea79d19b3f7e99ebf764ae53697cbe143603909873946af6ab1ece606861" ),
130
- plot_size = uint8 ( 0x80 | 32 ),
131
+ plot_size = PlotSize . make_v2 ( 32 ),
131
132
pool_public_key = g1 (
132
133
"b6449c2c68df97c19e884427e42ee7350982d4020571ead08732615ff39bd216bfd630b6460784982bec98b49fea79d0"
133
134
),
@@ -138,7 +139,7 @@ def b32(key: str) -> bytes32:
138
139
),
139
140
)
140
141
def test_verify_and_get_quality_string (caplog : pytest .LogCaptureFixture , case : ProofOfSpaceCase ) -> None :
141
- pos = ProofOfSpace (
142
+ pos = make_pos (
142
143
challenge = case .pos_challenge ,
143
144
pool_public_key = case .pool_public_key ,
144
145
pool_contract_puzzle_hash = case .pool_contract_puzzle_hash ,
@@ -160,7 +161,7 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
160
161
@datacases (
161
162
ProofOfSpaceCase (
162
163
id = "v2 plot are not implemented" ,
163
- plot_size = uint8 ( 0x80 | 30 ),
164
+ plot_size = PlotSize . make_v2 ( 30 ),
164
165
pos_challenge = b32 ("47deb938e145d25d7b3b3c85ca9e3972b76c01aeeb78a02fe5d3b040d282317e" ),
165
166
plot_public_key = g1 (
166
167
"afa3aaf09c03885154be49216ee7fb2e4581b9c4a4d7e9cc402e27280bf0cfdbdf1b9ba674e301fd1d1450234b3b1868"
@@ -172,7 +173,7 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
172
173
),
173
174
)
174
175
def test_verify_and_get_quality_string_v2 (caplog : pytest .LogCaptureFixture , case : ProofOfSpaceCase ) -> None :
175
- pos = ProofOfSpace (
176
+ pos = make_pos (
176
177
challenge = case .pos_challenge ,
177
178
pool_public_key = case .pool_public_key ,
178
179
pool_contract_puzzle_hash = case .pool_contract_puzzle_hash ,
0 commit comments