Esempio n. 1
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'
     func = NeoInvokeFunction('notify_args')
     func.set_params_value(bool_msg, int_msg, list_msg, str_msg,
                           bytes_address_msg)
     sdk.rpc.set_address('http://polaris5.ont.io:20336')
     response = sdk.rpc.send_neo_vm_tx_pre_exec(hex_contract_address, func)
     self.assertEqual(1, response['State'])
     self.assertEqual(20000, response['Gas'])
     notify = response['Notify'][0]
     self.assertEqual(hex_contract_address, notify['ContractAddress'])
     states = notify['States']
     states[0] = NeoData.to_utf8_str(states[0])
     self.assertEqual('notify args', states[0])
     states[1] = NeoData.to_bool(states[1])
     self.assertEqual(True, states[1])
     states[2] = NeoData.to_int(states[2])
     self.assertEqual(int_msg, states[2])
     states[3] = NeoData.to_int_list(states[3])
     self.assertEqual(list_msg, states[3])
     states[4] = NeoData.to_utf8_str(states[4])
     self.assertEqual(str_msg, states[4])
     states[5] = NeoData.to_b58_address(states[5])
     self.assertEqual(acct1.get_address_base58(), states[5])
Esempio n. 2
0
 def test_list(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     list_msg = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     func = NeoInvokeFunction('testList')
     func.set_params_value(list_msg)
     tx_hash = self.send_tx(hex_contract_address, None, acct1, func)
     if len(tx_hash) == 0:
         return
     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] = NeoData.to_utf8_str(states[0])
     self.assertEqual('testMsgList', states[0])
     states[1] = NeoData.to_int_list(states[1])
     self.assertEqual(list_msg, states[1])
Esempio n. 3
0
 def test_dict(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     dict_msg = {'key': 'value'}
     func = NeoInvokeFunction('testMap')
     func.set_params_value(dict_msg)
     result = sdk.rpc.send_neo_vm_tx_pre_exec(hex_contract_address, func)
     dict_value = result['Result']
     dict_value = NeoData.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 = NeoInvokeFunction('testMap')
     func.set_params_value(dict_msg)
     result = sdk.rpc.send_neo_vm_tx_pre_exec(hex_contract_address, func)
     dict_value = result['Result']
     dict_value = NeoData.to_int_list(dict_value)
     self.assertEqual(list_value, dict_value)