From 1ec9b7af847b7e5fbb66a0747ffce2fd536b9a40 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sat, 14 Mar 2026 22:04:33 +0100 Subject: [PATCH] Add `TestMoneroWalletFull::test_close` * This test is failing at current version of monero-cpp due to segmentation fault --- tests/test_monero_wallet_full.py | 65 +++++++++++++++++++++++++++++++- tests/utils/test_utils.py | 5 +++ tests/utils/wallet_utils.py | 9 +++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/tests/test_monero_wallet_full.py b/tests/test_monero_wallet_full.py index 74eeb93..e56660a 100644 --- a/tests/test_monero_wallet_full.py +++ b/tests/test_monero_wallet_full.py @@ -101,7 +101,7 @@ def get_test_wallet(self) -> MoneroWalletFull: #endregion - #region Tests + #region Test Relays # Can create a subaddress with and without a label @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") @@ -136,6 +136,69 @@ def test_create_subaddress(self, wallet: MoneroWalletFull) -> None: # type: igno AssertUtils.assert_equals(subaddress, subaddresses_new[len(subaddresses_new) - 1]) account_idx += 1 + # Can be closed + # TODO demonstration of monero-cpp segmentation fault bug + @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") + @pytest.mark.skip(reason="TODO monero-cpp closed and re-opened wallet full causes segmentation fault") + def test_close(self) -> None: + # create test wallet + path: str = Utils.get_random_wallet_path() + config: MoneroWalletConfig = MoneroWalletConfig() + config.path = path + wallet: MoneroWalletFull = self._create_wallet(config) + wallet.sync() + assert wallet.get_height() > 1, "Wallet height is still 1" + assert wallet.is_synced(), "Wallet is not synced" + # TODO monero-cpp add monero_wallet::is_closed() + #assert wallet.is_closed() is False + + # close wallet + wallet.close() + # TODO monero-cpp add monero_wallet::is_closed() + #assert wallet.is_closed() + + # attempt to interact with the wallet + try: + wallet.get_height() + except Exception as e: + WalletUtils.test_wallet_is_closed_error(e) + + try: + wallet.get_seed() + except Exception as e: + WalletUtils.test_wallet_is_closed_error(e) + + # TODO calling monero_wallet_full::sync() on a closed wallet causes segmentation fault + try: + wallet.sync() + except Exception as e: + WalletUtils.test_wallet_is_closed_error(e) + + try: + wallet.start_syncing() + except Exception as e: + WalletUtils.test_wallet_is_closed_error(e) + + try: + wallet.stop_syncing() + except Exception as e: + WalletUtils.test_wallet_is_closed_error(e) + + # re-open the wallet + config = MoneroWalletConfig() + config.path = path + # TODO calling monero_wallet_full::sync() on a re-opened wallet causes segmentation fault + wallet = self._open_wallet(config) + wallet.sync() + assert wallet.get_daemon_height() == wallet.get_height() + # TODO monero-cpp add monero_wallet::is_closed() + #assert wallet.is_closed() is False + + # close the wallet + wallet.close() + # TODO monero-cpp add monero_wallet::is_closed() + #assert wallet.is_closed() + #endregion #region Disabled Tests diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index 520f02f..91acd35 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -1,5 +1,6 @@ import logging +from time import time from typing import Optional from abc import ABC from os.path import exists as path_exists @@ -254,6 +255,10 @@ def create_test_wallets_dir(cls) -> None: """Create test wallets directory""" makedirs(cls.TEST_WALLETS_DIR) + @classmethod + def get_random_wallet_path(cls) -> str: + return f"{cls.TEST_WALLETS_DIR}/test_wallet_{int(time() * 1000)}" + @classmethod def get_daemon_rpc(cls) -> MoneroDaemonRpc: """Get test daemon rpc""" diff --git a/tests/utils/wallet_utils.py b/tests/utils/wallet_utils.py index c68f3b5..e6765e2 100644 --- a/tests/utils/wallet_utils.py +++ b/tests/utils/wallet_utils.py @@ -24,6 +24,9 @@ class WalletUtils(ABC): """Wallet test utilities""" + WALLET_IS_CLOSED_ERROR: str = "Wallet is closed" + """Wallet is closed error message""" + MAX_TX_PROOFS: Optional[int] = 25 """maximum number of transactions to check for each proof, undefined to check all""" @@ -223,6 +226,12 @@ def test_no_wallet_file_error(cls, error: Optional[Exception]) -> None: err_msg: str = str(error) assert err_msg == "No wallet file", err_msg + @classmethod + def test_wallet_is_closed_error(cls, error: Optional[Exception]) -> None: + assert error is not None + err_msg: str = str(error) + assert err_msg == cls.WALLET_IS_CLOSED_ERROR, err_msg + #endregion @classmethod