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. 3
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_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'])
 def query_commit_event(self, tx_hash: str):
     event = self.__sdk.get_network().get_smart_contract_event_by_tx_hash(
         tx_hash)
     notify = ContractEventParser.get_notify_list_by_contract_address(
         event, self.__hex_contract_address)
     if len(notify) == 0:
         return notify
     notify['States'][0] = ContractDataParser.to_utf8_str(
         notify['States'][0])
     notify['States'][1] = ContractDataParser.to_b58_address(
         notify['States'][1])
     notify['States'][2] = ContractDataParser.to_utf8_str(
         notify['States'][2])
     notify['States'][3] = ContractDataParser.to_hex_str(
         notify['States'][3])
     return notify
Esempio n. 6
0
 def test_dict_in_ctx(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     bool_value = True
     int_value = 100
     str_value = 'value3'
     dict_value = {'key': 'value'}
     list_value = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     dict_msg = {
         'key': dict_value,
         'key1': int_value,
         'key2': str_value,
         'key3': bool_value,
         'key4': list_value
     }
     func = InvokeFunction('testMapInMap')
     func.set_params_value(dict_msg)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                               acct1, gas_limit, gas_price,
                                               func, 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('mapInfo', states[0])
     states[1] = ContractDataParser.to_dict(states[1])
     self.assertTrue(isinstance(states[1], dict))
Esempio n. 7
0
 def name(self):
     func = InvokeFunction('name')
     res = self.__sdk.neo_vm().send_transaction(self.__hex_contract_address,
                                                None, None, 0, 0, func,
                                                True)
     res = ContractDataParser.to_utf8_str(res)
     return res
Esempio n. 8
0
 def test_oep4_transfer(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = InvokeFunction('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)
     try:
         tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address,
                                                   acct1, acct2, gas_limit,
                                                   gas_price, func, False)
         self.assertEqual(64, len(tx_hash))
     except SDKException as e:
         self.assertIn('already in the tx pool', e.args[1])
         return
     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('transfer', states[0])
     states[1] = ContractDataParser.to_b58_address(states[1])
     self.assertEqual(acct1.get_address().b58encode(), states[1])
     states[2] = ContractDataParser.to_b58_address(states[2])
     self.assertEqual(acct2.get_address().b58encode(), states[2])
     states[3] = ContractDataParser.to_int(states[3])
     self.assertEqual(value, states[3])
Esempio n. 9
0
 def test_oep4_symbol(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = InvokeFunction('symbol')
     result = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                              None, 0, 0, func, True)
     symbol = result['Result']
     symbol = ContractDataParser.to_utf8_str(symbol)
     self.assertEqual('DX', symbol)
Esempio n. 10
0
    def get_symbol(self) -> str:
        """
        This interface is used to call the Symbol method in ope4
        that return the symbol of an oep4 token.

        :return: a short string symbol of the oep4 token
        """
        symbol = self.__get_token_setting('symbol')
        return ContractDataParser.to_utf8_str(symbol)
Esempio n. 11
0
    def get_name(self) -> str:
        """
        This interface is used to call the Name method in ope4
        that return the name of an oep4 token.

        :return: the string name of the oep4 token.
        """
        name = self.__get_token_setting('name')
        return ContractDataParser.to_utf8_str(name)
Esempio n. 12
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 = InvokeFunction('transferMulti')
        func.set_params_value(transfer1, transfer2)
        try:
            tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address,
                                                      acct1, acct2, gas_limit,
                                                      gas_price, func, False)
        except SDKException as e:
            self.assertIn('already in the tx pool', e.args[1])
            return
        time.sleep(randint(6, 10))
        event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
        states_list = ContractEventParser.get_states_by_contract_address(
            event, hex_contract_address)
        states_list[0][0] = ContractDataParser.to_utf8_str(states_list[0][0])
        self.assertEqual('transfer', states_list[0][0])
        states_list[0][1] = ContractDataParser.to_b58_address(
            states_list[0][1])
        self.assertEqual(acct1.get_address().b58encode(), states_list[0][1])
        states_list[0][2] = ContractDataParser.to_b58_address(
            states_list[0][2])
        self.assertEqual(acct2.get_address().b58encode(), states_list[0][2])
        states_list[0][3] = ContractDataParser.to_int(states_list[0][3])
        self.assertEqual(value1, states_list[0][3])

        states_list[1][0] = ContractDataParser.to_utf8_str(states_list[1][0])
        self.assertEqual('transfer', states_list[1][0])
        states_list[1][1] = ContractDataParser.to_b58_address(
            states_list[1][1])
        self.assertEqual(acct2.get_address().b58encode(), states_list[1][1])
        states_list[1][2] = ContractDataParser.to_b58_address(
            states_list[1][2])
        self.assertEqual(acct3.get_address().b58encode(), states_list[1][2])
        states_list[1][3] = ContractDataParser.to_int(states_list[1][3])
        self.assertEqual(value2, states_list[1][3])
Esempio n. 13
0
 def hello(self, msg: str) -> str:
     if not isinstance(msg, str):
         raise RuntimeError('the type of msg should be str')
     func = InvokeFunction('hello')
     func.set_params_value(msg)
     res = self.__sdk.neo_vm().send_transaction(self.__hex_contract_address,
                                                None, None, 0, 0, func,
                                                True)
     res = ContractDataParser.to_utf8_str(res)
     return res
Esempio n. 14
0
 def test_get_dict_in_ctx(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     key = 'key'
     func = InvokeFunction('testGetMapInMap')
     func.set_params_value(key)
     result = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                              None, 0, 0, func, True)
     value = result['Result']
     value = ContractDataParser.to_utf8_str(value)
     self.assertEqual('value', value)
Esempio n. 15
0
 def test_oep4_name(self):
     contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     bytearray_contract_address = bytearray(
         binascii.a2b_hex(contract_address))
     bytearray_contract_address.reverse()
     func = InvokeFunction('name')
     result = sdk.rpc.send_neo_vm_transaction(bytearray_contract_address,
                                              None, None, 0, 0, func, True)
     name = result['Result']
     name = ContractDataParser.to_utf8_str(name)
     self.assertEqual('DXToken', name)
 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])
 def test_test_list_and_str(self):
     list_msg = [1, 2, 3]
     tx_hash = hello_ontology.test_list(list_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('testMsgList', states[0])
     states[1] = ContractDataParser.to_int_list(states[1])
     self.assertEqual(list_msg, states[1])
Esempio n. 18
0
    def test_transfer_multi(self):
        sdk = OntologySdk()
        sdk.rpc.connect_to_test_net()
        contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
        oep4 = sdk.neo_vm.oep4()
        oep4.hex_contract_address = contract_address
        transfer_list = list()

        b58_from_address1 = acct1.get_address_base58()
        b58_from_address2 = acct2.get_address_base58()
        hex_from_address1 = acct1.get_address_hex()
        hex_from_address2 = acct2.get_address_hex()
        from_address_list = [hex_from_address1, hex_from_address2]

        b58_to_address1 = acct2.get_address_base58()
        b58_to_address2 = acct3.get_address_base58()
        hex_to_address1 = acct2.get_address_hex()
        hex_to_address2 = acct3.get_address_hex()
        to_address_list = [hex_to_address1, hex_to_address2]

        value_list = [1, 2]

        transfer1 = [b58_from_address1, b58_to_address1, value_list[0]]
        transfer2 = [b58_from_address2, b58_to_address2, value_list[1]]

        signers = [acct1, acct2, acct3]
        transfer_list.append(transfer1)
        transfer_list.append(transfer2)

        gas_limit = 20000000
        gas_price = 500

        tx_hash = oep4.transfer_multi(transfer_list, signers[0], signers,
                                      gas_limit, gas_price)
        self.assertEqual(64, len(tx_hash))
        sdk = OntologySdk()
        sdk.rpc.connect_to_test_net()
        time.sleep(randint(6, 10))
        try:
            event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
            notify_list = event['Notify'][:-1]
            self.assertEqual(len(transfer_list), len(notify_list))
            for index, notify in enumerate(notify_list):
                self.assertEqual(
                    'transfer',
                    ContractDataParser.to_utf8_str(notify['States'][0]))
                self.assertEqual(from_address_list[index], notify['States'][1])
                self.assertEqual(to_address_list[index], notify['States'][2])
                notify_value = ContractDataParser.to_int(notify['States'][3])
                self.assertEqual(value_list[index], notify_value)
        except SDKException as e:
            raised = False
            self.assertTrue(raised, e)
Esempio n. 19
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])
Esempio n. 20
0
 def test_list(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     list_msg = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     func = InvokeFunction('testList')
     func.set_params_value(list_msg)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                               acct1, gas_limit, gas_price,
                                               func, 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('testMsgList', states[0])
     states[1] = ContractDataParser.to_int_list(states[1])
     self.assertEqual(list_msg, states[1])
Esempio n. 21
0
 def test_dict(self):
     hex_contract_address = '6690b6638251be951dded8c537678200a470c679'
     dict_msg = {'key': 'value'}
     func = InvokeFunction('testMap')
     func.set_params_value(dict_msg)
     result = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                              None, 0, 0, func, True)
     dict_value = result['Result']
     dict_value = ContractDataParser.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 = InvokeFunction('testMap')
     func.set_params_value(dict_msg)
     result = sdk.rpc.send_neo_vm_transaction(hex_contract_address, None,
                                              None, 0, 0, func, True)
     dict_value = result['Result']
     dict_value = ContractDataParser.to_int_list(dict_value)
     self.assertEqual(list_value, dict_value)
