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

clvm_tools==0.4.8 #17575

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1943,9 +1943,7 @@ async def get_offer_summary(self, request: Dict[str, Any]) -> EndpointResult:
"also": {
**info["also"],
"flags": ProofsChecker.from_program(
uncurry_puzzle(
Program(assemble(info["also"]["proofs_checker"])) # type: ignore[no-untyped-call]
)
uncurry_puzzle(Program(assemble(info["also"]["proofs_checker"])))
).flags,
},
}
Expand Down
2 changes: 1 addition & 1 deletion chia/wallet/puzzle_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def decode_info_value(cls: Any, value: Any) -> Any:
else:
if value == "()": # special case
return Program.to([])
expression: SExp = assemble(value) # type: ignore
expression: SExp = assemble(value)
if expression.atom is None:
return Program(expression)
else:
Expand Down
2 changes: 1 addition & 1 deletion chia/wallet/puzzles/prefarm/make_prefarm_ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def make_puzzle(amount: int) -> int:
# print(puzzle)

# TODO: properly type hint clvm_tools
assembled_puzzle = binutils.assemble(puzzle) # type: ignore[no-untyped-call]
assembled_puzzle = binutils.assemble(puzzle)
puzzle_prog = Program.to(assembled_puzzle)
print("Program: ", puzzle_prog)
puzzle_hash = puzzle_prog.get_tree_hash()
Expand Down
10 changes: 3 additions & 7 deletions chia/wallet/puzzles/prefarm/spend_prefarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,18 @@ async def main() -> None:
ph2 = decode_puzzle_hash(address2)

p_farmer_2 = SerializedProgram.to(
binutils.assemble(
f"(q . ((51 0x{ph1.hex()} {farmer_amounts}) " f"(51 0x{ph2.hex()} {farmer_amounts})))"
) # type: ignore[no-untyped-call]
binutils.assemble(f"(q . ((51 0x{ph1.hex()} {farmer_amounts}) " f"(51 0x{ph2.hex()} {farmer_amounts})))")
)
p_pool_2 = SerializedProgram.to(
binutils.assemble(
f"(q . ((51 0x{ph1.hex()} {pool_amounts}) " f"(51 0x{ph2.hex()} {pool_amounts})))"
) # type: ignore[no-untyped-call]
binutils.assemble(f"(q . ((51 0x{ph1.hex()} {pool_amounts}) " f"(51 0x{ph2.hex()} {pool_amounts})))")
)

print(f"Ph1: {ph1.hex()}")
print(f"Ph2: {ph2.hex()}")
assert ph1.hex() == "1b7ab2079fa635554ad9bd4812c622e46ee3b1875a7813afba127bb0cc9794f9"
assert ph2.hex() == "6f184a7074c925ef8688ce56941eb8929be320265f824ec7e351356cc745d38a"

p_solution = SerializedProgram.to(binutils.assemble("()")) # type: ignore[no-untyped-call]
p_solution = SerializedProgram.to(binutils.assemble("()"))

sb_farmer = SpendBundle([CoinSpend(farmer_prefarm, p_farmer_2, p_solution)], G2Element())
sb_pool = SpendBundle([CoinSpend(pool_prefarm, p_pool_2, p_solution)], G2Element())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"chiabip158==1.3", # bip158-style wallet filters
"chiapos==2.0.3", # proof of space
"clvm==0.9.8",
"clvm_tools==0.4.7", # Currying, Program.to, other conveniences
"clvm_tools==0.4.8", # Currying, Program.to, other conveniences
"chia_rs==0.5.2",
"clvm-tools-rs==0.1.40", # Rust implementation of clvm_tools' compiler
"aiohttp==3.9.1", # HTTP server for full node rpc
Expand Down
30 changes: 11 additions & 19 deletions tests/core/full_node/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class TestConditions:
async def test_unknown_conditions_with_cost(
self, opcode: int, expected_cost: int, bt: BlockTools, consensus_mode: ConsensusMode
) -> None:
conditions = Program.to(assemble(f"(({opcode} 1337))")) # type: ignore[no-untyped-call]
conditions = Program.to(assemble(f"(({opcode} 1337))"))
additions, removals, new_block = await check_conditions(bt, conditions)

