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
194 changes: 86 additions & 108 deletions src/cpp/py_monero.cpp

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions src/python/monero_block.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ class MoneroBlock(MoneroBlockHeader):
def __init__(self) -> None:
"""Initialize a Monero block."""
...
@typing.overload
def copy(self, src: MoneroBlock, tgt: MoneroBlock) -> MoneroBlock:
...
@typing.overload
def copy(self, src: MoneroBlockHeader, tgt: MoneroBlockHeader) -> MoneroBlockHeader:
@typing.override
def copy(self) -> MoneroBlock:
...
@typing.overload
def merge(self, _self: MoneroBlock, other: MoneroBlock) -> None:
def merge(self, other: MoneroBlock) -> None:
...
@typing.overload
def merge(self, _self: MoneroBlockHeader, other: MoneroBlockHeader) -> None:
def merge(self, other: MoneroBlockHeader) -> None:
...
4 changes: 2 additions & 2 deletions src/python/monero_block_header.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MoneroBlockHeader(SerializableStruct):
def __init__(self) -> None:
"""Initialize a Monero block header."""
...
def copy(self, src: MoneroBlockHeader, tgt: MoneroBlockHeader) -> MoneroBlockHeader:
def copy(self) -> MoneroBlockHeader:
...
def merge(self, _self: MoneroBlockHeader, other: MoneroBlockHeader) -> None:
def merge(self, other: MoneroBlockHeader) -> None:
...
6 changes: 1 addition & 5 deletions src/python/monero_destination.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ class MoneroDestination:
:param int amount: Amount sent to the destination.
"""
...
def copy(self, src: MoneroDestination, tgt: MoneroDestination) -> MoneroDestination:
def copy(self) -> MoneroDestination:
"""
Copy a Monero outgoing transfer destination.

