Ejemplo n.º 1
0
    def test_change_recovery(self):
        identity = sdk.wallet_manager.create_identity(password)
        ctrl_acct = sdk.wallet_manager.get_control_account_by_index(identity.did, 0, password)
        tx_hash = sdk.native_vm.did().registry_did(identity.did, ctrl_acct, acct3, self.gas_price,
                                                         self.gas_limit)
        self.assertEqual(64, len(tx_hash))
        time.sleep(randint(10, 15))
        event = sdk.restful.get_contract_event_by_tx_hash(tx_hash)
        hex_contract_address = sdk.native_vm.did().contract_address
        notify = Event.get_notify_by_contract_address(event, hex_contract_address)
        self.assertEqual(hex_contract_address, notify['ContractAddress'])
        self.assertEqual('Register', notify['States'][0])
        self.assertEqual(identity.did, notify['States'][1])

        rand_private_key = utils.get_random_bytes(32).hex()
        recovery = Account(rand_private_key, SignatureScheme.SHA256withECDSA)
        b58_recovery_address = recovery.get_address_base58()
        tx_hash = sdk.native_vm.did().add_recovery(identity.did, ctrl_acct, b58_recovery_address, acct2,
                                                      self.gas_price, self.gas_limit)
        time.sleep(randint(10, 15))
        event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
        notify = Event.get_notify_by_contract_address(event, hex_contract_address)
        self.assertEqual(hex_contract_address, notify['ContractAddress'])
        self.assertEqual('Recovery', notify['States'][0])
        self.assertEqual('add', notify['States'][1])
        self.assertEqual(identity.did, notify['States'][2])
        self.assertEqual(recovery.get_address_hex(little_endian=False), notify['States'][3])
        ddo = sdk.native_vm.did().get_ddo(identity.did)
        self.assertIn(ctrl_acct.get_did(), ddo['Owners'][0]['PubKeyId'])
        self.assertEqual('ECDSA', ddo['Owners'][0]['Type'])
        self.assertEqual('P256', ddo['Owners'][0]['Curve'])
        self.assertEqual(ctrl_acct.get_public_key_hex(), ddo['Owners'][0]['Value'])
        self.assertEqual(0, len(ddo['Attributes']))
        self.assertEqual(recovery.get_address_base58(), ddo['Recovery'])
        self.assertEqual(identity.did, ddo['DID'])

        rand_private_key = utils.get_random_bytes(32).hex()
        new_recovery = Account(rand_private_key, SignatureScheme.SHA256withECDSA)
        b58_new_recovery_address = new_recovery.get_address_base58()

        try:
            sdk.native_vm.did().change_recovery(identity.did, b58_new_recovery_address, ctrl_acct, acct2,
                                                   self.gas_price, self.gas_limit)
        except SDKException as e:
            self.assertIn('operator is not the recovery', e.args[1])
        tx_hash = sdk.native_vm.did().change_recovery(identity.did, b58_new_recovery_address, recovery, acct2,
                                                         self.gas_price, self.gas_limit)
        time.sleep(randint(10, 15))
        event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
        notify = Event.get_notify_by_contract_address(event, hex_contract_address)

        self.assertEqual(hex_contract_address, notify['ContractAddress'])
        self.assertEqual('Recovery', notify['States'][0])
        self.assertEqual('change', notify['States'][1])
        self.assertEqual(identity.did, notify['States'][2])
        self.assertEqual(new_recovery.get_address_hex(little_endian=False), notify['States'][3])
Ejemplo n.º 2
0
 async def test_transfer(self):
     amount = 1
     ont = sdk.native_vm.aio_ont()
     tx_hash = await ont.transfer(acct2, acct1.get_address(), amount, acct4, self.gas_price, self.gas_limit)
     await asyncio.sleep(randint(14, 20))
     event = await sdk.aio_rpc.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(event, ont.contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(acct2.get_address_base58(), notify['States'][1])
     self.assertEqual(acct1.get_address_base58(), notify['States'][2])
     self.assertEqual(amount, notify['States'][3])
     notify = Event.get_notify_by_contract_address(event, sdk.native_vm.aio_ong().contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(acct4.get_address_base58(), notify['States'][1])
     self.assertEqual(self.gas_price * self.gas_limit, notify['States'][3])
Ejemplo n.º 3
0
 def query_approve_event(self, tx_hash: str):
     event = self._sdk.default_network.get_contract_event_by_tx_hash(
         tx_hash)
     notify = Event.get_notify_by_contract_address(event,
                                                   self._contract_address)
     notify = NeoData.parse_addr_addr_int_notify(notify)
     return notify
Ejemplo n.º 4
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])
Ejemplo n.º 5
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])
Ejemplo n.º 6
0
 async def query_transfer_from_event(self, tx_hash: str):
     event = await self._sdk.default_aio_network.get_contract_event_by_tx_hash(
         tx_hash)
     notify = Event.get_notify_by_contract_address(event,
                                                   self._contract_address)
     notify = NeoData.parse_addr_addr_int_notify(notify)
     return notify