Esempio n. 22
0
    def query_symbol(self, asset: str) -> str:
        """
        This interface is used to query the asset's symbol of ONT or ONG.

        :param asset: a string which is used to indicate which asset's symbol we want to get.
        :return: asset's symbol in the form of string.
        """
        contract_address = self.get_asset_address(asset)
        method = 'symbol'
        invoke_code = build_native_invoke_code(contract_address, b'\x00', method, bytearray())
        unix_time_now = int(time())
        version = 0
        tx_type = 0xd1
        gas_price = 0
        gas_limit = 0
        attributes = bytearray()
        signers = list()
        tx = Transaction(version, tx_type, unix_time_now, gas_price, gas_limit, None, invoke_code, attributes, signers)
        response = self.__sdk.rpc.send_raw_transaction_pre_exec(tx)
        symbol = ContractDataParser.to_utf8_str(response['Result'])
        return symbol
Esempio n. 23
0
 def test_transfer_multi_args(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
     ]
     hex_contract_address = 'ca91a73433c016fbcbcf98051d385785a6a5d9be'
     func = InvokeFunction('transfer_multi_args')
     func.set_params_value(transfer_1, transfer_2)
     try:
         tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address,
                                                   acct1, acct2, gas_limit,
                                                   gas_price, func, False)
         self.assertEqual(64, len(tx_hash))
     except SDKException as e:
         self.assertIn('already in the tx pool', e.args[1])
         return
     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('transfer_multi_args', states[0])
     states[1][0][0] = ContractDataParser.to_b58_address(states[1][0][0])
     self.assertEqual(acct1.get_address_base58(), states[1][0][0])
     states[1][0][1] = ContractDataParser.to_b58_address(states[1][0][1])
     self.assertEqual(acct2.get_address_base58(), states[1][0][1])
     states[1][0][2] = ContractDataParser.to_int(states[1][0][2])
     self.assertEqual(10, states[1][0][2])
     states[1][1][0] = ContractDataParser.to_b58_address(states[1][1][0])
     self.assertEqual(acct2.get_address_base58(), states[1][1][0])
     states[1][1][1] = ContractDataParser.to_b58_address(states[1][1][1])
     self.assertEqual(acct3.get_address_base58(), states[1][1][1])
     states[1][1][2] = ContractDataParser.to_int(states[1][1][2])
     self.assertEqual(100, states[1][1][2])
 def test_test_dict_in_ctx(self):
     bool_value = True
     int_value = 100
     str_value = 'value3'
     dict_value = {'key': 'value'}
     list_value = [1, 10, 1024, [1, 10, 1024, [1, 10, 1024]]]
     dict_msg = {
         'key': dict_value,
         'key1': int_value,
         'key2': str_value,
         'key3': bool_value,
         'key4': list_value
     }
     tx_hash = hello_ontology.test_dict_in_ctx(dict_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('mapInfo', states[0])
     states[1] = ContractDataParser.to_dict(states[1])
     self.assertTrue(isinstance(states[1], dict))
Esempio n. 25
0
 def test_oep4_approve(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     func = InvokeFunction('approve')
     bytes_owner_address = acct1.get_address().to_bytes()
     bytes_spender_address = acct2.get_address().to_bytes()
     amount = 10
     func.set_params_value(bytes_owner_address, bytes_spender_address,
                           amount)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, acct1,
                                               acct2, gas_limit, gas_price,
                                               func, False)
     self.assertEqual(64, len(tx_hash))
     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('approval', states[0])
     states[1] = ContractDataParser.to_b58_address(states[1])
     self.assertEqual(acct1.get_address_base58(), states[1])
     states[2] = ContractDataParser.to_b58_address(states[2])
     self.assertEqual(acct2.get_address_base58(), states[2])
     states[3] = ContractDataParser.to_int(states[3])
     self.assertEqual(amount, states[3])
 def test_test_dict_pre_exec(self):
     dict_msg = {'key': 'value'}
     dict_value = hello_ontology.test_dict_pre_exec(dict_msg)
     dict_value = ContractDataParser.to_utf8_str(dict_value)
     self.assertEqual('value', dict_value)
 def test_test_get_dict(self):
     key = 'key'
     value = hello_ontology.test_get_dict(key)
     value = ContractDataParser.to_utf8_str(value)
     self.assertEqual('value', value)
Esempio n. 28
0
    def test_add_and_remove_attribute(self):
        sdk.rpc.connect_to_test_net()
        sdk.restful.connect_to_test_net()
        ont_id = sdk.native_vm.ont_id()
        label = 'label'
        identity = sdk.wallet_manager.create_identity(label, password)
        ctrl_acct = sdk.wallet_manager.get_control_account_by_index(
            identity.ont_id, 0, password)
        gas_limit = 20000
        gas_price = 500
        tx_hash = sdk.native_vm.ont_id().registry_ont_id(
            identity.ont_id, ctrl_acct, acct3, gas_limit, gas_price)
        self.assertEqual(64, len(tx_hash))
        time.sleep(randint(6, 10))
        event = sdk.restful.get_smart_contract_event_by_tx_hash(tx_hash)
        hex_contract_address = sdk.native_vm.ont_id().contract_address
        notify = ContractEventParser.get_notify_list_by_contract_address(
            event, hex_contract_address)
        self.assertEqual(hex_contract_address, notify['ContractAddress'])
        self.assertEqual('Register', notify['States'][0])
        self.assertEqual(identity.ont_id, notify['States'][1])

        attribute = Attribute('hello', 'string', 'attribute')
        gas_limit = 20000
        gas_price = 500
        tx_hash = ont_id.add_attribute(identity.ont_id, ctrl_acct, attribute,
                                       acct2, gas_limit, gas_price)
        time.sleep(randint(6, 10))
        event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
        notify = ContractEventParser.get_notify_list_by_contract_address(
            event, hex_contract_address)
        self.assertEqual('Attribute', notify['States'][0])
        self.assertEqual('add', notify['States'][1])
        self.assertEqual(identity.ont_id, notify['States'][2])
        self.assertEqual(
            'hello', ContractDataParser.to_utf8_str(notify['States'][3][0]))

        attrib_key = 'hello'
        tx_hash = ont_id.remove_attribute(identity.ont_id, ctrl_acct,
                                          attrib_key, acct3, gas_limit,
                                          gas_price)
        time.sleep(randint(6, 10))
        event = sdk.rpc.get_smart_contract_event_by_tx_hash(tx_hash)
        notify = ContractEventParser.get_notify_list_by_contract_address(
            event, hex_contract_address)
        self.assertEqual('Attribute', notify['States'][0])
        self.assertEqual('remove', notify['States'][1])
        self.assertEqual(identity.ont_id, notify['States'][2])
        self.assertEqual('hello',
                         ContractDataParser.to_utf8_str(notify['States'][3]))
        try:
            ont_id.remove_attribute(identity.ont_id, ctrl_acct, attrib_key,
                                    acct3, gas_limit, gas_price)
        except SDKException as e:
            self.assertIn('attribute not exist', e.args[1])
        attrib_key = 'key'
        try:
            ont_id.remove_attribute(identity.ont_id, ctrl_acct, attrib_key,
                                    acct3, gas_limit, gas_price)
        except SDKException as e:
            self.assertIn('attribute not exist', e.args[1])