def test_notify(self): hex_contract_address = '6690b6638251be951dded8c537678200a470c679' notify_args = NeoInvokeFunction('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 = self.send_tx(hex_contract_address, None, acct1, notify_args) 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('testHello', states[0]) states[1] = NeoData.to_bool(states[1]) self.assertEqual(bool_msg, states[1]) states[2] = NeoData.to_int(states[2]) self.assertEqual(int_msg, states[2]) states[3] = NeoData.to_bytes(states[3]) self.assertEqual(bytes_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])
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])
def test_send_raw_transaction_pre_exec(self): b58_address = acct1.get_address_base58() tx = sdk.native_vm.ong().new_transfer_tx(b58_address, acct2.get_address(), 2, b58_address, 500, 20000) tx.sign_transaction(acct1) result = sdk.rpc.send_raw_transaction_pre_exec(tx) self.assertTrue(NeoData.to_bool(result['Result'])) self.assertEqual(result['Gas'], 20000) self.assertEqual(result['State'], 1)
def decode_neo_raw_data(data: str, d_type: str): if d_type.lower() == 'hex': return NeoData.to_hex_str(data) if d_type.lower() == 'int': return NeoData.to_int(data) if d_type.lower() == 'bool': return NeoData.to_bool(data) if d_type.lower() == 'utf8': return NeoData.to_utf8_str(data) if d_type.lower() == 'dict': return NeoData.to_dict(data) if d_type.lower() == 'bytes': return NeoData.to_bytes(data) if d_type.lower() == 'address': return NeoData.to_b58_address(data) return data
def test_to_bool(self): self.assertTrue(NeoData.to_bool('01')) self.assertFalse(NeoData.to_bool('00'))
def to_bool_cmd(ctx, data: str): """ Decode Hex string to bool. """ echo(NeoData.to_bool(data))