From 835914ca3e12552349a5161e100576d66167e1e4 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 26 Apr 2025 10:38:55 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/main_txsend.py | 6 +++--- mmgen/proto/eth/contract.py | 1 + mmgen/proto/eth/tx/online.py | 6 +++++- mmgen/swap/proto/thorchain/asset.py | 2 +- mmgen/tx/base.py | 7 ++++++- mmgen/tx/online.py | 4 +++- test/cmdtest_d/ethbump.py | 20 +++++++++++--------- test/cmdtest_d/ethswap.py | 14 ++++++++++---- test/cmdtest_d/httpd/thornode.py | 2 +- 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/mmgen/main_txsend.py b/mmgen/main_txsend.py index 1b99f732..bac73c8d 100755 --- a/mmgen/main_txsend.py +++ b/mmgen/main_txsend.py @@ -99,7 +99,7 @@ elif not cfg._args and cfg.autosign: si = Signable.automount_transaction(asi) if cfg.abort: si.shred_abortable() # prompts user, then raises exception or exits - elif cfg.status: + elif cfg.status or cfg.receipt: if si.unsent: die(1, 'Transaction is unsent') if si.unsigned: @@ -120,7 +120,7 @@ async def main(): global cfg - if cfg.status and cfg.autosign: + if (cfg.status or cfg.receipt) and cfg.autosign: tx = await si.get_last_created() else: tx = await OnlineSignedTX( @@ -144,7 +144,7 @@ async def main(): await tx.post_send(asi) sys.exit(0) - if not cfg.status or cfg.receipt: + if not (cfg.status or cfg.receipt): if tx.is_swap and not tx.check_swap_expiry(): die(1, 'Swap quote has expired. Please re-create the transaction') diff --git a/mmgen/proto/eth/contract.py b/mmgen/proto/eth/contract.py index 2a33f4ea..ab13541a 100755 --- a/mmgen/proto/eth/contract.py +++ b/mmgen/proto/eth/contract.py @@ -150,6 +150,7 @@ class Token(Contract): from_decimal = True) def create_transfer_data(self, to_addr, amt, *, op): + # Method IDs: 0xa9059cbb (transfer), 0x095ea7b3 (approve) assert op in ('transfer', 'approve'), f'{op}: invalid operation (not ‘transfer’ or ‘approve’)' return ( self.create_method_id(f'{op}(address,uint256)') diff --git a/mmgen/proto/eth/tx/online.py b/mmgen/proto/eth/tx/online.py index 46910397..620043cf 100755 --- a/mmgen/proto/eth/tx/online.py +++ b/mmgen/proto/eth/tx/online.py @@ -56,7 +56,11 @@ class OnlineSigned(Signed, TxBase.OnlineSigned): if res.status == 0: if res.gas_used == res.gas_sent: msg(yellow('All gas was used!')) - die(1, f'Send of {coin_txid.hl()} failed (status=0)') + msg('{} {} {}'.format( + yellow('Send of'), + coin_txid.hl(), + yellow('failed (status=0)'))) + return False msg(f'Status: {green(str(res.status))}') if res.contract_addr: msg('Contract address: {}'.format(res.contract_addr.hl(0))) diff --git a/mmgen/swap/proto/thorchain/asset.py b/mmgen/swap/proto/thorchain/asset.py index f3185dcb..3339707f 100644 --- a/mmgen/swap/proto/thorchain/asset.py +++ b/mmgen/swap/proto/thorchain/asset.py @@ -9,7 +9,7 @@ # https://gitlab.com/mmgen/mmgen-wallet """ -swap.asset: THORChain swap asset class the MMGen Wallet suite +swap.asset: THORChain swap asset class for the MMGen Wallet suite """ from ...asset import SwapAsset diff --git a/mmgen/tx/base.py b/mmgen/tx/base.py index b44779c8..76421864 100755 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -236,4 +236,9 @@ class Base(MMGenObject): @cached_property def recv_asset(self): - return self.swap_proto_mod.SwapAsset(self.swap_recv_asset_spec, 'recv') + if hasattr(self, 'swap_recv_asset_spec'): + return self.swap_proto_mod.SwapAsset(self.swap_recv_asset_spec, 'recv') + else: # backwards-compatibility workaround + from ..swap.asset import SwapAsset + x = '[unknown]' + return SwapAsset._ad(x, x, x, x, x) diff --git a/mmgen/tx/online.py b/mmgen/tx/online.py index 6fb024c0..9d0e4db9 100755 --- a/mmgen/tx/online.py +++ b/mmgen/tx/online.py @@ -105,11 +105,13 @@ class OnlineSigned(Signed): if idx != '' and not cfg.test_suite: await asyncio.sleep(2) from .tx_proxy import send_tx - msg(f'Sending TX: {coin_txid.hl()}') + msg('{} TX: {}'.format('Testing' if cfg.test else 'Sending', coin_txid.hl())) if ret := send_tx(cfg, txhex): if ret != coin_txid: ymsg(f'Warning: txid mismatch (after sending) ({ret} != {coin_txid})') sent_status = 'confirm_post_send' + if cfg.test: + break elif cfg.test: await self.test_sendable(txhex) else: # node send diff --git a/test/cmdtest_d/ethbump.py b/test/cmdtest_d/ethbump.py index 7d1d9640..fa42eb00 100755 --- a/test/cmdtest_d/ethbump.py +++ b/test/cmdtest_d/ethbump.py @@ -39,14 +39,9 @@ def {name}(self): class CmdTestEthBumpMethods: - def init_block_period(self): - d = self.daemon - bp = self.cfg.devnet_block_period or self.dfl_devnet_block_period[d.id] - d.usr_coind_args = { - 'reth': [f'--dev.block-time={bp}s'], - 'geth': [f'--dev.period={bp}'] - }[d.id] - self.devnet_block_period = bp + @property + def devnet_block_period(self): + return self.cfg.devnet_block_period or self.dfl_devnet_block_period[self.daemon.id] def _txcreate(self, args, acct): self.get_file_with_ext('rawtx', delete_all=True) @@ -133,6 +128,7 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe ('subgroup.token_init', ['eth_init']), ('subgroup.token_feebump', ['token_init']), ('subgroup.token_new_outputs', ['token_init']), + ('ltc_stop', ''), ('stop', 'stopping daemon'), ) cmd_subgroups = { @@ -243,6 +239,11 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe if not trunner: return + self.daemon.usr_coind_args = { + 'reth': [f'--dev.block-time={self.devnet_block_period}s'], + 'geth': [f'--dev.period={self.devnet_block_period}'] + }[self.daemon.id] + global ethbump_ltc cfg = Config({ '_clone': trunner.cfg, @@ -294,7 +295,7 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe return self._bal_check(pat=rf'{dfl_sid}:E:2\s+777\s') def bal3(self): - return self._bal_check(pat=rf'{dfl_sid}:E:11\s+99987\.653466900170247\s') + return self._bal_check(pat=rf'{dfl_sid}:E:11\s+99987\.653431389777251448\s') def bal4(self): return self._bal_check(pat=rf'{dfl_sid}:E:12\s+4444\.3333\s') @@ -356,4 +357,5 @@ class CmdTestEthBumpLTC(CmdTestSwapMethods, CmdTestRegtest): ('walletconv_bob', 'LTC wallet generation'), ('addrgen_bob', 'LTC address generation'), ('addrimport_bob', 'importing LTC addresses'), + ('stop', 'stopping the Litecoin daemon'), ) diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index ac472ffb..88d972ec 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -250,18 +250,18 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev }[k] cmd_group_in = CmdTestEthdev.cmd_group_in + ( + # eth_fund: ('fund_mmgen_addr1', 'funding user address :1)'), ('fund_mmgen_addr2', 'funding user address :11)'), + ('bal1', 'the ETH balance'), + # eth_swap: ('swaptxcreate1', 'creating an ETH->BTC swap transaction'), ('swaptxcreate2', 'creating an ETH->BTC swap transaction (spec address, trade limit)'), ('swaptxsign1', 'signing the transaction'), ('swaptxsend1', 'sending the transaction'), ('swaptxstatus1', 'getting the transaction status (with --verbose)'), - ('swaptxcreate3', 'creating an ETH->MM1 swap transaction'), - ('swaptxsign3', 'signing the transaction'), - ('swaptxsend3', 'sending the transaction'), - ('bal1', 'the ETH balance'), ('bal2', 'the ETH balance'), + # token_init: ('token_compile1', 'compiling ERC20 token #1'), ('token_deploy_a', 'deploying ERC20 token MM1 (SafeMath)'), ('token_deploy_b', 'deploying ERC20 token MM1 (Owned)'), @@ -270,6 +270,12 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev ('token_addrgen', 'generating token addresses'), ('token_addrimport', 'importing token addresses using token address (MM1)'), ('token_bal1', 'the token balance'), + + # eth_token_swap: + # ETH -> MM1 + ('swaptxcreate3', 'creating an ETH->MM1 swap transaction'), + ('swaptxsign3', 'signing the transaction'), + ('swaptxsend3', 'sending the transaction'), ) def swaptxcreate1(self): diff --git a/test/cmdtest_d/httpd/thornode.py b/test/cmdtest_d/httpd/thornode.py index 84c0734f..f7e016b3 100755 --- a/test/cmdtest_d/httpd/thornode.py +++ b/test/cmdtest_d/httpd/thornode.py @@ -16,6 +16,7 @@ import time, re, json from mmgen.cfg import Config from mmgen.amt import UniAmt +from mmgen.protocol import init_proto from . import HTTPD @@ -152,7 +153,6 @@ class ThornodeServer(HTTPD): } if send_asset != 'RUNE': - from mmgen.protocol import init_proto send_proto = init_proto(cfg, send_chain, network='regtest', need_amt=True) data.update({ 'inbound_address': make_inbound_addr(send_proto, send_proto.preferred_mmtypes[0]),