Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
879 changes: 671 additions & 208 deletions chia/_tests/blockchain/test_blockchain.py

Large diffs are not rendered by default.

218 changes: 163 additions & 55 deletions chia/_tests/blockchain/test_blockchain_transactions.py

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions chia/_tests/blockchain/test_build_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def validate_chain(
print(
f"Block {i} in the block cache on disk differs "
"from what BlockTools generated. Please make sure "
"your test blocks are up-to-date"
"your test blocks are up-to-date",
)
print(f"disk:\n{blocks[i]}")
print(f"block-tools:\n{expected_blocks[i]}")
Expand Down Expand Up @@ -202,7 +202,9 @@ def test_validate_default_10000_compact(bt: BlockTools, default_10000_blocks_com


def test_validate_long_reorg_blocks(
bt: BlockTools, test_long_reorg_blocks: list[FullBlock], default_10000_blocks: list[FullBlock]
bt: BlockTools,
test_long_reorg_blocks: list[FullBlock],
default_10000_blocks: list[FullBlock],
) -> None:
validate_chain(
bt,
Expand All @@ -216,7 +218,9 @@ def test_validate_long_reorg_blocks(


def test_validate_long_reorg_blocks_light(
bt: BlockTools, test_long_reorg_blocks_light: list[FullBlock], default_10000_blocks: list[FullBlock]
bt: BlockTools,
test_long_reorg_blocks_light: list[FullBlock],
default_10000_blocks: list[FullBlock],
) -> None:
validate_chain(
bt,
Expand All @@ -229,7 +233,9 @@ def test_validate_long_reorg_blocks_light(


def test_validate_long_reorg_1500_blocks(
bt: BlockTools, test_long_reorg_1500_blocks: list[FullBlock], default_10000_blocks: list[FullBlock]
bt: BlockTools,
test_long_reorg_1500_blocks: list[FullBlock],
default_10000_blocks: list[FullBlock],
) -> None:
validate_chain(
bt,
Expand All @@ -243,7 +249,9 @@ def test_validate_long_reorg_1500_blocks(


def test_validate_long_reorg_1500_blocks_light(
bt: BlockTools, test_long_reorg_1500_blocks_light: list[FullBlock], default_10000_blocks: list[FullBlock]
bt: BlockTools,
test_long_reorg_1500_blocks_light: list[FullBlock],
default_10000_blocks: list[FullBlock],
) -> None:
validate_chain(
bt,
Expand Down
5 changes: 4 additions & 1 deletion chia/_tests/blockchain/test_lookup_fork_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ async def test_root_shared_right() -> None:
@pytest.mark.anyio
async def test_no_left_chain() -> None:
chain, fork_hash = await lookup_fork_chain(
test_chain, (-1, test_constants.GENESIS_CHALLENGE), (3, F), test_constants
test_chain,
(-1, test_constants.GENESIS_CHALLENGE),
(3, F),
test_constants,
)
assert chain == {0: G, 1: D, 2: E, 3: F}
assert fork_hash == test_constants.GENESIS_CHALLENGE
6 changes: 5 additions & 1 deletion chia/_tests/build-init-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def traverse_directory(path: pathlib.Path) -> list[pathlib.Path]:

@click.command()
@click.option(
"-r", "--root", "root_str", type=click.Path(dir_okay=True, file_okay=False, resolve_path=True), default="."
"-r",
"--root",
"root_str",
type=click.Path(dir_okay=True, file_okay=False, resolve_path=True),
default=".",
)
@click.option("-v", "--verbose", count=True, help=f"Increase verbosity up to {len(log_levels) - 1} times")
def command(verbose, root_str):
Expand Down
6 changes: 5 additions & 1 deletion chia/_tests/clvm/coin_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def validate_spend_bundle(self, spend_bundle: SpendBundle, now: CoinTimestamp, m
program = simple_solution_generator(spend_bundle)
# always use the post soft-fork2 semantics
result: NPCResult = get_name_puzzle_conditions(
program, max_cost, mempool_mode=True, height=uint32(3886635), constants=self._constants
program,
max_cost,
mempool_mode=True,
height=uint32(3886635),
constants=self._constants,
)
if result.error is not None:
raise BadSpendBundleError(f"condition validation failure {Err(result.error)}")
Expand Down
10 changes: 5 additions & 5 deletions chia/_tests/clvm/test_chialisp_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def serialized_atom_overflow(size):
(size >> 16) & 0xFF,
(size >> 8) & 0xFF,
(size >> 0) & 0xFF,
]
],
)
elif size < 0x400000000:
size_blob = bytes(
Expand All @@ -35,7 +35,7 @@ def serialized_atom_overflow(size):
(size >> 16) & 0xFF,
(size >> 8) & 0xFF,
(size >> 0) & 0xFF,
]
],
)
else:
size_blob = bytes(
Expand All @@ -46,7 +46,7 @@ def serialized_atom_overflow(size):
(size >> 16) & 0xFF,
(size >> 8) & 0xFF,
(size >> 0) & 0xFF,
]
],
)
extra_str = "01" * 1000
return size_blob.hex() + extra_str
Expand All @@ -64,7 +64,7 @@ def test_deserialization_simple_list():
def test_deserialization_password_coin():
# (i (= (sha256 2) (q 0x2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824)) (c (q 51) (c 5 (c (q 100) (q ())))) (q "wrong password")) # noqa
b = hexstr_to_bytes(
"ff04ffff0affff0bff0280ffff01ffa02cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98248080ffff05ffff01ff3380ffff05ff05ffff05ffff01ff6480ffff01ff8080808080ffff01ff8e77726f6e672070617373776f72648080"
"ff04ffff0affff0bff0280ffff01ffa02cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98248080ffff05ffff01ff3380ffff05ff05ffff05ffff01ff6480ffff01ff8080808080ffff01ff8e77726f6e672070617373776f72648080",
)
cost, output = DESERIALIZE_MOD.run_with_cost(INFINITE_COST, [b])
print(cost, output)
Expand All @@ -75,7 +75,7 @@ def test_deserialization_password_coin():
def test_deserialization_large_numbers():
# '(99999999999999999999999999999999999999999999999999999999999999999 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -99999999999999999999999999999999999999999999999999999999999999999999999999999)' # noqa
b = hexstr_to_bytes(
"ff9c00f316271c7fc3908a8bef464e3945ef7a253609ffffffffffffffffffb00fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa1ff22ea0179500526edb610f148ec0c614155678491902d6000000000000000000180"
"ff9c00f316271c7fc3908a8bef464e3945ef7a253609ffffffffffffffffffb00fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa1ff22ea0179500526edb610f148ec0c614155678491902d6000000000000000000180",
)
cost, output = DESERIALIZE_MOD.run_with_cost(INFINITE_COST, [b])
print(cost, output)
Expand Down
3 changes: 2 additions & 1 deletion chia/_tests/clvm/test_curry_and_treehash.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_curry_and_treehash() -> None:


@pytest.mark.parametrize(
"value", [[], [bytes32([3] * 32)], [bytes32.zeros, bytes32([1] * 32)], [bytes([1]), bytes([1, 2, 3])]]
"value",
[[], [bytes32([3] * 32)], [bytes32.zeros, bytes32([1] * 32)], [bytes([1]), bytes([1, 2, 3])]],
)
def test_shatree_atom_list(value: list[bytes]) -> None:
h1 = shatree_atom_list(value)
Expand Down
24 changes: 17 additions & 7 deletions chia/_tests/clvm/test_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def do_test_spend(


def default_payments_and_conditions(
initial_index: int, key_lookup: KeyTool
initial_index: int,
key_lookup: KeyTool,
) -> tuple[list[tuple[bytes32, int]], Program]:
# the coin we get from coin_db.farm_coin only has amount 1024, so we can
# only make small payments to avoid failing with MINTING_COIN
Expand Down Expand Up @@ -175,7 +176,10 @@ def test_p2_m_of_n_delegated_puzzle():
puzzle_program = p2_m_of_n_delegate_direct.puzzle_for_m_of_public_key_list(M, pks)
selectors = [1, [], [], 1, 1]
solution = p2_m_of_n_delegate_direct.solution_for_delegated_puzzle(
M, selectors, delegated_puzzle, delegated_solution
M,
selectors,
delegated_puzzle,
delegated_solution,
)

do_test_spend(puzzle_program, solution, payments, key_lookup)
Expand All @@ -189,10 +193,13 @@ def test_p2_delegated_puzzle_or_hidden_puzzle_with_hidden_puzzle():
hidden_public_key = public_key_for_index(10, key_lookup)

puzzle = p2_delegated_puzzle_or_hidden_puzzle.puzzle_for_public_key_and_hidden_puzzle(
G1Element.from_bytes_unchecked(hidden_public_key), hidden_puzzle
G1Element.from_bytes_unchecked(hidden_public_key),
hidden_puzzle,
)
solution = p2_delegated_puzzle_or_hidden_puzzle.solution_for_hidden_puzzle(
G1Element.from_bytes_unchecked(hidden_public_key), hidden_puzzle, Program.to(0)
G1Element.from_bytes_unchecked(hidden_public_key),
hidden_puzzle,
Program.to(0),
)

do_test_spend(puzzle, solution, payments, key_lookup)
Expand All @@ -207,22 +214,25 @@ def do_test_spend_p2_delegated_puzzle_or_hidden_puzzle_with_delegated_puzzle(hid
hidden_pub_key_point = G1Element.from_bytes(hidden_public_key)

puzzle = p2_delegated_puzzle_or_hidden_puzzle.puzzle_for_public_key_and_hidden_puzzle(
hidden_pub_key_point, hidden_puzzle
hidden_pub_key_point,
hidden_puzzle,
)
payable_payments, payable_conditions = default_payments_and_conditions(5, key_lookup)

delegated_puzzle = p2_conditions.puzzle_for_conditions(payable_conditions)
delegated_solution = []

synthetic_public_key = p2_delegated_puzzle_or_hidden_puzzle.calculate_synthetic_public_key(
G1Element.from_bytes(hidden_public_key), hidden_puzzle.get_tree_hash()
G1Element.from_bytes(hidden_public_key),
hidden_puzzle.get_tree_hash(),
)

solution = p2_delegated_puzzle_or_hidden_puzzle.solution_for_delegated_puzzle(delegated_puzzle, delegated_solution)

hidden_puzzle_hash = hidden_puzzle.get_tree_hash()
synthetic_offset = p2_delegated_puzzle_or_hidden_puzzle.calculate_synthetic_offset(
hidden_pub_key_point, hidden_puzzle_hash
hidden_pub_key_point,
hidden_puzzle_hash,
)

assert synthetic_public_key == int_to_public_key(synthetic_offset) + hidden_pub_key_point
Expand Down
42 changes: 28 additions & 14 deletions chia/_tests/clvm/test_singletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,19 @@ async def test_singleton_top_layer(version, cost_logger):
# Try to create an even singleton (driver test)
try:
conditions, launcher_coinsol = singleton_top_layer.launch_conditions_and_coinsol(
starting_coin, adapted_puzzle, comment, (START_AMOUNT - 1)
starting_coin,
adapted_puzzle,
comment,
(START_AMOUNT - 1),
)
raise AssertionError("This should fail due to an even amount")
except ValueError as msg:
assert str(msg) == "Coin amount cannot be even. Subtract one mojo."
conditions, launcher_coinsol = singleton_top_layer.launch_conditions_and_coinsol(
starting_coin, adapted_puzzle, comment, START_AMOUNT
starting_coin,
adapted_puzzle,
comment,
START_AMOUNT,
)

# Creating solution for standard transaction
Expand Down Expand Up @@ -155,9 +161,9 @@ async def test_singleton_top_layer(version, cost_logger):
ConditionOpcode.CREATE_COIN,
adapted_puzzle_hash,
singleton_eve.amount,
]
],
],
)
),
)
inner_solution: Program = Program.to([[], delegated_puzzle, []])
# Generate the lineage proof we will need from the launcher coin
Expand Down Expand Up @@ -235,7 +241,7 @@ async def test_singleton_top_layer(version, cost_logger):
assertion,
announcement,
],
)
),
)
inner_solution: Program = Program.to([[], delegated_puzzle, []])
lineage_proof: LineageProof = singleton_top_layer.lineage_proof_for_coinsol(singleton_coinsol)
Expand Down Expand Up @@ -293,7 +299,7 @@ async def test_singleton_top_layer(version, cost_logger):
assertion,
announcement,
],
)
),
)
inner_solution: Program = Program.to([[], delegated_puzzle, []])
lineage_proof: LineageProof = singleton_top_layer.lineage_proof_for_coinsol(singleton_claim_coinsol)
Expand Down Expand Up @@ -351,7 +357,7 @@ async def test_singleton_top_layer(version, cost_logger):
[ConditionOpcode.CREATE_COIN, adapted_puzzle_hash, 3],
[ConditionOpcode.CREATE_COIN, adapted_puzzle_hash, 7],
],
)
),
)
inner_solution: Program = Program.to([[], delegated_puzzle, []])
lineage_proof: LineageProof = singleton_top_layer.lineage_proof_for_coinsol(singleton_claim_coinsol)
Expand All @@ -360,7 +366,9 @@ async def test_singleton_top_layer(version, cost_logger):
adapted_puzzle,
)
full_solution: Program = singleton_top_layer.solution_for_singleton(
lineage_proof, singleton_child.amount, inner_solution
lineage_proof,
singleton_child.amount,
inner_solution,
)

multi_odd_coinsol = make_spend(
Expand All @@ -387,7 +395,7 @@ async def test_singleton_top_layer(version, cost_logger):
[ConditionOpcode.CREATE_COIN, adapted_puzzle_hash, 4],
[ConditionOpcode.CREATE_COIN, adapted_puzzle_hash, 10],
],
)
),
)
inner_solution: Program = Program.to([[], delegated_puzzle, []])
lineage_proof: LineageProof = singleton_top_layer.lineage_proof_for_coinsol(singleton_claim_coinsol)
Expand All @@ -396,7 +404,9 @@ async def test_singleton_top_layer(version, cost_logger):
adapted_puzzle,
)
full_solution: Program = singleton_top_layer.solution_for_singleton(
lineage_proof, singleton_child.amount, inner_solution
lineage_proof,
singleton_child.amount,
inner_solution,
)

no_odd_coinsol = make_spend(
Expand Down Expand Up @@ -429,7 +439,7 @@ async def test_singleton_top_layer(version, cost_logger):
],
[ConditionOpcode.CREATE_COIN, adapted_puzzle_hash, 1],
],
)
),
)
inner_solution: Program = Program.to([[], delegated_puzzle, []])
lineage_proof: LineageProof = singleton_top_layer.lineage_proof_for_coinsol(singleton_claim_coinsol)
Expand All @@ -438,7 +448,9 @@ async def test_singleton_top_layer(version, cost_logger):
adapted_puzzle,
)
full_solution: Program = singleton_top_layer.solution_for_singleton(
lineage_proof, singleton_child.amount, inner_solution
lineage_proof,
singleton_child.amount,
inner_solution,
)

singleton_even_coinsol = make_spend(
Expand Down Expand Up @@ -467,7 +479,7 @@ async def test_singleton_top_layer(version, cost_logger):
1,
],
],
)
),
)
inner_solution: Program = Program.to([[], delegated_puzzle, []])
lineage_proof: LineageProof = singleton_top_layer.lineage_proof_for_coinsol(singleton_even_coinsol)
Expand Down Expand Up @@ -516,7 +528,9 @@ async def test_singleton_top_layer(version, cost_logger):
adapted_puzzle,
)
full_solution: Program = singleton_top_layer.solution_for_singleton(
lineage_proof, singleton_child.amount, inner_solution
lineage_proof,
singleton_child.amount,
inner_solution,
)

melt_coinsol = make_spend(
Expand Down
6 changes: 4 additions & 2 deletions chia/_tests/clvm/test_spend_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ async def test_all_endpoints():
assert len(coin_records) == 4

coin_records = await sim_client.get_coin_records_by_puzzle_hashes(
[bytes32.zeros, bytes32([1] * 32)], start_height=0, end_height=2
[bytes32.zeros, bytes32([1] * 32)],
start_height=0,
end_height=2,
)
assert len(coin_records) == 0

Expand Down Expand Up @@ -146,7 +148,7 @@ async def test_all_endpoints():
spendable_coin,
Program.to(1),
Program.to([[51, puzzle_hash, 1]]),
)
),
],
G2Element(),
)
Expand Down
Loading