:param MoneroDestination src: Source.
:param MoneroDestination target: Target.
:return MoneroDestination: The copied destination.
"""
...
12 changes: 5 additions & 7 deletions src/python/monero_incoming_transfer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ class MoneroIncomingTransfer(MoneroTransfer):
def __init__(self) -> None:
"""Initialize a Monero incoming transfer."""
...
@typing.overload
def copy(self, src: MoneroIncomingTransfer, tgt: MoneroIncomingTransfer) -> MoneroIncomingTransfer:
...
@typing.overload
def copy(self, src: MoneroTransfer, tgt: MoneroTransfer) -> MoneroIncomingTransfer:
@typing.override
def copy(self) -> MoneroIncomingTransfer:
...
@typing.overload
def merge(self, _self: MoneroIncomingTransfer, other: MoneroIncomingTransfer) -> None:
def merge(self, other: MoneroIncomingTransfer) -> None:
...
@typing.overload
def merge(self, _self: MoneroTransfer, other: MoneroTransfer) -> None:
def merge(self, other: MoneroTransfer) -> None:
...

4 changes: 2 additions & 2 deletions src/python/monero_key_image.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MoneroKeyImage(SerializableStruct):
def __init__(self) -> None:
"""Initialize a Monero key image."""
...
def copy(self, src: MoneroKeyImage, tgt: MoneroKeyImage) -> MoneroKeyImage:
def copy(self) -> MoneroKeyImage:
...
def merge(self, _self: MoneroKeyImage, other: MoneroKeyImage) -> None:
def merge(self, other: MoneroKeyImage) -> None:
...
12 changes: 4 additions & 8 deletions src/python/monero_outgoing_transfer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import typing

from .monero_transfer import MoneroTransfer
from .monero_destination import MoneroDestination
from .monero_incoming_transfer import MoneroIncomingTransfer


class MoneroOutgoingTransfer(MoneroTransfer):
Expand All @@ -17,15 +16,12 @@ class MoneroOutgoingTransfer(MoneroTransfer):
"""Subaddresses from which the transfer originated."""
def __init__(self) -> None:
...
@typing.overload
def copy(self, src: MoneroOutgoingTransfer, tgt: MoneroIncomingTransfer) -> MoneroOutgoingTransfer:
...
@typing.overload
def copy(self, src: MoneroTransfer, tgt: MoneroTransfer) -> MoneroOutgoingTransfer:
@typing.override
def copy(self) -> MoneroOutgoingTransfer:
...
@typing.overload
def merge(self, _self: MoneroOutgoingTransfer, other: MoneroOutgoingTransfer) -> None:
def merge(self, other: MoneroOutgoingTransfer) -> None:
...
@typing.overload
def merge(self, _self: MoneroTransfer, other: MoneroTransfer) -> None:
def merge(self, other: MoneroTransfer) -> None:
...
4 changes: 2 additions & 2 deletions src/python/monero_output.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MoneroOutput(SerializableStruct):
def __init__(self) -> None:
"""Initialize a Monero output."""
...
def copy(self, src: MoneroOutput, tgt: MoneroOutput) -> MoneroOutput:
def copy(self) -> MoneroOutput:
...
def merge(self, _self: MoneroOutput, other: MoneroOutput) -> None:
def merge(self, other: MoneroOutput) -> None:
...
11 changes: 3 additions & 8 deletions src/python/monero_output_query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ class MoneroOutputQuery(MoneroOutputWallet):
def __init__(self) -> None:
"""Initialize a Monero output query."""
...
@typing.overload
def copy(self, src: MoneroOutputQuery, tgt: MoneroOutputQuery) -> MoneroOutputQuery:
...
@typing.overload
def copy(self, src: MoneroOutputWallet, tgt: MoneroOutputWallet) -> MoneroOutputQuery:
...
@typing.overload
def copy(self, src: MoneroOutput, tgt: MoneroOutput) -> MoneroOutputQuery: # type: ignore
@typing.override
def copy(self) -> MoneroOutputQuery:
...

def meets_criteria(self, output: MoneroOutputWallet, query_parent: bool = True) -> bool:
"""
Indicates if the output meets all the criteria defined within this query.
Expand Down
11 changes: 4 additions & 7 deletions src/python/monero_output_wallet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ class MoneroOutputWallet(MoneroOutput):
def __init__(self) -> None:
"""Initialize a Monero wallet output."""
...
@typing.overload
def copy(self, src: MoneroOutputWallet, tgt: MoneroOutputWallet) -> MoneroOutputWallet:
...
@typing.overload
def copy(self, src: MoneroOutput, tgt: MoneroOutput) -> MoneroOutputWallet:
@typing.override
def copy(self) -> MoneroOutputWallet:
...
@typing.overload
def merge(self, _self: MoneroOutputWallet, other: MoneroOutputWallet) -> None:
def merge(self, other: MoneroOutputWallet) -> None:
...
@typing.overload
def merge(self, _self: MoneroOutput, other: MoneroOutput) -> None:
def merge(self, other: MoneroOutput) -> None:
...
4 changes: 2 additions & 2 deletions src/python/monero_transfer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MoneroTransfer:
def __init__(self) -> None:
"""Initialize a Monero transfer."""
...
def copy(self, src: MoneroTransfer, tgt: MoneroTransfer) -> MoneroTransfer:
def copy(self) -> MoneroTransfer:
...
def is_incoming(self) -> bool | None:
"""
Expand All @@ -30,5 +30,5 @@ class MoneroTransfer:
:return Optional[bool]:
"""
...
def merge(self, _self: MoneroTransfer, other: MoneroTransfer) -> None:
def merge(self, other: MoneroTransfer) -> None:
...
7 changes: 2 additions & 5 deletions src/python/monero_transfer_query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ class MoneroTransferQuery(MoneroTransfer):
def __init__(self) -> None:
"""Initialize a Monero transfer query."""
...
@typing.overload
def copy(self, src: MoneroTransferQuery, tgt: MoneroTransferQuery) -> MoneroTransferQuery:
...
@typing.overload
def copy(self, src: MoneroTransfer, tgt: MoneroTransfer) -> MoneroTransferQuery:
@typing.override
def copy(self) -> MoneroTransferQuery:
...
def meets_criteria(self, transfer: MoneroTransferQuery, query_parent: bool = True) -> bool:
...
4 changes: 2 additions & 2 deletions src/python/monero_tx.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MoneroTx(SerializableStruct):
"""The weight of this transaction in bytes."""
def __init__(self) -> None:
...
def copy(self, src: MoneroTx, tgt: MoneroTx) -> MoneroTx:
def copy(self) -> MoneroTx:
...
def get_height(self) -> int | None:
"""
Expand All @@ -94,5 +94,5 @@ class MoneroTx(SerializableStruct):
:return int | None: The height of the transaction, if known.
"""
...
def merge(self, _self: MoneroTx, other: MoneroTx) -> None:
def merge(self, other: MoneroTx) -> None:
...
10 changes: 2 additions & 8 deletions src/python/monero_tx_query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ class MoneroTxQuery(MoneroTxWallet):
...
def __init__(self) -> None:
...
@typing.overload
def copy(self, src: MoneroTxQuery, tgt: MoneroTxQuery) -> MoneroTxQuery:
...
@typing.overload
def copy(self, src: MoneroTxWallet, tgt: MoneroTxWallet) -> MoneroTxQuery:
...
@typing.overload
def copy(self, src: MoneroTx, tgt: MoneroTx) -> MoneroTxQuery: # type: ignore
@typing.override
def copy(self) -> MoneroTxQuery:
...
def meets_criteria(self, tx: MoneroTxWallet, query_children: bool = False) -> bool:
...
11 changes: 4 additions & 7 deletions src/python/monero_tx_wallet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ class MoneroTxWallet(MoneroTx):
"""The transaction set"""
def __init__(self) -> None:
...
@typing.overload
def copy(self, src: MoneroTxWallet, tgt: MoneroTxWallet) -> MoneroTxWallet:
...
@typing.overload
def copy(self, src: MoneroTx, tgt: MoneroTx) -> MoneroTxWallet:
@typing.override
def copy(self) -> MoneroTxWallet:
...
def filter_outputs_wallet(self, query: MoneroOutputQuery) -> list[MoneroOutputWallet]:
...
Expand All @@ -65,8 +62,8 @@ class MoneroTxWallet(MoneroTx):
def get_transfers(self, query: MoneroTransferQuery) -> list[MoneroTransfer]:
...
@typing.overload
def merge(self, _self: MoneroTxWallet, tgt: MoneroTxWallet) -> None:
def merge(self, tgt: MoneroTxWallet) -> None:
...
@typing.overload
def merge(self, _self: MoneroTx, tgt: MoneroTx) -> None: # type: ignore
def merge(self, tgt: MoneroTx) -> None: # type: ignore
...
25 changes: 16 additions & 9 deletions tests/test_monero_wallet_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
MoneroTxConfig, MoneroDestination, MoneroRpcConnection, MoneroError,
MoneroKeyImage, MoneroTxQuery, MoneroUtils, MoneroWalletFull
)
from utils import TestUtils, WalletEqualityUtils, MiningUtils, OsUtils
from utils import (
TestUtils, WalletEqualityUtils, MiningUtils,
OsUtils, StringUtils
)

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

