Exemple #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 = InvokeFunction('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] = Data.to_utf8_str(states[0])
     states[1][0][0] = Data.to_b58_address(states[1][0][0])
     self.assertEqual(acct1.get_address_base58(), states[1][0][0])
     states[1][0][1] = Data.to_b58_address(states[1][0][1])
     self.assertEqual(acct2.get_address_base58(), states[1][0][1])
     states[1][0][2] = Data.to_int(states[1][0][2])
     self.assertEqual(10, states[1][0][2])
     states[1][1][0] = Data.to_b58_address(states[1][1][0])
     self.assertEqual(acct2.get_address_base58(), states[1][1][0])
     states[1][1][1] = Data.to_b58_address(states[1][1][1])
     self.assertEqual(acct3.get_address_base58(), states[1][1][1])
     states[1][1][2] = Data.to_int(states[1][1][2])
     self.assertEqual(100, states[1][1][2])
Exemple #2
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, 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 = Event.get_states_by_contract_address(event,
                                                   hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     self.assertEqual('mapInfo', states[0])
     states[1] = Data.to_dict(states[1])
     self.assertTrue(isinstance(states[1], dict))
Exemple #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 = 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] = Data.to_utf8_str(states[0])
     self.assertEqual('testHello', states[0])
     states[1] = Data.to_bool(states[1])
     self.assertEqual(bool_msg, states[1])
     states[2] = Data.to_int(states[2])
     self.assertEqual(int_msg, states[2])
     states[3] = Data.to_bytes(states[3])
     self.assertEqual(bytes_msg, states[3])
     states[4] = Data.to_utf8_str(states[4])
     self.assertEqual(str_msg, states[4])
     states[5] = Data.to_b58_address(states[5])
     self.assertEqual(acct1.get_address_base58(), states[5])
Exemple #4
0
 def test_test_list_and_str(self):
     list_msg = [1, 2, 3]
     tx_hash = self.hello_ontology.test_list(list_msg, self.acct, gas_limit, gas_price)
     time.sleep(6)
     event = self.ontology.rpc.get_contract_event_by_tx_hash(tx_hash)
     states = Event.get_states_by_contract_address(event, self.hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     self.assertEqual('testMsgList', states[0])
     states[1] = Data.to_int_list(states[1])
     self.assertEqual(list_msg, states[1])
Exemple #5
0
 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 = self.hello_ontology.test_dict_in_ctx(dict_msg, self.acct, gas_limit, gas_price)
     time.sleep(6)
     event = self.ontology.rpc.get_contract_event_by_tx_hash(tx_hash)
     states = Event.get_states_by_contract_address(event, self.hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     self.assertEqual('mapInfo', states[0])
     states[1] = Data.to_dict(states[1])
     self.assertTrue(isinstance(states[1], dict))
Exemple #6
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 = 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] = Data.to_utf8_str(states[0])
     self.assertEqual('testMsgList', states[0])
     states[1] = Data.to_int_list(states[1])
     self.assertEqual(list_msg, states[1])
Exemple #7
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)
     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] = Data.to_utf8_str(states[0])
     self.assertEqual('transfer', states[0])
     states[1] = Data.to_b58_address(states[1])
     self.assertEqual(acct1.get_address().b58encode(), states[1])
     states[2] = Data.to_b58_address(states[2])
     self.assertEqual(acct2.get_address().b58encode(), states[2])
     states[3] = Data.to_int(states[3])
     self.assertEqual(value, states[3])
Exemple #8
0
 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 = self.hello_ontology.test_struct_list_and_str(struct_list, str_msg, self.acct, gas_limit, gas_price)
     time.sleep(6)
     event = self.ontology.rpc.get_contract_event_by_tx_hash(tx_hash)
     states = Event.get_states_by_contract_address(event, self.hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     states[1][0] = Data.to_bool(states[1][0])
     self.assertEqual(bool_msg, states[1][0])
     states[1][1] = Data.to_int(states[1][1])
     self.assertEqual(int_msg, states[1][1])
     states[1][2] = Data.to_bytes(states[1][2])
     self.assertEqual(bytes_msg, states[1][2])
     states[1][3] = Data.to_utf8_str(states[1][3])
     self.assertEqual(str_msg, states[1][3])
     states[1][4] = Data.to_int_list(states[1][4])
     self.assertEqual(list_msg, states[1][4])
     states[2] = Data.to_utf8_str(states[2])
Exemple #9
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)
        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] = Data.to_utf8_str(states_list[0][0])
        self.assertEqual('transfer', states_list[0][0])
        states_list[0][1] = Data.to_b58_address(states_list[0][1])
        self.assertEqual(acct1.get_address().b58encode(), states_list[0][1])
        states_list[0][2] = Data.to_b58_address(states_list[0][2])
        self.assertEqual(acct2.get_address().b58encode(), states_list[0][2])
        states_list[0][3] = Data.to_int(states_list[0][3])
        self.assertEqual(value1, states_list[0][3])

        states_list[1][0] = Data.to_utf8_str(states_list[1][0])
        self.assertEqual('transfer', states_list[1][0])
        states_list[1][1] = Data.to_b58_address(states_list[1][1])
        self.assertEqual(acct2.get_address().b58encode(), states_list[1][1])
        states_list[1][2] = Data.to_b58_address(states_list[1][2])
        self.assertEqual(acct3.get_address().b58encode(), states_list[1][2])
        states_list[1][3] = Data.to_int(states_list[1][3])
        self.assertEqual(value2, states_list[1][3])
Exemple #10
0
 def test_test_hello(self):
     bool_msg = True
     int_msg = 1
     bytes_msg = b'Hello'
     str_msg = 'Hello'
     address_msg = self.acct.get_address().to_bytes()
     tx_hash = self.hello_ontology.test_hello(bool_msg, int_msg, bytes_msg, str_msg, address_msg, self.acct,
                                              gas_limit,
                                              gas_price)
     time.sleep(6)
     event = self.ontology.rpc.get_contract_event_by_tx_hash(tx_hash)
     states = Event.get_states_by_contract_address(event, self.hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     self.assertEqual('testHello', states[0])
     states[1] = Data.to_bool(states[1])
     self.assertEqual(bool_msg, states[1])
     states[2] = Data.to_int(states[2])
     self.assertEqual(int_msg, states[2])
     states[3] = Data.to_bytes(states[3])
     self.assertEqual(bytes_msg, states[3])
     states[4] = Data.to_utf8_str(states[4])
     self.assertEqual(str_msg, states[4])
     states[5] = Data.to_b58_address(states[5])
     self.assertEqual(self.acct.get_address_base58(), states[5])