def test_make_generator_args(self):
        generator_ref_list = [gen1]
        gen_args = create_generator_args(generator_ref_list)
        gen_args_as_program = Program.from_bytes(bytes(gen_args))

        # First Argument to the block generator is the first template generator
        arg2 = gen_args_as_program.first()
        print(arg2)
        assert arg2 == bytes(gen1)
def get_puzzle_and_solution_for_coin(generator: BlockGenerator,
                                     coin_name: bytes, max_cost: int):
    try:
        block_program = generator.program
        block_program_args = create_generator_args(generator.generator_refs)

        cost, result = GENERATOR_FOR_SINGLE_COIN_MOD.run_with_cost(
            max_cost, block_program, block_program_args, coin_name)
        puzzle = result.first()
        solution = result.rest().first()
        return None, puzzle, solution
    except Exception as e:
        return e, None, None
    def test_block_program_zero_with_curry(self):
        self.maxDiff = None
        cse1 = binutils.assemble(
            "(((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))))"
        )  # noqa
        cse2 = binutils.assemble("""
(
  ((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0)
   (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3
    (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))
  )

  ((0x0000000000000000000000000000000000000000000000000000000000000001 0x0186a0)
   (0xb0a6207f5173ec41491d9f2c1b8fff5579e13703077e0eaca8fe587669dcccf51e9209a6b65576845ece5f7c2f3229e7e3
   (() (q (51 0x24254a3efc3ebfac9979bbe0d615e2eda043aa329905f65b63846fa24149e2b6 0x0186a0)) ())))

)
        """)  # noqa

        start = 2 + 44
        end = start + 238

        # (mod (decompress_puzzle decompress_coin_solution_entry start end compressed_cses deserialize generator_list reserved_arg)
        # cost, out = DECOMPRESS_BLOCK.run_with_cost(INFINITE_COST, [DECOMPRESS_PUZZLE, DECOMPRESS_CSE, start, Program.to(end), cse0, DESERIALIZE_MOD, bytes(original_generator)])
        p = DECOMPRESS_BLOCK.curry(DECOMPRESS_PUZZLE,
                                   DECOMPRESS_CSE_WITH_PREFIX, start,
                                   Program.to(end))
        cost, out = p.run_with_cost(
            INFINITE_COST,
            [cse2, DESERIALIZE_MOD, [bytes(original_generator)]])

        print()
        print(p)
        print(out)

        p_with_cses = DECOMPRESS_BLOCK.curry(
            DECOMPRESS_PUZZLE,
            DECOMPRESS_CSE_WITH_PREFIX,
            start,
            Program.to(end),
            cse2,
            DESERIALIZE_MOD,
        )
        generator_args = create_generator_args(
            [SerializedProgram.from_bytes(original_generator)])
        cost, out = p_with_cses.run_with_cost(INFINITE_COST, generator_args)

        print()
        print(p_with_cses)
        print(out)
示例#4
0
    def test_make_generator_args(self):
        generator_ref_list = [gen1]
        gen_args = create_generator_args(generator_ref_list)
        gen_args_as_program = Program.from_bytes(bytes(gen_args))

        d = gen_args_as_program.first()

        # First argument: clvm deserializer

        b = bytes.fromhex(
            "ff8568656c6c6fff86667269656e6480")  # ("hello" "friend")
        cost, output = d.run_with_cost([b])
        # print(cost, output)
        out = Program.to(output)
        assert out == Program.from_bytes(b)

        # Second Argument to the block generator is the first template generator
        arg2 = gen_args_as_program.rest().first()
        print(arg2)
        assert arg2 == bytes(gen1)