Expand Down Expand Up @@ -359,7 +362,7 @@ def test_get_path(self) -> None:

# set a random attribute
#String uuid = UUID.randomUUID().toString()
uuid = TestUtils.get_random_string()
uuid = StringUtils.get_random_string()
wallet.set_attribute("uuid", uuid)

# record the wallet's path then save and close
Expand Down Expand Up @@ -699,7 +702,7 @@ def test_create_account_with_label(self):
wallet = self._wallet
# create account with label
accounts_before = wallet.get_accounts()
label = TestUtils.get_random_string()
label = StringUtils.get_random_string()
created_account = wallet.create_account(label)
TestUtils.test_account(created_account)
assert created_account.index is not None
Expand Down Expand Up @@ -728,7 +731,7 @@ def test_set_account_label(self):
wallet.create_account()

# set account label
label = TestUtils.get_random_string()
label = StringUtils.get_random_string()
wallet.set_account_label(1, label)
assert label == wallet.get_subaddress(1, 0).label

Expand Down Expand Up @@ -817,7 +820,7 @@ def test_create_subaddress(self):

# create subaddress with label
subaddresses = wallet.get_subaddresses(account_idx)
uuid = TestUtils.get_random_string()
uuid = StringUtils.get_random_string()
subaddress = wallet.create_subaddress(account_idx, uuid)
assert (uuid == subaddress.label)
TestUtils.test_subaddress(subaddress)
Expand All @@ -836,18 +839,20 @@ def test_set_subaddress_label(self):
# set subaddress labels
subaddress_idx = 0
while subaddress_idx < len(wallet.get_subaddresses(0)):
label = TestUtils.get_random_string()
label = StringUtils.get_random_string()
wallet.set_subaddress_label(0, subaddress_idx, label)
assert label == wallet.get_subaddress(0, subaddress_idx).label
subaddress_idx += 1

