def test_test_struct_list_and_str(self):
     bool_msg = True
     int_msg = 10
     bytes_msg = b'Hello'
     str_msg = 'Hello'
     list_msg = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     struct_list = [bool_msg, int_msg, bytes_msg, str_msg, list_msg]
     tx_hash = hello_ontology.test_struct_list_and_str(
         struct_list, str_msg, acct, gas_limit, gas_price)
     time.sleep(6)
     event = ontology.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
     states = ContractEventParser.get_states_by_contract_address(
         event, hex_contract_address)
     states[0] = ContractDataParser.to_utf8_str(states[0])
     states[1][0] = ContractDataParser.to_bool(states[1][0])
     self.assertEqual(bool_msg, states[1][0])
     states[1][1] = ContractDataParser.to_int(states[1][1])
     self.assertEqual(int_msg, states[1][1])
     states[1][2] = ContractDataParser.to_bytes(states[1][2])
     self.assertEqual(bytes_msg, states[1][2])
     states[1][3] = ContractDataParser.to_utf8_str(states[1][3])
     self.assertEqual(str_msg, states[1][3])
     states[1][4] = ContractDataParser.to_int_list(states[1][4])
     self.assertEqual(list_msg, states[1][4])
     states[2] = ContractDataParser.to_utf8_str(states[2])
 def test_test_list_and_str(self):
     list_msg = [1, 2, 3]
     tx_hash = hello_ontology.test_list(list_msg, acct, gas_limit,
                                        gas_price)
     time.sleep(6)
     event = ontology.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
     states = ContractEventParser.get_states_by_contract_address(
         event, hex_contract_address)
     states[0] = ContractDataParser.to_utf8_str(states[0])
     self.assertEqual('testMsgList', states[0])
     states[1] = ContractDataParser.to_int_list(states[1])
     self.assertEqual(list_msg, states[1])
예제 #3
0
 def test_list(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     list_msg = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     func = InvokeFunction('testList')
     func.set_params_value(list_msg)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                               acct1, gas_limit, gas_price,
                                               func, False)
     time.sleep(randint(6, 10))
     event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
     states = ContractEventParser.get_states_by_contract_address(
         event, hex_contract_address)
     states[0] = ContractDataParser.to_utf8_str(states[0])
     self.assertEqual('testMsgList', states[0])
     states[1] = ContractDataParser.to_int_list(states[1])
     self.assertEqual(list_msg, states[1])
예제 #4
0
 def test_dict(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     dict_msg = {'key': 'value'}
     func = InvokeFunction('testMap')
     func.set_params_value(dict_msg)
     result = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                              None, 0, 0, func, True)
     dict_value = result['Result']
     dict_value = ContractDataParser.to_utf8_str(dict_value)
     self.assertEqual('value', dict_value)
     list_value = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     dict_msg = {'key': list_value}
     func = InvokeFunction('testMap')
     func.set_params_value(dict_msg)
     result = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                              None, 0, 0, func, True)
     dict_value = result['Result']
     dict_value = ContractDataParser.to_int_list(dict_value)
     self.assertEqual(list_value, dict_value)
 def test_test_struct_list_and_str_pre_exec(self):
     bool_msg = True
     int_msg = 10
     bytes_msg = b'Hello'
     str_msg = 'Hello'
     list_msg = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     struct_list = [bool_msg, int_msg, bytes_msg, str_msg, list_msg]
     value = hello_ontology.test_struct_list_and_str_pre_exec(
         struct_list, str_msg)
     value[0][0] = ContractDataParser.to_bool(value[0][0])
     self.assertEqual(bool_msg, value[0][0])
     value[0][1] = ContractDataParser.to_int(value[0][1])
     self.assertEqual(int_msg, value[0][1])
     value[0][2] = ContractDataParser.to_bytes(value[0][2])
     self.assertEqual(bytes_msg, value[0][2])
     value[0][3] = ContractDataParser.to_utf8_str(value[0][3])
     self.assertEqual(str_msg, value[0][3])
     value[0][4] = ContractDataParser.to_int_list(value[0][4])
     self.assertEqual(list_msg, value[0][4])
     value[1] = ContractDataParser.to_utf8_str(value[1])
     self.assertEqual(str_msg, value[1])
예제 #6
0
 def test_notify_pre_exec(self):
     bool_msg = True
     int_msg = 1024
     list_msg = [1, 1024, 2048]
     str_msg = 'Hello'
     bytes_address_msg = acct1.get_address().to_bytes()
     hex_contract_address = '4855735ffadad50e7000d73e1c4e96f38d225f70'
     notify_args = InvokeFunction('notify_args')
     notify_args.set_params_value(bool_msg, int_msg, list_msg, str_msg,
                                  bytes_address_msg)
     rpc_address = 'http://polaris5.ont.io:20336'
     sdk.set_rpc_address(rpc_address)
     try:
         response = sdk.rpc.send_neo_vm_transaction(hex_contract_address,
                                                    None, None, 0, 0,
                                                    notify_args, True)
     except SDKException as e:
         self.assertIn('already in the tx pool', e.args[1])
         return
     sdk.rpc.connect_to_test_net()
     response['Result'] = ContractDataParser.to_bool(response['Result'])
     self.assertEqual(1, response['State'])
     self.assertEqual(20000, response['Gas'])
     self.assertEqual(True, response['Result'])
     notify = response['Notify'][0]
     self.assertEqual(hex_contract_address, notify['ContractAddress'])
     states = notify['States']
     states[0] = ContractDataParser.to_utf8_str(states[0])
     self.assertEqual('notify args', states[0])
     states[1] = ContractDataParser.to_bool(states[1])
     self.assertEqual(True, states[1])
     states[2] = ContractDataParser.to_int(states[2])
     self.assertEqual(int_msg, states[2])
     states[3] = ContractDataParser.to_int_list(states[3])
     self.assertEqual(list_msg, states[3])
     states[4] = ContractDataParser.to_utf8_str(states[4])
     self.assertEqual(str_msg, states[4])
     states[5] = ContractDataParser.to_b58_address(states[5])
     self.assertEqual(acct1.get_address_base58(), states[5])