Skip to content

Commit 7b3a773

Browse files
authored
Test conditions pool reward (#20288)
* make test_conditions.py use the farmer reward, and not the pool reward, for its tests. This prepares this test to work with v2 plots, since they don't support redirecting the pool reward * fix get_plot_id() for v2 proofs * fix proof-of-space tests
1 parent bc2a7f7 commit 7b3a773

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

chia/_tests/core/custom_types/test_proof_of_space.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def b32(key: str) -> bytes32:
128128
),
129129
ProofOfSpaceCase(
130130
id="Not passing the plot filter v2",
131-
pos_challenge=b32("5706ae15c4a437399f464c64ef4f33c362d860ccd2945b76b3ebdb0505783817"),
131+
pos_challenge=b32("4cfaacbd2782db64d07cf490ca938534adb07dfbd2f92b0e479e2e5b196178db"),
132132
plot_size=PlotParam.make_v2(32),
133133
pool_contract_puzzle_hash=bytes32(b"1" * 32),
134134
plot_public_key=g1(
@@ -180,7 +180,7 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
180180
ProofOfSpaceCase(
181181
id="not passing the plot filter v2",
182182
plot_size=PlotParam.make_v2(2),
183-
pos_challenge=b32("fb1d676f0e3ce173f4e6cfb06d7059886cbc3b91cf65be0af0fc2fbe569c6597"),
183+
pos_challenge=b32("aefba5c94bc9bbfe2c538b7faaaf03384ac5a6170e40b024657df6b0a27c34a7"),
184184
plot_public_key=g1(
185185
"afa3aaf09c03885154be49216ee7fb2e4581b9c4a4d7e9cc402e27280bf0cfdbdf1b9ba674e301fd1d1450234b3b1868"
186186
),

chia/_tests/core/full_node/test_conditions.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
1616
from chia._tests.conftest import ConsensusMode
1717
from chia._tests.core.full_node.ram_db import create_ram_blockchain
18+
from chia._tests.core.full_node.test_full_node import find_reward_coin
1819
from chia.consensus.condition_tools import agg_sig_additional_data
1920
from chia.simulator.block_tools import BlockTools
2021
from chia.simulator.keyring import TempKeyring
@@ -47,7 +48,6 @@ async def initial_blocks(bt: BlockTools, block_count: int = 4) -> list[FullBlock
4748
block_count,
4849
guarantee_transaction_block=True,
4950
farmer_reward_puzzle_hash=EASY_PUZZLE_HASH,
50-
pool_reward_puzzle_hash=EASY_PUZZLE_HASH,
5151
genesis_timestamp=uint64(10000),
5252
time_per_block=10,
5353
)
@@ -101,7 +101,7 @@ async def check_conditions(
101101
aggsig: G2Element = G2Element(),
102102
) -> tuple[list[CoinRecord], list[CoinRecord], FullBlock]:
103103
blocks = await initial_blocks(bt)
104-
coin = blocks[spend_reward_index].get_included_reward_coins()[0]
104+
coin = find_reward_coin(blocks[spend_reward_index], EASY_PUZZLE_HASH)
105105

106106
coin_spend = make_spend(coin, EASY_PUZZLE, condition_solution)
107107
spend_bundle = SpendBundle([coin_spend], aggsig)
@@ -143,9 +143,9 @@ async def test_unknown_conditions_with_cost(
143143
# once the hard fork activates, blocks no longer pay the cost of the ROM
144144
# generator (which includes hashing all puzzles).
145145
if consensus_mode >= ConsensusMode.HARD_FORK_2_0:
146-
block_base_cost = 756064
146+
block_base_cost = 756064 - 12000
147147
else:
148-
block_base_cost = 761056
148+
block_base_cost = 761056 - 12000
149149
assert new_block.transactions_info is not None
150150
assert new_block.transactions_info.cost - block_base_cost == expected_cost
151151

@@ -164,11 +164,11 @@ async def test_softfork_condition(
164164
_additions, _removals, new_block = await check_conditions(bt, conditions)
165165

166166
if consensus_mode < ConsensusMode.HARD_FORK_2_0:
167-
block_base_cost = 737056
167+
block_base_cost = 737056 - 12000
168168
else:
169169
# once the hard fork activates, blocks no longer pay the cost of the ROM
170170
# generator (which includes hashing all puzzles).
171-
block_base_cost = 732064
171+
block_base_cost = 732064 - 12000
172172

173173
# the block_base_cost includes the cost of the bytes for the condition
174174
# with 2 bytes argument. This test works as long as the conditions it's
@@ -267,7 +267,7 @@ async def test_condition(self, opcode: ConditionOpcode, value: int, expected: Er
267267
@pytest.mark.anyio
268268
async def test_invalid_my_id(self, bt: BlockTools) -> None:
269269
blocks = await initial_blocks(bt)
270-
coin = blocks[-2].get_included_reward_coins()[0]
270+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
271271
wrong_name = bytearray(coin.name())
272272
wrong_name[-1] ^= 1
273273
conditions = Program.to(assemble(f"(({ConditionOpcode.ASSERT_MY_COIN_ID[0]} 0x{wrong_name.hex()}))"))
@@ -276,14 +276,14 @@ async def test_invalid_my_id(self, bt: BlockTools) -> None:
276276
@pytest.mark.anyio
277277
async def test_valid_my_id(self, bt: BlockTools) -> None:
278278
blocks = await initial_blocks(bt)
279-
coin = blocks[-2].get_included_reward_coins()[0]
279+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
280280
conditions = Program.to(assemble(f"(({ConditionOpcode.ASSERT_MY_COIN_ID[0]} 0x{coin.name().hex()}))"))
281281
await check_conditions(bt, conditions)
282282

283283
@pytest.mark.anyio
284284
async def test_invalid_coin_announcement(self, bt: BlockTools) -> None:
285285
blocks = await initial_blocks(bt)
286-
coin = blocks[-2].get_included_reward_coins()[0]
286+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
287287
announce = AssertCoinAnnouncement(asserted_id=coin.name(), asserted_msg=b"test_bad")
288288
conditions = Program.to(
289289
assemble(
@@ -296,7 +296,7 @@ async def test_invalid_coin_announcement(self, bt: BlockTools) -> None:
296296
@pytest.mark.anyio
297297
async def test_valid_coin_announcement(self, bt: BlockTools) -> None:
298298
blocks = await initial_blocks(bt)
299-
coin = blocks[-2].get_included_reward_coins()[0]
299+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
300300
announce = AssertCoinAnnouncement(asserted_id=coin.name(), asserted_msg=b"test")
301301
conditions = Program.to(
302302
assemble(
@@ -374,7 +374,7 @@ async def test_announce_conditions_limit(
374374
"""
375375

376376
blocks = await initial_blocks(bt)
377-
coin = blocks[-2].get_included_reward_coins()[0]
377+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
378378
coin_announcement = AssertCoinAnnouncement(asserted_id=coin.name(), asserted_msg=b"test")
379379
puzzle_announcement = AssertPuzzleAnnouncement(asserted_ph=EASY_PUZZLE_HASH, asserted_msg=b"test")
380380

@@ -404,7 +404,7 @@ async def test_announce_conditions_limit(
404404
@pytest.mark.anyio
405405
async def test_coin_messages(self, bt: BlockTools, consensus_mode: ConsensusMode) -> None:
406406
blocks = await initial_blocks(bt)
407-
coin = blocks[-2].get_included_reward_coins()[0]
407+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
408408
conditions = Program.to(
409409
assemble(
410410
f"(({ConditionOpcode.SEND_MESSAGE[0]} 0x3f 'test' 0x{coin.name().hex()})"
@@ -416,7 +416,7 @@ async def test_coin_messages(self, bt: BlockTools, consensus_mode: ConsensusMode
416416
@pytest.mark.anyio
417417
async def test_parent_messages(self, bt: BlockTools, consensus_mode: ConsensusMode) -> None:
418418
blocks = await initial_blocks(bt)
419-
coin = blocks[-2].get_included_reward_coins()[0]
419+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
420420
conditions = Program.to(
421421
assemble(
422422
f"(({ConditionOpcode.SEND_MESSAGE[0]} 0x24 'test' 0x{coin.parent_coin_info})"
@@ -437,7 +437,7 @@ async def test_parent_messages(self, bt: BlockTools, consensus_mode: ConsensusMo
437437
('(66 0x27 "foo" {coin}) (67 0x3f "foo" {coin})', Err.MESSAGE_NOT_SENT_OR_RECEIVED),
438438
('(66 0 "foo") (67 0 "foo")', None),
439439
('(66 0 "foobar") (67 0 "foo")', Err.MESSAGE_NOT_SENT_OR_RECEIVED),
440-
('(66 0x09 "foo" 1750000000000) (67 0x09 "foo" 1750000000000)', None),
440+
('(66 0x09 "foo" 250000000000) (67 0x09 "foo" 250000000000)', None),
441441
('(66 -1 "foo")', Err.INVALID_MESSAGE_MODE),
442442
('(67 -1 "foo")', Err.INVALID_MESSAGE_MODE),
443443
('(66 0x40 "foo")', Err.INVALID_MESSAGE_MODE),
@@ -448,7 +448,7 @@ async def test_message_conditions(
448448
self, bt: BlockTools, consensus_mode: ConsensusMode, conds: str, expected: Err | None
449449
) -> None:
450450
blocks = await initial_blocks(bt)
451-
coin = blocks[-2].get_included_reward_coins()[0]
451+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
452452
conditions = Program.to(assemble("(" + conds.format(coin="0x" + coin.name().hex()) + ")"))
453453

454454
await check_conditions(bt, conditions, expected_err=expected)
@@ -521,7 +521,7 @@ async def test_agg_sig_illegal_suffix(
521521

522522
sk = AugSchemeMPL.key_gen(b"8" * 32)
523523
pubkey = sk.get_g1()
524-
coin = blocks[-2].get_included_reward_coins()[0]
524+
coin = find_reward_coin(blocks[-2], EASY_PUZZLE_HASH)
525525
for msg in [
526526
c.AGG_SIG_ME_ADDITIONAL_DATA,
527527
c.AGG_SIG_PARENT_ADDITIONAL_DATA,

chia/types/blockchain_format/proof_of_space.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_plot_id(pos: ProofOfSpace) -> bytes32:
4646
plot_param = pos.param()
4747
if plot_param.strength_v2 is not None:
4848
assert pos.pool_contract_puzzle_hash is not None
49-
return calculate_plot_id_v2(pos.pool_contract_puzzle_hash, pos.plot_public_key, plot_param.strength_v2)
49+
return calculate_plot_id_v2(pos.pool_contract_puzzle_hash, pos.plot_public_key, uint8(plot_param.strength_v2))
5050

5151
assert pos.pool_public_key is None or pos.pool_contract_puzzle_hash is None
5252
if pos.pool_public_key is None:

0 commit comments

Comments
 (0)