def test_p2_delegated_puzzle_or_hidden_puzzle_with_hidden_puzzle(self): key_lookup = KeyTool() payments, conditions = default_payments_and_conditions(1, key_lookup) hidden_puzzle = p2_conditions.puzzle_for_conditions(conditions) hidden_public_key = public_key_for_index(10, key_lookup) puzzle = p2_delegated_puzzle_or_hidden_puzzle.puzzle_for_public_key_and_hidden_puzzle( hidden_public_key, hidden_puzzle) solution = p2_delegated_puzzle_or_hidden_puzzle.solution_for_hidden_puzzle( hidden_public_key, hidden_puzzle, Program.to(0)) do_test_spend(puzzle, solution, payments, key_lookup)
def do_test_spend_p2_delegated_puzzle_or_hidden_puzzle_with_delegated_puzzle( self, hidden_pub_key_index): key_lookup = KeyTool() payments, conditions = default_payments_and_conditions(1, key_lookup) hidden_puzzle = p2_conditions.puzzle_for_conditions(conditions) hidden_public_key = public_key_for_index(hidden_pub_key_index, key_lookup) puzzle = p2_delegated_puzzle_or_hidden_puzzle.puzzle_for_public_key_and_hidden_puzzle( hidden_public_key, 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( 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_public_key, hidden_puzzle_hash) hidden_pub_key_point = G1Element.from_bytes(hidden_public_key) assert synthetic_public_key == int_to_public_key( synthetic_offset) + hidden_pub_key_point secret_exponent = key_lookup.get(hidden_public_key) assert int_to_public_key(secret_exponent) == hidden_pub_key_point synthetic_secret_exponent = secret_exponent + synthetic_offset key_lookup.add_secret_exponents([synthetic_secret_exponent]) do_test_spend(puzzle, solution, payable_payments, key_lookup)