Skip to content

Commit

Permalink
formatting and file hash
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-o-how committed Nov 7, 2024
1 parent 861fbaa commit 11a1667
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
79 changes: 42 additions & 37 deletions chia/_tests/clvm/test_member_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import itertools
from typing import List

from chia.util.hash import std_hash
import pytest
from chia_rs import AugSchemeMPL, G2Element

from chia._tests.clvm.test_custody_architecture import ACSDPuzValidator
from chia.clvm.spend_sim import CostLogger, sim_and_client
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program
from chia.types.coin_spend import CoinSpend, make_spend
from chia.types.coin_spend import make_spend
from chia.types.mempool_inclusion_status import MempoolInclusionStatus
from chia.types.spend_bundle import SpendBundle
from chia.util.hash import std_hash
from chia.util.ints import uint64
from chia.wallet.conditions import CreateCoinAnnouncement
from chia.wallet.puzzles.custody.custody_architecture import (
DelegatedPuzzleAndSolution,
Expand All @@ -26,10 +27,8 @@
)
from chia.wallet.puzzles.custody.member_puzzles.member_puzzles import BLSMember, SingletonMember
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_for_synthetic_public_key
from chia.types.blockchain_format.coin import Coin
from chia.wallet.singleton import SINGLETON_LAUNCHER_PUZZLE, SINGLETON_LAUNCHER_PUZZLE_HASH, SINGLETON_TOP_LAYER_MOD
from chia.wallet.wallet_spend_bundle import WalletSpendBundle
from chia.wallet.wallet import make_spend


@pytest.mark.anyio
Expand Down Expand Up @@ -102,6 +101,7 @@ async def test_bls_member(cost_logger: CostLogger) -> None:
await sim.farm_block()
await sim.rewind(block_height)