Ejemplo n.º 7
0
 async def test_subscribe(self):
     hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
     oep4 = sdk.neo_vm.aio_oep4(hex_contract_address)
     response = await sdk.websocket.subscribe(hex_contract_address, True, False, False, False)
     self.assertEqual([hex_contract_address], response['ContractsFilter'])
     self.assertEqual(True, response['SubscribeEvent'])
     self.assertEqual(False, response['SubscribeJsonBlock'])
     self.assertEqual(False, response['SubscribeRawBlock'])
     b58_to_address = acct2.get_address_base58()
     value = 10
     tx_hash = await oep4.transfer(acct1, b58_to_address, value, acct3, 500, 20000)
     self.assertEqual(64, len(tx_hash))
     try:
         event = await asyncio.wait_for(sdk.websocket.recv_subscribe_info(), timeout=10)
         self.assertEqual(False, response['SubscribeBlockTxHashs'])
         self.assertEqual(64, len(event['TxHash']))
         notify = Event.get_notify_by_contract_address(event, hex_contract_address)
         notify = NeoData.parse_addr_addr_int_notify(notify)
         self.assertEqual(hex_contract_address, notify['ContractAddress'])
         self.assertEqual('transfer', notify['States'][0])
         self.assertEqual(acct1.get_address_base58(), notify['States'][1])
         self.assertEqual(b58_to_address, notify['States'][2])
         self.assertEqual(value, notify['States'][3])
     except asyncio.TimeoutError:
         pass
     finally:
         await sdk.websocket.close_connect()
