diff --git a/apps/cic-eth/cic_eth/eth/erc20.py b/apps/cic-eth/cic_eth/eth/erc20.py index bf34acf6..62a5a0c3 100644 --- a/apps/cic-eth/cic_eth/eth/erc20.py +++ b/apps/cic-eth/cic_eth/eth/erc20.py @@ -71,8 +71,9 @@ def balance(tokens, holder_address, chain_spec_dict): for t in tokens: address = t['address'] logg.debug('address {} {}'.format(address, holder_address)) + gas_oracle = self.create_gas_oracle(rpc, min_price=self.min_fee_price) token = ERC20Token(chain_spec, rpc, add_0x(address)) - c = ERC20(chain_spec) + c = ERC20(chain_spec, gas_oracle=gas_oracle) o = c.balance_of(address, holder_address, sender_address=caller_address) r = rpc.do(o) t['balance_network'] = c.parse_balance(r) diff --git a/apps/cic-eth/cic_eth/task.py b/apps/cic-eth/cic_eth/task.py index 8a484ac2..4ca502b0 100644 --- a/apps/cic-eth/cic_eth/task.py +++ b/apps/cic-eth/cic_eth/task.py @@ -25,12 +25,14 @@ logg = logging.getLogger() celery_app = celery.current_app + class BaseTask(celery.Task): session_func = SessionBase.create_session call_address = ZERO_ADDRESS trusted_addresses = [] min_fee_price = 1 + min_fee_limit = 30000 default_token_address = None default_token_symbol = None default_token_name = None @@ -42,7 +44,7 @@ class BaseTask(celery.Task): if address == None: return RPCGasOracle( conn, - code_callback=kwargs.get('code_callback'), + code_callback=kwargs.get('code_callback', self.get_min_fee_limit), min_price=self.min_fee_price, id_generator=kwargs.get('id_generator'), ) @@ -56,6 +58,10 @@ class BaseTask(celery.Task): ) + def get_min_fee_limit(self, code): + return self.min_fee_limit + + def create_session(self): return BaseTask.session_func() diff --git a/apps/cic-eth/tests/task/test_task_gas.py b/apps/cic-eth/tests/task/test_task_gas.py index f69a2dd2..317f622d 100644 --- a/apps/cic-eth/tests/task/test_task_gas.py +++ b/apps/cic-eth/tests/task/test_task_gas.py @@ -35,10 +35,26 @@ from hexathon import strip_0x from cic_eth.eth.gas import cache_gas_data from cic_eth.error import OutOfGasError from cic_eth.queue.tx import queue_create +from cic_eth.task import BaseTask logg = logging.getLogger() +def test_task_gas_limit( + eth_rpc, + eth_signer, + default_chain_spec, + agent_roles, + celery_worker, + ): + rpc = RPCConnection.connect(default_chain_spec, 'default') + gas_oracle = BaseTask().create_gas_oracle(rpc) + c = Gas(default_chain_spec, signer=eth_signer, gas_oracle=gas_oracle) + (tx_hash_hex, o) = c.create(agent_roles['ALICE'], agent_roles['BOB'], 10, tx_format=TxFormat.RLP_SIGNED) + tx = unpack(bytes.fromhex(strip_0x(o)), default_chain_spec) + assert (tx['gas'], BaseTask.min_fee_price) + + def test_task_check_gas_ok( default_chain_spec, eth_rpc,