Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
env:
# what the docker compose commands of the steps work on
COMPOSE_FILE: tests/docker-compose.yml
TEST_SERVICES: node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
TEST_SERVICES: node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws

strategy:
fail-fast: false
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
- name: Install the Python test requirements (tests/requirements.txt)
run: pip3 install -r tests/requirements.txt --break-system-packages

- name: Start the test environment (2 nodes and 3 wallet rpc servers in docker)
- name: Start the test environment (2 nodes, 3 wallet rpc servers and monero-lws in docker)
if: ${{ matrix.docker }}
run: |
read -r -a services <<< "$TEST_SERVICES"
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ For example: `export LD_PRELOAD=/path/to/libjemalloc.so.2` then run your app. It
```
3. Setup docker test environment
```bash
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws
```
4. Or start RPC servers locally:
1. Download and install [Monero CLI](https://web.getmonero.org/downloads/).
Expand All @@ -269,6 +269,12 @@ For example: `export LD_PRELOAD=/path/to/libjemalloc.so.2` then run your app. It
pytest tests/wallet -k Rpc
```

The tests of each wallet type also have a marker, `wallet_full`, `wallet_rpc`, `wallet_keys` and `wallet_light`, that [tests/wallet/conftest.py](tests/wallet/conftest.py) adds from the name of the class, so they can be combined with `unit` and `integration`:
```bash
pytest -m wallet_rpc
pytest -m "wallet_light and integration"
```

The daemon tests are split in the same way: [tests/daemon/rpc](tests/daemon/rpc) has the integration tests of the rpc daemon (a file for each topic, such as `test_blocks.py`, `test_tx_pool.py` and `test_peers.py`), [tests/daemon/model](tests/daemon/model) the unit tests of the daemon models, grouped by model, and [tests/daemon/test_interface.py](tests/daemon/test_interface.py) the ones of the daemon interface.

The wallet models are tested in [tests/wallet/model](tests/wallet/model) (a file for each kind of model: queries, transfers, outputs, accounts...), the calls of the wallet interface in [tests/wallet/test_interface.py](tests/wallet/test_interface.py), and the tests of what is not about a wallet or a daemon, such as the rpc connection, in [tests/common](tests/common), where the tests of `MoneroUtils` are split by topic in [tests/common/monero_utils](tests/common/monero_utils).
Expand Down
2 changes: 1 addition & 1 deletion bin/setup_test_environment.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

# start docker containers
sudo docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
sudo docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws
5 changes: 5 additions & 0 deletions bin/stop_wallet_rpc_servers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# stop the wallet rpc servers of the test environment, only the rpc wallet tests use them
# the containers and their volumes stay, setup_test_environment.sh starts them again
sudo docker compose -f tests/docker-compose.yml stop xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
7 changes: 6 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

import pytest

from tests.utils.gen_utils import GenUtils
# pytest explains a failed assert (the values that it compared, the diff) only in the modules that it rewrites: the test files and the
# conftests. The helpers of the tests are imported by the test files, and their asserts failed as a bare `AssertionError`. It has to be
# registered before the first import of the package, under the two names that it has (the tests import it as `utils`)
pytest.register_assert_rewrite("utils", "tests.utils")

from tests.utils.gen_utils import GenUtils # noqa: E402

if TYPE_CHECKING:
from pluggy import Result # runtime-optional (pluggy < 1.2), only needed for typing
Expand Down
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
minversion = 9.0
required_plugins = pytest-rerunfailures pytest-timeout pytest-cov
addopts = -s -v --reruns 5 --reruns-delay 10 --only-rerun "Daemon is busy"
timeout = 900
log_level = INFO
log_cli = True
log_cli_level = INFO
Expand All @@ -15,5 +16,9 @@ testpaths =
markers =
unit: fast unit tests, no external dependencies
integration: slow integration tests, requires external services
wallet_full: tests of the full wallet, added to the classes of each wallet type by tests/wallet/conftest.py
wallet_rpc: tests of the rpc wallet
wallet_keys: tests of the keys-only wallet
wallet_light: tests of the light wallet
not_supported: inherited test whose operation is permanently unsupported for this type; passes when it raises a "not supported" error, fails otherwise
not_implemented: inherited test whose operation is not implemented yet; applied as a non-strict xfail (xfails while it raises, xpasses once the feature lands)
3 changes: 3 additions & 0 deletions src/cpp/py_monero_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ PYBIND11_MAKE_OPAQUE(VectorUint64);
#include "wallet/monero_wallet_rpc.h"
#include "wallet/monero_wallet_keys.h"
#include "wallet/monero_wallet_full.h"
#include "wallet/monero_wallet_light.h"
#include "utils/py_monero_utils.h"

// The destructor of a daemon or of a wallet waits for the thread of its poller to finish, and that thread can be calling a listener of
Expand Down Expand Up @@ -177,6 +178,7 @@ struct PyMoneroTypes {
py::class_<monero_wallet_keys, monero_wallet, std::shared_ptr<monero_wallet_keys>> py_monero_wallet_keys;
py::class_<monero_wallet_full, monero_wallet, std::shared_ptr<monero_wallet_full>> py_monero_wallet_full;
py::class_<monero_wallet_rpc, monero_wallet, std::shared_ptr<monero_wallet_rpc>> py_monero_wallet_rpc;
py::class_<monero_wallet_light, monero_wallet_keys, std::shared_ptr<monero_wallet_light>> py_monero_wallet_light;
py::class_<PyMoneroUtils> py_monero_utils;
py::class_<PyGenUtils> py_gen_utils;

Expand Down Expand Up @@ -230,6 +232,7 @@ struct PyMoneroTypes {
py_monero_wallet(m, "MoneroWallet"),
py_monero_wallet_keys(m, "MoneroWalletKeys"),
py_monero_wallet_full(m, "MoneroWalletFull"),
py_monero_wallet_light(m, "MoneroWalletLight"),
py_monero_wallet_rpc(m, "MoneroWalletRpc"),
py_monero_utils(m, "MoneroUtils"),
py_gen_utils(m, "GenUtils"),
Expand Down
18 changes: 18 additions & 0 deletions src/cpp/wallet/py_monero_wallet_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,24 @@ void py_monero_bind_wallet(py::module_& m, PyMoneroTypes& t) {
MONERO_CATCH_AND_RETHROW(py::bytes(self.get_cache_file_buffer()));
});

// monero_wallet_light
t.py_monero_wallet_light
.def_static("wallet_exists", [](const std::string& primary_address, const std::string& private_view_key, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::wallet_exists(primary_address, private_view_key, rpc));
}, py::arg("primary_address"), py::arg("private_view_key"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def_static("wallet_exists", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::wallet_exists(config, rpc));
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def_static("open_wallet", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::open_wallet(config, rpc));
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def_static("create_wallet", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::create_wallet(config, rpc));
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def("get_rpc_connection", [](monero_wallet_light& self) {
MONERO_CATCH_AND_RETHROW(self.get_rpc_connection());
}, py::call_guard<py::gil_scoped_release>());

// monero_wallet_rpc
t.py_monero_wallet_rpc
.def(py::init([](const std::shared_ptr<monero_rpc_connection>& rpc_connection) {
Expand Down
2 changes: 2 additions & 0 deletions src/python/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ from .monero_wallet_full import MoneroWalletFull
from .monero_wallet_keys import MoneroWalletKeys
from .monero_wallet_listener import MoneroWalletListener
from .monero_wallet_rpc import MoneroWalletRpc
from .monero_wallet_light import MoneroWalletLight


__all__ = [
Expand Down Expand Up @@ -226,6 +227,7 @@ __all__ = [
'MoneroWalletKeys',
'MoneroWalletListener',
'MoneroWalletRpc',
'MoneroWalletLight',
'SslOptions',
'SerializableStruct'
]
68 changes: 68 additions & 0 deletions src/python/monero_wallet_light.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from typing import overload

from .monero_rpc_connection import MoneroRpcConnection
from .monero_wallet_config import MoneroWalletConfig
from .monero_wallet_keys import MoneroWalletKeys


class MoneroWalletLight(MoneroWalletKeys):
"""
Implements a Monero wallet using `monero-lws`_.

.. _monero-lws: https://github.com/vtnerd/monero-lws
"""

@staticmethod
@overload
def wallet_exists(primary_address: str, private_view_key: str, rpc: MoneroRpcConnection) -> bool:
"""
Check if a wallet exists on the server.

:param primary_address: The primary address of the wallet.
:param private_view_key: The private view key of the wallet.
:param rpc: The RPC connection to the Monero server.
:return: True if the wallet exists, False otherwise.
"""
...

@staticmethod
@overload
def wallet_exists(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> bool:
"""
Check if a wallet exists on the server.

:param config: The wallet configuration.
:param rpc: The RPC connection to the Monero server.
:return: True if the wallet exists, False otherwise.
"""
...

@staticmethod
def open_wallet(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> MoneroWalletLight:
"""
Open an existing light wallet with the given configuration.

:param config: The configuration for opening the wallet.
:param rpc: The RPC connection to the Monero server.
:return: An instance of MoneroWalletLight.
"""
...

@staticmethod
def create_wallet(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> MoneroWalletLight:
"""
Create a new light wallet with the given configuration.

:param config: The configuration for creating the wallet.
:param rpc: The RPC connection to the Monero server.
:return: An instance of MoneroWalletLight.
"""
...

def get_rpc_connection(self) -> MoneroRpcConnection | None:
"""
Get the wallet's RPC connection.

:returns MoneroRpcConnection | None: the wallet's rpc connection.
"""
...
11 changes: 11 additions & 0 deletions tests/common/test_rpc_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def wallet_connection(cls) -> MoneroRpcConnection:
"""Rpc connection test instance."""
return MoneroRpcConnection(Utils.WALLET_RPC_URI, Utils.WALLET_RPC_USERNAME, Utils.WALLET_RPC_PASSWORD, timeout_ms=cls.TIMEOUT_MS)

# Light wallet server rpc connection fixture
@pytest.fixture(scope="class")
def lws_connection(self) -> MoneroRpcConnection:
"""Rpc connection test instance."""
return MoneroRpcConnection(Utils.LWS_RPC_URI, timeout_ms=self.TIMEOUT_MS)

#endregion

#region Tests
Expand Down Expand Up @@ -120,6 +126,11 @@ def test_node_rpc_connection(self, node_connection: MoneroRpcConnection) -> None
def test_wallet_rpc_connection(self, wallet_connection: MoneroRpcConnection) -> None:
RpcConnectionUtils.test_rpc_connection(wallet_connection, Utils.WALLET_RPC_URI, True, MoneroConnectionType.IPV4)

# Test light wallet server rpc connection
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_lws_rpc_connection(self, lws_connection: MoneroRpcConnection) -> None:
RpcConnectionUtils.test_rpc_connection(lws_connection, Utils.LWS_RPC_URI, True, MoneroConnectionType.IPV4)

# Test invalid connection
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_invalid_connection(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ zmq_uri=tcp://127.0.0.1:18085
zmq_pub_uri=tcp://127.0.0.1:18086
log_level=3
poll_period_in_ms=10000
lws_uri=http://127.0.0.1:8443
lws_admin_uri=http://127.0.0.1:8444

[wallet]
name=test_wallet_1
Expand Down
38 changes: 37 additions & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- xmr_wallet_1
- xmr_wallet_2
- xmr_wallet_3
- xmr_lws

node_1:
image: ghcr.io/libmonero/monero-daemon-rpc:${MONERO_TAG:-master}
Expand Down Expand Up @@ -92,6 +93,11 @@ services:
]
ports:
- "18082:18082"
# A wallet rpc that gets an address that is not valid looks it up as an OpenAlias domain (a DNSSEC query), and it does not answer any
# request until the query ends: in CI it took 3 to 4 minutes, and the tests that send to an invalid address timed out. The tests do
# not use OpenAlias: a resolver that is not reachable makes the query fail at once, and the wallet answers "wrong address"
environment:
DNS_PUBLIC: "tcp://127.0.0.1"
volumes:
- xmr_wallet_1_data:/home/monero/wallets
depends_on:
Expand All @@ -117,6 +123,8 @@ services:
]
ports:
- "18083:18083"
environment:
DNS_PUBLIC: "tcp://127.0.0.1"
volumes:
- xmr_wallet_2_data:/home/monero/wallets
depends_on:
Expand All @@ -142,15 +150,43 @@ services:
]
ports:
- "18084:18084"
environment:
DNS_PUBLIC: "tcp://127.0.0.1"
volumes:
- xmr_wallet_3_data:/home/monero/wallets
depends_on:
- node_1
- node_2

xmr_lws:
image: vtnerd/monero-lws:master
command: >
--daemon=tcp://node_2:18085
--sub=tcp://node_2:18086
--log-level=4
--webhook-ssl-verification=none
--disable-admin-auth
--rest-server=http://0.0.0.0:8443/
--admin-rest-server=http://0.0.0.0:8444/
--access-control-origin=*
--confirm-external-bind
--max-subaddresses=1000
--auto-accept-creation
--auto-accept-import
--regtest
volumes:
- xmr_lws_data:/data
ports:
- "8443:8443"
- "8444:8444"
depends_on:
- node_1
- node_2

volumes:
xmr_node_1_data:
xmr_node_2_data:
xmr_wallet_1_data:
xmr_wallet_2_data:
xmr_wallet_3_data:
xmr_wallet_3_data:
xmr_lws_data:
4 changes: 3 additions & 1 deletion tests/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from .wallet_send_utils import WalletSendUtils
from .wallet_test_utils import WalletTestUtils
from .wallet_error_utils import WalletErrorUtils
from .monero_daemon_lws import MoneroDaemonLws

__all__ = [
'WalletUtils',
Expand Down Expand Up @@ -105,5 +106,6 @@
'TxsStructureTester',
'DaemonNotificationCollector',
'FakeDaemonRpcServer',
'FakeWalletRpcServer'
'FakeWalletRpcServer',
'MoneroDaemonLws'
]
2 changes: 1 addition & 1 deletion tests/utils/from_multiple_tx_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _get_src_account(self) -> MoneroAccount:

if num_subaddress_balances >= self.NUM_SUBADDRESSES + 1:
has_balance = True
if len(unlocked_subaddresses) >= self.NUM_SUBADDRESSES + 1:
if len(unlocked_subaddresses) > self.NUM_SUBADDRESSES + 1:
src_account = account
break

Expand Down
Loading
Loading