if consensus_mode != ConsensusMode.HARD_FORK_2_0:
Expand All @@ -164,7 +164,7 @@ async def test_unknown_conditions_with_cost(
async def test_softfork_condition(
self, condition: str, expected_cost: int, bt: BlockTools, consensus_mode: ConsensusMode
) -> None:
conditions = Program.to(assemble(condition)) # type: ignore[no-untyped-call]
conditions = Program.to(assemble(condition))
additions, removals, new_block = await check_conditions(bt, conditions)

if consensus_mode != ConsensusMode.HARD_FORK_2_0:
Expand Down Expand Up @@ -267,7 +267,7 @@ async def test_softfork_condition(
],
)
async def test_condition(self, opcode: ConditionOpcode, value: int, expected: Err, bt: BlockTools) -> None:
conditions = Program.to(assemble(f"(({opcode[0]} {value}))")) # type: ignore[no-untyped-call]
conditions = Program.to(assemble(f"(({opcode[0]} {value}))"))
await check_conditions(bt, conditions, expected_err=expected)

@pytest.mark.anyio
Expand All @@ -276,22 +276,14 @@ async def test_invalid_my_id(self, bt: BlockTools) -> None:
coin = blocks[-2].get_included_reward_coins()[0]
wrong_name = bytearray(coin.name())
wrong_name[-1] ^= 1
conditions = Program.to(
assemble(
f"(({ConditionOpcode.ASSERT_MY_COIN_ID[0]} 0x{wrong_name.hex()}))"
) # type: ignore[no-untyped-call]
)
conditions = Program.to(assemble(f"(({ConditionOpcode.ASSERT_MY_COIN_ID[0]} 0x{wrong_name.hex()}))"))
await check_conditions(bt, conditions, expected_err=Err.ASSERT_MY_COIN_ID_FAILED)

@pytest.mark.anyio
async def test_valid_my_id(self, bt: BlockTools) -> None:
blocks = await initial_blocks(bt)
coin = blocks[-2].get_included_reward_coins()[0]
conditions = Program.to(
assemble(
f"(({ConditionOpcode.ASSERT_MY_COIN_ID[0]} 0x{coin.name().hex()}))"
) # type: ignore[no-untyped-call]
)
conditions = Program.to(assemble(f"(({ConditionOpcode.ASSERT_MY_COIN_ID[0]} 0x{coin.name().hex()}))"))
await check_conditions(bt, conditions)

@pytest.mark.anyio
Expand All @@ -300,7 +292,7 @@ async def test_invalid_coin_announcement(self, bt: BlockTools) -> None:
coin = blocks[-2].get_included_reward_coins()[0]
announce = AssertCoinAnnouncement(asserted_id=coin.name(), asserted_msg=b"test_bad")
conditions = Program.to(
assemble( # type: ignore[no-untyped-call]
assemble(
f"(({ConditionOpcode.CREATE_COIN_ANNOUNCEMENT[0]} 'test')"
f"({ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT[0]} 0x{announce.msg_calc.hex()}))"
)
Expand All @@ -313,7 +305,7 @@ async def test_valid_coin_announcement(self, bt: BlockTools) -> None:
coin = blocks[-2].get_included_reward_coins()[0]
announce = AssertCoinAnnouncement(asserted_id=coin.name(), asserted_msg=b"test")
conditions = Program.to(
assemble( # type: ignore[no-untyped-call]
assemble(
f"(({ConditionOpcode.CREATE_COIN_ANNOUNCEMENT[0]} 'test')"
f"({ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT[0]} 0x{announce.msg_calc.hex()}))"
)
Expand All @@ -324,7 +316,7 @@ async def test_valid_coin_announcement(self, bt: BlockTools) -> None:
async def test_invalid_puzzle_announcement(self, bt: BlockTools) -> None:
announce = AssertPuzzleAnnouncement(asserted_ph=EASY_PUZZLE_HASH, asserted_msg=b"test_bad")
conditions = Program.to(
assemble( # type: ignore[no-untyped-call]
assemble(
f"(({ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT[0]} 'test')"
f"({ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT[0]} 0x{announce.msg_calc.hex()}))"
)
Expand All @@ -335,7 +327,7 @@ async def test_invalid_puzzle_announcement(self, bt: BlockTools) -> None:
async def test_valid_puzzle_announcement(self, bt: BlockTools) -> None:
announce = AssertPuzzleAnnouncement(asserted_ph=EASY_PUZZLE_HASH, asserted_msg=b"test")
conditions = Program.to(
assemble( # type: ignore[no-untyped-call]
assemble(
f"(({ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT[0]} 'test')"
f"({ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT[0]} 0x{announce.msg_calc.hex()}))"
)
Expand Down Expand Up @@ -387,7 +379,7 @@ async def test_announce_conditions_limit(

conditions = b""
if prefix != "":
conditions += b"\xff" + assemble(prefix).as_bin() # type: ignore[no-untyped-call]
conditions += b"\xff" + assemble(prefix).as_bin()

cond = condition.format(
coin="0x" + coin.name().hex(),
Expand All @@ -396,7 +388,7 @@ async def test_announce_conditions_limit(
pann="0x" + puzzle_announcement.msg_calc.hex(),
)

conditions += (b"\xff" + assemble(cond).as_bin()) * num # type: ignore[no-untyped-call]
conditions += (b"\xff" + assemble(cond).as_bin()) * num
conditions += b"\x80"
conditions_program = Program.from_bytes(conditions)

Expand Down
12 changes: 4 additions & 8 deletions tests/core/test_cost_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async def test_mempool_mode(softfork_height: int, bt: BlockTools) -> None:
binutils.assemble(
f"(q ((0x3d2331635a58c0d49912bc1427d7db51afe3f20a7b4bcaffa17ee250dcbcbfaa {disassembly} 300"
f" (() (q . (({unknown_opcode} '00000000000000000000000000000000' 0x0cbba106e000))) ()))))"
).as_bin() # type: ignore[no-untyped-call]
).as_bin()
)
generator = BlockGenerator(program, [], [])
npc_result: NPCResult = get_name_puzzle_conditions(
Expand Down Expand Up @@ -183,9 +183,7 @@ async def test_clvm_mempool_mode(softfork_height: int) -> None:
# if-condition, that depends on executing an unknown operator
# ("0xfe"). In mempool mode, this should fail, but in non-mempool
# mode, the unknown operator should be treated as if it returns ().
program = SerializedProgram.from_bytes(
binutils.assemble(f"(i (0xfe (q . 0)) (q . ()) {disassembly})").as_bin() # type: ignore[no-untyped-call]
)
program = SerializedProgram.from_bytes(binutils.assemble(f"(i (0xfe (q . 0)) (q . ()) {disassembly})").as_bin())
generator = BlockGenerator(program, [], [])
npc_result: NPCResult = get_name_puzzle_conditions(
generator,
Expand Down Expand Up @@ -236,9 +234,7 @@ async def test_clvm_max_cost(softfork_height: int) -> None:
# mode, the unknown operator should be treated as if it returns ().
# the CLVM program has a cost of 391969
program = SerializedProgram.from_bytes(
binutils.assemble(
f"(i (softfork (q . 10000000)) (q . ()) {disassembly})"
).as_bin() # type: ignore[no-untyped-call]
binutils.assemble(f"(i (softfork (q . 10000000)) (q . ()) {disassembly})").as_bin()
)

# ensure we fail if the program exceeds the cost
Expand Down Expand Up @@ -273,7 +269,7 @@ async def test_standard_tx(benchmark_runner: BenchmarkRunner) -> None:
conditions = binutils.assemble(
"((51 0x699eca24f2b6f4b25b16f7a418d0dc4fc5fce3b9145aecdda184158927738e3e 10)"
" (51 0x847bb2385534070c39a39cc5dfdc7b35e2db472dc0ab10ab4dec157a2178adbf 0x00cbba106df6))"
) # type: ignore[no-untyped-call]
)
solution_program = SerializedProgram.from_bytes(
bytes(p2_delegated_puzzle_or_hidden_puzzle.solution_for_conditions(conditions))
)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_serialized_program_to() -> None:
Program.to([1, 2, 3]),
SerializedProgram.to([1, 2, 3]),
b"123",
binutils.assemble(prg), # type: ignore[no-untyped-call]
binutils.assemble(prg),
[b"1", b"2", b"3"],
(b"1", (b"2", b"3")),
None,
Expand Down
2 changes: 1 addition & 1 deletion tests/core/util/test_streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def test_ambiguous_deserialization_program() -> None:
class TestClassProgram(Streamable):
a: Program

program = Program.to(binutils.assemble("()")) # type: ignore[no-untyped-call] # TODO, add typing in clvm_tools
program = Program.to(binutils.assemble("()"))

TestClassProgram.from_bytes(bytes(program))

Expand Down
12 changes: 6 additions & 6 deletions tests/generator/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_decompress_puzzle(self) -> None:

def test_decompress_cse(self) -> None:
"""Decompress a single CSE / CoinSpendEntry"""
cse0 = binutils.assemble( # type: ignore[no-untyped-call]
cse0 = binutils.assemble(
"((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ())))"
)
cost, out = DECOMPRESS_CSE.run_with_cost(
Expand All @@ -228,7 +228,7 @@ def test_decompress_cse(self) -> None:
print(out)

def test_decompress_cse_with_prefix(self) -> None:
cse0 = binutils.assemble( # type: ignore[no-untyped-call]
cse0 = binutils.assemble(
"((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ())))"
)

Expand All @@ -245,10 +245,10 @@ def test_decompress_cse_with_prefix(self) -> None:

def test_block_program_zero(self) -> None:
"Decompress a list of CSEs"
cse1 = binutils.assemble( # type: ignore[no-untyped-call]
cse1 = binutils.assemble(
"(((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))))"
)
cse2 = binutils.assemble( # type: ignore[no-untyped-call]
cse2 = binutils.assemble(
"""
(
((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0)
Expand Down Expand Up @@ -286,10 +286,10 @@ def test_block_program_zero(self) -> None:
print(out)

def test_block_program_zero_with_curry(self) -> None:
cse1 = binutils.assemble( # type: ignore[no-untyped-call]
cse1 = binutils.assemble(
"(((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))))"
)
cse2 = binutils.assemble( # type: ignore[no-untyped-call]
cse2 = binutils.assemble(
"""
(
((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0)
Expand Down
4 changes: 2 additions & 2 deletions tests/generator/test_rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
COMPILED_GENERATOR_CODE = bytes(Program.to(compile_clvm_text(GENERATOR_CODE, []))) # type: ignore[no-untyped-call]

FIRST_GENERATOR = Program.to(
binutils.assemble( # type: ignore[no-untyped-call]
binutils.assemble(
"""
((0x0000000000000000000000000000000000000000000000000000000000000000 1 50000
((51 0x0000000000000000000000000000000000000000000000000000000000000001 500))
"extra" "data" "for" "coin" ))"""
)
).as_bin()

SECOND_GENERATOR = Program.to(binutils.assemble("(extra data for block)")).as_bin() # type: ignore[no-untyped-call]
SECOND_GENERATOR = Program.to(binutils.assemble("(extra data for block)")).as_bin()


def to_sp(sexp: bytes) -> SerializedProgram:
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/nft_wallet/test_ownership_outer_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_ownership_outer_puzzle() -> None:
# (mod (current_owner conditions solution)
# (list current_owner () conditions)
# )
transfer_program = assemble( # type: ignore
transfer_program = assemble(
"""
(c 2 (c () (c 5 ())))
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/wallet/test_singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_only_odd_coins() -> None:
solution = Program.to(
[
(singleton_mod_hash, (LAUNCHER_ID, LAUNCHER_PUZZLE_HASH)),
Program.to(binutils.assemble("(q (51 0xcafef00d 200))")), # type: ignore[no-untyped-call]
Program.to(binutils.assemble("(q (51 0xcafef00d 200))")),
[0xDEADBEEF, 0xCAFEF00D, 200],
200,
[],
Expand All @@ -59,7 +59,7 @@ def test_only_odd_coins() -> None:
solution = Program.to(
[
(singleton_mod_hash, (LAUNCHER_ID, LAUNCHER_PUZZLE_HASH)),
Program.to(binutils.assemble("(q (51 0xcafef00d 201))")), # type: ignore[no-untyped-call]
Program.to(binutils.assemble("(q (51 0xcafef00d 201))")),
[0xDEADBEEF, 0xCAFED00D, 210],
205,
0,
Expand All @@ -74,7 +74,7 @@ def test_only_one_odd_coin_created() -> None:
solution = Program.to(
[
(singleton_mod_hash, (LAUNCHER_ID, LAUNCHER_PUZZLE_HASH)),
Program.to(binutils.assemble(clsp)), # type: ignore[no-untyped-call]
Program.to(binutils.assemble(clsp)),
[0xDEADBEEF, 0xCAFEF00D, 411],
411,
[],
Expand All @@ -88,7 +88,7 @@ def test_only_one_odd_coin_created() -> None:
solution = Program.to(
[
(singleton_mod_hash, (LAUNCHER_ID, LAUNCHER_PUZZLE_HASH)),
Program.to(binutils.assemble(clsp)), # type: ignore[no-untyped-call]
Program.to(binutils.assemble(clsp)),
[0xDEADBEEF, 0xCAFEF00D, 411],
411,
[],
Expand Down
8 changes: 4 additions & 4 deletions tests/wallet/test_singleton_lifecycle_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
P2_SINGLETON_MOD_HASH = P2_SINGLETON_MOD.get_tree_hash()

ANYONE_CAN_SPEND_PUZZLE = Program.to(1)
ANYONE_CAN_SPEND_WITH_PADDING_PUZZLE_HASH = Program.to(binutils.assemble("(a (q . 1) 3)")).get_tree_hash() # type: ignore[no-untyped-call] # noqa: E501
ANYONE_CAN_SPEND_WITH_PADDING_PUZZLE_HASH = Program.to(binutils.assemble("(a (q . 1) 3)")).get_tree_hash()

POOL_REWARD_PREFIX_MAINNET = bytes32.fromhex("ccd5bb71183532bff220ba46c268991a00000000000000000000000000000000")

Expand Down Expand Up @@ -273,7 +273,7 @@ def adaptor_for_singleton_inner_puzzle(puzzle: Program) -> Program:
puzzle to work as a singleton inner puzzle.
"""
# this is pretty slow and lame
program = binutils.assemble("(a (q . %s) 3)" % binutils.disassemble(puzzle)) # type: ignore[no-untyped-call]
program = binutils.assemble("(a (q . %s) 3)" % binutils.disassemble(puzzle))
# TODO: Remove cast when we improve typing
return cast(Program, Program.to(program))

Expand All @@ -299,9 +299,9 @@ def launcher_conditions_and_spend_bundle(
)
expected_conditions = []
clsp = f"(0x{ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT.hex()} 0x{expected_announcement.msg_calc})"
expected_conditions.append(Program.to(binutils.assemble(clsp))) # type: ignore[no-untyped-call]
expected_conditions.append(Program.to(binutils.assemble(clsp)))
clsp = f"(0x{ConditionOpcode.CREATE_COIN.hex()} 0x{launcher_puzzle_hash} {launcher_amount})"
expected_conditions.append(Program.to(binutils.assemble(clsp))) # type: ignore[no-untyped-call]
expected_conditions.append(Program.to(binutils.assemble(clsp)))
solution = solve_puzzle(
puzzle_db,
launcher_puzzle,
Expand Down
Loading