Add admin api registry, proxy, resend tests
This commit is contained in:
		
							parent
							
								
									1c86d55043
								
							
						
					
					
						commit
						9558e20cc0
					
				| @ -5,6 +5,5 @@ omit = | ||||
| 	cic_eth/db/migrations/* | ||||
| 	cic_eth/sync/head.py | ||||
| 	cic_eth/sync/mempool.py | ||||
| 	cic_eth/eth/state.py | ||||
| 	cic_eth/admin/nonce.py | ||||
| 	cic_eth/queue/state.py | ||||
| 	*redis*.py | ||||
|  | ||||
| @ -92,16 +92,9 @@ def shift_nonce(self, chain_str, tx_hash_orig_hex, delta=1): | ||||
|         logg.debug('tx_nex {}'.format(tx_new)) | ||||
|         gas_oracle = OverrideGasOracle(limit=tx_new['gas'], price=tx_new['gas_price'] + 1) # TODO: it should be possible to merely set this price here and if missing in the existing struct then fill it in (chainlib.eth.tx) | ||||
|         c = TxFactory(chain_spec, signer=rpc_signer, gas_oracle=gas_oracle) | ||||
|         #(tx_hash_hex, tx_signed_raw_hex) = sign_tx(tx_new, chain_str) | ||||
|         (tx_hash_hex, tx_signed_raw_hex) = c.build_raw(tx_new) | ||||
|         logg.debug('tx {} -> {} nonce {} -> {}'.format(tx_previous_hash_hex, tx_hash_hex, tx_previous_nonce, tx_new['nonce'])) | ||||
| 
 | ||||
| #        otx = Otx( | ||||
| #            nonce=tx_new['nonce'], | ||||
| #            address=tx_new['from'], | ||||
| #            tx_hash=tx_hash_hex, | ||||
| #            signed_tx=tx_signed_raw_hex, | ||||
| #                ) | ||||
|         otx = Otx( | ||||
|             tx_new['nonce'], | ||||
|             tx_hash_hex, | ||||
|  | ||||
| @ -188,6 +188,7 @@ class AdminApi: | ||||
|         s_manual = celery.signature( | ||||
|             'cic_eth.queue.state.set_manual', | ||||
|             [ | ||||
|                 chain_spec.asdict(), | ||||
|                 tx_hash_hex, | ||||
|                 ], | ||||
|             queue=self.queue, | ||||
| @ -207,6 +208,7 @@ class AdminApi: | ||||
| 
 | ||||
|         return s_manual.apply_async() | ||||
|                      | ||||
| 
 | ||||
|     def check_nonce(self, address): | ||||
|         s = celery.signature( | ||||
|                 'cic_eth.queue.query.get_account_tx', | ||||
|  | ||||
| @ -36,150 +36,6 @@ from cic_eth.queue.tx import queue_create | ||||
| logg = logging.getLogger() | ||||
| 
 | ||||
| 
 | ||||
| #def test_resend_inplace( | ||||
| #    default_chain_spec, | ||||
| #    init_database, | ||||
| #    init_w3, | ||||
| #    celery_session_worker, | ||||
| #    ): | ||||
| #     | ||||
| #    chain_str = str(default_chain_spec) | ||||
| #    c = RpcClient(default_chain_spec) | ||||
| #     | ||||
| #    sigs = [] | ||||
| # | ||||
| #    gas_provider = c.gas_provider() | ||||
| # | ||||
| #    s_nonce = celery.signature( | ||||
| #        'cic_eth.eth.nonce.reserve_nonce', | ||||
| #        [ | ||||
| #            init_w3.eth.accounts[0], | ||||
| #            gas_provider, | ||||
| #            ], | ||||
| #        queue=None, | ||||
| #        ) | ||||
| #    s_refill = celery.signature( | ||||
| #        'cic_eth.eth.gas.refill_gas', | ||||
| #        [ | ||||
| #            chain_str, | ||||
| #            ], | ||||
| #        queue=None, | ||||
| #            ) | ||||
| #    s_nonce.link(s_refill) | ||||
| #    t = s_nonce.apply_async() | ||||
| #    t.get() | ||||
| #    for r in t.collect(): | ||||
| #        pass | ||||
| #    assert t.successful() | ||||
| # | ||||
| #    q = init_database.query(Otx) | ||||
| #    q = q.join(TxCache) | ||||
| #    q = q.filter(TxCache.recipient==init_w3.eth.accounts[0]) | ||||
| #    o = q.first() | ||||
| #    tx_raw = o.signed_tx | ||||
| # | ||||
| #    tx_dict = unpack(bytes.fromhex(tx_raw), default_chain_spec) | ||||
| #    gas_price_before = tx_dict['gasPrice']  | ||||
| # | ||||
| #    s = celery.signature( | ||||
| #        'cic_eth.admin.ctrl.lock_send', | ||||
| #        [ | ||||
| #            chain_str, | ||||
| #            init_w3.eth.accounts[0], | ||||
| #            ], | ||||
| #        queue=None, | ||||
| #            ) | ||||
| #    t = s.apply_async() | ||||
| #    t.get() | ||||
| #    assert t.successful() | ||||
| # | ||||
| #    api = AdminApi(c, queue=None) | ||||
| #    t = api.resend(tx_dict['hash'], chain_str, unlock=True) | ||||
| #    t.get() | ||||
| #    i = 0 | ||||
| #    tx_hash_new_hex = None | ||||
| #    for r in t.collect(): | ||||
| #        tx_hash_new_hex = r[1] | ||||
| #    assert t.successful() | ||||
| #   | ||||
| #    tx_raw_new = get_tx(tx_hash_new_hex)  | ||||
| #    logg.debug('get {}'.format(tx_raw_new)) | ||||
| #    tx_dict_new = unpack(bytes.fromhex(tx_raw_new['signed_tx']), default_chain_spec) | ||||
| #    assert tx_hash_new_hex != tx_dict['hash'] | ||||
| #    assert tx_dict_new['gasPrice'] > gas_price_before | ||||
| # | ||||
| #    tx_dict_after = get_tx(tx_dict['hash']) | ||||
| # | ||||
| #    logg.debug('logggg {}'.format(status_str(tx_dict_after['status']))) | ||||
| #    assert tx_dict_after['status'] & StatusBits.MANUAL | ||||
| 
 | ||||
| 
 | ||||
| #def test_check_fix_nonce( | ||||
| #    default_chain_spec, | ||||
| #    init_database, | ||||
| #    init_eth_account_roles, | ||||
| #    init_w3, | ||||
| #    eth_empty_accounts, | ||||
| #    celery_session_worker, | ||||
| #    ): | ||||
| # | ||||
| #    chain_str = str(default_chain_spec) | ||||
| #     | ||||
| #    sigs = [] | ||||
| #    for i in range(5): | ||||
| #        s = celery.signature( | ||||
| #            'cic_eth.eth.gas.refill_gas', | ||||
| #            [ | ||||
| #                eth_empty_accounts[i], | ||||
| #                chain_str, | ||||
| #                ], | ||||
| #            queue=None, | ||||
| #                ) | ||||
| #        sigs.append(s) | ||||
| # | ||||
| #    t = celery.group(sigs)() | ||||
| #    txs = t.get() | ||||
| #    assert t.successful() | ||||
| # | ||||
| #    tx_hash = web3.Web3.keccak(hexstr=txs[2]) | ||||
| #    c = RpcClient(default_chain_spec) | ||||
| #    api = AdminApi(c, queue=None) | ||||
| #    address = init_eth_account_roles['eth_account_gas_provider'] | ||||
| #    nonce_spec = api.check_nonce(address) | ||||
| #    assert nonce_spec['nonce']['network'] == 0 | ||||
| #    assert nonce_spec['nonce']['queue'] == 4 | ||||
| #    assert nonce_spec['nonce']['blocking'] == None | ||||
| # | ||||
| #    s_set = celery.signature( | ||||
| #            'cic_eth.queue.tx.set_rejected', | ||||
| #            [ | ||||
| #                tx_hash.hex(), | ||||
| #                ], | ||||
| #            queue=None, | ||||
| #            ) | ||||
| #    t = s_set.apply_async() | ||||
| #    t.get() | ||||
| #    t.collect() | ||||
| #    assert t.successful() | ||||
| # | ||||
| # | ||||
| #    nonce_spec = api.check_nonce(address) | ||||
| #    assert nonce_spec['nonce']['blocking'] == 2 | ||||
| #    assert nonce_spec['tx']['blocking'] == tx_hash.hex() | ||||
| # | ||||
| #    t = api.fix_nonce(address, nonce_spec['nonce']['blocking']) | ||||
| #    t.get() | ||||
| #    t.collect() | ||||
| #    assert t.successful() | ||||
| # | ||||
| #    for tx in txs[3:]: | ||||
| #        tx_hash = web3.Web3.keccak(hexstr=tx) | ||||
| #        tx_dict = get_tx(tx_hash.hex()) | ||||
| #        assert tx_dict['status'] == StatusEnum.OVERRIDDEN | ||||
| # | ||||
| # | ||||
| 
 | ||||
| 
 | ||||
| def test_have_account( | ||||
|     default_chain_spec, | ||||
|     custodial_roles, | ||||
|  | ||||
							
								
								
									
										163
									
								
								apps/cic-eth/tests/task/api/test_admin_noncritical.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										163
									
								
								apps/cic-eth/tests/task/api/test_admin_noncritical.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,163 @@ | ||||
| # external imports | ||||
| import pytest | ||||
| from chainlib.connection import RPCConnection | ||||
| from chainlib.eth.nonce import OverrideNonceOracle | ||||
| from chainqueue.tx import create as queue_create | ||||
| from chainlib.eth.tx import ( | ||||
|         TxFormat, | ||||
|         ) | ||||
| from chainlib.eth.block import block_latest | ||||
| from chainlib.eth.gas import ( | ||||
|         Gas, | ||||
|         OverrideGasOracle, | ||||
|         ) | ||||
| from chainqueue.state import ( | ||||
|         set_reserved, | ||||
|         set_sent, | ||||
|         set_ready, | ||||
|         ) | ||||
| from chainqueue.db.models.otx import Otx | ||||
| from chainqueue.db.enum import StatusBits | ||||
| from chainqueue.query import get_nonce_tx_cache | ||||
| 
 | ||||
| # local imports | ||||
| from cic_eth.api.api_admin import AdminApi | ||||
| from cic_eth.eth.gas import cache_gas_data | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.skip() | ||||
| def test_registry( | ||||
|         eth_rpc, | ||||
|         cic_registry, | ||||
|         contract_roles, | ||||
|         celery_session_worker, | ||||
|         ): | ||||
| 
 | ||||
|     api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) | ||||
|     t = api.registry() | ||||
|     r = t.get_leaf() | ||||
|     assert r == cic_registry | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.skip() | ||||
| def test_proxy_do( | ||||
|         default_chain_spec, | ||||
|         eth_rpc, | ||||
|         contract_roles, | ||||
|         celery_session_worker, | ||||
|         ): | ||||
| 
 | ||||
|     o = block_latest() | ||||
|     r = eth_rpc.do(o) | ||||
|      | ||||
|     api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) | ||||
|     t = api.proxy_do(default_chain_spec, o) | ||||
|     rr = t.get_leaf() | ||||
| 
 | ||||
|     assert r == rr | ||||
| 
 | ||||
| 
 | ||||
| def test_resend_inplace( | ||||
|         init_database, | ||||
|         default_chain_spec, | ||||
|         eth_rpc, | ||||
|         eth_signer, | ||||
|         agent_roles, | ||||
|         contract_roles, | ||||
|         celery_worker, | ||||
|         ): | ||||
| 
 | ||||
|     rpc = RPCConnection.connect(default_chain_spec, 'default') | ||||
|     nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) | ||||
|     gas_oracle = OverrideGasOracle(price=1000000000, limit=21000) | ||||
|     c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) | ||||
|     (tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED) | ||||
| 
 | ||||
|     queue_create( | ||||
|             default_chain_spec, | ||||
|             42, | ||||
|             agent_roles['ALICE'], | ||||
|             tx_hash_hex, | ||||
|             tx_signed_raw_hex, | ||||
|             session=init_database, | ||||
|             ) | ||||
|     cache_gas_data( | ||||
|             tx_hash_hex, | ||||
|             tx_signed_raw_hex, | ||||
|             default_chain_spec.asdict(), | ||||
|             ) | ||||
| 
 | ||||
|     set_ready(default_chain_spec, tx_hash_hex, session=init_database) | ||||
|     set_reserved(default_chain_spec, tx_hash_hex, session=init_database) | ||||
|     set_sent(default_chain_spec, tx_hash_hex, session=init_database) | ||||
| 
 | ||||
|     init_database.commit() | ||||
| 
 | ||||
|     api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) | ||||
|     t = api.resend(tx_hash_hex, default_chain_spec) | ||||
|     r = t.get_leaf() | ||||
|     assert t.successful() | ||||
| 
 | ||||
| 
 | ||||
|     otx = Otx.load(tx_hash_hex, session=init_database) | ||||
|     assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE | ||||
| 
 | ||||
|     txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database) | ||||
|     assert len(txs) == 2 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.xfail() | ||||
| def test_resend_clone( | ||||
|         init_database, | ||||
|         default_chain_spec, | ||||
|         eth_rpc, | ||||
|         eth_signer, | ||||
|         agent_roles, | ||||
|         contract_roles, | ||||
|         celery_worker, | ||||
|         ): | ||||
| 
 | ||||
|     rpc = RPCConnection.connect(default_chain_spec, 'default') | ||||
|     nonce_oracle = OverrideNonceOracle(agent_roles['ALICE'], 42) | ||||
|     gas_oracle = OverrideGasOracle(price=1000000000, limit=21000) | ||||
|     c = Gas(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) | ||||
|     (tx_hash_hex, tx_signed_raw_hex) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 100 * (10 ** 6), tx_format=TxFormat.RLP_SIGNED) | ||||
| 
 | ||||
|     queue_create( | ||||
|             default_chain_spec, | ||||
|             42, | ||||
|             agent_roles['ALICE'], | ||||
|             tx_hash_hex, | ||||
|             tx_signed_raw_hex, | ||||
|             session=init_database, | ||||
|             ) | ||||
|     cache_gas_data( | ||||
|             tx_hash_hex, | ||||
|             tx_signed_raw_hex, | ||||
|             default_chain_spec.asdict(), | ||||
|             ) | ||||
| 
 | ||||
|     set_ready(default_chain_spec, tx_hash_hex, session=init_database) | ||||
|     set_reserved(default_chain_spec, tx_hash_hex, session=init_database) | ||||
|     set_sent(default_chain_spec, tx_hash_hex, session=init_database) | ||||
| 
 | ||||
|     init_database.commit() | ||||
| 
 | ||||
|     api = AdminApi(eth_rpc, queue=None, call_address=contract_roles['CONTRACT_DEPLOYER']) | ||||
|     t = api.resend(tx_hash_hex, default_chain_spec, in_place=False) | ||||
|     r = t.get_leaf() | ||||
|     assert t.successful() | ||||
| 
 | ||||
|     otx = Otx.load(tx_hash_hex, session=init_database) | ||||
|     assert otx.status & StatusBits.IN_NETWORK == StatusBits.IN_NETWORK | ||||
|     assert otx.status & StatusBits.OBSOLETE == StatusBits.OBSOLETE | ||||
| 
 | ||||
|     txs = get_nonce_tx_cache(default_chain_spec, otx.nonce, agent_roles['ALICE'], session=init_database) | ||||
|     assert len(txs) == 1 | ||||
| 
 | ||||
|     txs = get_nonce_tx_cache(default_chain_spec, otx.nonce + 1, agent_roles['ALICE'], session=init_database) | ||||
|     assert len(txs) == 1 | ||||
| 
 | ||||
|     otx = Otx.load(txs[0], session=init_database) | ||||
|     assert otx.status == 0 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user