Пример #1
0
 def test_compressed_block_results(self):
     sb: SpendBundle = make_spend_bundle(1)
     start, end = match_standard_transaction_at_any_index(
         original_generator)
     ca = CompressorArg(uint32(0),
                        SerializedProgram.from_bytes(original_generator),
                        start, end)
     c = compressed_spend_bundle_solution(ca, sb)
     s = simple_solution_generator(sb)
     assert c != s
     cost_c, result_c = run_generator(c)
     cost_s, result_s = run_generator(s)
     print(result_c)
     assert result_c is not None
     assert result_s is not None
     assert result_c == result_s
Пример #2
0
    def test_get_name_puzzle_conditions(self):
        # this tests that extra block or coin data doesn't confuse `get_name_puzzle_conditions`

        gen = block_generator()
        cost, r = run_generator(gen, max_cost=MAX_COST)
        print(r)

        npc_result = get_name_puzzle_conditions(gen,
                                                max_cost=MAX_COST,
                                                cost_per_byte=COST_PER_BYTE,
                                                safe_mode=False)
        assert npc_result.error is None
        assert npc_result.clvm_cost == EXPECTED_COST
        cond_1 = ConditionWithArgs(
            ConditionOpcode.CREATE_COIN,
            [bytes([0] * 31 + [1]), int_to_bytes(500)])
        CONDITIONS = [
            (ConditionOpcode.CREATE_COIN, [cond_1]),
        ]

        npc = NPC(
            coin_name=bytes32.fromhex(
                "e8538c2d14f2a7defae65c5c97f5d4fae7ee64acef7fec9d28ad847a0880fd03"
            ),
            puzzle_hash=bytes32.fromhex(
                "9dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2"
            ),
            conditions=CONDITIONS,
        )

        assert npc_result.npc_list == [npc]
Пример #3
0
    def test_block_extras(self):
        # the ROM supports extra data after the coin spend list. This test checks that it actually gets passed through

        gen = block_generator()
        cost, r = run_generator(gen, max_cost=MAX_COST)
        extra_block_data = r.rest()
        assert extra_block_data.as_atom_list(
        ) == b"extra data for block".split()
Пример #4
0
    def test_coin_extras(self):
        # the ROM supports extra data after a coin. This test checks that it actually gets passed through

        gen = block_generator()
        cost, r = run_generator(gen, max_cost=MAX_COST)
        coin_spends = r.first()
        for coin_spend in coin_spends.as_iter():
            extra_data = coin_spend.rest().rest().rest().rest()
            assert extra_data.as_atom_list() == b"extra data for coin".split()
Пример #5
0
    def test_multiple_input_gen_refs(self):
        start1, end1 = match_standard_transaction_at_any_index(gen1)
        start2, end2 = match_standard_transaction_at_any_index(gen2)
        ca1 = CompressorArg(FAKE_BLOCK_HEIGHT1,
                            SerializedProgram.from_bytes(gen1), start1, end1)
        ca2 = CompressorArg(FAKE_BLOCK_HEIGHT2,
                            SerializedProgram.from_bytes(gen2), start2, end2)

        prefix_len1 = end1 - start1
        prefix_len2 = end2 - start2
        assert prefix_len1 == prefix_len2
        prefix_len = prefix_len1
        results = []
        for split_offset in range(prefix_len):
            gen_args = MultipleCompressorArg([ca1, ca2], split_offset)
            spend_bundle: SpendBundle = make_spend_bundle(1)
            multi_gen = create_multiple_ref_generator(gen_args, spend_bundle)
            cost, result = run_generator(multi_gen, INFINITE_COST)
            results.append(result)
            assert result is not None
            assert cost > 0
        assert all(r == results[0] for r in results)