How to use second_generator method in Slash

Best Python code snippet using slash

test_rom.py

Source:test_rom.py Github

copy

Full Screen

1from unittest import TestCase2from clvm_tools import binutils3from clvm_tools.clvmc import compile_clvm_text4from fork.full_node.generator import run_generator5from fork.full_node.mempool_check_conditions import get_name_puzzle_conditions6from fork.types.blockchain_format.program import Program, SerializedProgram7from fork.types.blockchain_format.sized_bytes import bytes328from fork.types.condition_with_args import ConditionWithArgs9from fork.types.name_puzzle_condition import NPC10from fork.types.generator_types import BlockGenerator, GeneratorArg11from fork.util.clvm import int_to_bytes12from fork.util.condition_tools import ConditionOpcode13from fork.util.ints import uint3214from fork.wallet.puzzles.load_clvm import load_clvm15MAX_COST = int(1e15)16COST_PER_BYTE = int(12000)17DESERIALIZE_MOD = load_clvm("chialisp_deserialisation.clvm", package_or_requirement="fork.wallet.puzzles")18GENERATOR_CODE = """19(mod (deserialize-mod historical-generators)20 (defun first-block (deserialize-mod historical-generators)21 (a deserialize-mod (list (f historical-generators))))22 (defun second-block (deserialize-mod historical-generators)23 (a deserialize-mod (r historical-generators)))24 (defun go (deserialize-mod historical-generators)25 (c (first-block deserialize-mod historical-generators)26 (second-block deserialize-mod historical-generators)27 ))28 (go deserialize-mod historical-generators)29)30"""31COMPILED_GENERATOR_CODE = bytes.fromhex(32 "ff02ffff01ff04ffff02ff04ffff04ff02ffff04ff05ffff04ff0bff8080808080ffff02"33 "ff06ffff04ff02ffff04ff05ffff04ff0bff808080808080ffff04ffff01ffff02ff05ff"34 "1380ff02ff05ff2b80ff018080"35)36COMPILED_GENERATOR_CODE = bytes(Program.to(compile_clvm_text(GENERATOR_CODE, [])))37FIRST_GENERATOR = Program.to(38 binutils.assemble('((parent_id (c 1 (q "puzzle blob")) 50000 "solution is here" extra data for coin))')39).as_bin()40SECOND_GENERATOR = Program.to(binutils.assemble("(extra data for block)")).as_bin()41FIRST_GENERATOR = Program.to(42 binutils.assemble(43 """44 ((0x0000000000000000000000000000000000000000000000000000000000000000 1 5000045 ((51 0x0000000000000000000000000000000000000000000000000000000000000001 500)) "extra" "data" "for" "coin" ))"""46 )47).as_bin()48SECOND_GENERATOR = Program.to(binutils.assemble("(extra data for block)")).as_bin()49def to_sp(sexp) -> SerializedProgram:50 return SerializedProgram.from_bytes(bytes(sexp))51def block_generator() -> BlockGenerator:52 generator_args = [GeneratorArg(uint32(0), to_sp(FIRST_GENERATOR)), GeneratorArg(uint32(1), to_sp(SECOND_GENERATOR))]53 return BlockGenerator(to_sp(COMPILED_GENERATOR_CODE), generator_args)54EXPECTED_ABBREVIATED_COST = 10837955EXPECTED_COST = 11341556EXPECTED_OUTPUT = (57 "ffffffa00000000000000000000000000000000000000000000000000000000000000000"58 "ff01ff8300c350ffffff33ffa00000000000000000000000000000000000000000000000"59 "000000000000000001ff8201f48080ff856578747261ff8464617461ff83666f72ff8463"60 "6f696e8080ff856578747261ff8464617461ff83666f72ff85626c6f636b80"61)62class TestROM(TestCase):63 def test_rom_inputs(self):64 # this test checks that the generator just works65 # It's useful for debugging the generator prior to having the ROM invoke it.66 args = Program.to([DESERIALIZE_MOD, [FIRST_GENERATOR, SECOND_GENERATOR]])67 sp = to_sp(COMPILED_GENERATOR_CODE)68 cost, r = sp.run_with_cost(MAX_COST, args)69 assert cost == EXPECTED_ABBREVIATED_COST70 assert r.as_bin().hex() == EXPECTED_OUTPUT71 def test_get_name_puzzle_conditions(self):72 # this tests that extra block or coin data doesn't confuse `get_name_puzzle_conditions`73 gen = block_generator()74 cost, r = run_generator(gen, max_cost=MAX_COST)75 print(r)76 npc_result = get_name_puzzle_conditions(gen, max_cost=MAX_COST, cost_per_byte=COST_PER_BYTE, safe_mode=False)77 assert npc_result.error is None78 assert npc_result.clvm_cost == EXPECTED_COST79 cond_1 = ConditionWithArgs(ConditionOpcode.CREATE_COIN, [bytes([0] * 31 + [1]), int_to_bytes(500)])80 CONDITIONS = [81 (ConditionOpcode.CREATE_COIN, [cond_1]),82 ]83 npc = NPC(84 coin_name=bytes32.fromhex("e8538c2d14f2a7defae65c5c97f5d4fae7ee64acef7fec9d28ad847a0880fd03"),85 puzzle_hash=bytes32.fromhex("9dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2"),86 conditions=CONDITIONS,87 )88 assert npc_result.npc_list == [npc]89 def test_coin_extras(self):90 # the ROM supports extra data after a coin. This test checks that it actually gets passed through91 gen = block_generator()92 cost, r = run_generator(gen, max_cost=MAX_COST)93 coin_spends = r.first()94 for coin_spend in coin_spends.as_iter():95 extra_data = coin_spend.rest().rest().rest().rest()96 self.assertEqual(extra_data.as_atom_list(), b"extra data for coin".split())97 def test_block_extras(self):98 # the ROM supports extra data after the coin spend list. This test checks that it actually gets passed through99 gen = block_generator()100 cost, r = run_generator(gen, max_cost=MAX_COST)101 extra_block_data = r.rest()...