Ejemplo n.º 8
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 = NeoInvokeFunction('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] = NeoData.to_utf8_str(states[0])
     self.assertEqual('mapInfo', states[0])
     states[1] = NeoData.to_dict(states[1])
     self.assertTrue(isinstance(states[1], dict))
Ejemplo n.º 9
0
    async def test_add_and_remove_attribute(self):
        did = sdk.native_vm.aio_did()
        identity = sdk.wallet_manager.create_identity(password)
        ctrl_acct = sdk.wallet_manager.get_control_account_by_index(
            identity.did, 0, password)
        tx_hash = await did.registry_did(identity.did, ctrl_acct, acct3,
                                         self.gas_price, self.gas_limit)
        await self.check_register_did_event(identity.did, tx_hash)

        hex_contract_address = did.contract_address
        attribute = Attribute('hello', 'string', 'attribute')
        tx_hash = await did.add_attribute(identity.did, ctrl_acct, attribute,
                                          acct2, self.gas_price,
                                          self.gas_limit)
        await asyncio.sleep(randint(10, 15))
        event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
        notify = Event.get_notify_by_contract_address(event,
                                                      hex_contract_address)
        self.assertEqual('Attribute', notify['States'][0])
        self.assertEqual('add', notify['States'][1])
        self.assertEqual(identity.did, notify['States'][2])
        self.assertEqual('hello', NeoData.to_utf8_str(notify['States'][3][0]))

        attrib_key = 'hello'
        tx_hash = await did.remove_attribute(identity.did, ctrl_acct,
                                             attrib_key, acct3, self.gas_price,
                                             self.gas_limit)
        await asyncio.sleep(randint(10, 15))
        event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
        notify = Event.get_notify_by_contract_address(event,
                                                      hex_contract_address)
        self.assertEqual('Attribute', notify['States'][0])
        self.assertEqual('remove', notify['States'][1])
        self.assertEqual(identity.did, notify['States'][2])
        self.assertEqual('hello', NeoData.to_utf8_str(notify['States'][3]))
        try:
            await did.remove_attribute(identity.did, ctrl_acct, attrib_key,
                                       acct3, self.gas_price, self.gas_limit)
        except SDKException as e:
            self.assertIn('attribute not exist', e.args[1])
        attrib_key = 'key'
        try:
            await did.remove_attribute(identity.did, ctrl_acct, attrib_key,
                                       acct3, self.gas_price, self.gas_limit)
        except SDKException as e:
            self.assertIn('attribute not exist', e.args[1])
Ejemplo n.º 10
0
 def _parse_multi_transfer_event(self, event: dict):
     notify_list = Event.get_notify_by_contract_address(
         event, self._contract_address)
     for index, notify in enumerate(notify_list):
         if notify.get('ContractAddress', '') == self._contract_address:
             notify_list[index] = NeoData.parse_addr_addr_int_notify(
                 notify_list[index])
     return notify_list
Ejemplo n.º 11
0
 def test_transfer(self):
     amount = 1
     gas = sdk.native_vm.gas()
     tx_hash = gas.transfer(acct1, acct2.get_address(), amount, acct4,
                            self.gas_price, self.gas_limit)
     time.sleep(randint(14, 20))
     event = sdk.default_network.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(event,
                                                   gas.contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(acct1.get_address_base58(), notify['States'][1])
     self.assertEqual(acct2.get_address_base58(), notify['States'][2])
     self.assertEqual(amount, notify['States'][3])
     notify = Event.get_notify_by_contract_address(
         event,
         sdk.native_vm.aio_ong().contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(acct4.get_address_base58(), notify['States'][1])
     self.assertEqual(self.gas_price * self.gas_limit, notify['States'][3])
Ejemplo n.º 12
0
 async def test_withdraw_ong(self):
     amount, gas_price, gas_limit = 1, 500, 20000
     tx_hash = await sdk.native_vm.aio_ong().withdraw(
         acct1, acct1.get_address(), amount, acct2, gas_price, gas_limit)
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(14, 20))
     event = await sdk.aio_rpc.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(
         event,
         sdk.native_vm.aio_ong().contract_address)
     self.assertEqual('transfer', notify[0]['States'][0])
     self.assertEqual(acct1.get_address_base58(), notify[0]['States'][2])
     self.assertEqual(amount, notify[0]['States'][3])
     notify = Event.get_notify_by_contract_address(
         event,
         sdk.native_vm.aio_ong().contract_address)
     self.assertEqual('transfer', notify[1]['States'][0])
     self.assertEqual(acct2.get_address_base58(), notify[1]['States'][1])
     self.assertEqual(gas_price * gas_limit, notify[1]['States'][3])
Ejemplo n.º 13
0
    def test_invoke_transaction(self):
        """
        from dna.interop.System.Runtime import Notify

        def main(operation, args):
            if operation == 'hello':
                return hello(args[0])
            return False


        def hello(msg):
            Notify(["hello", msg])
            return msg
        """
        avm_code = '51c56b6c58c56b6a00527ac46a51527ac46a52527ac46a51c30568656c6c6f7d9c7c756427' \
                   '00006a53527ac46a52c300c3516a53c3936a53527ac46a53c36a00c365f2006c7566620300' \
                   '006c75660111c56b6a00527ac46a51527ac46a51c300947600a0640c00c16a52527ac4620e' \
                   '007562030000c56a52527ac46a52c3c0517d9c7c75641c00006a53527ac46a52c300c36a54' \
                   '527ac4516a55527ac4625c006a52c3c0527d9c7c756421006a52c300c36a53527ac46a52c3' \
                   '51c36a54527ac4516a55527ac4616232006a52c3c0537d9c7c756424006a52c300c36a5352' \
                   '7ac46a52c351c36a54527ac46a52c352c36a55527ac462050000f100c176c96a56527ac46a' \
                   '53c36a57527ac46a57c36a54c37d9f7c756419006a56c36a57c3c86a57c36a55c3936a5752' \
                   '7ac462e0ff6a56c36c756656c56b6a00527ac46a51527ac46a52527ac46203000568656c6c' \
                   '6f6a52c352c176c9681553797374656d2e52756e74696d652e4e6f746966796a52c36c7566'
        contract_address = sdk.neo_vm.address_from_avm_code(avm_code).hex()
        self.assertEqual('f7b9970fd6def5229c1f30ad15372bd1c20bb260',
                         contract_address)
        hello = NeoInvokeFunction('hello')
        hello.set_params_value('dna')
        tx = sdk.neo_vm.make_invoke_transaction(contract_address, hello,
                                                acct1.get_address_base58(),
                                                500, 20000)
        response = sdk.rpc.send_raw_transaction_pre_exec(tx)
        self.assertEqual(1, response['State'])
        response['Result'] = NeoData.to_utf8_str(response['Result'])
        self.assertEqual('dna', response['Result'])
        tx.sign_transaction(acct1)
        tx_hash = sdk.rpc.send_raw_transaction(tx)
        sleep(10)
        for _ in range(5):
            try:
                event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
                if isinstance(event, dict) and event.get('Notify', '') != '':
                    notify = Event.get_notify_by_contract_address(
                        event, contract_address)
                    self.assertEqual(contract_address,
                                     notify['ContractAddress'])
                    self.assertEqual('hello',
                                     NeoData.to_utf8_str(notify['States'][0]))
                    self.assertEqual('dna',
                                     NeoData.to_utf8_str(notify['States'][1]))
                    break
            except SDKException:
                continue
            sleep(2)
Ejemplo n.º 14
0
 def query_revoke_event(self, tx_hash: str):
     event = self._sdk.default_network.get_contract_event_by_tx_hash(
         tx_hash)
     notify = Event.get_notify_by_contract_address(
         event, self.__hex_contract_address)
     if len(notify['States']) == 4:
         notify['States'][0] = NeoData.to_utf8_str(notify['States'][0])
         notify['States'][1] = NeoData.to_b58_address(notify['States'][1])
         notify['States'][2] = NeoData.to_utf8_str(notify['States'][2])
         notify['States'][3] = NeoData.to_hex_str(notify['States'][3])
     return notify
Ejemplo n.º 15
0
 async def check_register_did_event(self, did: str, tx_hash: str):
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(10, 15))
     event = await sdk.default_aio_network.get_contract_event_by_tx_hash(
         tx_hash)
     hex_contract_address = sdk.native_vm.aio_did().contract_address
     notify = Event.get_notify_by_contract_address(event,
                                                   hex_contract_address)
     self.assertEqual(hex_contract_address, notify['ContractAddress'])
     self.assertEqual('Register', notify['States'][0])
     self.assertEqual(did, notify['States'][1])
Ejemplo n.º 16
0
 def test_init(self):
     oep4 = sdk.neo_vm.oep4()
     oep4.hex_contract_address = self.contract_address
     tx_hash = oep4.init(acct1, acct2, self.gas_price, self.gas_limit)
     self.assertEqual(len(tx_hash), 64)
     time.sleep(randint(10, 15))
     event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(
         event, oep4.hex_contract_address)
     self.assertEqual('Already initialized!',
                      NeoData.to_utf8_str(notify['States']))
Ejemplo n.º 17
0
 async def test_transfer_from(self):
     sdk.rpc.connect_to_localhost()
     b58_from_address = acct1.get_address_base58()
     b58_recv_address = acct2.get_address_base58()
     ont = sdk.native_vm.aio_ont()
     amount = 1
     tx_hash = await ont.transfer_from(acct2, b58_from_address, b58_recv_address, amount, acct2, self.gas_price,
                                       self.gas_limit)
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(10, 15))
     event = await sdk.aio_rpc.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(event, sdk.native_vm.ong().contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(b58_recv_address, notify['States'][1])
     self.assertEqual(self.gas_price * self.gas_limit, notify['States'][3])
     notify = Event.get_notify_by_contract_address(event, sdk.native_vm.ont().contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(b58_from_address, notify['States'][1])
     self.assertEqual(b58_recv_address, notify['States'][2])
     self.assertEqual(amount, notify['States'][3])
Ejemplo n.º 18
0
 async def test_init(self):
     oep4 = sdk.neo_vm.aio_oep4()
     oep4.hex_contract_address = contract_address
     tx_hash = await oep4.init(acct1, acct2, 500, 20000000)
     self.assertEqual(len(tx_hash), 64)
     await asyncio.sleep(randint(14, 20))
     event = await sdk.default_aio_network.get_contract_event_by_tx_hash(
         tx_hash)
     notify = Event.get_notify_by_contract_address(
         event, oep4.hex_contract_address)
     self.assertEqual('Already initialized!',
                      NeoData.to_utf8_str(notify['States']))
Ejemplo n.º 19
0
 async def test_transfer_from_tx(self):
     acct2_b58_address = acct2.get_address_base58()
     tx_hash = await sdk.native_vm.aio_ont().transfer_from(acct2, acct1.get_address(), acct2_b58_address, 1, acct2,
                                                           self.gas_price, self.gas_limit)
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(14, 20))
     event = await sdk.aio_rpc.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(event, sdk.native_vm.aio_ont().contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(acct1.get_address_base58(), notify['States'][1])
     self.assertEqual(acct2.get_address_base58(), notify['States'][2])
     self.assertEqual(1, notify['States'][3])
Ejemplo n.º 20
0
 async def check_revoke_pk_event(self, did: str, tx_hash: str,
                                 hex_public_key: str):
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(10, 15))
     event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
     hex_contract_address = sdk.native_vm.aio_did().contract_address
     notify = Event.get_notify_by_contract_address(event,
                                                   hex_contract_address)
     self.assertIn('PublicKey', notify['States'])
     self.assertIn('remove', notify['States'])
     self.assertIn(did, notify['States'])
     self.assertIn(hex_public_key, notify['States'])
Ejemplo n.º 21
0
 async def test_transfer_from_tx(self):
     acct2_b58_address = acct2.get_address_base58()
     tx_hash = await sdk.native_vm.aio_ong().transfer_from(
         acct2, acct1.get_address(), acct2_b58_address, 1, acct2, 500,
         20000)
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(14, 20))
     event = await sdk.aio_rpc.get_contract_event_by_tx_hash(tx_hash)
     notify_list = Event.get_notify_by_contract_address(
         event,
         sdk.native_vm.aio_ong().contract_address)
     self.assertEqual(2, len(notify_list))
