Repository: Chia-Network/chia-blockchain
File: chia/_tests/core/full_node/test_generator_tools.py (Python)

Code before:
        [],
        [],
        [],
        0,
    ),
]


def test_tx_removals_and_additions() -> None:
    conditions = SpendBundleConditions(
        spends, uint64(0), uint32(0), uint64(0), None, None, [], uint64(0), 0, 0, False, 0, 0
    )
    expected_rems = [coin_ids[0], coin_ids[1]]
    expected_additions = []
    for spend in spends:
        for puzzle_hash, am, _ in spend.create_coin:
            expected_additions.append(Coin(bytes32(spend.coin_id), bytes32(puzzle_hash), uint64(am)))
    rems, adds = tx_removals_and_additions(conditions)
    assert rems == expected_rems
    assert adds == expected_additions


def test_empty_conditions() -> None:
    assert tx_removals_and_additions(None) == ([], [])


TEST_GENERATOR = BlockGenerator(
    SerializedProgram.fromhex(
        "ff02ffff01ff02ffff01ff04ffff04ffff04ffff01a00101010101010101010101010101010101010101010101010101010101010101ffff04ffff04ffff0101ffff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ff17ff80808080808080ffff01ff7bffff80ffff018080808080ff8080ff8080ffff04ffff01ff02ffff03ff17ffff01ff04ff05ffff04ff0bffff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ffff11ff17ffff010180ff8080808080808080ff8080ff0180ff018080ffff04ffff01ff42ff24ff8568656c6c6fffa0010101010101010101010101010101010101010101010101010101010101010180ffff04ffff01ff43ff24ff8568656c6c6fffa0010101010101010101010101010101010101010101010101010101010101010180ffff04ffff01830f4240ff0180808080"
    ),
    [],
)


def test_get_spends_for_block(caplog: pytest.LogCaptureFixture) -> None:
    conditions = get_spends_for_block(TEST_GENERATOR, 100, test_constants)
    assert conditions == []
    assert "get_spends_for_block() encountered a puzzle we couldn't serialize: " in caplog.text


def test_get_spends_for_block_with_conditions(caplog: pytest.LogCaptureFixture) -> None:
    conditions = get_spends_for_block_with_conditions(TEST_GENERATOR, 100, test_constants)
    assert conditions == []
    assert "get_spends_for_block_with_conditions() encountered a puzzle we couldn't serialize: " in caplog.text


Review comment (bug):
Do we not have this elsewhere that we can import?
I'd also suggest renaming it to make it more explicit that this is a malicious generator

```suggestion
# this is a malicious generator which should fail
```

Code after:
        [],
        [],
        [],
        0,
    ),
]


def test_tx_removals_and_additions() -> None:
    conditions = SpendBundleConditions(
        spends, uint64(0), uint32(0), uint64(0), None, None, [], uint64(0), 0, 0, False, 0, 0
    )
    expected_rems = [coin_ids[0], coin_ids[1]]
    expected_additions = []
    for spend in spends:
        for puzzle_hash, am, _ in spend.create_coin:
            expected_additions.append(Coin(bytes32(spend.coin_id), bytes32(puzzle_hash), uint64(am)))
    rems, adds = tx_removals_and_additions(conditions)
    assert rems == expected_rems
    assert adds == expected_additions


def test_empty_conditions() -> None:
    assert tx_removals_and_additions(None) == ([], [])


# this is a malicious generator which should fail
TEST_GENERATOR = BlockGenerator(
    SerializedProgram.fromhex(
        "ff02ffff01ff02ffff01ff04ffff04ffff04ffff01a00101010101010101010101010101010101010101010101010101010101010101ffff04ffff04ffff0101ffff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ff17ff80808080808080ffff01ff7bffff80ffff018080808080ff8080ff8080ffff04ffff01ff02ffff03ff17ffff01ff04ff05ffff04ff0bffff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ffff11ff17ffff010180ff8080808080808080ff8080ff0180ff018080ffff04ffff01ff42ff24ff8568656c6c6fffa0010101010101010101010101010101010101010101010101010101010101010180ffff04ffff01ff43ff24ff8568656c6c6fffa0010101010101010101010101010101010101010101010101010101010101010180ffff04ffff01830f4240ff0180808080"
    ),
    [],
)


def test_get_spends_for_block(caplog: pytest.LogCaptureFixture) -> None:
    conditions = get_spends_for_block(TEST_GENERATOR, 100, test_constants)
    assert conditions == []
    assert "get_spends_for_block() encountered a puzzle we couldn't serialize: " in caplog.text


def test_get_spends_for_block_with_conditions(caplog: pytest.LogCaptureFixture) -> None:
    conditions = get_spends_for_block_with_conditions(TEST_GENERATOR, 100, test_constants)
    assert conditions == []
    assert "get_spends_for_block_with_conditions() encountered a puzzle we couldn't serialize: " in caplog.text