From 9400a558ba7546ffd33955aeab651c2503284ce6 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 7 May 2025 18:24:07 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/proto/eth/contract.py | 24 ++++++++++++++++++------ test/cmdtest_d/ethdev.py | 10 ++++++---- test/cmdtest_d/ethswap.py | 8 ++++++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/mmgen/proto/eth/contract.py b/mmgen/proto/eth/contract.py index c7436b23..5d1b860d 100755 --- a/mmgen/proto/eth/contract.py +++ b/mmgen/proto/eth/contract.py @@ -53,18 +53,30 @@ class Contract: async def code(self): return (await self.rpc.call('eth_getCode', '0x'+self.addr))[2:] - async def do_call(self, method_sig, method_args='', *, toUnit=False): + async def do_call( + self, + method_sig, + method_args = '', + *, + block = 'pending', # earliest, latest, safe, finalized + toUnit = False): + data = self.create_method_id(method_sig) + method_args + + args = { + 'to': '0x' + self.addr, + 'input': '0x' + data} + if self.cfg.debug: msg('ETH_CALL {}: {}'.format( method_sig, '\n '.join(parse_abi(data)))) - ret = await self.rpc.call('eth_call', {'to': '0x'+self.addr, 'data': '0x'+data}, 'pending') + + ret = await self.rpc.call('eth_call', args, block) + await erigon_sleep(self) - if toUnit: - return int(ret, 16) * self.base_unit - else: - return ret + + return int(ret, 16) * self.base_unit if toUnit else ret def make_tx_in(self, *, gas, gasPrice, nonce, data): assert isinstance(gas, int), f'{type(gas)}: incorrect type for ‘gas’ (must be an int)' diff --git a/test/cmdtest_d/ethdev.py b/test/cmdtest_d/ethdev.py index 1243dfd6..e8e40d12 100755 --- a/test/cmdtest_d/ethdev.py +++ b/test/cmdtest_d/ethdev.py @@ -27,7 +27,7 @@ from subprocess import run, PIPE, DEVNULL from pathlib import Path from mmgen.color import red, yellow, blue, cyan, orange, set_vt100 -from mmgen.util import msg, rmsg, die +from mmgen.util import msg, msg_r, rmsg, die from mmgen.proto.eth.misc import compute_contract_addr from ..include.common import ( @@ -1763,8 +1763,10 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared): def stop(self): self.spawn(msg_only=True) - if not self.cfg.no_daemon_stop: - if not stop_test_daemons(self.proto.coin+'_rt', remove_datadir=True): - return False + if self.cfg.no_daemon_stop: + msg_r(f'(leaving {self.daemon.id} daemon running by user request)') + imsg('') + elif not stop_test_daemons(self.proto.coin+'_rt', remove_datadir=True): + return False set_vt100() return 'ok' diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index 32940f76..e2f914c2 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -15,7 +15,7 @@ test.cmdtest_d.ethswap: Ethereum swap tests for the cmdtest.py test suite from subprocess import run, PIPE, DEVNULL from mmgen.cfg import Config -from mmgen.util import rmsg, die +from mmgen.util import msg_r, rmsg, die from mmgen.protocol import init_proto from mmgen.fileutil import get_data_from_file @@ -328,7 +328,11 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): def thornode_server_stop(self): self.spawn(msg_only=True) - thornode_server.stop() + if self.cfg.no_daemon_stop: + msg_r('(leaving thornode server running by user request)') + imsg('') + else: + thornode_server.stop() return 'ok' class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev):