Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion tests/test_monero_wallet_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"""
Expand Down
9 changes: 9 additions & 0 deletions tests/utils/wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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
Expand Down
Loading