#region Txs Tests

@pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_set_tx_note(self) -> None:
wallet = self._wallet
txs = TestUtils.get_random_transactions(wallet, None, 1, 5)

# set notes
uuid = TestUtils.get_random_string()
uuid = StringUtils.get_random_string()
i: int = 0

while i < len(txs):
Expand All @@ -868,7 +873,7 @@ def test_set_tx_note(self) -> None:
def test_set_tx_notes(self):
wallet = self._wallet
# set tx notes
uuid = TestUtils.get_random_string()
uuid = StringUtils.get_random_string()
txs = wallet.get_txs()
assert len(txs) >= 3, "Test requires 3 or more wallet transactions run send tests"
tx_hashes: list[str] = []
Expand All @@ -890,6 +895,8 @@ def test_set_tx_notes(self):

# TODO: test that get transaction has note

#endregion

@pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_export_key_images(self):
wallet = self._wallet
Expand Down Expand Up @@ -1064,7 +1071,7 @@ def test_save_and_close(self) -> None:
path: str = wallet.get_path()

# set an attribute
uuid: str = TestUtils.get_random_string()
uuid: str = StringUtils.get_random_string()
wallet.set_attribute("id", uuid)

# close the wallet without saving
Expand Down
6 changes: 3 additions & 3 deletions tests/test_monero_wallet_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
MoneroSubaddress, MoneroDaemonRpc, MoneroWallet
)

from utils import TestUtils as Utils, OsUtils
from utils import TestUtils as Utils, OsUtils, StringUtils
from test_monero_wallet_common import BaseTestMoneroWallet

logger: logging.Logger = logging.getLogger("TestMoneroWalletFull")
Expand All @@ -29,7 +29,7 @@ def _create_wallet(self, config: Optional[MoneroWalletConfig], start_syncing: bo
config = MoneroWalletConfig()
random: bool = self.is_random_wallet_config(config)
if config.path is None:
config.path = Utils.TEST_WALLETS_DIR + "/" + Utils.get_random_string()
config.path = Utils.TEST_WALLETS_DIR + "/" + StringUtils.get_random_string()
if config.password is None:
config.password = Utils.WALLET_PASSWORD
if config.network_type is None:
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_create_subaddress(self):

# create subaddress with label
subaddresses = self._wallet.get_subaddresses(account_idx)
uuid: str = Utils.get_random_string()
uuid: str = StringUtils.get_random_string()
subaddress = self._wallet.create_subaddress(account_idx, uuid)
Utils.assert_equals(uuid, subaddress.label)
Utils.test_subaddress(subaddress)
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/string_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC
from secrets import token_hex


class StringUtils(ABC):
Expand All @@ -11,3 +12,7 @@ def get_percentage(cls, n: int, m: int, precision: int = 2) -> str:
@classmethod
def get_percentage_float(cls, n: float, precision: int = 2) -> str:
return f"{round(n, precision)}%"

@classmethod
def get_random_string(cls, n: int = 25) -> str:
return token_hex(n)
Loading