def test_invoke_transaction(self):
     avm_code = '58c56b6a00527ac46a51527ac46a00c30548656c6c6f9c6416006a51c300c36a52527ac46a52c3650b006c756' \
                '661006c756655c56b6a00527ac46a00c3681553797374656d2e52756e74696d652e4e6f7469667961516c7566'
     hex_contract_address = sdk.neo_vm.avm_code_to_hex_contract_address(
         avm_code)
     self.assertEqual('39f3fb644842c808828817bd73da0946d99f237f',
                      hex_contract_address)
     hello = InvokeFunction('Hello')
     hello.set_params_value('Ontology')
     response = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                                None, 0, 0, hello, True)
     self.assertEqual(1, response['State'])
     result = response['Result']
     result = ContractDataParser.to_bool(result)
     self.assertEqual(True, result)
     gas_limit = 20000
     gas_price = 500
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                               acct1, gas_limit, gas_price,
                                               hello, False)
     sleep(6)
     response = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
     notify = response['Notify'][0]
     self.assertEqual(hex_contract_address, notify['ContractAddress'])
     notify['States'] = ContractDataParser.to_utf8_str(notify['States'])
     self.assertEqual('Ontology', notify['States'])
Esempio n. 2
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_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(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])
Esempio n. 5
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])
 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])