Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHIA-2108 Cover computing transactions filter for transaction blocks with only reward coins #19076

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions chia/_tests/wallet/sync/test_wallet_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,17 @@ async def test_request_block_headers(

@pytest.mark.limit_consensus_modes(reason="save time")
@pytest.mark.anyio
@pytest.mark.parametrize("rewards_only_tx_block", [True, False])
async def test_request_block_headers_transactions_filter(
one_node_one_block: tuple[FullNodeSimulator, ChiaServer, BlockTools],
one_node_one_block: tuple[FullNodeSimulator, ChiaServer, BlockTools], rewards_only_tx_block: bool
) -> None:
"""
Tests that `request_block_headers` returns a transactions filter that
correctly reflects the blocks transactions.

We use `rewards_only_tx_block` to control whether the test transaction
block contains our test spend as well, or just the reward coins.

For completeness, we're also comparing the outcome of
`request_block_headers` in this regard, to `request_header_blocks` as
well as `request_block_header`.
Expand All @@ -130,28 +135,36 @@ async def test_request_block_headers_transactions_filter(
ph = SerializedProgram.to(1).get_tree_hash()
for _ in range(2):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
# Generate a block with our test spend
coins = await full_node_api.full_node.coin_store.get_coin_records_by_puzzle_hash(False, ph)
[parent_coin] = [c.coin for c in coins if c.coin.amount == 250_000_000_000]
sb = SpendBundle(
[
make_spend(
parent_coin, SerializedProgram.to(1), SerializedProgram.to([[ConditionOpcode.CREATE_COIN, ph, 42]])
)
],
G2Element(),
)
if rewards_only_tx_block:
# Generate a transaction block without any spends
sb = None
else:
# Generate a transaction block with our test spend
coins = await full_node_api.full_node.coin_store.get_coin_records_by_puzzle_hash(False, ph)
[parent_coin] = [c.coin for c in coins if c.coin.amount == 250_000_000_000]
sb = SpendBundle(
[
make_spend(
parent_coin, SerializedProgram.to(1), SerializedProgram.to([[ConditionOpcode.CREATE_COIN, ph, 42]])
)
],
G2Element(),
)
blocks = await full_node_api.get_all_full_blocks()
blocks = bt.get_consecutive_blocks(1, blocks, guarantee_transaction_block=True, transaction_data=sb)
new_block = blocks[-1]
await full_node_api.full_node.add_block(new_block)
# Compute the expected transactions filter
[test_spend] = sb.additions()
byte_array_tx = (
[bytearray(test_spend.puzzle_hash)]
+ [bytearray(coin.puzzle_hash) for coin in new_block.get_included_reward_coins()]
+ [bytearray(parent_coin.name())]
)
if rewards_only_tx_block:
byte_array_tx = [bytearray(coin.puzzle_hash) for coin in new_block.get_included_reward_coins()]
else:
assert sb is not None
[test_spend] = sb.additions()
byte_array_tx = (
[bytearray(test_spend.puzzle_hash)]
+ [bytearray(coin.puzzle_hash) for coin in new_block.get_included_reward_coins()]
+ [bytearray(parent_coin.name())]
)
expected_transactions_filter = bytes(PyBIP158(byte_array_tx).GetEncoded())
# Perform the request and check the transactions filter
msg = await full_node_api.request_block_headers(
Expand Down
Loading