Ejemplo n.º 22
0
 async def check_add_pk_event(self, did: str, tx_hash: str,
                              new_hex_public_key: str):
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(10, 15))
     event = await sdk.default_aio_network.get_contract_event_by_tx_hash(
         tx_hash)
     hex_contract_address = sdk.native_vm.aio_did().contract_address
     notify = Event.get_notify_by_contract_address(event,
                                                   hex_contract_address)
     self.assertIn('PublicKey', notify['States'])
     self.assertIn('add', notify['States'])
     self.assertIn(did, notify['States'])
     self.assertIn(new_hex_public_key, notify['States'])
Ejemplo n.º 23
0
 async def test_transfer_from(self):
     sdk.rpc.connect_to_localhost()
     b58_from_address = acct1.get_address_base58()
     b58_recv_address = acct2.get_address_base58()
     ong = sdk.native_vm.aio_ong()
     tx_hash = await ong.transfer_from(acct2, b58_from_address,
                                       b58_recv_address, 1, acct2, 500,
                                       20000)
     self.assertEqual(64, len(tx_hash))
     await asyncio.sleep(randint(14, 20))
     event = await sdk.aio_rpc.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(event,
                                                   ong.contract_address)
     self.assertEqual(2, len(notify))
Ejemplo n.º 24
0
 def test_transfer_from(self):
     b58_from_address = acct2.get_address_base58()
     b58_recv_address = acct1.get_address_base58()
     gas = sdk.native_vm.gas()
     amount = 1
     tx_hash = gas.transfer_from(acct1, b58_from_address, b58_recv_address,
                                 amount, acct2, self.gas_price,
                                 self.gas_limit)
     self.assertEqual(64, len(tx_hash))
     time.sleep(randint(10, 15))
     event = sdk.default_network.get_contract_event_by_tx_hash(tx_hash)
     notify = Event.get_notify_by_contract_address(
         event,
         sdk.native_vm.ong().contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(b58_from_address, notify['States'][1])
     self.assertEqual(self.gas_price * self.gas_limit, notify['States'][3])
     notify = Event.get_notify_by_contract_address(
         event,
         sdk.native_vm.gas().contract_address)
     self.assertEqual('transfer', notify['States'][0])
     self.assertEqual(b58_from_address, notify['States'][1])
     self.assertEqual(b58_recv_address, notify['States'][2])
     self.assertEqual(amount, notify['States'][3])
Ejemplo n.º 25
0
    def test_verify_signature(self):
        identity = sdk.wallet_manager.create_identity(password)
        ctrl_acct = sdk.wallet_manager.get_control_account_by_index(identity.did, 0, password)
        did = sdk.native_vm.did()
        tx_hash = did.registry_did(identity.did, ctrl_acct, acct3, self.gas_price, self.gas_limit)
        self.assertEqual(64, len(tx_hash))
        time.sleep(randint(10, 15))
        event = sdk.default_network.get_contract_event_by_tx_hash(tx_hash)
        hex_contract_address = did.contract_address
        notify = Event.get_notify_by_contract_address(event, hex_contract_address)
        self.assertEqual(hex_contract_address, notify['ContractAddress'])
        self.assertEqual('Register', notify['States'][0])
        self.assertEqual(identity.did, notify['States'][1])

        private_key = utils.get_random_bytes(32)
        public_key = Signature.ec_get_public_key_by_private_key(private_key, Curve.P256)
        new_ctrl_acct = Account(private_key)
        hex_new_public_key = public_key.hex()

        tx_hash = did.add_public_key(identity.did, ctrl_acct, hex_new_public_key, acct4, self.gas_price,
                                        self.gas_limit)
        time.sleep(randint(10, 15))
        event = sdk.default_network.get_contract_event_by_tx_hash(tx_hash)
        notify = Event.get_notify_by_contract_address(event, hex_contract_address)
        self.assertIn('PublicKey', notify['States'])
        self.assertIn('add', notify['States'])
        self.assertIn(identity.did, notify['States'])
        self.assertIn(hex_new_public_key, notify['States'])
        result = did.verify_signature(identity.did, 1, ctrl_acct)
        self.assertTrue(result)
        result = did.verify_signature(identity.did, 2, ctrl_acct)
        self.assertFalse(result)
        result = did.verify_signature(identity.did, 1, new_ctrl_acct)
        self.assertFalse(result)
        result = did.verify_signature(identity.did, 2, new_ctrl_acct)
        self.assertTrue(result)
Ejemplo n.º 26
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])
Ejemplo n.º 27
0
 def test_transfer_tx(self):
     amount = 100
     func = WasmInvokeFunction('transfer')
     func.set_params_value(acct1.get_address(), Address.b58decode('AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve'), amount)
     tx = sdk.wasm_vm.make_invoke_transaction(self.oep4_contract_address, func, acct2.get_address(), self.gas_price,
                                              self.gas_limit)
     target_payload = '0faeff23255536928b308e5caa38bc2dc14f30c341087472616e7366657246b1a18af6b7c9f8a4602f9f73' \
                      'eeb3030f0c29b7d2c124dd088190f709b684e0bc676d70c41b377664000000000000000000000000000000'
     self.assertEqual(target_payload, tx.payload.hex())
     tx.sign_transaction(acct1, acct2)
     result = sdk.rpc.send_raw_transaction_pre_exec(tx)
     self.assertEqual('01', result.get('Result'))
     self.assertEqual(1, result.get('State'))
     notify_list = Event.get_event_from_event_list_by_contract_address(result.get('Notify'),
                                                                       self.oep4_contract_address)
     self.assertEqual(self.oep4_contract_address, notify_list[0].get('ContractAddress'))
     states = notify_list[1].get('States')
     self.assertEqual('transfer', WasmData.to_utf8(states[0]))
     self.assertEqual(acct1.get_address().b58encode(), WasmData.to_b58_address(states[1]))
     self.assertEqual('AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve', WasmData.to_b58_address(states[2]))
     self.assertEqual(amount, WasmData.to_int(states[3]))
Ejemplo n.º 28
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])
Ejemplo n.º 29
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])
Ejemplo n.º 30
0
 def get_did_contract_notify(self, tx_hash: str):
     self.assertEqual(64, len(tx_hash))
     time.sleep(randint(10, 15))
     event = sdk.default_network.get_contract_event_by_tx_hash(tx_hash)
     return Event.get_notify_by_contract_address(event, sdk.native_vm.did().contract_address)