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
6 changes: 3 additions & 3 deletions src/cpp/py_monero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,14 +1446,14 @@ PYBIND11_MODULE(monero, m) {
assert_wallet_is_not_closed(&self);
MONERO_CATCH_AND_RETHROW(self.get_connection_manager());
})
.def("set_daemon_connection", [](PyMoneroWallet& self, const monero::monero_rpc_connection& connection) {
.def("set_daemon_connection", [](PyMoneroWallet& self, const boost::optional<monero::monero_rpc_connection>& connection) {
assert_wallet_is_not_closed(&self);
MONERO_CATCH_AND_RETHROW(self.set_daemon_connection(connection));
}, py::arg("connection"))
.def("set_daemon_connection", [](PyMoneroWallet& self, const std::string& uri, const std::string& username, const std::string& password, const std::string& proxy) {
assert_wallet_is_not_closed(&self);
MONERO_CATCH_AND_RETHROW(self.set_daemon_connection(uri, username, password, proxy));
}, py::arg("uri") = "", py::arg("username") = "", py::arg("password") = "", py::arg("proxy") = "")
}, py::arg("uri"), py::arg("username") = "", py::arg("password") = "", py::arg("proxy") = "")
.def("get_daemon_connection", [](PyMoneroWallet& self) {
assert_wallet_is_not_closed(&self);
MONERO_CATCH_AND_RETHROW(self.get_daemon_connection());
Expand Down Expand Up @@ -2012,7 +2012,7 @@ PYBIND11_MODULE(monero, m) {
MONERO_CATCH_AND_RETHROW(monero::monero_wallet_full::open_wallet_data(password, nettype, keys_data, cache_data, daemon_connection));
}, py::arg("password"), py::arg("nettype"), py::arg("keys_data"), py::arg("cache_data"), py::arg("daemon_connection"))
.def_static("create_wallet", [](const PyMoneroWalletConfig& config) {
MONERO_CATCH_AND_RETHROW(monero::monero_wallet_full::create_wallet(config));
MONERO_CATCH_AND_RETHROW(PyMoneroWalletFull::create_wallet(config));
}, py::arg("config"))
.def_static("get_seed_languages", []() {
MONERO_CATCH_AND_RETHROW(monero::monero_wallet_full::get_seed_languages());
Expand Down
11 changes: 11 additions & 0 deletions src/cpp/wallet/py_monero_wallet_full.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ void PyMoneroWalletFull::close(bool save) {
void PyMoneroWalletFull::set_account_label(uint32_t account_idx, const std::string& label) {
set_subaddress_label(account_idx, 0, label);
}

monero_wallet_full* PyMoneroWalletFull::create_wallet(const monero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory) {
try {
return monero_wallet_full::create_wallet(config, std::move(http_client_factory));
} catch(const std::exception& ex) {
std::string msg = ex.what();
if (msg.find("file already exists") != std::string::npos && config.m_path != boost::none)
msg = std::string("Wallet already exists: ") + config.m_path.get();
throw PyMoneroError(msg);
}
}
2 changes: 2 additions & 0 deletions src/cpp/wallet/py_monero_wallet_full.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
class PyMoneroWalletFull : public monero::monero_wallet_full {
public:

static monero_wallet_full* create_wallet(const monero_wallet_config& config, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = nullptr);

bool is_closed() const { return m_is_closed; }
void close(bool save = false) override;
void set_account_label(uint32_t account_idx, const std::string& label);
Expand Down
2 changes: 1 addition & 1 deletion src/python/monero_wallet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ class MoneroWallet:
"""
...
@typing.overload
def set_daemon_connection(self, uri: str = '', username: str = '', password: str = '', proxy_uri: str = '') -> None:
def set_daemon_connection(self, uri: str, username: str = '', password: str = '', proxy_uri: str = '') -> None:
"""
Set the wallet's daemon connection.

Expand Down
8 changes: 8 additions & 0 deletions tests/test_monero_connection_manager.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import pytest
import logging

from typing import Optional
from monero import (
MoneroWallet, MoneroConnectionManager, MoneroRpcConnection, MoneroConnectionPollType
)
from utils import ConnectionChangeCollector, TestUtils as Utils

logger: logging.Logger = logging.getLogger("TestMoneroConnectionManager")

# TODO enable connection manager tests
@pytest.mark.skipif(True, reason="TODO")
class TestMoneroConnectionManager:

@pytest.fixture(autouse=True)
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before {request.node.name}") # type: ignore
yield
logger.info(f"After {request.node.name}") # type: ignore

def test_connection_manager(self):
wallet_rpcs: list[MoneroWallet] = Utils.get_wallets("rpc")
connection_manager: Optional[MoneroConnectionManager] = None
Expand Down
11 changes: 6 additions & 5 deletions tests/test_monero_daemon_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from utils import TestUtils as Utils, TestContext, BinaryBlockContext, MiningUtils

logger: logging.Logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger("TestMoneroDaemonRpc")


class TestMoneroDaemonRpc:
Expand All @@ -30,9 +30,9 @@ def before_all(self):

@pytest.fixture(autouse=True)
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before test {request.node.name}") # type: ignore
logger.info(f"Before {request.node.name}") # type: ignore
yield
logger.info(f"After test {request.node.name}") # type: ignore
logger.info(f"After {request.node.name}") # type: ignore

#endregion

Expand Down Expand Up @@ -654,6 +654,7 @@ def test_get_mining_status(self):

# Can submit a mined block to the network
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
@pytest.mark.flaky(reruns=5, reruns_delay=5)
def test_submit_mined_block(self):
# get template to mine on
template: MoneroBlockTemplate = self._daemon.get_block_template(Utils.ADDRESS)
Expand Down Expand Up @@ -682,14 +683,14 @@ def test_prune_blockchain(self):

# Can check for an update
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
@pytest.mark.flaky(reruns=5, reruns_delay=2)
@pytest.mark.flaky(reruns=5, reruns_delay=5)
def test_check_for_update(self):
result: MoneroDaemonUpdateCheckResult = self._daemon.check_for_update()
Utils.test_update_check_result(result)

# Can download an update
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
@pytest.mark.flaky(reruns=5, reruns_delay=2)
@pytest.mark.flaky(reruns=5, reruns_delay=5)
def test_download_update(self):
# download to default path
result: MoneroDaemonUpdateDownloadResult = self._daemon.download_update()
Expand Down
9 changes: 9 additions & 0 deletions tests/test_monero_rpc_connection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import pytest
import logging

from monero import MoneroRpcConnection
from utils import TestUtils as Utils

logger: logging.Logger = logging.getLogger("TestMoneroRpcConnection")


class TestMoneroRpcConnection:

@pytest.fixture(autouse=True)
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before {request.node.name}") # type: ignore
yield
logger.info(f"After {request.node.name}") # type: ignore

# Test monerod rpc connection
def test_node_rpc_connection(self):
connection = MoneroRpcConnection(Utils.DAEMON_RPC_URI, Utils.DAEMON_RPC_USERNAME, Utils.DAEMON_RPC_PASSWORD)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_monero_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from __future__ import annotations

import pytest
import logging

from typing import Any
from configparser import ConfigParser
from monero import (
MoneroNetworkType, MoneroIntegratedAddress, MoneroUtils, MoneroTxConfig
)
from utils import TestUtils, AddressBook, KeysBook

logger: logging.Logger = logging.getLogger("TestMoneroUtils")


class TestMoneroUtils:

Expand Down Expand Up @@ -35,6 +40,14 @@ def config(self) -> TestMoneroUtils.Config:
parser.read('tests/config/test_monero_utils.ini')
return TestMoneroUtils.Config.parse(parser)

@pytest.fixture(autouse=True)
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before {request.node.name}") # type: ignore
yield
logger.info(f"After {request.node.name}") # type: ignore

#region Tests

# Can get integrated addresses
def test_get_integrated_address(self, config: TestMoneroUtils.Config):
primary_address: str = config.stagenet.primary_address_4
Expand Down Expand Up @@ -270,3 +283,5 @@ def test_get_payment_uri(self, config: TestMoneroUtils.Config):
payment_uri = MoneroUtils.get_payment_uri(tx_config)
query = "tx_amount=0.250000000000&recipient_name=John%20Doe&tx_description=My%20transfer%20to%20wallet"
assert payment_uri == f"monero:{address}?{query}"

#endregion
7 changes: 4 additions & 3 deletions tests/test_monero_wallet_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from utils import TestUtils, WalletEqualityUtils

logger: logging.Logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger("TestMoneroWalletCommon")


class BaseTestMoneroWallet(ABC):
Expand Down Expand Up @@ -83,9 +83,9 @@ def test_config(self) -> BaseTestMoneroWallet.Config:

@pytest.fixture(autouse=True)
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before test {request.node.name}") # type: ignore
logger.info(f"Before {request.node.name}") # type: ignore
yield
logger.info(f"After test {request.node.name}") # type: ignore
logger.info(f"After {request.node.name}") # type: ignore

#endregion

Expand Down Expand Up @@ -130,6 +130,7 @@ def test_create_wallet_random(self) -> None:
try:
config = MoneroWalletConfig()
config.language = "english"
self._create_wallet(config)
raise Exception("Should have thrown error")
except Exception as e:
TestUtils.assert_equals("Unknown language: english", str(e))
Expand Down
40 changes: 10 additions & 30 deletions tests/test_monero_wallet_full.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import logging

from typing import Optional
from typing_extensions import override
Expand All @@ -10,6 +11,8 @@
from utils import TestUtils as Utils
from test_monero_wallet_common import BaseTestMoneroWallet

logger: logging.Logger = logging.getLogger("TestMoneroWalletFull")


class TestMoneroWalletFull(BaseTestMoneroWallet):

Expand Down Expand Up @@ -79,6 +82,13 @@ def _get_seed_languages(self) -> list[str]:
def get_test_wallet(self) -> MoneroWallet:
return Utils.get_wallet_full()

@pytest.fixture(autouse=True)
@override
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before test {request.node.name}") # type: ignore
yield
logger.info(f"After test {request.node.name}") # type: ignore

#endregion

#region Tests
Expand Down Expand Up @@ -127,26 +137,6 @@ def test_create_subaddress(self):
def test_get_height_by_date(self):
return super().test_get_height_by_date()

@pytest.mark.skip(reason="TODO")
@override
def test_create_wallet_random(self) -> None:
return super().test_create_wallet_random()

@pytest.mark.skip(reason="TODO")
@override
def test_create_wallet_from_seed(self, test_config: BaseTestMoneroWallet.Config) -> None:
return super().test_create_wallet_from_seed(test_config)

@pytest.mark.skip(reason="TODO")
@override
def test_create_wallet_from_keys(self) -> None:
return super().test_create_wallet_from_keys()

@pytest.mark.skip(reason="TODO")
@override
def test_create_wallet_from_seed_with_offset(self) -> None:
return super().test_create_wallet_from_seed_with_offset()

@pytest.mark.skip(reason="TODO")
@override
def test_wallet_equality_ground_truth(self):
Expand All @@ -167,16 +157,6 @@ def test_set_tx_note(self) -> None:
def test_set_tx_notes(self):
return super().test_set_tx_notes()

@pytest.mark.skip(reason="TODO")
@override
def test_set_daemon_connection(self):
return super().test_set_daemon_connection()

@pytest.mark.skip(reason="TODO")
@override
def test_mining(self):
return super().test_mining()

@pytest.mark.skip(reason="TODO")
@override
def test_export_key_images(self):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_monero_wallet_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from test_monero_wallet_common import BaseTestMoneroWallet

logger: logging.Logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger("TestMoneroWalletKeys")


class TestMoneroWalletKeys(BaseTestMoneroWallet):
Expand All @@ -21,6 +21,7 @@ class TestMoneroWalletKeys(BaseTestMoneroWallet):
_wallet: MoneroWalletKeys = Utils.get_wallet_keys() # type: ignore

@pytest.fixture(autouse=True)
@override
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before test {request.node.name}") # type: ignore
yield
Expand Down Expand Up @@ -196,6 +197,8 @@ def test_mining(self):

#endregion

#region Tests

@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
@override
def test_create_wallet_random(self) -> None:
Expand Down Expand Up @@ -458,6 +461,8 @@ def test_get_subaddress_by_index(self):
subaddress, self._wallet.get_subaddresses(account.index, [subaddress.index])[0]
)

#endregion

#region Utils

def _get_subaddress(self, account_idx: int, subaddress_idx: int) -> Optional[MoneroSubaddress]:
Expand Down
18 changes: 12 additions & 6 deletions tests/test_monero_wallet_rpc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import pytest
import logging

from monero import MoneroWallet, MoneroWalletConfig, MoneroDaemonRpc, MoneroWalletRpc

from typing_extensions import override
from utils import TestUtils as Utils
from test_monero_wallet_common import BaseTestMoneroWallet

logger: logging.Logger = logging.getLogger("TestMoneroWalletRpc")


class TestMoneroWalletRpc(BaseTestMoneroWallet):

Expand Down Expand Up @@ -33,6 +37,13 @@ def _close_wallet(self, wallet: MoneroWallet, save: bool = False) -> None:
def _get_seed_languages(self) -> list[str]:
return self._wallet.get_seed_languages() # type: ignore

@pytest.fixture(autouse=True)
@override
def before_each(self, request: pytest.FixtureRequest):
logger.info(f"Before test {request.node.name}") # type: ignore
yield
logger.info(f"After test {request.node.name}") # type: ignore

#endregion

#region Tests
Expand Down Expand Up @@ -118,16 +129,11 @@ def test_set_tx_note(self) -> None:
def test_set_tx_notes(self):
return super().test_set_tx_notes()

@pytest.mark.skip(reason="TODO")
@pytest.mark.skip(reason="TODO implement TestUtils.create_wallet_rpc()")
@override
def test_set_daemon_connection(self):
return super().test_set_daemon_connection()

@pytest.mark.skip(reason="TODO")
@override
def test_mining(self):
return super().test_mining()

@pytest.mark.skip(reason="TODO")
@override
def test_export_key_images(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/mining_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .test_utils import TestUtils as Utils
from .string_utils import StringUtils

logger: logging.Logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger("MiningUtils")


class MiningUtils:
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/print_height.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .test_utils import TestUtils

logger: logging.Logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger("PrintHeight")


class PrintHeight(ABC):
Expand Down
Loading