def __init__(self, history_filename=None): PromptData.Prompt = self if history_filename: PromptInterface.history = PromptFileHistory(history_filename) self.input_parser = InputParser() self.start_height = Blockchain.Default().Height self.start_dt = datetime.datetime.utcnow()
def __init__(self): self.input_parser = InputParser() self.start_height = Blockchain.Default().Height self.start_dt = datetime.datetime.utcnow() self.token_style = style_from_dict({ Token.Command: preferences.token_style['Command'], Token.Neo: preferences.token_style['Neo'], Token.Default: preferences.token_style['Default'], Token.Number: preferences.token_style['Number'], })
class TestInputParser(TestCase): input_parser = InputParser() def test_simple_whitespace_separation(self): command, arguments = self.input_parser.parse_input("this is a simple test") self.assertEqual(command, "this") self.assertEqual(arguments, ["is", "a", "simple", "test"]) def test_keeping_double_quoted_strings_together(self): command, arguments = self.input_parser.parse_input("this \"is a simple\" test") self.assertEqual(command, "this") self.assertEqual(arguments, ["\"is a simple\"", "test"]) def test_keeping_single_quoted_strings_together(self): command, arguments = self.input_parser.parse_input("this 'is a simple' test") self.assertEqual(command, "this") self.assertEqual(arguments, ["'is a simple'", "test"]) def test_keeping_bracket_elements_together(self): command, arguments = self.input_parser.parse_input("this [is a simple] test") self.assertEqual(command, "this") self.assertEqual(arguments, ["[is a simple]", "test"]) def test_keeping_brackets_and_strings_together(self): command, arguments = self.input_parser.parse_input("this [is \"a simple\"] test") self.assertEqual(command, "this") self.assertEqual(arguments, ["[is \"a simple\"]", "test"]) def test_unmatched_brackets(self): command, arguments = self.input_parser.parse_input("this [is \"a simple\" test") self.assertEqual(command, "this") self.assertEqual(arguments, ["[is", "\"a simple\"", "test"]) def test_unmatched_single_quotes(self): command, arguments = self.input_parser.parse_input("this is 'a simple test") self.assertEqual(command, "this") self.assertEqual(arguments, ["is", "'a", "simple", "test"]) def test_unmatched_double_quotes(self): command, arguments = self.input_parser.parse_input("this is \"a simple test") self.assertEqual(command, "this") self.assertEqual(arguments, ["is", "\"a", "simple", "test"]) def test_python_bytearrays(self): command, arguments = self.input_parser.parse_input("testinvoke bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)') b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'") self.assertEqual(command, "testinvoke") self.assertEqual(arguments, ["bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')", "b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'"]) def test_python_bytearrays_in_lists(self): command, arguments = self.input_parser.parse_input("testinvoke f8d448b227991cf07cb96a6f9c0322437f1599b9 transfer [bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)'), bytearray(b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'), 1000]") self.assertEqual(command, "testinvoke") self.assertEqual(arguments, ["f8d448b227991cf07cb96a6f9c0322437f1599b9", "transfer", "[bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)'), bytearray(b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'), 1000]"])
def __init__(self, history_filename=None): if history_filename: PromptInterface.history = PromptFileHistory(history_filename) self.input_parser = InputParser() self.start_height = Blockchain.Default().Height self.start_dt = datetime.datetime.utcnow() self.token_style = Style.from_dict({ "command": preferences.token_style['Command'], "neo": preferences.token_style['Neo'], "default": preferences.token_style['Default'], "number": preferences.token_style['Number'], })
def __init__(self, history_filename=None): if history_filename: self.history = PromptFileHistory(history_filename) self.input_parser = InputParser() self.start_height = Blockchain.Default().Height self.start_dt = datetime.datetime.utcnow() self.token_style = style_from_dict({ Token.Command: preferences.token_style['Command'], Token.Neo: preferences.token_style['Neo'], Token.Default: preferences.token_style['Default'], Token.Number: preferences.token_style['Number'], })
def __init__(self, engine): self.engine = engine self.parser = InputParser() self.debug_map = engine._debug_map self.index = engine.CurrentContext.InstructionPointer
class TestInputParser(TestCase): input_parser = InputParser() def test_simple_whitespace_separation(self): command, arguments = self.input_parser.parse_input( "this is a simple test") self.assertEqual(command, "this") self.assertEqual(arguments, ["is", "a", "simple", "test"]) def test_keeping_double_quoted_strings_together(self): command, arguments = self.input_parser.parse_input( "this \"is a simple\" test") self.assertEqual(command, "this") self.assertEqual(arguments, ["\"is a simple\"", "test"]) def test_keeping_single_quoted_strings_together(self): command, arguments = self.input_parser.parse_input( "this 'is a simple' test") self.assertEqual(command, "this") self.assertEqual(arguments, ["'is a simple'", "test"]) def test_keeping_bracket_elements_together(self): command, arguments = self.input_parser.parse_input( "this [is a simple] test") self.assertEqual(command, "this") self.assertEqual(arguments, ["[is a simple]", "test"]) def test_keeping_brackets_and_strings_together(self): command, arguments = self.input_parser.parse_input( "this [is \"a simple\"] test") self.assertEqual(command, "this") self.assertEqual(arguments, ["[is \"a simple\"]", "test"]) def test_unmatched_brackets(self): command, arguments = self.input_parser.parse_input( "this [is \"a simple\" test") self.assertEqual(command, "this") self.assertEqual(arguments, ["[is \"a simple\" test"]) def test_unmatched_single_quotes(self): command, arguments = self.input_parser.parse_input( "this is 'a simple test") self.assertEqual(command, "this") self.assertEqual(arguments, ["is", "'a", "simple", "test"]) def test_unmatched_double_quotes(self): command, arguments = self.input_parser.parse_input( "this is \"a simple test") self.assertEqual(command, "this") self.assertEqual(arguments, ["is", "\"a", "simple", "test"]) def test_nested_lists(self): command, arguments = self.input_parser.parse_input( 'sc build_run sc.py False False False 0210 01 2 ["notused",["helloworld"]]' ) self.assertEqual(command, "sc") self.assertEqual(arguments, [ 'build_run', 'sc.py', 'False', 'False', 'False', '0210', '01', '2', '["notused",["helloworld"] ]' ]) def test_nested_lists_2(self): command, arguments = self.input_parser.parse_input( 'test ["notused",["helloworld", 1, ["a", 1]]]') self.assertEqual(command, "test") self.assertEqual(arguments, ['["notused",["helloworld", 1, ["a", 1] ]]']) def test_python_bytearrays(self): command, arguments = self.input_parser.parse_input( "testinvoke bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)') b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'" ) self.assertEqual(command, "testinvoke") self.assertEqual(arguments, [ "bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')", "b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'" ]) def test_python_bytearrays_in_lists(self): command, arguments = self.input_parser.parse_input( "testinvoke f8d448b227991cf07cb96a6f9c0322437f1599b9 transfer [bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)'), bytearray(b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'), 1000]" ) self.assertEqual(command, "testinvoke") self.assertEqual(arguments, [ "f8d448b227991cf07cb96a6f9c0322437f1599b9", "transfer", "[bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)'), bytearray(b'\xaf\x12\xa8h{\x14\x94\x8b\xc4\xa0\x08\x12\x8aU\nci[\xc1\xa5'), 1000]" ]) def test_attribute_spacing(self): command, arguments = self.input_parser.parse_input( 'wallet send neo Ae7bSUtT5Qvpkh7473q9FsxT4tSv5KK6dt 100 --tx-attr=[{"usage": 0x90,"data":"my brief description"}]' ) self.assertEqual(command, "wallet") self.assertEqual(arguments, [ 'send', 'neo', 'Ae7bSUtT5Qvpkh7473q9FsxT4tSv5KK6dt', '100', '--tx-attr=[{"usage": 0x90,"data":"my brief description"}]' ])
def __init__(self, input_args=None, debug=False): self.input_parser = InputParser() self.input_args = input_args self.start_height = Blockchain.Default().Height self.start_dt = datetime.datetime.utcnow() settings.set_log_smart_contract_events(False) self.notify = NotificationDB.instance() # if debug: # settings.set_log_smart_contract_events(True) # EVENTS @events.on(SmartContractEvent.RUNTIME_NOTIFY) @events.on(SmartContractEvent.RUNTIME_LOG) @events.on(SmartContractEvent.EXECUTION_SUCCESS) @events.on(SmartContractEvent.EXECUTION_FAIL) @events.on(SmartContractEvent.STORAGE) def on_sc_event(sc_event): if sc_event.test_mode: self.active_color = colors.WARNING else: self.active_color = colors.GREEN if str(sc_event.contract_hash) == str(self.SC_hash): et = sc_event.event_type results = sc_event.event_payload if not debug and sc_event.test_mode: return # Inding the invoked op if et == SmartContractEvent.RUNTIME_LOG and sc_event.test_mode: try: decoded_result = results[0].decode("utf-8") if ':' in decoded_result: self.invoked_operation = decoded_result.split( ':')[-1] except: pass if et == SmartContractEvent.EXECUTION_SUCCESS or et == SmartContractEvent.RUNTIME_NOTIFY: print( self.active_color + '\n|-------- T H E C O N S T R U C T --------|' + colors.ENDC) for result in results: if self.invoked_operation in [ 'fs_attribute', 'get_active_index', 'update_active_ms_progress', 'get_ms_progess' ]: result = int.from_bytes(result, byteorder='little', signed=False) print('\033[1m Output:\033[0m \t\t\t', result) if sc_event.test_mode: print('\n \033[1mSuccessfully Sent Request:\033[0m\t', self.invoked_operation) print('\n Please wait for block to process.. ') else: print( '\n \033[1mSuccessfully Executed Request:\033[0m\t', self.invoked_operation) self.invoking = False self.invoked_operation = '' self.op_output = results print(self.active_color + '|-----------------------------------------------|' + colors.ENDC) print('\n') elif debug: print( self.active_color + '\n|-------- T H E C O N S T R U C T --------|' + colors.ENDC) print(' Event Type: ', et) for result in results: print(' \033[1mOutput:\033[0m \t\t\t', result) print('\n')