Beispiel #1
0
 def test_dict_in_ctx(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     bool_value = True
     int_value = 100
     str_value = 'value3'
     dict_value = {'key': 'value'}
     list_value = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     dict_msg = {
         'key': dict_value,
         'key1': int_value,
         'key2': str_value,
         'key3': bool_value,
         'key4': list_value
     }
     func = InvokeFunction('testMapInMap')
     func.set_params_value(dict_msg)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                               acct1, self.gas_price,
                                               self.gas_limit, func, False)
     time.sleep(randint(10, 15))
     event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
     states = Event.get_states_by_contract_address(event,
                                                   hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     self.assertEqual('mapInfo', states[0])
     states[1] = Data.to_dict(states[1])
     self.assertTrue(isinstance(states[1], dict))
Beispiel #2
0
 def parse_status(result: dict):
     status = result['Result']
     if status == '':
         status = False
     else:
         status = Data.to_dict(status)
         status = bool(status[3])
     return status
Beispiel #3
0
 def test_test_dict_in_ctx(self):
     bool_value = True
     int_value = 100
     str_value = 'value3'
     dict_value = {'key': 'value'}
     list_value = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     dict_msg = {'key': dict_value, 'key1': int_value, 'key2': str_value, 'key3': bool_value, 'key4': list_value}
     tx_hash = self.hello_ontology.test_dict_in_ctx(dict_msg, self.acct, gas_limit, gas_price)
     time.sleep(6)
     event = self.ontology.rpc.get_contract_event_by_tx_hash(tx_hash)
     states = Event.get_states_by_contract_address(event, self.hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     self.assertEqual('mapInfo', states[0])
     states[1] = Data.to_dict(states[1])
     self.assertTrue(isinstance(states[1], dict))
Beispiel #4
0
 def decode_raw_data(data: str, d_type: str):
     if d_type.lower() == 'hex':
         return Data.to_hex_str(data)
     if d_type.lower() == 'int':
         return Data.to_int(data)
     if d_type.lower() == 'bool':
         return Data.to_bool(data)
     if d_type.lower() == 'utf8':
         return Data.to_utf8_str(data)
     if d_type.lower() == 'dict':
         return Data.to_dict(data)
     if d_type.lower() == 'bytes':
         return Data.to_bytes(data)
     if d_type.lower() == 'address':
         return Data.to_b58_address(data)
     return data
Beispiel #5
0
def to_dict_cmd(ctx, data: str):
    """
    Decode Hex string to JSON string.
    """
    Info.echo_dict_info(Data.to_dict(data))