Repository: Chia-Network/chia-blockchain
File: chia/_tests/blockchain/test_blockchain.py (Python)

Code before:
    blocks = bt.get_consecutive_blocks(2)
    for block in blocks:
        await _validate_and_add_block(b, block)
    non_tx_block = next(block for block in blocks if not block.is_transaction_block())
    blocks_with_filter = await b.get_header_blocks_in_range(0, 42, tx_filter=True)
    empty_tx_filter = b"\x00"
    assert blocks_with_filter[non_tx_block.header_hash].transactions_filter == empty_tx_filter


@dataclass(frozen=True)
class ForkInfoTestSetup:
    fork_info: ForkInfo
    initial_additions_since_fork: dict[bytes32, ForkAdd]
    test_block: FullBlock
    coin: Coin
    child_coin: Coin

    @classmethod
    def create(cls, same_ph_as_parent: bool, same_amount_as_parent: bool, odd_amount: bool = True) -> ForkInfoTestSetup:
        from chia._tests.util.network_protocol_data import full_block as test_block

        puzzle_hash = bytes32([0] * 32)
        amount = uint64(1337) if odd_amount else uint64(42)
        init_coin_parent_id = bytes32([1] * 32)
        init_coin = Coin(init_coin_parent_id, puzzle_hash, amount)
        initial_additions_since_fork = {init_coin.name(): ForkAdd(init_coin, uint32(1), uint64(0), None, False, False)}
        fork_info = ForkInfo(
            test_block.height - 1,
            test_block.height - 1,
            test_block.prev_header_hash,
            additions_since_fork=copy.copy(initial_additions_since_fork),
        )
        coin = Coin(bytes32([2] * 32), puzzle_hash, amount)
        child_coin_ph = puzzle_hash if same_ph_as_parent else bytes32([3] * 32)
        child_coin_amount = amount if same_amount_as_parent else uint64(0)
        child_coin = Coin(coin.name(), child_coin_ph, child_coin_amount)
        return cls(
            fork_info=fork_info,
            initial_additions_since_fork=initial_additions_since_fork,
            test_block=test_block,
            coin=coin,
            child_coin=child_coin,
        )

    def check_additions(self, expected_same_parent_additions: set[bytes32]) -> None:
        assert all(
            a in self.fork_info.additions_since_fork and self.fork_info.additions_since_fork[a].same_as_parent
            for a in expected_same_parent_additions
        )
        remaining_additions = set(self.fork_info.additions_since_fork) - expected_same_parent_additions
        assert not any(self.fork_info.additions_since_fork[a].same_as_parent for a in remaining_additions)

Review comment (suggestion):
`None, False, False`, it's not so easy to know what this means. I think this crosses the line for number of unnamed `bool` parameters

Code after:
    for block in blocks:
        await _validate_and_add_block(b, block)
    non_tx_block = next(block for block in blocks if not block.is_transaction_block())
    blocks_with_filter = await b.get_header_blocks_in_range(0, 42, tx_filter=True)
    empty_tx_filter = b"\x00"
    assert blocks_with_filter[non_tx_block.header_hash].transactions_filter == empty_tx_filter


@dataclass(frozen=True)
class ForkInfoTestSetup:
    fork_info: ForkInfo
    initial_additions_since_fork: dict[bytes32, ForkAdd]
    test_block: FullBlock
    coin: Coin
    child_coin: Coin

    @classmethod
    def create(cls, same_ph_as_parent: bool, same_amount_as_parent: bool) -> ForkInfoTestSetup:
        from chia._tests.util.network_protocol_data import full_block as test_block

        unrelated_coin = Coin(bytes32([0] * 32), bytes32([1] * 32), uint64(42))
        # We add this initial state with an unrelated addition, to create a
        # difference between the `rollback` state and the completely empty
        # `reset` state.
        initial_additions_since_fork = {
            unrelated_coin.name(): ForkAdd(
                coin=unrelated_coin,
                confirmed_height=uint32(1),
                timestamp=uint64(0),
                hint=None,
                is_coinbase=False,
                same_as_parent=False,
            )
        }
        fork_info = ForkInfo(
            test_block.height - 1,
            test_block.height - 1,
            test_block.prev_header_hash,
            additions_since_fork=copy.copy(initial_additions_since_fork),
        )
        puzzle_hash = bytes32([2] * 32)
        amount = uint64(1337)
        coin = Coin(bytes32([3] * 32), puzzle_hash, amount)
        child_coin_ph = puzzle_hash if same_ph_as_parent else bytes32([4] * 32)
        child_coin_amount = amount if same_amount_as_parent else uint64(0)
        child_coin = Coin(coin.name(), child_coin_ph, child_coin_amount)
        return cls(
            fork_info=fork_info,
            initial_additions_since_fork=initial_additions_since_fork,
            test_block=test_block,
            coin=coin,