Esempio n. 1
0
 def test_notify(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     notify_args = InvokeFunction('testHello')
     bool_msg = True
     int_msg = 1
     bytes_msg = b'Hello'
     str_msg = 'Hello'
     bytes_address_msg = acct1.get_address().to_bytes()
     notify_args.set_params_value(bool_msg, int_msg, bytes_msg, str_msg,
                                  bytes_address_msg)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                               acct1, gas_limit, gas_price,
                                               notify_args, 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('testHello', states[0])
     states[1] = ContractDataParser.to_bool(states[1])
     self.assertEqual(bool_msg, states[1])
     states[2] = ContractDataParser.to_int(states[2])
     self.assertEqual(int_msg, states[2])
     states[3] = ContractDataParser.to_bytes(states[3])
     self.assertEqual(bytes_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])
 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_hello(self):
     bool_msg = True
     int_msg = 1
     bytes_msg = b'Hello'
     str_msg = 'Hello'
     address_msg = acct.get_address().to_bytes()
     tx_hash = hello_ontology.test_hello(bool_msg, int_msg, bytes_msg,
                                         str_msg, address_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('testHello', states[0])
     states[1] = ContractDataParser.to_bool(states[1])
     self.assertEqual(bool_msg, states[1])
     states[2] = ContractDataParser.to_int(states[2])
     self.assertEqual(int_msg, states[2])
     states[3] = ContractDataParser.to_bytes(states[3])
     self.assertEqual(bytes_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(acct.get_address_base58(), states[5])
 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])