@pytest.mark.anyio
@pytest.mark.parametrize(
"with_restrictions",
Expand Down Expand Up @@ -167,7 +167,7 @@ async def test_2_of_4_bls_members(cost_logger: CostLogger, with_restrictions: bo
sig,
keys[index].sign(
delegated_puzzle_hash + m_of_n_coin.name() + DEFAULT_CONSTANTS.AGG_SIG_ME_ADDITIONAL_DATA
), # noqa)
),
]
)
assert isinstance(m_of_n.puzzle, MofN)
Expand Down Expand Up @@ -204,11 +204,12 @@ async def test_2_of_4_bls_members(cost_logger: CostLogger, with_restrictions: bo
await sim.farm_block()
await sim.rewind(block_height)


@pytest.mark.anyio
async def test_singleton_member(cost_logger: CostLogger) -> None:
async with sim_and_client() as (sim, client):
delegated_puzzle = Program.to(1)

sk = AugSchemeMPL.key_gen(bytes.fromhex(str(0) * 64))
pk = sk.public_key()
puz = puzzle_for_synthetic_public_key(pk)
Expand All @@ -217,32 +218,36 @@ async def test_singleton_member(cost_logger: CostLogger) -> None:
coin = (await client.get_coin_records_by_puzzle_hashes([puz.get_tree_hash()], include_spent_coins=False))[
0
].coin
eve_coin = Coin(coin.name(), SINGLETON_LAUNCHER_PUZZLE_HASH, 1)
eve_coin = Coin(coin.name(), SINGLETON_LAUNCHER_PUZZLE_HASH, uint64(1))
singleton_struct = (SINGLETON_TOP_LAYER_MOD.get_tree_hash(), (eve_coin.name(), SINGLETON_LAUNCHER_PUZZLE_HASH))
singleton_innerpuz = Program.to((
1,
[
[51, Program.to(1).get_tree_hash(), 1],
[66, 0x07, delegated_puzzle.get_tree_hash(), coin.name()]
], # create approval message to singleton member puzzle
))
singleton_innerpuz = Program.to(
(
1,
[
[51, Program.to(1).get_tree_hash(), 1],
[66, 0x07, delegated_puzzle.get_tree_hash(), coin.name()],
], # create approval message to singleton member puzzle
)
)
singleton_puzzle = SINGLETON_TOP_LAYER_MOD.curry(singleton_struct, singleton_innerpuz)
launcher_solution = Program.to([singleton_puzzle.get_tree_hash(), 1, 0])

conditions_list = [
[51, SINGLETON_LAUNCHER_PUZZLE_HASH, 1],
[61, std_hash(eve_coin.name() + launcher_solution.get_tree_hash())]
[51, SINGLETON_LAUNCHER_PUZZLE_HASH, 1],
[61, std_hash(eve_coin.name() + launcher_solution.get_tree_hash())],
]
solution = Program.to([0, (1, conditions_list), 0])

msg = bytes(solution.rest().first().get_tree_hash()) + coin.name() + DEFAULT_CONSTANTS.AGG_SIG_ME_ADDITIONAL_DATA

msg = (
bytes(solution.rest().first().get_tree_hash()) + coin.name() + DEFAULT_CONSTANTS.AGG_SIG_ME_ADDITIONAL_DATA
)
sig = sk.sign(msg)
sb = WalletSpendBundle(
[
make_spend(coin, puz, solution),
make_spend(eve_coin, SINGLETON_LAUNCHER_PUZZLE, launcher_solution),
],
sig
sig,
)
result = await client.push_tx(
cost_logger.add_cost(
Expand All @@ -254,9 +259,11 @@ async def test_singleton_member(cost_logger: CostLogger) -> None:

await sim.farm_block(singleton_puzzle.get_tree_hash())

singleton_coin = (await client.get_coin_records_by_puzzle_hashes([singleton_puzzle.get_tree_hash()], include_spent_coins=False))[
0
].coin
singleton_coin = (
await client.get_coin_records_by_puzzle_hashes(
[singleton_puzzle.get_tree_hash()], include_spent_coins=False
)
)[0].coin

singleton_member_puzzle = PuzzleWithRestrictions(0, [], SingletonMember(eve_coin.name()))
memo = PuzzleHint(
Expand All @@ -278,23 +285,19 @@ async def test_singleton_member(cost_logger: CostLogger) -> None:

# Farm and find coin
await sim.farm_block(singleton_member_puzzle.puzzle_hash())
coin = (await client.get_coin_records_by_puzzle_hashes([singleton_member_puzzle.puzzle_hash()], include_spent_coins=False))[
0
].coin
coin = (
await client.get_coin_records_by_puzzle_hashes(
[singleton_member_puzzle.puzzle_hash()], include_spent_coins=False
)
)[0].coin
block_height = sim.block_height

# Create an announcements to be asserted in the delegated puzzle
announcement = CreateCoinAnnouncement(msg=b"foo", coin_id=coin.name())

# Make solution for singleton
fullsol = Program.to(
[
[eve_coin.parent_coin_info, 1],
1,
0
]
)

fullsol = Program.to([[eve_coin.parent_coin_info, 1], 1, 0])

sb = WalletSpendBundle(
[
make_spend(
Expand All @@ -303,7 +306,9 @@ async def test_singleton_member(cost_logger: CostLogger) -> None:
singleton_member_puzzle.solve(
[],
[],
Program.to([[singleton_coin.parent_coin_info, singleton_innerpuz.get_tree_hash(), 1]]), # singleton member puzzle only requires singleton's current innerpuz
Program.to(
[[singleton_coin.parent_coin_info, singleton_innerpuz.get_tree_hash(), 1]]
), # singleton member puzzle only requires singleton's current innerpuz
DelegatedPuzzleAndSolution(
delegated_puzzle,
Program.to(
Expand All @@ -319,7 +324,7 @@ async def test_singleton_member(cost_logger: CostLogger) -> None:
singleton_coin,
singleton_puzzle,
fullsol,
)
),
],
G2Element(),
)
Expand All @@ -331,4 +336,4 @@ async def test_singleton_member(cost_logger: CostLogger) -> None:
)
assert result == (MempoolInclusionStatus.SUCCESS, None)
await sim.farm_block()
await sim.rewind(block_height)
await sim.rewind(block_height)
2 changes: 1 addition & 1 deletion chia/wallet/puzzles/deployed_puzzle_hashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"singleton_launcher": "eff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9",
"singleton_top_layer": "24e044101e57b3d8c908b8a38ad57848afd29d3eecc439dba45f4412df4954fd",
"singleton_top_layer_v1_1": "7faa3253bfddd1e0decb0906b2dc6247bbc4cf608f58345d173adb63e8b47c9f",
"singleton_member": "414fa2172f3ed47c0504aa93b78acf4c656f69312332224cddc3fc2d7cc9a832",
"singleton_member": "b2a3576fb4737ff078caef58bcbd5464968d92ebdd493814f495c75fd6d769de",
"standard_vc_backdoor_puzzle": "fbce76408ebaf9b3d0b8cd90cc68607755eeca67cd7432d5eea85f3f498cc002",
"std_parent_morpher": "8c3f1dc2e46c0d7ec4c2cbd007e23c0368ff8f80c5bc0101647a5c27626ebce6",
"test_generator_deserialize": "52add794fc76e89512e4a063c383418bda084c8a78c74055abe80179e4a7832c",
Expand Down

0 comments on commit 11a1667

Please sign in to comment.