Full Screen

Full Screen

helpers.py

Source:helpers.py Github

copy

Full Screen

1def diff_sorted(first, second, key=None, first_label="first", second_label="second"):2 key = key or (lambda x: x)3 first_generator = iter(first)4 second_generator = iter(second)5 p = None6 q = None7 p_sent = True8 q_sent = True9 try:10 p = next(first_generator)11 p_sent = False12 q = next(second_generator)13 q_sent = False14 while True:15 k_p = key(p)16 k_q = key(q)17 if k_p == k_q:18 p_sent = True19 q_sent = True20 p = next(first_generator)21 p_sent = False22 q = next(second_generator)23 q_sent = False24 elif k_p < k_q:25 yield first_label, p26 p_sent = True27 p = next(first_generator)28 p_sent = False29 else:30 yield second_label, q31 q_sent = True32 q = next(second_generator)33 q_sent = False34 except StopIteration:35 pass36 try:37 if not p_sent:38 yield first_label, p39 while True:40 yield first_label, next(first_generator)41 except StopIteration:42 pass43 try:44 if not q_sent:45 yield second_label, q46 while True:47 yield second_label, next(second_generator)48 except StopIteration:...

Full Screen

Full Screen

test_generator_fixture.py

Source:test_generator_fixture.py Github

copy

Full Screen

...8 @slash.generator_fixture(name='a_generator')9 def my_generator():10 yield 511 @slash.generator_fixture12 def second_generator(): # pylint: disable=unused-variable13 yield 1014 def test_something(a_generator, second_generator):15 assert a_generator == 516 assert second_generator == 1017 session = slash.Session()18 session.fixture_store.add_fixture(my_generator)19 session.fixture_store.add_fixture(second_generator)20 session.fixture_store.resolve()21 with session, session.get_started_context():22 run_tests_in_session(test_something, session=session)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful