Exemplo n.º 1
0
 def test_transfer_multi_args_0(self):
     transfer_1 = [
         acct1.get_address().to_bytes(),
         acct2.get_address().to_bytes(), 10
     ]
     transfer_2 = [
         acct2.get_address().to_bytes(),
         acct3.get_address().to_bytes(), 100
     ]
     transfer_list = [transfer_1, transfer_2]
     hex_contract_address = 'ca91a73433c016fbcbcf98051d385785a6a5d9be'
     func = NeoInvokeFunction('transfer_multi')
     func.set_params_value(transfer_list)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, acct1,
                                               acct2, self.gas_price,
                                               self.gas_limit, func, False)
     self.assertEqual(64, len(tx_hash))
     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])
     states[1][0][0] = NeoData.to_b58_address(states[1][0][0])
     self.assertEqual(acct1.get_address_base58(), states[1][0][0])
     states[1][0][1] = NeoData.to_b58_address(states[1][0][1])
     self.assertEqual(acct2.get_address_base58(), states[1][0][1])
     states[1][0][2] = NeoData.to_int(states[1][0][2])
     self.assertEqual(10, states[1][0][2])
     states[1][1][0] = NeoData.to_b58_address(states[1][1][0])
     self.assertEqual(acct2.get_address_base58(), states[1][1][0])
     states[1][1][1] = NeoData.to_b58_address(states[1][1][1])
     self.assertEqual(acct3.get_address_base58(), states[1][1][1])
     states[1][1][2] = NeoData.to_int(states[1][1][2])
     self.assertEqual(100, states[1][1][2])
Exemplo n.º 2
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])
Exemplo n.º 3
0
 async def test_get_storage(self):
     hex_contract_address = '0100000000000000000000000000000000000000'
     key = '746f74616c537570706c79'
     storage = await sdk.websocket.get_storage(hex_contract_address, key)
     await sdk.websocket.close_connect()
     value = NeoData.to_int(storage)
     self.assertEqual(1000000000, value)
Exemplo n.º 4
0
 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])
Exemplo n.º 5
0
 def test_oep4_decimal(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = NeoInvokeFunction('decimals')
     result = sdk.rpc.send_neo_vm_tx_pre_exec(hex_contract_address, func)
     decimals = result['Result']
     decimals = NeoData.to_int(decimals)
     self.assertEqual(10, decimals)
Exemplo n.º 6
0
 def test_oep4_total_supply(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = NeoInvokeFunction('totalSupply')
     result = sdk.default_network.send_neo_vm_tx_pre_exec(
         hex_contract_address, func)
     total_supply = result['Result']
     total_supply = NeoData.to_int(total_supply)
     self.assertEqual(10000000000000000000, total_supply)
Exemplo n.º 7
0
 def decimals(self):
     """
     This interface is used to the number of decimals the token uses synchronously.
     E.g. 8, means to divide the token amount by 100000000 to get its user representation.
     """
     tx = self.new_decimals_tx()
     response = self._sdk.default_network.send_raw_transaction_pre_exec(tx)
     return NeoData.to_int(response.get('Result', ''))
Exemplo n.º 8
0
 def allowance(self, from_address: Union[str, Address],
               to_address: Union[str, Address]) -> int:
     tx = self.new_allowance_tx(from_address, to_address)
     response = self._sdk.default_network.send_raw_transaction_pre_exec(tx)
     try:
         allowance = NeoData.to_int(response['Result'])
         return allowance
     except SDKException:
         return 0
Exemplo n.º 9
0
 def balance_of(self, owner: str) -> int:
     """
     This interface is used to get the account balance of another account with owner address synchronously.
     """
     tx = self.new_balance_of_tx(owner)
     result = self._sdk.default_network.send_raw_transaction_pre_exec(tx)
     try:
         balance = NeoData.to_int(result['Result'])
     except SDKException:
         balance = 0
     return balance
Exemplo n.º 10
0
 def balance_of(self, owner: Union[str, Address]) -> int:
     """
     This interface is used to query the account's ONT or ONG balance.
     """
     tx = self.new_balance_of_tx(owner)
     response = self._sdk.default_network.send_raw_transaction_pre_exec(tx)
     try:
         balance = NeoData.to_int(response['Result'])
         return balance
     except SDKException:
         return 0
Exemplo n.º 11
0
 def decimals(self) -> int:
     """
     This interface is used to query the asset's decimals of ONT or ONG.
     """
     tx = self.new_decimals_tx()
     response = self._sdk.default_network.send_raw_transaction_pre_exec(tx)
     try:
         decimal = NeoData.to_int(response['Result'])
         return decimal
     except SDKException:
         return 0
Exemplo n.º 12
0
 def total_supply(self) -> int:
     """
     This interface is used to get the total token supply synchronously.
     """
     tx = self.new_total_supply_tx()
     response = self._sdk.default_network.send_raw_transaction_pre_exec(tx)
     try:
         total_supply = NeoData.to_int(response['Result'])
     except SDKException:
         total_supply = 0
     return total_supply
Exemplo n.º 13
0
    def test_oep4_transfer_multi(self):
        hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
        bytes_from_address1 = acct1.get_address().to_bytes()
        bytes_to_address1 = acct2.get_address().to_bytes()
        value1 = 2
        transfer1 = [bytes_from_address1, bytes_to_address1, value1]
        bytes_from_address2 = acct2.get_address().to_bytes()
        bytes_to_address2 = acct3.get_address().to_bytes()
        value2 = 1
        transfer2 = [bytes_from_address2, bytes_to_address2, value2]
        func = NeoInvokeFunction('transferMulti')
        func.set_params_value(transfer1, transfer2)
        tx_hash = sdk.default_network.send_neo_vm_transaction(
            hex_contract_address, acct1, acct2, self.gas_price, self.gas_limit,
            func, False)
        time.sleep(randint(10, 15))
        event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
        states_list = Event.get_states_by_contract_address(
            event, hex_contract_address)
        states_list[0][0] = NeoData.to_utf8_str(states_list[0][0])
        self.assertEqual('transfer', states_list[0][0])
        states_list[0][1] = NeoData.to_b58_address(states_list[0][1])
        self.assertEqual(acct1.get_address().b58encode(), states_list[0][1])
        states_list[0][2] = NeoData.to_b58_address(states_list[0][2])
        self.assertEqual(acct2.get_address().b58encode(), states_list[0][2])
        states_list[0][3] = NeoData.to_int(states_list[0][3])
        self.assertEqual(value1, states_list[0][3])

        states_list[1][0] = NeoData.to_utf8_str(states_list[1][0])
        self.assertEqual('transfer', states_list[1][0])
        states_list[1][1] = NeoData.to_b58_address(states_list[1][1])
        self.assertEqual(acct2.get_address().b58encode(), states_list[1][1])
        states_list[1][2] = NeoData.to_b58_address(states_list[1][2])
        self.assertEqual(acct3.get_address().b58encode(), states_list[1][2])
        states_list[1][3] = NeoData.to_int(states_list[1][3])
        self.assertEqual(value2, states_list[1][3])
Exemplo n.º 14
0
 def test_oep4_balance_of(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = NeoInvokeFunction('balanceOf')
     self.assertEqual(bytearray(b'\x00\xc1\tbalanceOf'),
                      func.create_invoke_code())
     bytes_address = acct1.get_address().to_bytes()
     func.set_params_value(bytes_address)
     target = bytearray(
         b'\x14F\xb1\xa1\x8a\xf6\xb7\xc9\xf8\xa4`/\x9fs\xee\xb3\x03\x0f\x0c)\xb7Q\xc1\tbalanceOf'
     )
     self.assertEqual(target, func.create_invoke_code())
     result = sdk.rpc.send_neo_vm_tx_pre_exec(hex_contract_address, func)
     balance = result['Result']
     balance = NeoData.to_int(balance)
     self.assertGreater(balance, 100)
Exemplo n.º 15
0
 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
Exemplo n.º 16
0
 def test_oep4_transfer(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = NeoInvokeFunction('transfer')
     bytes_from_address = acct1.get_address().to_bytes()
     bytes_to_address = acct2.get_address().to_bytes()
     value = 1
     func.set_params_value(bytes_from_address, bytes_to_address, value)
     tx_hash = self.send_tx(hex_contract_address, acct1, acct2, 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('transfer', states[0])
     states[1] = NeoData.to_b58_address(states[1])
     self.assertEqual(acct1.get_address().b58encode(), states[1])
     states[2] = NeoData.to_b58_address(states[2])
     self.assertEqual(acct2.get_address().b58encode(), states[2])
     states[3] = NeoData.to_int(states[3])
     self.assertEqual(value, states[3])
Exemplo n.º 17
0
 def test_get_storage(self):
     hex_contract_address = "0100000000000000000000000000000000000000"
     key = "746f74616c537570706c79"
     value = sdk.rpc.get_storage(hex_contract_address, key)
     value = NeoData.to_int(value)
     self.assertEqual(1000000000, value)
Exemplo n.º 18
0
def to_int_cmd(ctx, data: str):
    """
    Convert ASCII string to a number.
    """
    echo(NeoData.to_int(data))
Exemplo n.º 19
0
 async def test_get_storage(self):
     contract_address = "0100000000000000000000000000000000000000"
     key = "746f74616c537570706c79"
     value = await sdk.aio_restful.get_storage(contract_address, key)
     value = NeoData.to_int(value)
     self.assertEqual(1000000000, value)