From d2f8b9fddfa6204c294e05f60a81c412af2db614 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 29 Nov 2026 23:17:05 +0100 Subject: [PATCH 01/11] tests: go through the trampoline in the interface test --- tests/daemon/test_interface.py | 7 ++++++- tests/wallet/model/test_transfers.py | 22 ++++++++++++++++++++++ tests/wallet/test_interface.py | 7 ++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/daemon/test_interface.py b/tests/daemon/test_interface.py index 14bb40ef..f86ce367 100644 --- a/tests/daemon/test_interface.py +++ b/tests/daemon/test_interface.py @@ -18,7 +18,12 @@ class TestMoneroDaemonInterface(BaseTestClass): @classmethod def daemon(cls) -> MoneroDaemon: """Test daemon interface instance.""" - return MoneroDaemon() + + # only the instances of a subclass go through the trampoline, which calls MoneroDaemon for what they do not override + class DefaultDaemon(MoneroDaemon): + pass + + return DefaultDaemon() #region Tests diff --git a/tests/wallet/model/test_transfers.py b/tests/wallet/model/test_transfers.py index 872a5ed0..89823c73 100644 --- a/tests/wallet/model/test_transfers.py +++ b/tests/wallet/model/test_transfers.py @@ -6,10 +6,13 @@ from monero import ( IncomingTransferComparator, MoneroDestination, + MoneroError, MoneroIncomingTransfer, MoneroOutgoingTransfer, + MoneroTransfer, MoneroTxWallet, ) +from typing_extensions import override from utils import AssertUtils, BaseTestClass, TestUtils @@ -175,3 +178,22 @@ def test_outgoing_transfer_merge_conflicting_destinations_raises(self) -> None: with pytest.raises(RuntimeError) as exc_info: a.merge(b) assert str(exc_info.value) == "Destination vectors are different" + + # the C++ code gets the direction of a python subclass of MoneroTransfer from its override, through the trampoline + @pytest.mark.parametrize("incoming", [True, False, None]) + def test_transfer_is_incoming_override(self, incoming: bool | None) -> None: + class DirectedTransfer(MoneroTransfer): + @override + def is_incoming(self) -> bool | None: + return incoming + + transfer: MoneroTransfer = DirectedTransfer() + + # the method of the base class and is_outgoing() are the ones of C++, which call the override + assert MoneroTransfer.is_incoming(transfer) is incoming + assert transfer.is_outgoing() is (None if incoming is None else not incoming) + + # MoneroTransfer does not know its direction, which its subclasses have to implement + def test_transfer_is_incoming_without_override_raises(self) -> None: + with pytest.raises(MoneroError, match="pure virtual"): + MoneroTransfer().is_incoming() diff --git a/tests/wallet/test_interface.py b/tests/wallet/test_interface.py index 0dd4b6a3..9d360114 100644 --- a/tests/wallet/test_interface.py +++ b/tests/wallet/test_interface.py @@ -23,7 +23,12 @@ class TestMoneroWalletInterface(BaseTestClass): @classmethod def wallet(cls) -> MoneroWallet: """Test wallet instance.""" - return MoneroWallet() + + # only the instances of a subclass go through the trampoline, which calls MoneroWallet for what they do not override + class DefaultWallet(MoneroWallet): + pass + + return DefaultWallet() #region Tests From 32b44e40ea1e4cbdc1bcb3c340eaa86e8c20f893 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Mon, 30 Nov 2026 00:16:11 +0100 Subject: [PATCH 02/11] integration tests: fix test_set_log_hash_rate --- tests/daemon/rpc/test_admin.py | 14 +++++++++----- tests/utils/mining_utils.py | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/daemon/rpc/test_admin.py b/tests/daemon/rpc/test_admin.py index 7cb3ce97..6ef585fc 100644 --- a/tests/daemon/rpc/test_admin.py +++ b/tests/daemon/rpc/test_admin.py @@ -12,7 +12,7 @@ MoneroRpcError, ) -from utils import DaemonUtils, TestUtils as Utils +from utils import DaemonUtils, MiningUtils, TestUtils as Utils from .base_test_monero_daemon_rpc import BaseTestMoneroDaemonRpc logger: logging.Logger = logging.getLogger("TestMoneroDaemonRpcAdmin") @@ -126,12 +126,16 @@ def test_set_log_categories(self, daemon: MoneroDaemonRpc) -> None: # re-applying the configured level also resets categories to its mapping daemon.set_log_level(Utils.DAEMON_LOG_LEVEL) - # Can toggle the mining hash rate in the daemon log + # Can toggle the mining hash rate in the daemon log, which the daemon rejects while it is not mining @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_set_log_hash_rate(self, daemon: MoneroDaemonRpc) -> None: + MiningUtils.try_stop_mining(daemon) + with pytest.raises(MoneroRpcError, match="Daemon is not currently mining"): + daemon.set_log_hash_rate(True) + try: + MiningUtils.start_mining(daemon) daemon.set_log_hash_rate(True) daemon.set_log_hash_rate(False) - except Exception as e: - # daemon rejects the call while not mining - logger.warning(f"set_log_hash_rate: {e}") + finally: + MiningUtils.try_stop_mining(daemon) diff --git a/tests/utils/mining_utils.py b/tests/utils/mining_utils.py index a88be5af..ed43451f 100644 --- a/tests/utils/mining_utils.py +++ b/tests/utils/mining_utils.py @@ -60,7 +60,7 @@ def start_mining(cls, d: MoneroDaemonRpc | None = None) -> None: :param MoneroDaemonRpc | None d: daemon to start mining with (default internal daemon). """ - if cls.is_mining(): + if cls.is_mining(d): raise Exception("Mining already started") daemon: MoneroDaemonRpc = cls.get_daemon() if d is None else d @@ -73,7 +73,7 @@ def stop_mining(cls, d: MoneroDaemonRpc | None = None) -> None: :param MoneroDaemonRpc | None d: daemon to stop mining with (default internal daemon). """ - if not cls.is_mining(): + if not cls.is_mining(d): raise Exception("Mining already stopped") daemon: MoneroDaemonRpc = cls.get_daemon() if d is None else d From d7218e3bdea4033198d0bb64497544d910c4ad94 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Mon, 30 Nov 2026 00:35:45 +0100 Subject: [PATCH 03/11] unit tests: implement and enable tx deep copy test --- tests/daemon/model/test_txs.py | 53 ++++++++++++++++++++++++++++++++++ tests/utils/tx_tester.py | 5 ---- tests/utils/tx_utils.py | 20 ++++++++----- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/tests/daemon/model/test_txs.py b/tests/daemon/model/test_txs.py index b82e4a4e..229ac50f 100644 --- a/tests/daemon/model/test_txs.py +++ b/tests/daemon/model/test_txs.py @@ -182,6 +182,59 @@ def test_tx_copy_deep_copies_inputs(self) -> None: assert copy.inputs[0].amount == 1234 assert copy.inputs[0].tx is copy + # The copy of a tx equals it and shares nothing with it, so changing the copy leaves the tx as it was + def test_tx_copy_is_deep(self) -> None: + tx_input: MoneroOutput = MoneroOutput( + amount=1, key_image=MoneroKeyImage(hex="1" * 64, signature="signature"), ring_output_indices=[2, 3] + ) + tx_output: MoneroOutput = MoneroOutput(amount=4, index=5, stealth_public_key="2" * 64, mask="3" * 64) + tx: MoneroTx = MoneroTx( + hash="a" * 64, fee=7500000, inputs=[tx_input], outputs=[tx_output], output_indices=[6, 7], extra=[8, 9], + signatures=["signature"] + ) + tx_input.tx = tx + tx_output.tx = tx + tx.block = MoneroBlock(height=10, txs=[tx]) + original: str = tx.serialize() + + tx_copy: MoneroTx = tx.copy() + + # the copy is equal and not in a block + assert tx_copy is not tx + assert tx_copy == tx + assert tx_copy.block is None + + # its inputs and outputs are copies too, which are in the copy + assert tx_copy.inputs[0] is not tx_input + assert tx_copy.outputs[0] is not tx_output + assert tx_copy.inputs[0].tx is tx_copy + assert tx_copy.outputs[0].tx is tx_copy + assert tx_input.tx is tx + assert tx_output.tx is tx + + # change the copy, also its lists and its nested objects + key_image_copy: MoneroKeyImage | None = tx_copy.inputs[0].key_image + assert key_image_copy is not None + key_image_copy.hex = "b" * 64 + tx_copy.inputs[0].ring_output_indices.append(100) + tx_copy.outputs[0].amount = 100 + tx_copy.outputs.append(MoneroOutput()) + tx_copy.output_indices.append(100) + tx_copy.extra.append(100) + tx_copy.signatures.append("other") + assert list(tx_copy.extra) == [8, 9, 100] + + # the tx is as it was + assert tx_input.key_image is not None + assert tx_input.key_image.hex == "1" * 64 + assert list(tx_input.ring_output_indices) == [2, 3] + assert tx_output.amount == 4 + assert len(tx.outputs) == 1 + assert list(tx.output_indices) == [6, 7] + assert list(tx.extra) == [8, 9] + assert list(tx.signatures) == ["signature"] + assert tx.serialize() == original + def test_tx_merge(self) -> None: a: MoneroTx = MoneroTx() a.hash = "a" * 64 diff --git a/tests/utils/tx_tester.py b/tests/utils/tx_tester.py index dd90c873..506cab37 100644 --- a/tests/utils/tx_tester.py +++ b/tests/utils/tx_tester.py @@ -228,8 +228,3 @@ def run(self) -> None: self._test_pruning() # TODO test failed tx - - # TODO implement extra copy - # test deep copy - #if ctx.do_not_test_copy is not True: - # cls.test_tx_copy(tx, ctx) diff --git a/tests/utils/tx_utils.py b/tests/utils/tx_utils.py index d29e720c..f6deec7a 100644 --- a/tests/utils/tx_utils.py +++ b/tests/utils/tx_utils.py @@ -35,13 +35,15 @@ def test_tx_copy(cls, tx: Optional[MoneroTx], context: Optional[TestContext]) -> AssertUtils.assert_equals(tx, copy) assert copy is not tx - # test different input references - if len(copy.inputs) == 0: - assert len(tx.inputs) == 0 - else: - assert copy.inputs != tx.inputs - for i, output in enumerate(copy.outputs): - assert tx.outputs[i].amount == output.amount + # test different input and output references: the vectors compare by value, so the references of their elements + assert len(copy.inputs) == len(tx.inputs) + assert len(copy.outputs) == len(tx.outputs) + for original, copied in zip([*tx.inputs, *tx.outputs], [*copy.inputs, *copy.outputs]): + assert copied is not original + assert copied.amount == original.amount + assert copied.tx is copy + if original.key_image is not None: + assert copied.key_image is not original.key_image # test copied tx ctx: TestContext = TestContext(context) @@ -70,6 +72,10 @@ def test_tx(cls, tx: MoneroTx | None, ctx: TestContext) -> None: tester: TxTester = TxTester(tx, ctx) tester.run() + # test deep copy + if ctx.do_not_test_copy is not True: + cls.test_tx_copy(tx, ctx) + @classmethod def test_miner_tx(cls, miner_tx: Optional[MoneroTx]) -> None: """Test monero miner tx. From 27ecbe97b9559c2787dcbf677dcf50b02f29b8db Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Mon, 30 Nov 2026 00:35:59 +0100 Subject: [PATCH 04/11] fix: handle diagnostics without range in check_types.py --- bin/check_types.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/check_types.py b/bin/check_types.py index 84b7dd08..08902f04 100755 --- a/bin/check_types.py +++ b/bin/check_types.py @@ -72,7 +72,8 @@ def main() -> int: for diagnostic in report.get("generalDiagnostics", []): if diagnostic["severity"] == "information": continue - start: dict[str, int] = diagnostic["range"]["start"] + # one about a whole file, as a cycle of imports, has no range: it is of its first line, so VS Code lists it too + start: dict[str, int] = diagnostic["range"]["start"] if "range" in diagnostic else {"line": 0, "character": 0} file: Path = Path(diagnostic["file"]) name: Path = file.relative_to(ROOT) if file.is_relative_to(ROOT) else file message: str = " ".join(line.strip() for line in diagnostic["message"].splitlines()) From b59c805fcc5691791f3032bdc10b69a6a120a02a Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Tue, 1 Dec 2026 22:51:24 +0100 Subject: [PATCH 05/11] tests: test the confirmations of the miner tx of JSON and binary blocks Binary blocks have no depth, so their miner tx has no number of confirmations, while the one of a block from a JSON request does. Pass the kind of request to test_miner_tx() and check both cases, instead of leaving the check commented out. Replace the commented out call of test_tx() with a note on why it does not work yet for miner txs. --- tests/utils/block_utils.py | 3 +-- tests/utils/context/binary_block_context.py | 1 + tests/utils/tx_utils.py | 26 ++++++++++----------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/utils/block_utils.py b/tests/utils/block_utils.py index 3b9d2ff8..755682d6 100644 --- a/tests/utils/block_utils.py +++ b/tests/utils/block_utils.py @@ -112,8 +112,7 @@ def test_block(cls, block: MoneroBlock, ctx: TestContext) -> None: # test required fields assert block.miner_tx is not None, "Expected block miner tx" - # TODO: miner tx doesn't have as much stuff, can't call TxUtils.test_tx? - TxUtils.test_miner_tx(block.miner_tx) + TxUtils.test_miner_tx(block.miner_tx, ctx.from_binary_block is True) cls.test_block_header(block, ctx.header_is_full, False) if ctx.has_hex: diff --git a/tests/utils/context/binary_block_context.py b/tests/utils/context/binary_block_context.py index bc02f4bd..0956c1ae 100644 --- a/tests/utils/context/binary_block_context.py +++ b/tests/utils/context/binary_block_context.py @@ -8,6 +8,7 @@ def __init__(self) -> None: """Initialize a new binary block test context.""" super().__init__() # set binary block test context constants + self.from_binary_block = True self.has_hex = False self.header_is_full = False self.has_txs = True diff --git a/tests/utils/tx_utils.py b/tests/utils/tx_utils.py index f6deec7a..4ae8c6ec 100644 --- a/tests/utils/tx_utils.py +++ b/tests/utils/tx_utils.py @@ -77,10 +77,11 @@ def test_tx(cls, tx: MoneroTx | None, ctx: TestContext) -> None: cls.test_tx_copy(tx, ctx) @classmethod - def test_miner_tx(cls, miner_tx: Optional[MoneroTx]) -> None: + def test_miner_tx(cls, miner_tx: Optional[MoneroTx], is_binary: bool) -> None: """Test monero miner tx. :param MoneroTx | None miner_tx: miner transaction to test. + :param bool is_binary: whether the transaction comes from a binary block request. """ assert miner_tx is not None assert miner_tx.is_miner_tx is not None @@ -91,16 +92,13 @@ def test_miner_tx(cls, miner_tx: Optional[MoneroTx]) -> None: assert miner_tx.unlock_time is not None assert miner_tx.unlock_time >= 0 assert miner_tx.is_confirmed - # TODO binary blocks doesn't have depth? - # assert miner_tx.num_confirmations is not None - # assert miner_tx.num_confirmations > 0 - - # TODO: miner tx does not have hashes in binary requests so this will fail, need to derive using prunable data - # ctx = new TestContext() - # ctx.has_json = false - # ctx.is_pruned = true - # ctx.is_full = false - # ctx.is_confirmed = true - # ctx.is_miner = true - # ctx.from_get_tx_pool = true - # cls.test_tx(miner_tx, ctx) + + # the number of confirmations is derived from the block depth, which binary blocks don't have + if is_binary: + assert miner_tx.num_confirmations is None + else: + assert miner_tx.num_confirmations is not None + assert miner_tx.num_confirmations > 0 + + # TODO monero-cpp: can't call cls.test_tx() on miner txs. Neither JSON nor binary requests set their hash, + # `in_tx_pool`, `is_double_spend_seen` and `fee`, and they are not listed in `block.txs` From 63b49f6bc8d111eb1aa599911d8794383873f77e Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 29 Nov 2026 22:43:04 +0100 Subject: [PATCH 06/11] tests: construct the objects of the data model from keywords --- tests/common/monero_utils/test_blocks.py | 63 +++---- tests/common/monero_utils/test_memory.py | 60 +++---- tests/common/test_serializable_struct.py | 22 +-- tests/daemon/model/test_blocks.py | 81 +++------ tests/daemon/model/test_info.py | 10 +- tests/daemon/model/test_mining.py | 8 +- tests/daemon/model/test_outputs.py | 42 ++--- tests/daemon/model/test_peers.py | 12 +- tests/daemon/model/test_rpc.py | 8 +- tests/daemon/model/test_txs.py | 81 +++------ tests/daemon/rpc/test_outputs.py | 4 +- tests/daemon/rpc/test_peers.py | 20 +-- tests/daemon/rpc/test_txs.py | 3 +- tests/daemon/test_interface.py | 3 +- tests/utils/send_and_update_txs_tester.py | 3 +- tests/utils/single_tx_sender.py | 6 +- tests/utils/sync_seed_tester.py | 4 +- tests/utils/test_utils.py | 4 +- tests/utils/tx_spammer.py | 3 +- .../view_only_and_offline_wallet_tester.py | 3 +- tests/utils/wallet_calls.py | 3 +- tests/utils/wallet_equality_utils.py | 3 +- tests/utils/wallet_notifications_tester.py | 15 +- tests/utils/wallet_send_utils.py | 5 +- tests/utils/wallet_sweeper.py | 6 +- tests/utils/wallet_sync_tester.py | 3 +- tests/utils/wallet_test_utils.py | 5 +- tests/utils/wallet_tx_tracker.py | 3 +- tests/wallet/base_test_monero_wallet.py | 4 +- tests/wallet/model/test_accounts.py | 3 +- tests/wallet/model/test_config.py | 4 +- tests/wallet/model/test_output_query.py | 39 ++--- tests/wallet/model/test_outputs.py | 17 +- tests/wallet/model/test_results.py | 25 +-- tests/wallet/model/test_transfer_query.py | 82 +++------ tests/wallet/model/test_transfers.py | 20 +-- tests/wallet/model/test_tx_query.py | 99 ++++------- tests/wallet/model/test_txs.py | 91 +++------- tests/wallet/test_creation.py | 160 +++++------------- tests/wallet/test_equality.py | 7 +- tests/wallet/test_full_offline.py | 3 +- tests/wallet/test_interface.py | 10 +- tests/wallet/test_keys_and_addresses.py | 45 ++--- tests/wallet/test_multisig.py | 30 +--- tests/wallet/test_outputs.py | 88 +++------- tests/wallet/test_proofs.py | 15 +- tests/wallet/test_send.py | 6 +- tests/wallet/test_support.py | 3 +- tests/wallet/test_sweep.py | 17 +- tests/wallet/test_sync.py | 12 +- tests/wallet/test_transfers.py | 69 +++----- tests/wallet/test_txs.py | 100 ++++------- 52 files changed, 419 insertions(+), 1013 deletions(-) diff --git a/tests/common/monero_utils/test_blocks.py b/tests/common/monero_utils/test_blocks.py index d5861b89..35280253 100644 --- a/tests/common/monero_utils/test_blocks.py +++ b/tests/common/monero_utils/test_blocks.py @@ -15,17 +15,13 @@ class TestMoneroUtilsBlocks(BaseTestClass): """Monero utilities blocks unit tests.""" def test_get_blocks_from_txs_dedup_and_order(self) -> None: - block1: MoneroBlock = MoneroBlock() - block1.height = 100 - block2: MoneroBlock = MoneroBlock() - block2.height = 200 + block1: MoneroBlock = MoneroBlock(height=100) + block2: MoneroBlock = MoneroBlock(height=200) - tx1: MoneroTxWallet = MoneroTxWallet() - tx1.hash = "a" * 64 + tx1: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx1.block = block1 - tx2: MoneroTxWallet = MoneroTxWallet() - tx2.hash = "b" * 64 + tx2: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) tx2.block = block2 tx3: MoneroTxWallet = MoneroTxWallet() # shares block1 with tx1 @@ -38,10 +34,8 @@ def test_get_blocks_from_txs_dedup_and_order(self) -> None: assert blocks[1] is block2 def test_get_blocks_from_txs_unconfirmed_placeholder(self) -> None: - tx1: MoneroTxWallet = MoneroTxWallet() - tx1.hash = "a" * 64 - tx2: MoneroTxWallet = MoneroTxWallet() - tx2.hash = "b" * 64 + tx1: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) + tx2: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) assert tx1.block is None and tx2.block is None blocks: list[MoneroBlock] = MoneroUtils.get_blocks_from_txs([tx1, tx2]) @@ -58,16 +52,12 @@ def test_get_blocks_from_txs_unconfirmed_placeholder(self) -> None: assert tx2.block is placeholder def test_get_blocks_from_txs_mixed_confirmed_and_unconfirmed(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 100 - confirmed: MoneroTxWallet = MoneroTxWallet() - confirmed.hash = "a" * 64 + block: MoneroBlock = MoneroBlock(height=100) + confirmed: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) confirmed.block = block - unconfirmed1: MoneroTxWallet = MoneroTxWallet() - unconfirmed1.hash = "b" * 64 - unconfirmed2: MoneroTxWallet = MoneroTxWallet() - unconfirmed2.hash = "c" * 64 + unconfirmed1: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) + unconfirmed2: MoneroTxWallet = MoneroTxWallet(hash="c" * 64) blocks: list[MoneroBlock] = MoneroUtils.get_blocks_from_txs([confirmed, unconfirmed1, unconfirmed2]) assert len(blocks) == 2 # the real block, plus one shared unconfirmed placeholder @@ -79,10 +69,8 @@ def test_get_blocks_from_txs_empty(self) -> None: assert MoneroUtils.get_blocks_from_txs([]) == [] def test_get_blocks_from_transfers_dedup_and_order(self) -> None: - block1: MoneroBlock = MoneroBlock() - block1.height = 100 - block2: MoneroBlock = MoneroBlock() - block2.height = 200 + block1: MoneroBlock = MoneroBlock(height=100) + block2: MoneroBlock = MoneroBlock(height=200) t1: MoneroIncomingTransfer = MoneroIncomingTransfer() t1.tx = MoneroTxWallet() @@ -123,8 +111,7 @@ def test_get_blocks_from_transfers_unconfirmed_placeholder(self) -> None: assert t2.tx.block is placeholder def test_get_blocks_from_transfers_mixed_confirmed_and_unconfirmed(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 100 + block: MoneroBlock = MoneroBlock(height=100) confirmed: MoneroIncomingTransfer = MoneroIncomingTransfer() confirmed.tx = MoneroTxWallet() confirmed.tx.hash = "a" * 64 @@ -147,8 +134,7 @@ def test_get_blocks_from_transfers_missing_tx_raises(self) -> None: # a transfer with no tx set is a legitimate, reachable state (it's just # never assigned); get_blocks_from_transfers() must raise a catchable # exception, not dereference transfer.tx and segfault - transfer: MoneroIncomingTransfer = MoneroIncomingTransfer() - transfer.amount = 500000 + transfer: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=500000) with pytest.raises(RuntimeError) as exc_info: MoneroUtils.get_blocks_from_transfers([transfer]) assert str(exc_info.value) == "Transfer has no tx" @@ -173,16 +159,12 @@ def test_get_blocks_from_transfers_empty(self) -> None: assert MoneroUtils.get_blocks_from_transfers([]) == [] def test_get_blocks_from_outputs_dedup_and_order(self) -> None: - block1: MoneroBlock = MoneroBlock() - block1.height = 100 - block2: MoneroBlock = MoneroBlock() - block2.height = 200 + block1: MoneroBlock = MoneroBlock(height=100) + block2: MoneroBlock = MoneroBlock(height=200) - tx1: MoneroTxWallet = MoneroTxWallet() - tx1.hash = "a" * 64 + tx1: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx1.block = block1 - tx2: MoneroTxWallet = MoneroTxWallet() - tx2.hash = "b" * 64 + tx2: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) tx2.block = block2 o1: MoneroOutputWallet = MoneroOutputWallet() @@ -211,10 +193,8 @@ def test_get_blocks_from_outputs_unconfirmed_raises(self) -> None: def test_get_blocks_from_outputs_unconfirmed_raises_after_earlier_match(self) -> None: # unlike get_blocks_from_transfers(), get_blocks_from_outputs() never mutates its inputs - block: MoneroBlock = MoneroBlock() - block.height = 100 - confirmed_tx: MoneroTxWallet = MoneroTxWallet() - confirmed_tx.hash = "a" * 64 + block: MoneroBlock = MoneroBlock(height=100) + confirmed_tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) confirmed_tx.block = block good: MoneroOutputWallet = MoneroOutputWallet() good.tx = confirmed_tx @@ -229,8 +209,7 @@ def test_get_blocks_from_outputs_unconfirmed_raises_after_earlier_match(self) -> def test_get_blocks_from_outputs_missing_tx_raises(self) -> None: # same as get_blocks_from_transfers(): output.tx is a legitimate but # unchecked null; must raise rather than dereference and segfault - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 1000000 + output: MoneroOutputWallet = MoneroOutputWallet(amount=1000000) with pytest.raises(RuntimeError) as exc_info: MoneroUtils.get_blocks_from_outputs([output]) assert str(exc_info.value) == "Output has no tx" diff --git a/tests/common/monero_utils/test_memory.py b/tests/common/monero_utils/test_memory.py index 9fc772a2..0865054e 100644 --- a/tests/common/monero_utils/test_memory.py +++ b/tests/common/monero_utils/test_memory.py @@ -28,10 +28,8 @@ class TestMoneroUtilsMemory(BaseTestClass): """Monero utilities memory unit tests.""" def test_free_block_breaks_tx_backlink(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 100 - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + block: MoneroBlock = MoneroBlock(height=100) + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx.block = block block.txs = [tx] @@ -39,17 +37,13 @@ def test_free_block_breaks_tx_backlink(self) -> None: assert tx.block is None def test_free_blocks_list(self) -> None: - block1: MoneroBlock = MoneroBlock() - block1.height = 1 - tx1: MoneroTxWallet = MoneroTxWallet() - tx1.hash = "a" * 64 + block1: MoneroBlock = MoneroBlock(height=1) + tx1: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx1.block = block1 block1.txs = [tx1] - block2: MoneroBlock = MoneroBlock() - block2.height = 2 - tx2: MoneroTxWallet = MoneroTxWallet() - tx2.hash = "b" * 64 + block2: MoneroBlock = MoneroBlock(height=2) + tx2: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) tx2.block = block2 block2.txs = [tx2] @@ -61,17 +55,14 @@ def test_free_tx_without_block_does_not_crash(self) -> None: # free(tx) creates a throwaway placeholder block for an unconfirmed # tx, then immediately frees it. Net no-op on tx.block, but exercises # that code path safely - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) assert tx.block is None MoneroUtils.free(tx) assert tx.block is None def test_free_tx_with_block(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 100 - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + block: MoneroBlock = MoneroBlock(height=100) + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx.block = block block.txs = [tx] @@ -79,25 +70,20 @@ def test_free_tx_with_block(self) -> None: assert tx.block is None def test_free_txs_list_confirmed_and_unconfirmed(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 100 - confirmed: MoneroTxWallet = MoneroTxWallet() - confirmed.hash = "a" * 64 + block: MoneroBlock = MoneroBlock(height=100) + confirmed: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) confirmed.block = block block.txs = [confirmed] - unconfirmed: MoneroTxWallet = MoneroTxWallet() - unconfirmed.hash = "b" * 64 + unconfirmed: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) MoneroUtils.free([confirmed, unconfirmed]) assert confirmed.block is None assert unconfirmed.block is None def test_free_transfers_list(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 100 - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + block: MoneroBlock = MoneroBlock(height=100) + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx.block = block block.txs = [tx] @@ -108,10 +94,8 @@ def test_free_transfers_list(self) -> None: assert transfer.tx.block is None def test_free_outputs_list(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 100 - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + block: MoneroBlock = MoneroBlock(height=100) + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx.block = block block.txs = [tx] @@ -136,12 +120,10 @@ def rss_mb() -> float: def run_batch(rounds: int) -> None: for _ in range(rounds): for _ in range(50): - block: MoneroBlock = MoneroBlock() - block.height = 100 + block: MoneroBlock = MoneroBlock(height=100) txs: list[MoneroTx] = [] for i in range(20): - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 63 + str(i % 10) + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 63 + str(i % 10)) tx.block = block txs.append(tx) block.txs = txs @@ -175,16 +157,14 @@ def test_free_none_does_not_crash(self) -> None: def test_free_transfers_missing_tx_raises(self) -> None: # free([transfers]) delegates to get_blocks_from_transfers(): a transfer # with no tx must surface a catchable exception, not segfault - transfer: MoneroIncomingTransfer = MoneroIncomingTransfer() - transfer.amount = 500000 + transfer: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=500000) with pytest.raises(RuntimeError) as exc_info: MoneroUtils.free([transfer]) assert str(exc_info.value) == "Transfer has no tx" def test_free_outputs_missing_tx_raises(self) -> None: # free([outputs]) delegates to get_blocks_from_outputs(): same guarantee - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 1000000 + output: MoneroOutputWallet = MoneroOutputWallet(amount=1000000) with pytest.raises(RuntimeError) as exc_info: MoneroUtils.free([output]) assert str(exc_info.value) == "Output has no tx" diff --git a/tests/common/test_serializable_struct.py b/tests/common/test_serializable_struct.py index 3afee76a..4099a50b 100644 --- a/tests/common/test_serializable_struct.py +++ b/tests/common/test_serializable_struct.py @@ -45,9 +45,7 @@ def test_equals_children(self) -> None: assert tx1 == tx2 # the block of a tx and the tx of an output are back references, like with monero-java - block: MoneroBlock = MoneroBlock() - block.height = 10 - block.txs = [tx1] + block: MoneroBlock = MoneroBlock(height=10, txs=[tx1]) tx1.block = block assert tx1.block is not None assert tx2.block is None @@ -55,8 +53,7 @@ def test_equals_children(self) -> None: assert tx1.outputs[0] == tx2.outputs[0] # the txs of a block are its children - other_block: MoneroBlock = MoneroBlock() - other_block.height = 10 + other_block: MoneroBlock = MoneroBlock(height=10) assert block != other_block other_block.txs = [tx2] assert block == other_block @@ -89,8 +86,7 @@ def test_vector_equals(self) -> None: assert tx.outputs != (copy,) # the vectors of structs without a shared_ptr too - account: MoneroAccount = MoneroAccount() - account.subaddresses = [self._get_subaddress()] + account: MoneroAccount = MoneroAccount(subaddresses=[self._get_subaddress()]) assert self._get_subaddress() in account.subaddresses assert account.subaddresses == [self._get_subaddress()] @@ -159,9 +155,7 @@ def test_connection_repr(self) -> None: # Cannot see the secrets of a wallet config in its representation def test_wallet_config_repr(self) -> None: secrets: list[str] = ["supersecretpassword123", "my seed words", "my seed offset", "my private view key", "my private spend key"] - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = "wallets/main" - config.primary_address = "my primary address" + config: MoneroWalletConfig = MoneroWalletConfig(path="wallets/main", primary_address="my primary address") config.password, config.seed, config.seed_offset, config.private_view_key, config.private_spend_key = secrets representation: str = repr(config) assert representation.startswith("MoneroWalletConfig(") @@ -200,12 +194,8 @@ def _get_subaddress(cls) -> MoneroSubaddress: @classmethod def _get_tx(cls) -> MoneroTx: - tx: MoneroTx = MoneroTxWallet() - tx.hash = "my tx hash" - tx.fee = 10 - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 1 - output.account_index = 0 + tx: MoneroTx = MoneroTxWallet(hash="my tx hash", fee=10) + output: MoneroOutputWallet = MoneroOutputWallet(amount=1, account_index=0) output.tx = tx tx.outputs = [output] return tx diff --git a/tests/daemon/model/test_blocks.py b/tests/daemon/model/test_blocks.py index b2a3b8f8..bccec2ea 100644 --- a/tests/daemon/model/test_blocks.py +++ b/tests/daemon/model/test_blocks.py @@ -64,19 +64,12 @@ def test_block_header_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(header) def test_block_deserialize(self) -> None: - block: MoneroBlock = MoneroBlock() - block.hash = "a" * 64 - block.height = 12345 - block.hex = "deadbeef" - block.tx_hashes = ["b" * 64, "c" * 64] - - miner_tx: MoneroTx = MoneroTx() - miner_tx.hash = "d" * 64 - miner_tx.is_miner_tx = True + block: MoneroBlock = MoneroBlock(hash="a" * 64, height=12345, hex="deadbeef", tx_hashes=["b" * 64, "c" * 64]) + + miner_tx: MoneroTx = MoneroTx(hash="d" * 64, is_miner_tx=True) block.miner_tx = miner_tx - tx: MoneroTx = MoneroTx() - tx.hash = "e" * 64 + tx: MoneroTx = MoneroTx(hash="e" * 64) block.txs = [tx] restored: MoneroBlock = AssertUtils.assert_serialization_integrity(block) @@ -98,17 +91,14 @@ def test_get_block_hashes_result_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(result) def test_get_blocks_by_hash_result_deserialize(self) -> None: - result: MoneroGetBlocksByHashResult = MoneroGetBlocksByHashResult() - result.current_height = 3000000 + result: MoneroGetBlocksByHashResult = MoneroGetBlocksByHashResult(current_height=3000000) # blocks are serialized but from_property_tree() never reads them back # (monero_block has no from_property_tree of its own); see test below AssertUtils.assert_serialization_integrity(result) def test_get_blocks_by_hash_result_blocks_deserialize(self) -> None: result: MoneroGetBlocksByHashResult = MoneroGetBlocksByHashResult() - block: MoneroBlock = MoneroBlock() - block.hash = "a" * 64 - block.height = 100 + block: MoneroBlock = MoneroBlock(hash="a" * 64, height=100) result.blocks = [block] json_str: str = result.serialize() logger.debug(f"Serialized get blocks by hash result: {json_str}") @@ -137,10 +127,7 @@ def test_block_header_copy(self) -> None: assert header.height == 100 def test_block_header_merge(self) -> None: - a: MoneroBlockHeader = MoneroBlockHeader() - a.hash = "a" * 64 - a.height = 100 - a.timestamp = 1700000000 + a: MoneroBlockHeader = MoneroBlockHeader(hash="a" * 64, height=100, timestamp=1700000000) b: MoneroBlockHeader = a.copy() b.height = 200 # height can increase -> resolves to the higher value @@ -156,27 +143,18 @@ def test_block_header_merge(self) -> None: def test_block_header_merge_conflict_raises(self) -> None: # fields without special reconciliation (e.g. hash) must match on both # sides, or merge() raises rather than silently picking one - a: MoneroBlockHeader = MoneroBlockHeader() - a.hash = "a" * 64 - b: MoneroBlockHeader = MoneroBlockHeader() - b.hash = "b" * 64 + a: MoneroBlockHeader = MoneroBlockHeader(hash="a" * 64) + b: MoneroBlockHeader = MoneroBlockHeader(hash="b" * 64) with pytest.raises(Exception, match="[Cc]annot reconcile"): a.merge(b) def test_block_copy(self) -> None: - block: MoneroBlock = MoneroBlock() - block.hash = "a" * 64 - block.height = 100 - block.hex = "deadbeef" - block.tx_hashes = ["b" * 64, "c" * 64] - - miner_tx: MoneroTx = MoneroTx() - miner_tx.hash = "d" * 64 - miner_tx.is_miner_tx = True + block: MoneroBlock = MoneroBlock(hash="a" * 64, height=100, hex="deadbeef", tx_hashes=["b" * 64, "c" * 64]) + + miner_tx: MoneroTx = MoneroTx(hash="d" * 64, is_miner_tx=True) block.miner_tx = miner_tx - tx: MoneroTx = MoneroTx() - tx.hash = "e" * 64 + tx: MoneroTx = MoneroTx(hash="e" * 64) block.txs = [tx] copy: MoneroBlock = block.copy() @@ -193,34 +171,26 @@ def test_block_copy(self) -> None: assert copy.txs[0].block is copy def test_block_merge(self) -> None: - a: MoneroBlock = MoneroBlock() - a.hash = "a" * 64 - a.height = 100 + a: MoneroBlock = MoneroBlock(hash="a" * 64, height=100) b: MoneroBlock = a.copy() b.hex = "deadbeef" # a.hex is unset -> merge fills the gap a.merge(b) assert a.hex == "deadbeef" def test_block_header_merge_dispatches_to_block_merge(self) -> None: - a: MoneroBlock = MoneroBlock() - a.height = 100 - b: MoneroBlock = MoneroBlock() - b.height = 100 + a: MoneroBlock = MoneroBlock(height=100) + b: MoneroBlock = MoneroBlock(height=100) b.hex = "deadbeef" # a.hex is unset -> merge fills the gap MoneroBlockHeader.merge(a, b) assert a.hex == "deadbeef" def test_block_merge_adopts_other_miner_tx(self) -> None: - a: MoneroBlock = MoneroBlock() - a.height = 100 + a: MoneroBlock = MoneroBlock(height=100) # a.miner_tx is unset -> merge adopts other's miner tx and repoints its block at a - b: MoneroBlock = MoneroBlock() - b.height = 100 - miner_tx: MoneroTx = MoneroTx() - miner_tx.hash = "a" * 64 - miner_tx.is_miner_tx = True + b: MoneroBlock = MoneroBlock(height=100) + miner_tx: MoneroTx = MoneroTx(hash="a" * 64, is_miner_tx=True) b.miner_tx = miner_tx a.merge(b) @@ -230,18 +200,13 @@ def test_block_merge_adopts_other_miner_tx(self) -> None: assert a.miner_tx.block is a def test_block_merge_merges_distinct_miner_txs(self) -> None: - a: MoneroBlock = MoneroBlock() - a.height = 100 - miner_a: MoneroTx = MoneroTx() - miner_a.hash = "a" * 64 + a: MoneroBlock = MoneroBlock(height=100) + miner_a: MoneroTx = MoneroTx(hash="a" * 64) miner_a.is_confirmed = True # required: tx merge() dereferences is_confirmed directly a.miner_tx = miner_a - b: MoneroBlock = MoneroBlock() - b.height = 100 - miner_b: MoneroTx = MoneroTx() - miner_b.hash = "a" * 64 - miner_b.is_confirmed = True + b: MoneroBlock = MoneroBlock(height=100) + miner_b: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True) miner_b.num_confirmations = 5 # miner_a's num_confirmations is unset -> merge fills the gap b.miner_tx = miner_b diff --git a/tests/daemon/model/test_info.py b/tests/daemon/model/test_info.py index 3d4cb616..3a3111af 100644 --- a/tests/daemon/model/test_info.py +++ b/tests/daemon/model/test_info.py @@ -38,16 +38,14 @@ def test_alt_chain_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(alt_chain) def test_prune_result_deserialize(self) -> None: - result: MoneroPruneResult = MoneroPruneResult() - result.pruning_seed = 387 + result: MoneroPruneResult = MoneroPruneResult(pruning_seed=387) # is_pruned is deliberately not set here: to_rapidjson_val() serializes it # under "isPruned" but from_property_tree() looks for "pruned" instead, so # it never round trips (see test below) AssertUtils.assert_serialization_integrity(result) def test_prune_result_is_pruned_deserialize(self) -> None: - result: MoneroPruneResult = MoneroPruneResult() - result.is_pruned = True + result: MoneroPruneResult = MoneroPruneResult(is_pruned=True) json_str: str = result.serialize() logger.debug(f"Serialized prune result: {json_str}") assert '"isPruned"' in json_str @@ -119,9 +117,7 @@ def test_daemon_sync_info_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(info) def test_daemon_sync_info_peers_and_spans_deserialize(self) -> None: - info: MoneroDaemonSyncInfo = MoneroDaemonSyncInfo() - info.peers = [MoneroPeer()] - info.spans = [MoneroConnectionSpan()] + info: MoneroDaemonSyncInfo = MoneroDaemonSyncInfo(peers=[MoneroPeer()], spans=[MoneroConnectionSpan()]) json_str: str = info.serialize() logger.debug(f"Serialized daemon sync info: {json_str}") assert "peers" in json_str and "spans" in json_str diff --git a/tests/daemon/model/test_mining.py b/tests/daemon/model/test_mining.py index 364c73f8..27fde899 100644 --- a/tests/daemon/model/test_mining.py +++ b/tests/daemon/model/test_mining.py @@ -54,9 +54,7 @@ def test_miner_tx_sum_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(summ) def test_generate_blocks_result_deserialize(self) -> None: - result: MoneroGenerateBlocksResult = MoneroGenerateBlocksResult() - result.block_hashes = ["a" * 64, "b" * 64] - result.height = 12345 + result: MoneroGenerateBlocksResult = MoneroGenerateBlocksResult(block_hashes=["a" * 64, "b" * 64], height=12345) AssertUtils.assert_serialization_integrity(result) def test_miner_data_deserialize(self) -> None: @@ -70,9 +68,7 @@ def test_miner_data_deserialize(self) -> None: data.difficulty = "0x1f4" # daemon reports difficulty as a hex string data.median_weight = 300000 data.already_generated_coins = 5646232813355588 - tx: MoneroTx = MoneroTx() - tx.hash = "d" * 64 - tx.fee = 10000 + tx: MoneroTx = MoneroTx(hash="d" * 64, fee=10000) data.tx_pool_backlog = [tx] AssertUtils.assert_serialization_integrity(data) diff --git a/tests/daemon/model/test_outputs.py b/tests/daemon/model/test_outputs.py index ca5ae2a0..5f862fa0 100644 --- a/tests/daemon/model/test_outputs.py +++ b/tests/daemon/model/test_outputs.py @@ -42,9 +42,7 @@ def test_output_is_locked(self) -> None: assert "isLocked" not in output.serialize() def test_key_image_deserialize(self) -> None: - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "a" * 64 - key_image.signature = "b" * 128 + key_image: MoneroKeyImage = MoneroKeyImage(hex="a" * 64, signature="b" * 128) AssertUtils.assert_serialization_integrity(key_image) def test_key_image_deserialize_key_images(self) -> None: @@ -70,12 +68,8 @@ def test_key_image_deserialize_key_images(self) -> None: MoneroKeyImage.deserialize_key_images("") def test_output_deserialize(self) -> None: - output: MoneroOutput = MoneroOutput() - output.amount = 1000000 - output.index = 5 - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "a" * 64 - key_image.signature = "b" * 128 + output: MoneroOutput = MoneroOutput(amount=1000000, index=5) + key_image: MoneroKeyImage = MoneroKeyImage(hex="a" * 64, signature="b" * 128) output.key_image = key_image AssertUtils.assert_serialization_integrity(output) @@ -105,28 +99,22 @@ def test_output_histogram_entry_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(entry) def test_key_image_copy(self) -> None: - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "a" * 64 - key_image.signature = "b" * 128 + key_image: MoneroKeyImage = MoneroKeyImage(hex="a" * 64, signature="b" * 128) copy: MoneroKeyImage = key_image.copy() assert copy is not key_image assert copy.serialize() == key_image.serialize() def test_key_image_merge(self) -> None: - a: MoneroKeyImage = MoneroKeyImage() - a.hex = "a" * 64 + a: MoneroKeyImage = MoneroKeyImage(hex="a" * 64) b: MoneroKeyImage = a.copy() b.signature = "b" * 128 # a.signature is unset -> merge fills the gap a.merge(b) assert a.signature == "b" * 128 def test_output_copy(self) -> None: - output: MoneroOutput = MoneroOutput() - output.amount = 1000000 - output.index = 5 - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "a" * 64 + output: MoneroOutput = MoneroOutput(amount=1000000, index=5) + key_image: MoneroKeyImage = MoneroKeyImage(hex="a" * 64) output.key_image = key_image copy: MoneroOutput = output.copy() @@ -135,9 +123,7 @@ def test_output_copy(self) -> None: assert copy.serialize() == output.serialize() def test_output_merge(self) -> None: - a: MoneroOutput = MoneroOutput() - a.amount = 1000000 - a.index = 5 + a: MoneroOutput = MoneroOutput(amount=1000000, index=5) b: MoneroOutput = a.copy() # preserves the (unset) tx reference, so merge won't recurse into tx merge b.key_image = MoneroKeyImage() b.key_image.hex = "a" * 64 @@ -146,13 +132,9 @@ def test_output_merge(self) -> None: assert a.key_image.hex == "a" * 64 def test_output_merge_recurses_into_tx_merge(self) -> None: - tx_a: MoneroTx = MoneroTx() - tx_a.hash = "a" * 64 - tx_a.is_confirmed = True + tx_a: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True) - tx_b: MoneroTx = MoneroTx() - tx_b.hash = "a" * 64 - tx_b.is_confirmed = True + tx_b: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True) tx_b.num_confirmations = 9 # only tx merge reconciles this out_a: MoneroOutput = MoneroOutput() @@ -170,9 +152,7 @@ def test_output_merge_recurses_into_tx_merge(self) -> None: assert tx_a.num_confirmations == 9 def test_output_merge_ring_output_indices_and_stealth_public_key(self) -> None: - a: MoneroOutput = MoneroOutput() - a.amount = 1000000 - a.index = 5 + a: MoneroOutput = MoneroOutput(amount=1000000, index=5) b: MoneroOutput = a.copy() # preserves the (unset) tx reference, so merge won't recurse into tx merge b.ring_output_indices = [10, 20, 30] b.stealth_public_key = "a" * 64 diff --git a/tests/daemon/model/test_peers.py b/tests/daemon/model/test_peers.py index bafeb988..086f8596 100644 --- a/tests/daemon/model/test_peers.py +++ b/tests/daemon/model/test_peers.py @@ -15,11 +15,7 @@ class TestMoneroDaemonModelPeers(BaseTestClass): """Daemon peers model unit tests.""" def test_ban_deserialize(self) -> None: - ban: MoneroBan = MoneroBan() - ban.host = "127.0.0.1" - ban.ip = 2130706433 - ban.is_banned = True - ban.seconds = 3600 + ban: MoneroBan = MoneroBan(host="127.0.0.1", ip=2130706433, is_banned=True, seconds=3600) AssertUtils.assert_serialization_integrity(ban) def test_connection_span_deserialize(self) -> None: @@ -65,8 +61,7 @@ def test_peer_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(peer) def test_peer_is_online_deserialize(self) -> None: - peer: MoneroPeer = MoneroPeer() - peer.is_online = True + peer: MoneroPeer = MoneroPeer(is_online=True) json_str: str = peer.serialize() logger.debug(f"Serialized peer: {json_str}") assert "isOnline" in json_str @@ -75,8 +70,7 @@ def test_peer_is_online_deserialize(self) -> None: assert restored.is_online == peer.is_online def test_peer_connection_serialization_integrity(self) -> None: - peer: MoneroPeer = MoneroPeer() - peer.connection_type = MoneroConnectionType.IPV6 + peer: MoneroPeer = MoneroPeer(connection_type=MoneroConnectionType.IPV6) json_str: str = peer.serialize() logger.debug(f"Serialized peer: {json_str}") assert "addressType" in json_str diff --git a/tests/daemon/model/test_rpc.py b/tests/daemon/model/test_rpc.py index 7ab6648a..5c1effb7 100644 --- a/tests/daemon/model/test_rpc.py +++ b/tests/daemon/model/test_rpc.py @@ -15,15 +15,11 @@ class TestMoneroDaemonModelRpc(BaseTestClass): """Daemon rpc model unit tests.""" def test_version_deserialize(self) -> None: - version: MoneroVersion = MoneroVersion() - version.number = 65552 - version.is_release = True + version: MoneroVersion = MoneroVersion(number=65552, is_release=True) AssertUtils.assert_serialization_integrity(version) def test_rpc_payment_info_deserialize(self) -> None: - info: MoneroRpcPaymentInfo = MoneroRpcPaymentInfo() - info.credits = 42 - info.top_block_hash = "a" * 64 + info: MoneroRpcPaymentInfo = MoneroRpcPaymentInfo(credits=42, top_block_hash="a" * 64) AssertUtils.assert_serialization_integrity(info) def test_rpc_connection_deserialize(self) -> None: diff --git a/tests/daemon/model/test_txs.py b/tests/daemon/model/test_txs.py index 229ac50f..d6b26ad6 100644 --- a/tests/daemon/model/test_txs.py +++ b/tests/daemon/model/test_txs.py @@ -65,34 +65,25 @@ def test_tx_unimplemented_fields(self, json_fragment: str) -> None: MoneroTx.deserialize(json_fragment) def test_tx_version_common_tx_sets_last_failed_and_max_used_block_height_deserialize(self) -> None: - tx: MoneroTx = MoneroTx() - tx.version = 2 - tx.common_tx_sets = "sets" - tx.last_failed_height = 100 - tx.max_used_block_height = 200 + tx: MoneroTx = MoneroTx(version=2, common_tx_sets="sets", last_failed_height=100, max_used_block_height=200) AssertUtils.assert_serialization_integrity(tx) def test_tx_ring_size_deserialize(self) -> None: - tx: MoneroTx = MoneroTx() - tx.ring_size = 16 + tx: MoneroTx = MoneroTx(ring_size=16) AssertUtils.assert_serialization_integrity(tx) def test_tx_extra_deserialize(self) -> None: - tx: MoneroTx = MoneroTx() - tx.extra = [1, 2, 3, 255] + tx: MoneroTx = MoneroTx(extra=[1, 2, 3, 255]) AssertUtils.assert_serialization_integrity(tx) def test_tx_inputs_outputs_and_output_indices_deserialize(self) -> None: - tx: MoneroTx = MoneroTx() - tx.output_indices = [100, 101] + tx: MoneroTx = MoneroTx(output_indices=[100, 101]) vin: MoneroOutput = MoneroOutput() vin.amount = 1 vin.key_image = MoneroKeyImage() vin.key_image.hex = "a" * 64 tx.inputs = [vin] - vout: MoneroOutput = MoneroOutput() - vout.amount = 2 - vout.index = 0 + vout: MoneroOutput = MoneroOutput(amount=2, index=0) tx.outputs = [vout] AssertUtils.assert_serialization_integrity(tx) @@ -117,8 +108,7 @@ def test_submit_tx_result_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(result) def test_submit_tx_result_is_good_deserialize(self) -> None: - result: MoneroSubmitTxResult = MoneroSubmitTxResult() - result.is_good = True + result: MoneroSubmitTxResult = MoneroSubmitTxResult(is_good=True) json_str: str = result.serialize() logger.debug(f"Serialized submit tx result: {json_str}") assert "isGood" in json_str @@ -144,8 +134,7 @@ def test_tx_pool_stats_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(stats) def test_tx_pool_stats_histo_deserialize(self) -> None: - stats: MoneroTxPoolStats = MoneroTxPoolStats() - stats.histo = {100: 1, 200: 2} + stats: MoneroTxPoolStats = MoneroTxPoolStats(histo={100: 1, 200: 2}) json_str: str = stats.serialize() logger.debug(f"Serialized tx pool stats: {json_str}") assert "histo" in json_str @@ -154,21 +143,16 @@ def test_tx_pool_stats_histo_deserialize(self) -> None: assert dict(restored.histo) == dict(stats.histo) def test_tx_copy(self) -> None: - tx: MoneroTx = MoneroTx() - tx.hash = "a" * 64 - tx.is_confirmed = True - tx.fee = 7500000 + tx: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True, fee=7500000) copy: MoneroTx = tx.copy() assert copy is not tx assert copy.serialize() == tx.serialize() def test_tx_copy_deep_copies_inputs(self) -> None: - tx: MoneroTx = MoneroTx() - tx.hash = "a" * 64 + tx: MoneroTx = MoneroTx(hash="a" * 64) - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "1" * 64 + key_image: MoneroKeyImage = MoneroKeyImage(hex="1" * 64) tx_input: MoneroOutput = MoneroOutput() tx_input.tx = tx tx_input.key_image = key_image @@ -236,8 +220,7 @@ def test_tx_copy_is_deep(self) -> None: assert tx.serialize() == original def test_tx_merge(self) -> None: - a: MoneroTx = MoneroTx() - a.hash = "a" * 64 + a: MoneroTx = MoneroTx(hash="a" * 64) a.is_confirmed = True # required: merge() dereferences is_confirmed directly a.fee = 7500000 @@ -247,56 +230,41 @@ def test_tx_merge(self) -> None: assert a.num_confirmations == 5 def test_tx_merge_adopts_other_block(self) -> None: - block: MoneroBlock = MoneroBlock() - block.height = 200 + block: MoneroBlock = MoneroBlock(height=200) - other: MoneroTx = MoneroTx() - other.hash = "a" * 64 - other.is_confirmed = True + other: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True) other.block = block block.txs = [other] - tx: MoneroTx = MoneroTx() - tx.hash = "a" * 64 - tx.is_confirmed = True + tx: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True) # tx.block is unset -> merge adopts other's block and repoints the block at tx tx.merge(other) assert tx.block is block assert block.txs[0] is tx def test_tx_merge_is_confirmed_can_become_true(self) -> None: - a: MoneroTx = MoneroTx() - a.hash = "a" * 64 - a.is_confirmed = False + a: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=False) b: MoneroTx = a.copy() b.is_confirmed = True a.merge(b) assert a.is_confirmed is True def test_tx_merge_is_double_spend_seen_can_become_true(self) -> None: - a: MoneroTx = MoneroTx() - a.hash = "a" * 64 - a.is_confirmed = True - a.is_double_spend_seen = False + a: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True, is_double_spend_seen=False) b: MoneroTx = a.copy() b.is_double_spend_seen = True a.merge(b) assert a.is_double_spend_seen is True def test_tx_merge_in_tx_pool_can_become_true(self) -> None: - a: MoneroTx = MoneroTx() - a.hash = "a" * 64 - a.is_confirmed = False - a.in_tx_pool = False + a: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=False, in_tx_pool=False) b: MoneroTx = a.copy() b.in_tx_pool = True a.merge(b) assert a.in_tx_pool is True def test_tx_merge_is_locked_can_become_false(self) -> None: - a: MoneroTx = MoneroTx() - a.hash = "a" * 64 - a.is_confirmed = True + a: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True) a.is_locked = False # self: already unlocked b: MoneroTx = a.copy() b.is_locked = True # other: still locked @@ -304,8 +272,7 @@ def test_tx_merge_is_locked_can_become_false(self) -> None: assert a.is_locked is False def test_tx_merge_extra_and_output_indices(self) -> None: - a: MoneroTx = MoneroTx() - a.hash = "a" * 64 + a: MoneroTx = MoneroTx(hash="a" * 64) a.is_confirmed = True # required: merge() dereferences is_confirmed directly b: MoneroTx = a.copy() b.extra = [1, 2, 3, 255] @@ -316,21 +283,17 @@ def test_tx_merge_extra_and_output_indices(self) -> None: def test_tx_merge_inputs(self) -> None: def make_input(tx: MoneroTx, key_image_hex: str) -> MoneroOutput: - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = key_image_hex + key_image: MoneroKeyImage = MoneroKeyImage(hex=key_image_hex) tx_input: MoneroOutput = MoneroOutput() tx_input.tx = tx tx_input.key_image = key_image return tx_input - a: MoneroTx = MoneroTx() - a.hash = "a" * 64 + a: MoneroTx = MoneroTx(hash="a" * 64) a.is_confirmed = True # required: merge() dereferences is_confirmed directly a.inputs = [make_input(a, "1" * 64)] - b: MoneroTx = MoneroTx() - b.hash = "a" * 64 - b.is_confirmed = True + b: MoneroTx = MoneroTx(hash="a" * 64, is_confirmed=True) shared_input: MoneroOutput = make_input(b, "1" * 64) # same key image -> merged into a's input shared_input.amount = 5000 b.inputs = [shared_input, make_input(b, "2" * 64)] # new key image -> appended diff --git a/tests/daemon/rpc/test_outputs.py b/tests/daemon/rpc/test_outputs.py index a5043054..340b0298 100644 --- a/tests/daemon/rpc/test_outputs.py +++ b/tests/daemon/rpc/test_outputs.py @@ -118,9 +118,7 @@ def test_get_outputs(self, daemon: MoneroDaemonRpc) -> None: requested: list[MoneroOutput] = [] for tx_hash in tx_hashes: for index in daemon.get_output_indices(tx_hash): - output: MoneroOutput = MoneroOutput() - output.amount = 0 - output.index = index + output: MoneroOutput = MoneroOutput(amount=0, index=index) requested.append(output) num_requested: int = len(requested) diff --git a/tests/daemon/rpc/test_peers.py b/tests/daemon/rpc/test_peers.py index 07e4fd54..9466cf88 100644 --- a/tests/daemon/rpc/test_peers.py +++ b/tests/daemon/rpc/test_peers.py @@ -109,10 +109,7 @@ def test_set_upload_bandwidth(self, daemon: MoneroDaemonRpc) -> None: def test_ban_peer(self, daemon: MoneroDaemonRpc) -> None: # set ban host: str = "192.168.1.51" - ban: MoneroBan = MoneroBan() - ban.host = host - ban.is_banned = True - ban.seconds = 60 + ban: MoneroBan = MoneroBan(host=host, is_banned=True, seconds=60) daemon.set_peer_ban(ban) # test ban @@ -131,14 +128,8 @@ def test_ban_peers(self, daemon: MoneroDaemonRpc) -> None: # set bans addr1: str = "192.168.1.52" addr2: str = "192.168.1.53" - ban1: MoneroBan = MoneroBan() - ban1.host = addr1 - ban1.is_banned = True - ban1.seconds = 60 - ban2: MoneroBan = MoneroBan() - ban2.host = addr2 - ban2.is_banned = True - ban2.seconds = 60 + ban1: MoneroBan = MoneroBan(host=addr1, is_banned=True, seconds=60) + ban2: MoneroBan = MoneroBan(host=addr2, is_banned=True, seconds=60) bans: list[MoneroBan] = [] bans.append(ban1) bans.append(ban2) @@ -162,10 +153,7 @@ def test_ban_peers(self, daemon: MoneroDaemonRpc) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_peer_ban(self, daemon: MoneroDaemonRpc) -> None: host: str = "192.168.1.60" - ban: MoneroBan = MoneroBan() - ban.host = host - ban.is_banned = True - ban.seconds = 60 + ban: MoneroBan = MoneroBan(host=host, is_banned=True, seconds=60) daemon.set_peer_ban(ban) banned: MoneroBan = daemon.get_peer_ban(host) diff --git a/tests/daemon/rpc/test_txs.py b/tests/daemon/rpc/test_txs.py index 630d9eed..c7d2be77 100644 --- a/tests/daemon/rpc/test_txs.py +++ b/tests/daemon/rpc/test_txs.py @@ -81,8 +81,7 @@ def test_get_txs_by_hashes(self, daemon: MoneroDaemonRpc, wallet: MoneroWalletRp dest: MoneroDestination = MoneroDestination() dest.address = wallet.get_primary_address() dest.amount = TxWalletUtils.MAX_FEE - config: MoneroTxConfig = MoneroTxConfig() - config.account_index = 0 + config: MoneroTxConfig = MoneroTxConfig(account_index=0) config.destinations.append(dest) tx = wallet.create_tx(config) assert tx.hash is not None diff --git a/tests/daemon/test_interface.py b/tests/daemon/test_interface.py index f86ce367..9128ed84 100644 --- a/tests/daemon/test_interface.py +++ b/tests/daemon/test_interface.py @@ -47,8 +47,7 @@ def get_listeners(self) -> set[MoneroDaemonListener]: @override def get_block_headers_by_range(self, start_height: int, end_height: int) -> list[MoneroBlockHeader]: - header: MoneroBlockHeader = MoneroBlockHeader() - header.height = start_height + header: MoneroBlockHeader = MoneroBlockHeader(height=start_height) return [header] daemon: MoneroDaemon = CustomDaemon() diff --git a/tests/utils/send_and_update_txs_tester.py b/tests/utils/send_and_update_txs_tester.py index 296254e9..2fb21352 100644 --- a/tests/utils/send_and_update_txs_tester.py +++ b/tests/utils/send_and_update_txs_tester.py @@ -169,8 +169,7 @@ def wait_for_confirmations(self, sent_txs: list[MoneroTxWallet], num_confirmatio assert sent_tx.hash is not None tx_hashes.append(sent_tx.hash) - query: MoneroTxQuery = MoneroTxQuery() - query.hashes = tx_hashes + query: MoneroTxQuery = MoneroTxQuery(hashes=tx_hashes) fetched_txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(self.wallet, query, None, True, TestUtils.REGTEST) assert len(fetched_txs) > 0 diff --git a/tests/utils/single_tx_sender.py b/tests/utils/single_tx_sender.py index 3f9da93c..a8f3883b 100644 --- a/tests/utils/single_tx_sender.py +++ b/tests/utils/single_tx_sender.py @@ -114,8 +114,7 @@ def _get_locked_txs(self) -> list[MoneroTxWallet]: :returns list[MoneroTxWallet]: locked txs. """ # query locked txs - query: MoneroTxQuery = MoneroTxQuery() - query.is_locked = True + query: MoneroTxQuery = MoneroTxQuery(is_locked=True) locked_txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(self._wallet, query, None, True, TestUtils.REGTEST) for locked_tx in locked_txs: @@ -246,8 +245,7 @@ def _handle_non_relayed_tx(self, txs: list[MoneroTxWallet], config: MoneroTxConf assert len(tx_hash) == 64 # fetch txs for testing - query: MoneroTxQuery = MoneroTxQuery() - query.hashes = tx_hashes + query: MoneroTxQuery = MoneroTxQuery(hashes=tx_hashes) return self._wallet.get_txs(query) #endregion diff --git a/tests/utils/sync_seed_tester.py b/tests/utils/sync_seed_tester.py index b7c1a664..041ad1cb 100644 --- a/tests/utils/sync_seed_tester.py +++ b/tests/utils/sync_seed_tester.py @@ -177,9 +177,7 @@ def test(self) -> None: TestUtils.WALLET_TX_TRACKER.wait_for_txs_to_clear_pool(self.wallet) # create wallet from seed - config: MoneroWalletConfig = MoneroWalletConfig() - config.seed = TestUtils.SEED - config.restore_height = self.restore_height + config: MoneroWalletConfig = MoneroWalletConfig(seed=TestUtils.SEED, restore_height=self.restore_height) wallet: MoneroWalletFull = self.create_wallet(config, False) # sanitize expected sync bounds diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index f9098b28..c63c1175 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -355,9 +355,7 @@ def get_wallet_keys_config(cls) -> MoneroWalletConfig: :returns MoneroWalletConfig: new test wallet keys configuration. """ - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = cls.NETWORK_TYPE - config.seed = cls.SEED + config: MoneroWalletConfig = MoneroWalletConfig(network_type=cls.NETWORK_TYPE, seed=cls.SEED) return config @classmethod diff --git a/tests/utils/tx_spammer.py b/tests/utils/tx_spammer.py index c65cf019..344d9d18 100644 --- a/tests/utils/tx_spammer.py +++ b/tests/utils/tx_spammer.py @@ -33,8 +33,7 @@ def create_spam_wallets(self, n: int = 10) -> list[MoneroWallet]: assert n >= 0, "n must be >= 0" wallets: list[MoneroWallet] = [] # setup basic wallet config - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = self._network_type + config: MoneroWalletConfig = MoneroWalletConfig(network_type=self._network_type) # create n random wallets for i in range(n): wallet: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) diff --git a/tests/utils/view_only_and_offline_wallet_tester.py b/tests/utils/view_only_and_offline_wallet_tester.py index dca22ca7..c9b09558 100644 --- a/tests/utils/view_only_and_offline_wallet_tester.py +++ b/tests/utils/view_only_and_offline_wallet_tester.py @@ -96,8 +96,7 @@ def _test_offline_wallet(self) -> None: # TODO monero-project: cannot get seed from offline wallet rpc assert TestUtils.SEED == self._offline_wallet.get_seed() - query: MoneroTxQuery = MoneroTxQuery() - query.in_tx_pool = False + query: MoneroTxQuery = MoneroTxQuery(in_tx_pool=False) txs: list[MoneroTxWallet] = self._offline_wallet.get_txs(query) assert len(txs) == 0 diff --git a/tests/utils/wallet_calls.py b/tests/utils/wallet_calls.py index 58f2c6df..35491abe 100644 --- a/tests/utils/wallet_calls.py +++ b/tests/utils/wallet_calls.py @@ -48,8 +48,7 @@ def __str__(self) -> str: def _tx_with_metadata() -> MoneroTxWallet: - tx: MoneroTxWallet = MoneroTxWallet() - tx.metadata = StringUtils.get_random_string() + tx: MoneroTxWallet = MoneroTxWallet(metadata=StringUtils.get_random_string()) return tx diff --git a/tests/utils/wallet_equality_utils.py b/tests/utils/wallet_equality_utils.py index 918f1783..46e1cb7a 100644 --- a/tests/utils/wallet_equality_utils.py +++ b/tests/utils/wallet_equality_utils.py @@ -46,8 +46,7 @@ def test_wallet_equality_on_chain(cls, w1: MoneroWallet, w2: MoneroWallet) -> No assert w1.get_private_view_key() == w2.get_private_view_key() assert w1.get_private_spend_key() == w2.get_private_spend_key() - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_confirmed = True + tx_query: MoneroTxQuery = MoneroTxQuery(is_confirmed=True) cls.test_tx_wallets_equal_on_chain(w1.get_txs(tx_query), w2.get_txs(tx_query)) tx_query.include_outputs = True cls.test_tx_wallets_equal_on_chain(w1.get_txs(tx_query), w2.get_txs(tx_query)) # fetch and compare outputs diff --git a/tests/utils/wallet_notifications_tester.py b/tests/utils/wallet_notifications_tester.py index 83b6a0d7..393b7fb0 100644 --- a/tests/utils/wallet_notifications_tester.py +++ b/tests/utils/wallet_notifications_tester.py @@ -173,8 +173,7 @@ def _run(self) -> None: destination_accounts = [1] if self.sweep_output else [1, 2, 3] expected_outputs: list[MoneroOutputWallet] = [] sender_tx: MoneroTxWallet - config: MoneroTxConfig = MoneroTxConfig() - config.relay = not self.create_then_relay + config: MoneroTxConfig = MoneroTxConfig(relay=not self.create_then_relay) if self.sweep_output: ctx.is_sweep_response = True ctx.is_sweep_output_response = True @@ -182,8 +181,7 @@ def _run(self) -> None: output_query.is_spent = False output_query.account_index = 0 output_query.min_amount = TxWalletUtils.MAX_FEE * 5 - unlocked_query: MoneroTxQuery = MoneroTxQuery() - unlocked_query.is_locked = False + unlocked_query: MoneroTxQuery = MoneroTxQuery(is_locked=False) output_query.set_tx_query(unlocked_query, True) outputs: list[MoneroOutputWallet] = sender.get_outputs(output_query) if len(outputs) == 0: @@ -230,9 +228,7 @@ def _run(self) -> None: issues.append("WARNING: sender tx incoming amount != outgoing amount - fee when sent to same wallet") elif sender_tx.get_incoming_amount() != 0: issues.append("ERROR: tx incoming amount should be 0") - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hash = tx_hash - tx_query.include_outputs = True + tx_query: MoneroTxQuery = MoneroTxQuery(hash=tx_hash, include_outputs=True) sender_tx = sender.get_txs(tx_query)[0] assert sender_tx.fee is not None sender_balance: int = sender.get_balance() @@ -547,10 +543,7 @@ def _output_str(output: MoneroOutputWallet) -> str: @staticmethod def _outputs_query(tx_hash: str, is_confirmed: Optional[bool] = None, is_locked: Optional[bool] = None) -> MoneroOutputQuery: """Query for the outputs of the tx with `tx_hash`.""" - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hash = tx_hash - tx_query.is_confirmed = is_confirmed - tx_query.is_locked = is_locked + tx_query: MoneroTxQuery = MoneroTxQuery(hash=tx_hash, is_confirmed=is_confirmed, is_locked=is_locked) query: MoneroOutputQuery = MoneroOutputQuery() query.set_tx_query(tx_query, True) return query diff --git a/tests/utils/wallet_send_utils.py b/tests/utils/wallet_send_utils.py index 11abf016..57137c31 100644 --- a/tests/utils/wallet_send_utils.py +++ b/tests/utils/wallet_send_utils.py @@ -24,10 +24,7 @@ def test_send_to_single(cls, wallet: MoneroWallet, can_split: bool, relay: Optio :param bool | None relay: Relay created transaction(s). :param str | None payment_id: Transaction payment id. """ - config: MoneroTxConfig = MoneroTxConfig() - config.can_split = can_split - config.relay = relay - config.payment_id = payment_id + config: MoneroTxConfig = MoneroTxConfig(can_split=can_split, relay=relay, payment_id=payment_id) sender: SingleTxSender = SingleTxSender(wallet, config) sender.send() diff --git a/tests/utils/wallet_sweeper.py b/tests/utils/wallet_sweeper.py index fbc20526..666ed832 100644 --- a/tests/utils/wallet_sweeper.py +++ b/tests/utils/wallet_sweeper.py @@ -49,10 +49,8 @@ def _check_for_balance(self) -> None: def _check_outputs(self) -> None: """Check for outputs amount after sweep.""" # all unspent, unlocked outputs must be less than fee - query: MoneroOutputQuery = MoneroOutputQuery() - query.is_spent = False - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_locked = False + query: MoneroOutputQuery = MoneroOutputQuery(is_spent=False) + tx_query: MoneroTxQuery = MoneroTxQuery(is_locked=False) query.set_tx_query(tx_query, True) spendable_outputs: list[MoneroOutputWallet] = self._wallet.get_outputs(query) for spendable_output in spendable_outputs: diff --git a/tests/utils/wallet_sync_tester.py b/tests/utils/wallet_sync_tester.py index 747f5638..95e66396 100644 --- a/tests/utils/wallet_sync_tester.py +++ b/tests/utils/wallet_sync_tester.py @@ -169,8 +169,7 @@ def on_done(self, chain_height: int) -> None: # output notifications do not include pool fees or outgoing amount pool_spend_amount: int = 0 - query: MoneroTxQuery = MoneroTxQuery() - query.in_tx_pool = True + query: MoneroTxQuery = MoneroTxQuery(in_tx_pool=True) for pool_tx in self.wallet.get_txs(query): assert pool_tx.fee is not None pool_spend_amount += pool_tx.get_outgoing_amount() + pool_tx.fee diff --git a/tests/utils/wallet_test_utils.py b/tests/utils/wallet_test_utils.py index b75b7037..38082fe4 100644 --- a/tests/utils/wallet_test_utils.py +++ b/tests/utils/wallet_test_utils.py @@ -120,10 +120,7 @@ def build_tx_config( :param bool supports_get_accounts: `True` if the wallet supports listing/creating accounts. :returns MoneroTxConfig: tx configuration with one destination per underfunded subaddress. """ - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = 0 - tx_config.relay = True - tx_config.can_split = True + tx_config: MoneroTxConfig = MoneroTxConfig(account_index=0, relay=True, can_split=True) while supports_get_accounts and len(wallet.get_accounts()) < num_accounts: wallet.create_account() diff --git a/tests/utils/wallet_tx_tracker.py b/tests/utils/wallet_tx_tracker.py index a612abb6..e0a3acde 100644 --- a/tests/utils/wallet_tx_tracker.py +++ b/tests/utils/wallet_tx_tracker.py @@ -95,8 +95,7 @@ def _wait_for_txs_to_clear(self, clear_from_wallet: bool, wallets: list[MoneroWa assert result.num_blocks_fetched is not None if result.num_blocks_fetched > 0: logger.debug(f"Synced wallet {i + 1}, blocks fetched {result.num_blocks_fetched}") - query: MoneroTxQuery = MoneroTxQuery() - query.in_tx_pool = True + query: MoneroTxQuery = MoneroTxQuery(in_tx_pool=True) pool_txs: list[MoneroTxWallet] = wallet.get_txs(query) for tx in pool_txs: assert tx.hash is not None diff --git a/tests/wallet/base_test_monero_wallet.py b/tests/wallet/base_test_monero_wallet.py index 12a830bc..07089e48 100644 --- a/tests/wallet/base_test_monero_wallet.py +++ b/tests/wallet/base_test_monero_wallet.py @@ -129,9 +129,7 @@ def _open_wallet_from_path(self, path: str, password: str | None) -> MoneroWalle :param str | None password: wallet password. :returns MoneroWallet: opened wallet. """ - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path - config.password = password + config: MoneroWalletConfig = MoneroWalletConfig(path=path, password=password) return self._open_wallet(config) diff --git a/tests/wallet/model/test_accounts.py b/tests/wallet/model/test_accounts.py index 07c830fc..7a6c3958 100644 --- a/tests/wallet/model/test_accounts.py +++ b/tests/wallet/model/test_accounts.py @@ -48,8 +48,7 @@ def test_account_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(account) def test_account_subaddresses_deserialize(self) -> None: - account: MoneroAccount = MoneroAccount() - account.subaddresses = [MoneroSubaddress()] + account: MoneroAccount = MoneroAccount(subaddresses=[MoneroSubaddress()]) json_str: str = account.serialize() logger.debug(f"Serialized account: {json_str}") assert "subaddresses" in json_str diff --git a/tests/wallet/model/test_config.py b/tests/wallet/model/test_config.py index faf18110..29f55e30 100644 --- a/tests/wallet/model/test_config.py +++ b/tests/wallet/model/test_config.py @@ -79,9 +79,7 @@ def test_get_normalized_destinations_uses_destinations_when_address_and_amount_u assert config.get_normalized_destinations() == config.destinations def test_get_normalized_destinations_builds_single_destination(self) -> None: - config: MoneroTxConfig = MoneroTxConfig() - config.address = TestUtils.ADDRESS - config.amount = 500000 + config: MoneroTxConfig = MoneroTxConfig(address=TestUtils.ADDRESS, amount=500000) assert len(config.destinations) == 0 # address/amount alone don't populate destinations normalized: list[MoneroDestination] = config.get_normalized_destinations() diff --git a/tests/wallet/model/test_output_query.py b/tests/wallet/model/test_output_query.py index efc9339d..3250b811 100644 --- a/tests/wallet/model/test_output_query.py +++ b/tests/wallet/model/test_output_query.py @@ -82,8 +82,7 @@ def test_output_query_reassign_same_tx_query(self, output_query: bool) -> None: assert (tx_query.output_query if output_query else tx_query.input_query) == query def test_output_query_meets_criteria_matches_unconstrained_output(self) -> None: - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 1 + output: MoneroOutputWallet = MoneroOutputWallet(amount=1) assert MoneroOutputQuery().meets_criteria(output, False) is True @pytest.mark.parametrize("field,value,other_value", [ @@ -94,8 +93,7 @@ def test_output_query_meets_criteria_matches_unconstrained_output(self) -> None: ("is_frozen", False, True), ]) def test_output_query_meets_criteria_field_filters(self, field: str, value: object, other_value: object) -> None: - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 1 + output: MoneroOutputWallet = MoneroOutputWallet(amount=1) setattr(output, field, value) query: MoneroOutputQuery = MoneroOutputQuery() @@ -147,44 +145,34 @@ def test_output_query_meets_criteria_key_image(self) -> None: assert no_key_image_query.meets_criteria(MoneroOutputWallet(), False) is False def test_output_query_meets_criteria_subaddress_indices(self) -> None: - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 1 - output.subaddress_index = 7 + output: MoneroOutputWallet = MoneroOutputWallet(amount=1, subaddress_index=7) - query: MoneroOutputQuery = MoneroOutputQuery() - query.subaddress_indices = [7, 8] + query: MoneroOutputQuery = MoneroOutputQuery(subaddress_indices=[7, 8]) assert query.meets_criteria(output, False) is True query.subaddress_indices = [1, 2] assert query.meets_criteria(output, False) is False def test_output_query_meets_criteria_min_max_amount(self) -> None: - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 50 + output: MoneroOutputWallet = MoneroOutputWallet(amount=50) - min_query: MoneroOutputQuery = MoneroOutputQuery() - min_query.min_amount = 10 + min_query: MoneroOutputQuery = MoneroOutputQuery(min_amount=10) assert min_query.meets_criteria(output, False) is True min_query.min_amount = 100 assert min_query.meets_criteria(output, False) is False - max_query: MoneroOutputQuery = MoneroOutputQuery() - max_query.max_amount = 100 + max_query: MoneroOutputQuery = MoneroOutputQuery(max_amount=100) assert max_query.meets_criteria(output, False) is True max_query.max_amount = 10 assert max_query.meets_criteria(output, False) is False def test_output_query_meets_criteria_query_parent_links_tx_query(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 1 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) + output: MoneroOutputWallet = MoneroOutputWallet(amount=1) output.tx = tx - query: MoneroOutputQuery = MoneroOutputQuery() - query.amount = 1 - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hash = "b" * 64 + query: MoneroOutputQuery = MoneroOutputQuery(amount=1) + tx_query: MoneroTxQuery = MoneroTxQuery(hash="b" * 64) query.set_tx_query(tx_query, True) # query_parent defaults to True: the mismatching tx_query rejects the output @@ -239,10 +227,7 @@ def test_output_query_deserialize_from_block_no_txs(self) -> None: assert restored.tx_query is None def test_output_query_copy(self) -> None: - query: MoneroOutputQuery = MoneroOutputQuery() - query.amount = 1000000 - query.min_amount = 100000 - query.max_amount = 2000000 + query: MoneroOutputQuery = MoneroOutputQuery(amount=1000000, min_amount=100000, max_amount=2000000) copy: MoneroOutputQuery = query.copy() assert copy is not query diff --git a/tests/wallet/model/test_outputs.py b/tests/wallet/model/test_outputs.py index 0f8537db..9dff67ee 100644 --- a/tests/wallet/model/test_outputs.py +++ b/tests/wallet/model/test_outputs.py @@ -15,12 +15,8 @@ class TestMoneroWalletModelOutputs(BaseTestClass): """Wallet output model unit tests.""" def test_output_wallet_deserialize(self) -> None: - output_wallet: MoneroOutputWallet = MoneroOutputWallet() - output_wallet.amount = 1000000 - output_wallet.index = 2 - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "a" * 64 - key_image.signature = "b" * 128 + output_wallet: MoneroOutputWallet = MoneroOutputWallet(amount=1000000, index=2) + key_image: MoneroKeyImage = MoneroKeyImage(hex="a" * 64, signature="b" * 128) output_wallet.key_image = key_image output_wallet.account_index = 0 output_wallet.subaddress_index = 1 @@ -31,8 +27,7 @@ def test_output_wallet_deserialize(self) -> None: def test_output_wallet_is_locked(self) -> None: output: MoneroOutputWallet = MoneroOutputWallet() assert output.is_locked is None - tx: MoneroTx = MoneroTx() - tx.is_locked = True + tx: MoneroTx = MoneroTx(is_locked=True) output.tx = tx assert output.is_locked is True @@ -50,11 +45,7 @@ def test_output_wallet_copy(self) -> None: assert copy.serialize() == output.serialize() def test_output_wallet_merge(self) -> None: - a: MoneroOutputWallet = MoneroOutputWallet() - a.amount = 1000000 - a.index = 2 - a.account_index = 0 - a.subaddress_index = 1 + a: MoneroOutputWallet = MoneroOutputWallet(amount=1000000, index=2, account_index=0, subaddress_index=1) # a.tx is left unset on both sides so merge() won't recurse into tx merge b: MoneroOutputWallet = a.copy() diff --git a/tests/wallet/model/test_results.py b/tests/wallet/model/test_results.py index 7eeadd2a..f81f76d9 100644 --- a/tests/wallet/model/test_results.py +++ b/tests/wallet/model/test_results.py @@ -56,24 +56,15 @@ def test_check_tx_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(check) def test_check_reserve_deserialize(self) -> None: - check: MoneroCheckReserve = MoneroCheckReserve() - check.is_good = True - check.total_amount = 1000000 - check.unconfirmed_spent_amount = 0 + check: MoneroCheckReserve = MoneroCheckReserve(is_good=True, total_amount=1000000, unconfirmed_spent_amount=0) AssertUtils.assert_serialization_integrity(check) def test_multisig_info_deserialize(self) -> None: - info: MoneroMultisigInfo = MoneroMultisigInfo() - info.is_multisig = True - info.is_ready = True - info.threshold = 2 - info.num_participants = 3 + info: MoneroMultisigInfo = MoneroMultisigInfo(is_multisig=True, is_ready=True, threshold=2, num_participants=3) AssertUtils.assert_serialization_integrity(info) def test_multisig_init_result_deserialize(self) -> None: - result: MoneroMultisigInitResult = MoneroMultisigInitResult() - result.address = TestUtils.ADDRESS - result.multisig_hex = "deadbeef" + result: MoneroMultisigInitResult = MoneroMultisigInitResult(address=TestUtils.ADDRESS, multisig_hex="deadbeef") AssertUtils.assert_serialization_integrity(result) def test_multisig_sign_result_deserialize(self) -> None: @@ -89,15 +80,11 @@ def test_sync_result_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(result) def test_check_deserialize(self) -> None: - check: MoneroCheck = MoneroCheck() - check.is_good = True + check: MoneroCheck = MoneroCheck(is_good=True) AssertUtils.assert_serialization_integrity(check) def test_key_image_export_result_deserialize(self) -> None: - result: MoneroKeyImageExportResult = MoneroKeyImageExportResult() - result.offset = 3 - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "a" * 64 - key_image.signature = "b" * 128 + result: MoneroKeyImageExportResult = MoneroKeyImageExportResult(offset=3) + key_image: MoneroKeyImage = MoneroKeyImage(hex="a" * 64, signature="b" * 128) result.key_images = [key_image] AssertUtils.assert_serialization_integrity(result) diff --git a/tests/wallet/model/test_transfer_query.py b/tests/wallet/model/test_transfer_query.py index 5f84c66c..0db0b3e6 100644 --- a/tests/wallet/model/test_transfer_query.py +++ b/tests/wallet/model/test_transfer_query.py @@ -75,8 +75,7 @@ def test_transfer_query_reassign_same_tx_query(self) -> None: assert tx_query.transfer_query is transfer_query def test_transfer_query_meets_criteria_matches_unconstrained_transfer(self) -> None: - transfer: MoneroIncomingTransfer = MoneroIncomingTransfer() - transfer.amount = 100 + transfer: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=100) assert MoneroTransferQuery().meets_criteria(transfer, False) is True @pytest.mark.parametrize("field,value,other_value", [ @@ -84,8 +83,7 @@ def test_transfer_query_meets_criteria_matches_unconstrained_transfer(self) -> N ("account_index", 2, 5), ]) def test_transfer_query_meets_criteria_common_field_filters(self, field: str, value: object, other_value: object) -> None: - transfer: MoneroIncomingTransfer = MoneroIncomingTransfer() - transfer.amount = 1 + transfer: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=1) setattr(transfer, field, value) query: MoneroTransferQuery = MoneroTransferQuery() @@ -96,13 +94,10 @@ def test_transfer_query_meets_criteria_common_field_filters(self, field: str, va assert query.meets_criteria(transfer, False) is False def test_transfer_query_meets_criteria_incoming_outgoing_flags(self) -> None: - incoming: MoneroIncomingTransfer = MoneroIncomingTransfer() - incoming.amount = 1 - outgoing: MoneroOutgoingTransfer = MoneroOutgoingTransfer() - outgoing.amount = 1 + incoming: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=1) + outgoing: MoneroOutgoingTransfer = MoneroOutgoingTransfer(amount=1) - incoming_query: MoneroTransferQuery = MoneroTransferQuery() - incoming_query.incoming = True + incoming_query: MoneroTransferQuery = MoneroTransferQuery(incoming=True) assert incoming_query.meets_criteria(incoming, False) is True assert incoming_query.meets_criteria(outgoing, False) is False @@ -114,15 +109,12 @@ def test_transfer_query_meets_criteria_incoming_outgoing_flags(self) -> None: def test_transfer_query_meets_criteria_incoming_has_destinations_always_false(self) -> None: # has_destinations is an outgoing-only concept; setting it on the query # rejects an incoming transfer regardless of True/False - incoming: MoneroIncomingTransfer = MoneroIncomingTransfer() - incoming.amount = 1 + incoming: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=1) - query_true: MoneroTransferQuery = MoneroTransferQuery() - query_true.has_destinations = True + query_true: MoneroTransferQuery = MoneroTransferQuery(has_destinations=True) assert query_true.meets_criteria(incoming, False) is False - query_false: MoneroTransferQuery = MoneroTransferQuery() - query_false.has_destinations = False + query_false: MoneroTransferQuery = MoneroTransferQuery(has_destinations=False) assert query_false.meets_criteria(incoming, False) is False def test_transfer_query_meets_criteria_incoming_address_fields(self) -> None: @@ -131,8 +123,7 @@ def test_transfer_query_meets_criteria_incoming_address_fields(self) -> None: incoming.address = TestUtils.ADDRESS incoming.subaddress_index = 3 - address_query: MoneroTransferQuery = MoneroTransferQuery() - address_query.address = TestUtils.ADDRESS + address_query: MoneroTransferQuery = MoneroTransferQuery(address=TestUtils.ADDRESS) assert address_query.meets_criteria(incoming, False) is True address_query.address = TestUtils.MINING_ADDRESS assert address_query.meets_criteria(incoming, False) is False @@ -143,14 +134,12 @@ def test_transfer_query_meets_criteria_incoming_address_fields(self) -> None: addresses_query.addresses = [TestUtils.MINING_ADDRESS] assert addresses_query.meets_criteria(incoming, False) is False - subaddress_index_query: MoneroTransferQuery = MoneroTransferQuery() - subaddress_index_query.subaddress_index = 3 + subaddress_index_query: MoneroTransferQuery = MoneroTransferQuery(subaddress_index=3) assert subaddress_index_query.meets_criteria(incoming, False) is True subaddress_index_query.subaddress_index = 9 assert subaddress_index_query.meets_criteria(incoming, False) is False - subaddress_indices_query: MoneroTransferQuery = MoneroTransferQuery() - subaddress_indices_query.subaddress_indices = [3, 4] + subaddress_indices_query: MoneroTransferQuery = MoneroTransferQuery(subaddress_indices=[3, 4]) assert subaddress_indices_query.meets_criteria(incoming, False) is True subaddress_indices_query.subaddress_indices = [9] assert subaddress_indices_query.meets_criteria(incoming, False) is False @@ -161,34 +150,28 @@ def test_transfer_query_meets_criteria_outgoing_address_fields(self) -> None: outgoing.addresses = [TestUtils.ADDRESS, TestUtils.MINING_ADDRESS] # a single address must be a member of the transfer's address list - address_query: MoneroTransferQuery = MoneroTransferQuery() - address_query.address = TestUtils.ADDRESS + address_query: MoneroTransferQuery = MoneroTransferQuery(address=TestUtils.ADDRESS) assert address_query.meets_criteria(outgoing, False) is True address_query.address = "9" + "z" * 94 assert address_query.meets_criteria(outgoing, False) is False assert address_query.meets_criteria(MoneroOutgoingTransfer(), False) is False # no addresses at all # a list of addresses only needs to intersect - addresses_query: MoneroTransferQuery = MoneroTransferQuery() - addresses_query.addresses = [TestUtils.MINING_ADDRESS, "9" + "z" * 94] + addresses_query: MoneroTransferQuery = MoneroTransferQuery(addresses=[TestUtils.MINING_ADDRESS, "9" + "z" * 94]) assert addresses_query.meets_criteria(outgoing, False) is True addresses_query.addresses = ["9" + "z" * 94] assert addresses_query.meets_criteria(outgoing, False) is False def test_transfer_query_meets_criteria_outgoing_subaddress_fields(self) -> None: - outgoing: MoneroOutgoingTransfer = MoneroOutgoingTransfer() - outgoing.amount = 1 - outgoing.subaddress_indices = [3, 4] + outgoing: MoneroOutgoingTransfer = MoneroOutgoingTransfer(amount=1, subaddress_indices=[3, 4]) - subaddress_index_query: MoneroTransferQuery = MoneroTransferQuery() - subaddress_index_query.subaddress_index = 3 + subaddress_index_query: MoneroTransferQuery = MoneroTransferQuery(subaddress_index=3) assert subaddress_index_query.meets_criteria(outgoing, False) is True subaddress_index_query.subaddress_index = 9 assert subaddress_index_query.meets_criteria(outgoing, False) is False assert subaddress_index_query.meets_criteria(MoneroOutgoingTransfer(), False) is False # no indices at all - subaddress_indices_query: MoneroTransferQuery = MoneroTransferQuery() - subaddress_indices_query.subaddress_indices = [4, 100] + subaddress_indices_query: MoneroTransferQuery = MoneroTransferQuery(subaddress_indices=[4, 100]) assert subaddress_indices_query.meets_criteria(outgoing, False) is True subaddress_indices_query.subaddress_indices = [100, 200] assert subaddress_indices_query.meets_criteria(outgoing, False) is False @@ -197,31 +180,25 @@ def test_transfer_query_meets_criteria_outgoing_has_destinations(self) -> None: with_destinations: MoneroOutgoingTransfer = MoneroOutgoingTransfer() with_destinations.amount = 1 with_destinations.destinations = [MoneroDestination(TestUtils.ADDRESS, 1)] - without_destinations: MoneroOutgoingTransfer = MoneroOutgoingTransfer() - without_destinations.amount = 1 + without_destinations: MoneroOutgoingTransfer = MoneroOutgoingTransfer(amount=1) - query_true: MoneroTransferQuery = MoneroTransferQuery() - query_true.has_destinations = True + query_true: MoneroTransferQuery = MoneroTransferQuery(has_destinations=True) assert query_true.meets_criteria(with_destinations, False) is True assert query_true.meets_criteria(without_destinations, False) is False - query_false: MoneroTransferQuery = MoneroTransferQuery() - query_false.has_destinations = False + query_false: MoneroTransferQuery = MoneroTransferQuery(has_destinations=False) assert query_false.meets_criteria(without_destinations, False) is True assert query_false.meets_criteria(with_destinations, False) is False def test_transfer_query_meets_criteria_invalid_transfer_type_raises(self) -> None: - transfer: MoneroTransfer = MoneroTransfer() - transfer.amount = 1 + transfer: MoneroTransfer = MoneroTransfer(amount=1) with pytest.raises(RuntimeError) as exc_info: MoneroTransferQuery().meets_criteria(transfer, False) assert str(exc_info.value) == "Transfer must be monero_incoming_transfer or monero_outgoing_transfer" def test_transfer_query_meets_criteria_query_parent_links_tx_query(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 - transfer: MoneroIncomingTransfer = MoneroIncomingTransfer() - transfer.amount = 100 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) + transfer: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=100) transfer.tx = tx query: MoneroTransferQuery = MoneroTransferQuery() @@ -263,11 +240,8 @@ def test_transfer_query_unimplemented_fields(self, json_fragment: str) -> None: MoneroTransferQuery.deserialize(json_fragment) def test_transfer_query_deserialize_from_block(self) -> None: - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hash = "a" * 64 - transfer_query: MoneroTransferQuery = MoneroTransferQuery() - transfer_query.amount = 500000 - transfer_query.account_index = 0 + tx_query: MoneroTxQuery = MoneroTxQuery(hash="a" * 64) + transfer_query: MoneroTransferQuery = MoneroTransferQuery(amount=500000, account_index=0) tx_query.transfer_query = transfer_query # deserialize_from_block expects a block node wrapping the tx query under "txs" @@ -280,8 +254,7 @@ def test_transfer_query_deserialize_from_block(self) -> None: def test_transfer_query_deserialize_from_block_no_nested_query(self) -> None: # a tx with no nested transferQuery gets an empty one, linked to the tx query - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hash = "a" * 64 + tx_query: MoneroTxQuery = MoneroTxQuery(hash="a" * 64) block_json: str = '{"txs":[' + tx_query.serialize() + ']}' restored: MoneroTransferQuery = MoneroTransferQuery.deserialize_from_block(block_json) assert restored.amount is None @@ -294,10 +267,7 @@ def test_transfer_query_deserialize_from_block_no_txs(self) -> None: assert restored.tx_query is None def test_transfer_query_copy(self) -> None: - query: MoneroTransferQuery = MoneroTransferQuery() - query.amount = 500000 - query.incoming = True - query.address = TestUtils.ADDRESS + query: MoneroTransferQuery = MoneroTransferQuery(amount=500000, incoming=True, address=TestUtils.ADDRESS) copy: MoneroTransferQuery = query.copy() assert copy is not query diff --git a/tests/wallet/model/test_transfers.py b/tests/wallet/model/test_transfers.py index 89823c73..9f7ebc3f 100644 --- a/tests/wallet/model/test_transfers.py +++ b/tests/wallet/model/test_transfers.py @@ -54,10 +54,7 @@ def test_incoming_transfer_copy(self) -> None: assert copy.serialize() == transfer.serialize() def test_incoming_transfer_merge(self) -> None: - a: MoneroIncomingTransfer = MoneroIncomingTransfer() - a.amount = 500000 - a.account_index = 0 - a.subaddress_index = 1 + a: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=500000, account_index=0, subaddress_index=1) # a.tx is left unset on both sides so merge() won't recurse into tx merge b: MoneroIncomingTransfer = a.copy() @@ -66,13 +63,9 @@ def test_incoming_transfer_merge(self) -> None: assert a.address == TestUtils.ADDRESS def test_incoming_transfer_merge_recurses_into_tx_merge(self) -> None: - tx_a: MoneroTxWallet = MoneroTxWallet() - tx_a.hash = "a" * 64 - tx_a.is_confirmed = True + tx_a: MoneroTxWallet = MoneroTxWallet(hash="a" * 64, is_confirmed=True) - tx_b: MoneroTxWallet = MoneroTxWallet() - tx_b.hash = "a" * 64 - tx_b.is_confirmed = True + tx_b: MoneroTxWallet = MoneroTxWallet(hash="a" * 64, is_confirmed=True) tx_b.num_confirmations = 9 # tx_a's num_confirmations is unset -> merge fills the gap a: MoneroIncomingTransfer = MoneroIncomingTransfer() @@ -90,8 +83,7 @@ def test_incoming_transfer_merge_recurses_into_tx_merge(self) -> None: assert tx_a.num_confirmations == 9 def test_incoming_transfer_merge_zero_amount_conflict_keeps_original(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) a: MoneroIncomingTransfer = MoneroIncomingTransfer() a.tx = tx @@ -142,9 +134,7 @@ def test_outgoing_transfer_copy(self) -> None: assert copy.serialize() == transfer.serialize() def test_outgoing_transfer_merge(self) -> None: - a: MoneroOutgoingTransfer = MoneroOutgoingTransfer() - a.amount = 500000 - a.account_index = 0 + a: MoneroOutgoingTransfer = MoneroOutgoingTransfer(amount=500000, account_index=0) # a.addresses/subaddress_indices/destinations left empty on both sides so far b: MoneroOutgoingTransfer = a.copy() diff --git a/tests/wallet/model/test_tx_query.py b/tests/wallet/model/test_tx_query.py index d6049d41..51bf2673 100644 --- a/tests/wallet/model/test_tx_query.py +++ b/tests/wallet/model/test_tx_query.py @@ -70,8 +70,7 @@ def test_tx_query(self) -> None: assert input_query.tx_query is None def test_tx_query_meets_criteria_matches_unconstrained_tx(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) assert MoneroTxQuery().meets_criteria(tx) is True @pytest.mark.parametrize("field,value,other_value", [ @@ -87,8 +86,7 @@ def test_tx_query_meets_criteria_matches_unconstrained_tx(self) -> None: ("is_outgoing", True, False), ]) def test_tx_query_meets_criteria_field_filters(self, field: str, value: object, other_value: object) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) setattr(tx, field, value) query: MoneroTxQuery = MoneroTxQuery() @@ -99,42 +97,31 @@ def test_tx_query_meets_criteria_field_filters(self, field: str, value: object, assert query.meets_criteria(tx) is False def test_tx_query_meets_criteria_has_payment_id(self) -> None: - with_payment_id: MoneroTxWallet = MoneroTxWallet() - with_payment_id.hash = "a" * 64 - with_payment_id.payment_id = "b" * 16 - without_payment_id: MoneroTxWallet = MoneroTxWallet() - without_payment_id.hash = "c" * 64 - - query_true: MoneroTxQuery = MoneroTxQuery() - query_true.has_payment_id = True + with_payment_id: MoneroTxWallet = MoneroTxWallet(hash="a" * 64, payment_id="b" * 16) + without_payment_id: MoneroTxWallet = MoneroTxWallet(hash="c" * 64) + + query_true: MoneroTxQuery = MoneroTxQuery(has_payment_id=True) assert query_true.meets_criteria(with_payment_id) is True assert query_true.meets_criteria(without_payment_id) is False - query_false: MoneroTxQuery = MoneroTxQuery() - query_false.has_payment_id = False + query_false: MoneroTxQuery = MoneroTxQuery(has_payment_id=False) assert query_false.meets_criteria(without_payment_id) is True assert query_false.meets_criteria(with_payment_id) is False def test_tx_query_meets_criteria_hashes(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) - query: MoneroTxQuery = MoneroTxQuery() - query.hashes = ["a" * 64, "b" * 64] + query: MoneroTxQuery = MoneroTxQuery(hashes=["a" * 64, "b" * 64]) assert query.meets_criteria(tx) is True query.hashes = ["c" * 64] assert query.meets_criteria(tx) is False def test_tx_query_meets_criteria_payment_ids(self) -> None: - with_payment_id: MoneroTxWallet = MoneroTxWallet() - with_payment_id.hash = "a" * 64 - with_payment_id.payment_id = "b" * 16 - without_payment_id: MoneroTxWallet = MoneroTxWallet() - without_payment_id.hash = "c" * 64 + with_payment_id: MoneroTxWallet = MoneroTxWallet(hash="a" * 64, payment_id="b" * 16) + without_payment_id: MoneroTxWallet = MoneroTxWallet(hash="c" * 64) - query: MoneroTxQuery = MoneroTxQuery() - query.payment_ids = ["b" * 16, "d" * 16] + query: MoneroTxQuery = MoneroTxQuery(payment_ids=["b" * 16, "d" * 16]) assert query.meets_criteria(with_payment_id) is True assert query.meets_criteria(without_payment_id) is False # tx has no payment id at all @@ -143,36 +130,30 @@ def test_tx_query_meets_criteria_payment_ids(self) -> None: def test_tx_query_meets_criteria_height_filters(self) -> None: def confirmed_tx(height: int) -> MoneroTxWallet: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 - block: MoneroBlock = MoneroBlock() - block.height = height + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) + block: MoneroBlock = MoneroBlock(height=height) tx.block = block return tx tx: MoneroTxWallet = confirmed_tx(100) - height_query: MoneroTxQuery = MoneroTxQuery() - height_query.height = 100 + height_query: MoneroTxQuery = MoneroTxQuery(height=100) assert height_query.meets_criteria(tx) is True height_query.height = 200 assert height_query.meets_criteria(tx) is False - min_query: MoneroTxQuery = MoneroTxQuery() - min_query.min_height = 50 + min_query: MoneroTxQuery = MoneroTxQuery(min_height=50) assert min_query.meets_criteria(tx) is True min_query.min_height = 150 assert min_query.meets_criteria(tx) is False - max_query: MoneroTxQuery = MoneroTxQuery() - max_query.max_height = 150 + max_query: MoneroTxQuery = MoneroTxQuery(max_height=150) assert max_query.meets_criteria(tx) is True max_query.max_height = 50 assert max_query.meets_criteria(tx) is False # an unconfirmed tx (no height) meets a min height, as in monero-java, but not a height or a max height - unconfirmed: MoneroTxWallet = MoneroTxWallet() - unconfirmed.hash = "b" * 64 + unconfirmed: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) assert min_query.meets_criteria(unconfirmed) is True assert height_query.meets_criteria(unconfirmed) is False assert max_query.meets_criteria(unconfirmed) is False @@ -199,10 +180,8 @@ def tx_with_outgoing(amount: int) -> MoneroTxWallet: return tx def tx_with_incoming(amount: int) -> MoneroTxWallet: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 - transfer: MoneroIncomingTransfer = MoneroIncomingTransfer() - transfer.amount = amount + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) + transfer: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=amount) transfer.tx = tx tx.incoming_transfers = [transfer] return tx @@ -217,20 +196,16 @@ def tx_with_incoming(amount: int) -> MoneroTxWallet: # outgoing fails the query but an incoming transfer still matches as a fallback tx: MoneroTxWallet = tx_with_outgoing(1) - incoming: MoneroIncomingTransfer = MoneroIncomingTransfer() - incoming.amount = 500 + incoming: MoneroIncomingTransfer = MoneroIncomingTransfer(amount=500) incoming.tx = tx tx.incoming_transfers = [incoming] assert query.meets_criteria(tx, True) is True def test_tx_query_meets_criteria_input_query(self) -> None: - tx_no_inputs: MoneroTxWallet = MoneroTxWallet() - tx_no_inputs.hash = "a" * 64 + tx_no_inputs: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) - tx_with_input: MoneroTxWallet = MoneroTxWallet() - tx_with_input.hash = "b" * 64 - tx_input: MoneroOutputWallet = MoneroOutputWallet() - tx_input.amount = 100 + tx_with_input: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) + tx_input: MoneroOutputWallet = MoneroOutputWallet(amount=100) tx_with_input.inputs = [tx_input] query: MoneroTxQuery = MoneroTxQuery() @@ -244,13 +219,10 @@ def test_tx_query_meets_criteria_input_query(self) -> None: assert query.meets_criteria(tx_with_input, True) is True # one input matches def test_tx_query_meets_criteria_output_query(self) -> None: - tx_no_outputs: MoneroTxWallet = MoneroTxWallet() - tx_no_outputs.hash = "a" * 64 + tx_no_outputs: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) - tx_with_output: MoneroTxWallet = MoneroTxWallet() - tx_with_output.hash = "b" * 64 - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 100 + tx_with_output: MoneroTxWallet = MoneroTxWallet(hash="b" * 64) + output: MoneroOutputWallet = MoneroOutputWallet(amount=100) tx_with_output.outputs = [output] query: MoneroTxQuery = MoneroTxQuery() @@ -285,9 +257,7 @@ def test_tx_query_deserialize(self) -> None: AssertUtils.assert_serialization_integrity(tx_query) def test_tx_query_is_incoming_deserialize_not_duplicated(self) -> None: - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_incoming = True - tx_query.is_outgoing = False + tx_query: MoneroTxQuery = MoneroTxQuery(is_incoming=True, is_outgoing=False) json_str: str = tx_query.serialize() logger.debug(f"Serialized tx query: {json_str}") assert json_str.count("isIncoming") == 1 @@ -308,12 +278,8 @@ def test_tx_query_is_incoming_deserialize_not_duplicated(self) -> None: def test_tx_query_nested_transfer_query_deserialize(self) -> None: # transfer_query is a nested sub-object that to_rapidjson_val() and # from_property_tree() both handle recursively - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.height = 3000000 - transfer_query: MoneroTransferQuery = MoneroTransferQuery() - transfer_query.incoming = True - transfer_query.amount = 500000 - transfer_query.account_index = 0 + tx_query: MoneroTxQuery = MoneroTxQuery(height=3000000) + transfer_query: MoneroTransferQuery = MoneroTransferQuery(incoming=True, amount=500000, account_index=0) tx_query.transfer_query = transfer_query json_str: str = tx_query.serialize() @@ -387,10 +353,7 @@ def test_tx_query_deserialize_from_block_no_txs(self) -> None: assert restored.block is None def test_tx_query_copy(self) -> None: - query: MoneroTxQuery = MoneroTxQuery() - query.hash = "a" * 64 - query.height = 3000000 - query.is_confirmed = True + query: MoneroTxQuery = MoneroTxQuery(hash="a" * 64, height=3000000, is_confirmed=True) copy: MoneroTxQuery = query.copy() assert copy is not query diff --git a/tests/wallet/model/test_txs.py b/tests/wallet/model/test_txs.py index ce87ac95..ae374cf5 100644 --- a/tests/wallet/model/test_txs.py +++ b/tests/wallet/model/test_txs.py @@ -63,14 +63,11 @@ def test_tx_wallet_unimplemented_fields(self, json_fragment: str) -> None: MoneroTxWallet.deserialize(json_fragment) def test_tx_set_deserialize(self) -> None: - tx_set: MoneroTxSet = MoneroTxSet() - tx_set.unsigned_tx_hex = "deadbeef" - tx_set.multisig_tx_hex = "beefdead" + tx_set: MoneroTxSet = MoneroTxSet(unsigned_tx_hex="deadbeef", multisig_tx_hex="beefdead") AssertUtils.assert_serialization_integrity(tx_set) def test_tx_set_signed_tx_hex_deserialize(self) -> None: - tx_set: MoneroTxSet = MoneroTxSet() - tx_set.signed_tx_hex = "deadbeef" + tx_set: MoneroTxSet = MoneroTxSet(signed_tx_hex="deadbeef") AssertUtils.assert_serialization_integrity(tx_set) def test_tx_set_txs_deserialize(self) -> None: @@ -120,21 +117,16 @@ def test_tx_wallet_merge_incoming_transfers_with_unset_indices_are_kept_distinct ) def test_tx_wallet_copy(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 - tx.is_confirmed = True - tx.note = "hello" + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64, is_confirmed=True, note="hello") copy: MoneroTxWallet = tx.copy() assert copy is not tx assert copy.serialize() == tx.serialize() def test_tx_wallet_copy_re_copies_inputs_as_output_wallet(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "1" * 64 + key_image: MoneroKeyImage = MoneroKeyImage(hex="1" * 64) tx_input: MoneroOutputWallet = MoneroOutputWallet() tx_input.tx = tx tx_input.key_image = key_image @@ -157,8 +149,7 @@ def test_tx_wallet_copy_re_copies_inputs_as_output_wallet(self) -> None: assert copy.inputs[0].tx is copy def test_tx_wallet_merge(self) -> None: - a: MoneroTxWallet = MoneroTxWallet() - a.hash = "a" * 64 + a: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) a.is_confirmed = True # required: base monero_tx::merge() dereferences is_confirmed directly b: MoneroTxWallet = a.copy() @@ -167,9 +158,7 @@ def test_tx_wallet_merge(self) -> None: assert a.note == "hello" def test_tx_wallet_merge_is_locked_can_become_false(self) -> None: - a: MoneroTxWallet = MoneroTxWallet() - a.hash = "a" * 64 - a.is_confirmed = True + a: MoneroTxWallet = MoneroTxWallet(hash="a" * 64, is_confirmed=True) a.is_locked = False # self: already unlocked b: MoneroTxWallet = a.copy() b.is_locked = True # other: still locked @@ -177,8 +166,7 @@ def test_tx_wallet_merge_is_locked_can_become_false(self) -> None: assert a.is_locked is False def test_tx_wallet_inputs_deserialize_as_output_wallet(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) tx_input: MoneroOutputWallet = MoneroOutputWallet() tx_input.amount = 500000 tx_input.index = 7 @@ -208,8 +196,7 @@ def test_tx_wallet_inputs_deserialize_as_output_wallet(self) -> None: assert restored.inputs[0].tx is restored def test_tx_wallet_outputs_deserialize_as_output_wallet(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) output: MoneroOutputWallet = MoneroOutputWallet() output.amount = 500000 output.index = 3 @@ -232,11 +219,8 @@ def test_tx_wallet_outputs_deserialize_as_output_wallet(self) -> None: assert restored.outputs[0].is_frozen is False def test_tx_wallet_get_outputs_wallet_after_deserialize(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 500000 - output.index = 3 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) + output: MoneroOutputWallet = MoneroOutputWallet(amount=500000, index=3) tx.outputs = [output] restored: MoneroTxWallet = MoneroTxWallet.deserialize(tx.serialize()) @@ -247,17 +231,14 @@ def test_tx_wallet_get_outputs_wallet_after_deserialize(self) -> None: def test_tx_wallet_filter_inputs_wallet(self) -> None: def make_input(account_index: int, amount: int) -> MoneroOutputWallet: - tx_input: MoneroOutputWallet = MoneroOutputWallet() - tx_input.account_index = account_index - tx_input.amount = amount + tx_input: MoneroOutputWallet = MoneroOutputWallet(account_index=account_index, amount=amount) return tx_input tx: MoneroTxWallet = MoneroTxWallet() tx.hash = "a" * 64 tx.inputs = [make_input(0, 100), make_input(1, 200), make_input(0, 300)] - query: MoneroOutputQuery = MoneroOutputQuery() - query.account_index = 0 + query: MoneroOutputQuery = MoneroOutputQuery(account_index=0) # filter returns the matches and drops the rest from tx.inputs in place matched: list[MoneroOutputWallet] = tx.filter_inputs_wallet(query) @@ -270,17 +251,14 @@ def make_input(account_index: int, amount: int) -> MoneroOutputWallet: def test_tx_wallet_get_inputs_wallet(self) -> None: def make_input(account_index: int, amount: int) -> MoneroOutputWallet: - tx_input: MoneroOutputWallet = MoneroOutputWallet() - tx_input.account_index = account_index - tx_input.amount = amount + tx_input: MoneroOutputWallet = MoneroOutputWallet(account_index=account_index, amount=amount) return tx_input tx: MoneroTxWallet = MoneroTxWallet() tx.hash = "a" * 64 tx.inputs = [make_input(0, 100), make_input(1, 200), make_input(0, 300)] - query: MoneroOutputQuery = MoneroOutputQuery() - query.account_index = 0 + query: MoneroOutputQuery = MoneroOutputQuery(account_index=0) # get_inputs_wallet() does not mutate tx.inputs matched: list[MoneroOutputWallet] = tx.get_inputs_wallet(query) @@ -292,17 +270,14 @@ def make_input(account_index: int, amount: int) -> MoneroOutputWallet: def test_tx_wallet_filter_outputs_wallet(self) -> None: def make_output(account_index: int, amount: int) -> MoneroOutputWallet: - output: MoneroOutputWallet = MoneroOutputWallet() - output.account_index = account_index - output.amount = amount + output: MoneroOutputWallet = MoneroOutputWallet(account_index=account_index, amount=amount) return output tx: MoneroTxWallet = MoneroTxWallet() tx.hash = "a" * 64 tx.outputs = [make_output(0, 100), make_output(1, 200), make_output(0, 300)] - query: MoneroOutputQuery = MoneroOutputQuery() - query.account_index = 0 + query: MoneroOutputQuery = MoneroOutputQuery(account_index=0) # filter returns the matches and drops the rest from tx.outputs in place matched: list[MoneroOutputWallet] = tx.filter_outputs_wallet(query) @@ -314,26 +289,18 @@ def make_output(account_index: int, amount: int) -> MoneroOutputWallet: assert len(tx.filter_outputs_wallet(MoneroOutputQuery())) == 2 def test_tx_wallet_filter_transfers(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) - outgoing: MoneroOutgoingTransfer = MoneroOutgoingTransfer() - outgoing.amount = 1000 + outgoing: MoneroOutgoingTransfer = MoneroOutgoingTransfer(amount=1000) - incoming_1: MoneroIncomingTransfer = MoneroIncomingTransfer() - incoming_1.account_index = 0 - incoming_1.amount = 100 + incoming_1: MoneroIncomingTransfer = MoneroIncomingTransfer(account_index=0, amount=100) - incoming_2: MoneroIncomingTransfer = MoneroIncomingTransfer() - incoming_2.account_index = 1 - incoming_2.amount = 200 + incoming_2: MoneroIncomingTransfer = MoneroIncomingTransfer(account_index=1, amount=200) tx.outgoing_transfer = outgoing tx.incoming_transfers = [incoming_1, incoming_2] - query: MoneroTransferQuery = MoneroTransferQuery() - query.incoming = True - query.account_index = 0 + query: MoneroTransferQuery = MoneroTransferQuery(incoming=True, account_index=0) # filter returns the matches and drops the rest (outgoing_transfer cleared, incoming_2 removed) matched: list[MoneroTransfer] = tx.filter_transfers(query) @@ -369,25 +336,19 @@ def test_tx_wallet_get_transfers_with_query(self) -> None: tx.incoming_transfers[0].amount = 100 tx.incoming_transfers[1].amount = 200 - incoming_query: MoneroTransferQuery = MoneroTransferQuery() - incoming_query.incoming = True + incoming_query: MoneroTransferQuery = MoneroTransferQuery(incoming=True) assert [t.amount for t in tx.get_transfers(incoming_query)] == [100, 200] outgoing_query: MoneroTransferQuery = MoneroTransferQuery() outgoing_query.outgoing = True assert [t.amount for t in tx.get_transfers(outgoing_query)] == [1000] - no_match_query: MoneroTransferQuery = MoneroTransferQuery() - no_match_query.amount = 999999 + no_match_query: MoneroTransferQuery = MoneroTransferQuery(amount=999999) assert tx.get_transfers(no_match_query) == [] def test_tx_wallet_copy_preserves_output_wallet_type(self) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.hash = "a" * 64 - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = 500000 - output.account_index = 2 - output.is_spent = True + tx: MoneroTxWallet = MoneroTxWallet(hash="a" * 64) + output: MoneroOutputWallet = MoneroOutputWallet(amount=500000, account_index=2, is_spent=True) tx.outputs = [output] copy: MoneroTxWallet = tx.copy() diff --git a/tests/wallet/test_creation.py b/tests/wallet/test_creation.py index a25a532c..042ab395 100644 --- a/tests/wallet/test_creation.py +++ b/tests/wallet/test_creation.py @@ -64,15 +64,13 @@ def test_create_wallet_random(self) -> None: self._close_wallet(wallet) # attempt to create wallet at same path - config = MoneroWalletConfig() - config.path = path + config = MoneroWalletConfig(path=path) with pytest.raises(Exception) as exc_info: self._create_wallet(config) assert str(exc_info.value) == "Wallet already exists: " + path # attempt to create wallet with unknown language - config = MoneroWalletConfig() - config.language = "english" + config = MoneroWalletConfig(language="english") with pytest.raises(Exception) as exc_info: self._create_wallet(config) assert str(exc_info.value) == "Unknown language: english" @@ -103,16 +101,13 @@ def test_create_wallet_from_seed(self, wallet: MoneroWallet, test_config: BaseTe self._close_wallet(w) # attempt to create wallet with two missing words - config = MoneroWalletConfig() - config.seed = test_config.seed - config.restore_height = TestUtils.FIRST_RECEIVE_HEIGHT + config = MoneroWalletConfig(seed=test_config.seed, restore_height=TestUtils.FIRST_RECEIVE_HEIGHT) with pytest.raises(Exception) as exc_info: self._create_wallet(config) assert str(exc_info.value) == "Invalid mnemonic" # attempt to create wallet at same path - config = MoneroWalletConfig() - config.path = path + config = MoneroWalletConfig(path=path) with pytest.raises(Exception) as exc_info: self._create_wallet(config) assert str(exc_info.value) == "Wallet already exists: " + path @@ -171,9 +166,7 @@ def test_create_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWa # recreate test wallet from spend key if not isinstance(w, MoneroWalletRpc): # TODO monero-wallet-rpc: cannot create wallet from spend key? - config = MoneroWalletConfig() - config.private_spend_key = private_spend_key - config.restore_height = daemon.get_height() + config = MoneroWalletConfig(private_spend_key=private_spend_key, restore_height=daemon.get_height()) w = self._create_wallet(config) try: @@ -192,8 +185,7 @@ def test_create_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWa self._close_wallet(w) # attempt to create wallet at same path - config = MoneroWalletConfig() - config.path = path + config = MoneroWalletConfig(path=path) with pytest.raises(Exception) as exc_info: self._create_wallet(config) assert str(exc_info.value) == "Wallet already exists: " + path @@ -204,14 +196,11 @@ def test_subaddress_lookahead(self, wallet: MoneroWallet) -> None: receiver: MoneroWallet | None = None try: # create wallet with high subaddress lookahead - config: MoneroWalletConfig = MoneroWalletConfig() - config.account_lookahead = 1 - config.subaddress_lookahead = 100000 + config: MoneroWalletConfig = MoneroWalletConfig(account_lookahead=1, subaddress_lookahead=100000) receiver = self._create_wallet(config) # transfer funds to subaddress with high index - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = 0 + tx_config: MoneroTxConfig = MoneroTxConfig(account_index=0) dest: MoneroDestination = MoneroDestination() dest.address = receiver.get_subaddress(0, 85000).address dest.amount = TxWalletUtils.MAX_FEE @@ -263,8 +252,7 @@ def test_get_path(self) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_change_password(self) -> None: # create random wallet - config: MoneroWalletConfig = MoneroWalletConfig() - config.password = TestUtils.WALLET_PASSWORD + config: MoneroWalletConfig = MoneroWalletConfig(password=TestUtils.WALLET_PASSWORD) wallet: MoneroWallet = self._create_wallet(config) path: str = wallet.get_path() @@ -276,9 +264,7 @@ def test_change_password(self) -> None: self._close_wallet(wallet) # old password does not work (password change is auto saved) - config = MoneroWalletConfig() - config.path = path - config.password = TestUtils.WALLET_PASSWORD + config = MoneroWalletConfig(path=path, password=TestUtils.WALLET_PASSWORD) with pytest.raises(Exception) as exc_info: self._open_wallet(config) # TODO: different errors from rpc and wallet2 @@ -286,9 +272,7 @@ def test_change_password(self) -> None: assert "failed to open wallet" in e_str or "invalid password" in e_str # open wallet with new password - config = MoneroWalletConfig() - config.path = path - config.password = new_password + config = MoneroWalletConfig(path=path, password=new_password) wallet = self._open_wallet(config) # change password with incorrect password @@ -299,9 +283,7 @@ def test_change_password(self) -> None: self._close_wallet(wallet, True) # open wallet - config = MoneroWalletConfig() - config.path = path - config.password = new_password + config = MoneroWalletConfig(path=path, password=new_password) wallet = self._open_wallet(config) # close wallet @@ -312,8 +294,7 @@ def test_change_password(self) -> None: def test_save_and_close(self) -> None: # create random wallet password: str = "" - config: MoneroWalletConfig = MoneroWalletConfig() - config.password = password + config: MoneroWalletConfig = MoneroWalletConfig(password=password) wallet: MoneroWallet = self._create_wallet(config) path: str = wallet.get_path() @@ -325,9 +306,7 @@ def test_save_and_close(self) -> None: self._close_wallet(wallet) # re-open the wallet and ensure attribute was not saved - config = MoneroWalletConfig() - config.path = path - config.password = password + config = MoneroWalletConfig(path=path, password=password) wallet = self._open_wallet(config) assert wallet.get_attribute("id") is None @@ -429,10 +408,7 @@ def test_create_wallet_random_full(self, daemon: MoneroDaemonRpc) -> None: # create random wallet with non defaults path = Utils.get_random_wallet_path() - config = MoneroWalletConfig() - config.path = path - config.network_type = MoneroNetworkType.TESTNET - config.language = "Spanish" + config = MoneroWalletConfig(path=path, network_type=MoneroNetworkType.TESTNET, language="Spanish") wallet = self._create_wallet(config, False) MoneroUtils.validate_mnemonic(wallet.get_seed()) MoneroUtils.validate_address(wallet.get_primary_address(), MoneroNetworkType.TESTNET) @@ -479,9 +455,7 @@ def test_create_wallet_from_seed_full(self, daemon: MoneroDaemonRpc) -> None: # create wallet without restore height path = Utils.get_random_wallet_path() - config = MoneroWalletConfig() - config.path = path - config.seed = Utils.SEED + config = MoneroWalletConfig(path=path, seed=Utils.SEED) wallet = self._create_wallet(config, False) assert wallet.get_seed() == Utils.SEED assert wallet.get_primary_address() == Utils.ADDRESS @@ -518,9 +492,7 @@ def test_create_wallet_from_seed_full(self, daemon: MoneroDaemonRpc) -> None: assert wallet.get_restore_height() == restore_height assert wallet.get_path() == path wallet.close(True) - config = MoneroWalletConfig() - config.path = path - config.server = MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + config = MoneroWalletConfig(path=path, server=MoneroRpcConnection(Utils.OFFLINE_SERVER_URI)) wallet = self._open_wallet(config) assert wallet.is_connected_to_daemon() is False assert wallet.is_synced() is False @@ -530,10 +502,7 @@ def test_create_wallet_from_seed_full(self, daemon: MoneroDaemonRpc) -> None: # create wallet with seed, connection, and restore height path = Utils.get_random_wallet_path() - config = MoneroWalletConfig() - config.path = path - config.seed = Utils.SEED - config.restore_height = restore_height + config = MoneroWalletConfig(path=path, seed=Utils.SEED, restore_height=restore_height) wallet = self._create_wallet(config, False) assert wallet.get_seed() == Utils.SEED assert wallet.get_primary_address() == Utils.ADDRESS @@ -555,12 +524,10 @@ def test_create_wallet_from_seed_full(self, daemon: MoneroDaemonRpc) -> None: def test_create_wallet_from_keys_pybind(self, wallet: MoneroWalletFull) -> None: # recreate test wallet from keys path: str = Utils.get_random_wallet_path() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path - config.primary_address = wallet.get_primary_address() - config.private_view_key = wallet.get_private_view_key() - config.private_spend_key = wallet.get_private_spend_key() - config.restore_height = Utils.FIRST_RECEIVE_HEIGHT + config: MoneroWalletConfig = MoneroWalletConfig( + path=path, primary_address=wallet.get_primary_address(), private_view_key=wallet.get_private_view_key(), + private_spend_key=wallet.get_private_spend_key(), restore_height=Utils.FIRST_RECEIVE_HEIGHT + ) wallet_keys: MoneroWalletFull = self._create_wallet(config) try: @@ -584,14 +551,10 @@ def test_wallets_do_not_interfere(self, daemon: MoneroDaemonRpc) -> None: # create 2 wallets with a recent restore height height: int = daemon.get_height() restore_height: int = height - 5 - config: MoneroWalletConfig = MoneroWalletConfig() - config.seed = Utils.SEED - config.restore_height = restore_height + config: MoneroWalletConfig = MoneroWalletConfig(seed=Utils.SEED, restore_height=restore_height) wallet1: MoneroWalletFull = self._create_wallet(config, False) - config = MoneroWalletConfig() - config.seed = Utils.SEED - config.restore_height = restore_height + config = MoneroWalletConfig(seed=Utils.SEED, restore_height=restore_height) wallet2: MoneroWalletFull = self._create_wallet(config, False) # track notifications of each wallet @@ -617,8 +580,7 @@ def test_wallets_do_not_interfere(self, daemon: MoneroDaemonRpc) -> None: def test_close(self) -> None: # create test wallet path: str = Utils.get_random_wallet_path() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path + config: MoneroWalletConfig = MoneroWalletConfig(path=path) wallet: MoneroWalletFull = self._create_wallet(config) wallet.sync() assert wallet.get_height() > 1, "Wallet height is still 1" @@ -652,8 +614,7 @@ def test_close(self) -> None: WalletErrorUtils.test_wallet_is_closed_error(exc_info.value) # re-open the wallet - config = MoneroWalletConfig() - config.path = path + config = MoneroWalletConfig(path=path) wallet = self._open_wallet(config) assert wallet.is_closed() is False @@ -675,8 +636,7 @@ class TestMoneroWalletRpcCreation(RpcWalletSupport, BaseTestMoneroWalletCreation def test_create_wallet_random_rpc(self) -> None: # create random wallet with defaults path: str = StringUtils.get_random_string() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path + config: MoneroWalletConfig = MoneroWalletConfig(path=path) wallet: MoneroWalletRpc = self._create_wallet(config) seed: str = wallet.get_seed() MoneroUtils.validate_mnemonic(seed) @@ -688,9 +648,7 @@ def test_create_wallet_random_rpc(self) -> None: # create random wallet non defaults path = StringUtils.get_random_string() - config = MoneroWalletConfig() - config.path = path - config.language = "Spanish" + config = MoneroWalletConfig(path=path, language="Spanish") wallet = self._create_wallet(config) MoneroUtils.validate_mnemonic(wallet.get_seed()) assert seed != wallet.get_seed() @@ -730,13 +688,10 @@ def test_create_wallet_from_seed_rpc(self, daemon: MoneroDaemonRpc) -> None: # create wallet with non-defaults path = StringUtils.get_random_string() - config = MoneroWalletConfig() - config.path = path - config.seed = Utils.SEED - config.restore_height = Utils.FIRST_RECEIVE_HEIGHT - config.language = "German" - config.seed_offset = "my offset!" - config.save_current = False + config = MoneroWalletConfig( + path=path, seed=Utils.SEED, restore_height=Utils.FIRST_RECEIVE_HEIGHT, language="German", + seed_offset="my offset!", save_current=False + ) wallet = self._create_wallet(config) # validate wallet @@ -764,8 +719,7 @@ def test_open_wallet(self)-> None: # create test wallets seeds: list[str] = [] for name in names: - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = name + config: MoneroWalletConfig = MoneroWalletConfig(path=name) wallet: MoneroWalletRpc = self._create_wallet(config) seeds.append(wallet.get_seed()) self._close_wallet(wallet, True) @@ -773,17 +727,13 @@ def test_open_wallet(self)-> None: # open test wallets wallets: list[MoneroWalletRpc] = [] for i in range(num_test_wallets): - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = names[i] - config.password = Utils.WALLET_PASSWORD + config: MoneroWalletConfig = MoneroWalletConfig(path=names[i], password=Utils.WALLET_PASSWORD) wallet: MoneroWalletRpc = self._open_wallet(config) assert seeds[i] == wallet.get_seed() wallets.append(wallet) # attempt to open non-existent - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = "btc_integrity" - config.password = Utils.WALLET_PASSWORD + config: MoneroWalletConfig = MoneroWalletConfig(path="btc_integrity", password=Utils.WALLET_PASSWORD) with pytest.raises(Exception): self._open_wallet(config) @@ -801,8 +751,7 @@ def test_save(self, wallet: MoneroWallet) -> None: def test_close(self, daemon: MoneroDaemonRpc) -> None: # create a test wallet path: str = StringUtils.get_random_string() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path + config: MoneroWalletConfig = MoneroWalletConfig(path=path) wallet: MoneroWalletRpc = self._create_wallet(config) wallet.sync() @@ -835,8 +784,7 @@ def test_close(self, daemon: MoneroDaemonRpc) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_is_closed(self) -> None: # create a test wallet - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = StringUtils.get_random_string() + config: MoneroWalletConfig = MoneroWalletConfig(path=StringUtils.get_random_string()) wallet: MoneroWalletRpc = self._create_wallet(config) assert wallet.is_closed() is False @@ -910,8 +858,7 @@ def test_create_wallet_random(self) -> None: assert MoneroWallet.DEFAULT_LANGUAGE == wallet.get_seed_language() # attempt to create wallet with unknown language - config = MoneroWalletConfig() - config.language = "english" + config = MoneroWalletConfig(language="english") with pytest.raises(Exception, match="Unknown language: english"): self._create_wallet(config) @@ -924,8 +871,7 @@ def test_create_wallet_from_seed(self, wallet: MoneroWallet, test_config: BaseTe private_spend_key: str = wallet.get_private_spend_key() # recreate test wallet from seed - config: MoneroWalletConfig = MoneroWalletConfig() - config.seed = Utils.SEED + config: MoneroWalletConfig = MoneroWalletConfig(seed=Utils.SEED) w: MoneroWallet = self._create_wallet(config) assert primary_address == w.get_primary_address() @@ -935,8 +881,7 @@ def test_create_wallet_from_seed(self, wallet: MoneroWallet, test_config: BaseTe assert MoneroWallet.DEFAULT_LANGUAGE == w.get_seed_language() # attempt to create wallet with two missing words - config = MoneroWalletConfig() - config.seed = test_config.seed + config = MoneroWalletConfig(seed=test_config.seed) with pytest.raises(Exception) as exc_info: self._create_wallet(config) assert str(exc_info.value) == "Invalid mnemonic" @@ -945,9 +890,7 @@ def test_create_wallet_from_seed(self, wallet: MoneroWallet, test_config: BaseTe @override def test_create_wallet_from_seed_with_offset(self) -> None: # create test wallet with offset - config: MoneroWalletConfig = MoneroWalletConfig() - config.seed = Utils.SEED - config.seed_offset = "my secret offset!" + config: MoneroWalletConfig = MoneroWalletConfig(seed=Utils.SEED, seed_offset="my secret offset!") wallet: MoneroWallet = self._create_wallet(config) MoneroUtils.validate_mnemonic(wallet.get_seed()) @@ -976,9 +919,7 @@ def test_create_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWa w.close() # recreate test wallet from spend key - config = MoneroWalletConfig() - config.primary_address = primary_address - config.private_spend_key = private_spend_key + config = MoneroWalletConfig(primary_address=primary_address, private_spend_key=private_spend_key) w = self._create_wallet(config) WalletUtils.test_wallet_keys(primary_address, private_view_key, private_spend_key, w) assert w.get_network_type() == Utils.NETWORK_TYPE @@ -986,9 +927,7 @@ def test_create_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWa w.close() # recreate test wallet from view keys - config = MoneroWalletConfig() - config.primary_address = primary_address - config.private_view_key = private_view_key + config = MoneroWalletConfig(primary_address=primary_address, private_view_key=private_view_key) w = self._create_wallet(config) logger.info(f"Created wallet with config: {config.serialize()}") assert primary_address == w.get_primary_address() @@ -1006,8 +945,7 @@ def test_create_wallet_from_keys_no_keys(self) -> None: """ create_wallet_from_keys() must require at least one of the private spend/view keys. """ - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) with pytest.raises(RuntimeError, match="Neither spend key nor view key supplied"): MoneroWalletKeys.create_wallet_from_keys(config) @@ -1040,9 +978,7 @@ def test_create_wallet_from_keys_view_key_without_address(self) -> None: """ create_wallet_from_keys() must require a primary address when a private view key is given. """ - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE - config.private_view_key = "a" * 64 + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE, private_view_key="a" * 64) with pytest.raises(RuntimeError, match="must provide address if providing private view key"): MoneroWalletKeys.create_wallet_from_keys(config) @@ -1050,8 +986,7 @@ def test_create_wallet_from_keys_view_key_without_address(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_is_closed(self) -> None: """A keys-only wallet reports its open/closed state and rejects use once closed.""" - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) # a freshly created wallet is open @@ -1078,8 +1013,7 @@ def test_is_closed(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_close_with_save_not_supported(self) -> None: """`close(save=True)` is rejected because a keys-only wallet has nothing to persist.""" - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) with pytest.raises(RuntimeError, match="does not support saving"): diff --git a/tests/wallet/test_equality.py b/tests/wallet/test_equality.py index a0b6bd74..9b14d485 100644 --- a/tests/wallet/test_equality.py +++ b/tests/wallet/test_equality.py @@ -75,8 +75,7 @@ def test_accounting(self, wallet: MoneroWallet) -> None: # wallet balance is sum of all unspent outputs wallet_sum: int = 0 - output_query: MoneroOutputQuery = MoneroOutputQuery() - output_query.is_spent = False + output_query: MoneroOutputQuery = MoneroOutputQuery(is_spent=False) for output in wallet.get_outputs(output_query): assert output.amount is not None wallet_sum += output.amount @@ -94,9 +93,7 @@ def test_accounting(self, wallet: MoneroWallet) -> None: # account balances are sum of their unspent outputs for account in accounts: account_sum: int = 0 - output_query = MoneroOutputQuery() - output_query.account_index = account.index - output_query.is_spent = False + output_query = MoneroOutputQuery(account_index=account.index, is_spent=False) account_outputs: list[MoneroOutputWallet] = wallet.get_outputs(output_query) for output in account_outputs: assert output.amount is not None diff --git a/tests/wallet/test_full_offline.py b/tests/wallet/test_full_offline.py index 072d4905..ea858f0b 100644 --- a/tests/wallet/test_full_offline.py +++ b/tests/wallet/test_full_offline.py @@ -48,8 +48,7 @@ def test_import_key_images_hex_not_defined(self, wallet: MoneroWalletFull) -> No assert str(exc_info.value) == "key image hex is not defined" def test_import_key_images_signature_not_defined(self, wallet: MoneroWalletFull) -> None: - key_image: MoneroKeyImage = MoneroKeyImage() - key_image.hex = "a" * 64 + key_image: MoneroKeyImage = MoneroKeyImage(hex="a" * 64) with pytest.raises(RuntimeError) as exc_info: wallet.import_key_images([key_image]) assert str(exc_info.value) == "key image signature is not defined" diff --git a/tests/wallet/test_interface.py b/tests/wallet/test_interface.py index 9d360114..769dd506 100644 --- a/tests/wallet/test_interface.py +++ b/tests/wallet/test_interface.py @@ -55,8 +55,7 @@ def test_relay_txs_uninitialized_metadata_raises(self, wallet: MoneroWallet) -> assert str(exc_info.value) == "Tx metadata is not initialized" def test_relay_txs_empty_metadata_raises(self, wallet: MoneroWallet) -> None: - tx: MoneroTxWallet = MoneroTxWallet() - tx.metadata = "" + tx: MoneroTxWallet = MoneroTxWallet(metadata="") with pytest.raises(RuntimeError) as exc_info: wallet.relay_txs([tx]) assert str(exc_info.value) == "Tx metadata is not initialized" @@ -209,9 +208,7 @@ def get_subaddresses(self, account_idx: int, subaddress_indices: Optional[list[i result: list[MoneroSubaddress] = [] # the wallet has no subaddress of an index above 0 if list(subaddress_indices) == [0]: - subaddress: MoneroSubaddress = MoneroSubaddress() - subaddress.account_index = account_idx - subaddress.index = 0 + subaddress: MoneroSubaddress = MoneroSubaddress(account_index=account_idx, index=0) result.append(subaddress) return result @@ -226,6 +223,5 @@ def get_subaddresses(self, account_idx: int, subaddress_indices: Optional[list[i @staticmethod def _create_wallet_keys() -> MoneroWalletKeys: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = TestUtils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=TestUtils.NETWORK_TYPE) return MoneroWalletKeys.create_wallet_random(config) diff --git a/tests/wallet/test_keys_and_addresses.py b/tests/wallet/test_keys_and_addresses.py index 04a862a6..1904aea1 100644 --- a/tests/wallet/test_keys_and_addresses.py +++ b/tests/wallet/test_keys_and_addresses.py @@ -197,15 +197,9 @@ def test_decode_integrated_address(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_sign_and_verify_messages(self, wallet: MoneroWallet) -> None: msg: str = "This is a super important message which needs to be signed and verified." - subaddress1: MoneroSubaddress = MoneroSubaddress() - subaddress1.account_index = 0 - subaddress1.index = 0 - subaddress2: MoneroSubaddress = MoneroSubaddress() - subaddress2.account_index = 0 - subaddress2.index = 1 - subaddress3: MoneroSubaddress = MoneroSubaddress() - subaddress3.account_index = 1 - subaddress3.index = 0 + subaddress1: MoneroSubaddress = MoneroSubaddress(account_index=0, index=0) + subaddress2: MoneroSubaddress = MoneroSubaddress(account_index=0, index=1) + subaddress3: MoneroSubaddress = MoneroSubaddress(account_index=1, index=0) subaddresses: list[MoneroSubaddress] = [subaddress1, subaddress2, subaddress3] # test signing message with subaddresses @@ -369,8 +363,7 @@ def test_get_subaddress_address_out_of_range(self, wallet: MoneroWallet) -> None @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_integrated_address_with_empty_standard_address(self) -> None: """An empty standard_address uses the wallet's own primary address (account 0, subaddress 0).""" - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: integrated: MoneroIntegratedAddress = w.get_integrated_address("", "a" * 16) @@ -381,8 +374,7 @@ def test_get_integrated_address_with_empty_standard_address(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_integrated_address_with_standard_address(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: address: str = w.get_primary_address() @@ -394,8 +386,7 @@ def test_get_integrated_address_with_standard_address(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_integrated_address_invalid_address_raises(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: with pytest.raises(RuntimeError, match="Invalid address"): @@ -405,8 +396,7 @@ def test_get_integrated_address_invalid_address_raises(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_integrated_address_subaddress_raises(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: subaddress: str = w.get_address(1, 1) @@ -417,8 +407,7 @@ def test_get_integrated_address_subaddress_raises(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_integrated_address_already_integrated_raises(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: integrated: str = w.get_integrated_address("", "a" * 16).integrated_address @@ -429,8 +418,7 @@ def test_get_integrated_address_already_integrated_raises(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_integrated_address_missing_payment_id_raises(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: with pytest.raises(RuntimeError, match="Payment ID shouldn't be left unspecified"): @@ -440,8 +428,7 @@ def test_get_integrated_address_missing_payment_id_raises(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_sign_message_invalid_signature_type_base_address_raises(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: invalid_type: MoneroMessageSignatureType = MoneroMessageSignatureType(99) @@ -452,8 +439,7 @@ def test_sign_message_invalid_signature_type_base_address_raises(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_sign_message_invalid_signature_type_subaddress_raises(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: invalid_type: MoneroMessageSignatureType = MoneroMessageSignatureType(99) @@ -464,8 +450,7 @@ def test_sign_message_invalid_signature_type_subaddress_raises(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_verify_message_no_signature_header(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: result: MoneroMessageSignatureResult = w.verify_message("hello", w.get_primary_address(), "not-a-signature") @@ -475,8 +460,7 @@ def test_verify_message_no_signature_header(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_verify_message_invalid_base58(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: result: MoneroMessageSignatureResult = w.verify_message("hello", w.get_primary_address(), "SigV2!!!not-base58!!!") @@ -486,8 +470,7 @@ def test_verify_message_invalid_base58(self) -> None: @pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_verify_message_wrong_decoded_size(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) w: MoneroWalletKeys = MoneroWalletKeys.create_wallet_random(config) try: address: str = w.get_primary_address() diff --git a/tests/wallet/test_multisig.py b/tests/wallet/test_multisig.py index 8e5f7d1e..322d57e5 100644 --- a/tests/wallet/test_multisig.py +++ b/tests/wallet/test_multisig.py @@ -119,9 +119,7 @@ def _test_multisig_participants( # sweep an output from subaddress [account_idx, 1] return_address: str = wallet.get_primary_address() - output_query: MoneroOutputQuery = MoneroOutputQuery() - output_query.account_index = account_idx - output_query.subaddress_index = 1 + output_query: MoneroOutputQuery = MoneroOutputQuery(account_index=account_idx, subaddress_index=1) outputs: list[MoneroOutputWallet] = participant.get_outputs(output_query) assert len(outputs) > 0 assert outputs[0].is_spent is False @@ -152,10 +150,7 @@ def _test_multisig_participants( # sweep remaining balance logger.info("Sweeping") - sweep_config = MoneroTxConfig() - sweep_config.address = return_address - sweep_config.account_index = account_idx - sweep_config.relay = True + sweep_config = MoneroTxConfig(address=return_address, account_index=account_idx, relay=True) # TODO: test multisig with sweep_each_subaddress which will generate multiple tx sets without synchronizing participants txs = participant.sweep_unlocked(sweep_config) assert len(txs) > 0, "No txs created on sweep_unlocked" @@ -300,10 +295,7 @@ def _init_multisig_wallets( # send funds from the main test wallet to destinations in the first multisig wallet assert wallet.get_balance() > 0 logger.info("Sending funds from main wallet") - fund_config: MoneroTxConfig = MoneroTxConfig() - fund_config.account_index = 0 - fund_config.destinations = destinations - fund_config.relay = True + fund_config: MoneroTxConfig = MoneroTxConfig(account_index=0, destinations=destinations, relay=True) wallet.create_tx(fund_config) # start mining @@ -348,8 +340,7 @@ def _init_multisig_wallets( # multisig wallet should have unlocked balance in subaddresses 0-3 for i in range(num_addresses_to_fund): assert participant.get_unlocked_balance(account_idx, i) > 0 - account_query: MoneroOutputQuery = MoneroOutputQuery() - account_query.account_index = account_idx + account_query: MoneroOutputQuery = MoneroOutputQuery(account_index=account_idx) outputs = participant.get_outputs(account_query) assert len(outputs) > 0 if len(outputs) < 3: @@ -382,12 +373,10 @@ def _init_multisig_wallets( assert "key_image generated not matched with cached key image" in str(e), f"Unexpected error: {e}" # attempt relaying created transactions without co-signing - relay_config: MoneroTxConfig = MoneroTxConfig() - relay_config.address = return_address - relay_config.amount = TxWalletUtils.MAX_FEE - relay_config.account_index = account_idx - relay_config.subaddress_indices = [0] - relay_config.relay = True + relay_config: MoneroTxConfig = MoneroTxConfig( + address=return_address, amount=TxWalletUtils.MAX_FEE, account_index=account_idx, subaddress_indices=[0], + relay=True + ) with pytest.raises(Exception) as exc_info: participant.create_tx(relay_config) assert str(exc_info.value) == "Cannot relay multisig transaction until co-signed" @@ -440,8 +429,7 @@ def _test_multisig_tx_set(tx_set: MoneroTxSet) -> None: @staticmethod def _test_multisig_txs(participant: MoneroWallet, tx_hashes: list[str]) -> None: """Test that the multisig wallet has the submitted txs.""" - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hashes = tx_hashes + tx_query: MoneroTxQuery = MoneroTxQuery(hashes=tx_hashes) assert len(participant.get_txs(tx_query)) == len(tx_hashes) def _start_mining(self) -> None: diff --git a/tests/wallet/test_outputs.py b/tests/wallet/test_outputs.py index 129ec5f8..2ec482ee 100644 --- a/tests/wallet/test_outputs.py +++ b/tests/wallet/test_outputs.py @@ -49,8 +49,7 @@ def test_get_outputs(self, wallet: MoneroWallet) -> None: break # get outputs by account index - output_query: MoneroOutputQuery = MoneroOutputQuery() - output_query.account_index = account.index + output_query: MoneroOutputQuery = MoneroOutputQuery(account_index=account.index) account_outputs: list[MoneroOutputWallet] = OutputUtils.get_and_test_outputs(wallet, output_query, is_used) for output in account_outputs: assert output.account_index == account.index @@ -77,8 +76,7 @@ def test_get_outputs(self, wallet: MoneroWallet) -> None: assert output.subaddress_index is not None subaddress_indices.add(output.subaddress_index) - output_query = MoneroOutputQuery() - output_query.account_index = account.index + output_query = MoneroOutputQuery(account_index=account.index) for sub_idx in subaddress_indices: output_query.subaddress_indices.append(sub_idx) @@ -97,9 +95,7 @@ def test_get_outputs(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_outputs_with_query(self, wallet: MoneroWallet) -> None: # get unspent outputs to account 0 - output_query: MoneroOutputQuery = MoneroOutputQuery() - output_query.account_index = 0 - output_query.is_spent = False + output_query: MoneroOutputQuery = MoneroOutputQuery(account_index=0, is_spent=False) outputs: list[MoneroOutputWallet] = OutputUtils.get_and_test_outputs(wallet, output_query, None) for output in outputs: @@ -107,9 +103,7 @@ def test_get_outputs_with_query(self, wallet: MoneroWallet) -> None: assert output.is_spent is False # get spent outputs to account 1 - output_query = MoneroOutputQuery() - output_query.account_index = 1 - output_query.is_spent = True + output_query = MoneroOutputQuery(account_index=1, is_spent=True) outputs = OutputUtils.get_and_test_outputs(wallet, output_query, True) for output in outputs: @@ -117,8 +111,7 @@ def test_get_outputs_with_query(self, wallet: MoneroWallet) -> None: assert output.is_spent is True # get random transactions - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_confirmed = True + tx_query: MoneroTxQuery = MoneroTxQuery(is_confirmed=True) txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, tx_query, 3, 5) # get outputs with a tx hash @@ -138,8 +131,7 @@ def test_get_outputs_with_query(self, wallet: MoneroWallet) -> None: assert output.tx.hash in tx_hashes # get outputs with tx hashes - tx_query = MoneroTxQuery() - tx_query.hashes = tx_hashes + tx_query = MoneroTxQuery(hashes=tx_hashes) output_query = MoneroOutputQuery() output_query.set_tx_query(tx_query, True) outputs = OutputUtils.get_and_test_outputs(wallet, output_query, True) @@ -152,11 +144,8 @@ def test_get_outputs_with_query(self, wallet: MoneroWallet) -> None: # get confirmed outputs to a specific subaddress with pre-built query account_idx: int = 0 subaddress_idx: int = 1 - output_query = MoneroOutputQuery() - output_query.account_index = account_idx - output_query.subaddress_index = subaddress_idx - tx_query = MoneroTxQuery() - tx_query.is_confirmed = True + output_query = MoneroOutputQuery(account_index=account_idx, subaddress_index=subaddress_idx) + tx_query = MoneroTxQuery(is_confirmed=True) output_query.set_tx_query(tx_query, True) output_query.min_amount = TxWalletUtils.MAX_FEE outputs = OutputUtils.get_and_test_outputs(wallet, output_query, True) @@ -173,9 +162,7 @@ def test_get_outputs_with_query(self, wallet: MoneroWallet) -> None: output: MoneroOutputWallet = outputs[0] assert output.key_image is not None assert output.key_image.hex is not None - output_query = MoneroOutputQuery() - output_query.key_image = MoneroKeyImage() - output_query.key_image.hex = output.key_image.hex + output_query = MoneroOutputQuery(key_image=MoneroKeyImage(hex=output.key_image.hex)) outputs = wallet.get_outputs(output_query) assert len(outputs) == 1 output_result: MoneroOutputWallet = outputs[0] @@ -184,11 +171,7 @@ def test_get_outputs_with_query(self, wallet: MoneroWallet) -> None: # get outputs whose transaction is confirmed and has incoming and outgoing transfers output_query = MoneroOutputQuery() - tx_query = MoneroTxQuery() - tx_query.is_confirmed = True - tx_query.is_incoming = True - tx_query.is_outgoing = True - tx_query.include_outputs = True + tx_query = MoneroTxQuery(is_confirmed=True, is_incoming=True, is_outgoing=True, include_outputs=True) output_query.set_tx_query(tx_query, True) outputs = wallet.get_outputs(output_query) assert len(outputs) > 0 @@ -216,9 +199,7 @@ def test_validate_inputs_get_outputs(self, wallet: MoneroWallet) -> None: assert len(outputs) == 0 # test invalid hash in list - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_confirmed = True - tx_query.include_outputs = True + tx_query: MoneroTxQuery = MoneroTxQuery(is_confirmed=True, include_outputs=True) random_txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, tx_query, 3, 5) for random_tx in random_txs: @@ -269,9 +250,7 @@ def test_import_outputs(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_freeze_outputs(self, wallet: MoneroWallet) -> None: # get an available output - output_query: MoneroOutputQuery = MoneroOutputQuery() - output_query.is_spent = False - output_query.is_frozen = False + output_query: MoneroOutputQuery = MoneroOutputQuery(is_spent=False, is_frozen=False) output_query.set_tx_query(MoneroTxQuery(), True) assert output_query.tx_query is not None output_query.tx_query.is_locked = False @@ -291,8 +270,7 @@ def test_freeze_outputs(self, wallet: MoneroWallet) -> None: assert wallet.is_output_frozen(output.key_image.hex) is False # freeze output by key image - output_query = MoneroOutputQuery() - output_query.is_frozen = True + output_query = MoneroOutputQuery(is_frozen=True) num_frozen_before: int = len(wallet.get_outputs(output_query)) wallet.freeze_output(output.key_image.hex) is_frozen: bool = wallet.is_output_frozen(output.key_image.hex) @@ -302,10 +280,7 @@ def test_freeze_outputs(self, wallet: MoneroWallet) -> None: frozen_outputs: list[MoneroOutputWallet] = wallet.get_outputs(output_query) num_frozen: int = len(frozen_outputs) assert num_frozen == num_frozen_before + 1 - output_query = MoneroOutputQuery() - output_query.key_image = MoneroKeyImage() - output_query.key_image.hex = output.key_image.hex - output_query.is_frozen = True + output_query = MoneroOutputQuery(key_image=MoneroKeyImage(hex=output.key_image.hex), is_frozen=True) outputs = wallet.get_outputs(output_query) assert len(outputs) == 1 output_frozen: MoneroOutputWallet = outputs[0] @@ -314,9 +289,7 @@ def test_freeze_outputs(self, wallet: MoneroWallet) -> None: assert output.key_image.hex == output_frozen.key_image.hex # try to sweep frozen output - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.address = wallet.get_primary_address() - tx_config.key_image = output.key_image.hex + tx_config: MoneroTxConfig = MoneroTxConfig(address=wallet.get_primary_address(), key_image=output.key_image.hex) with pytest.raises(Exception) as exc_info: wallet.sweep_output(tx_config) assert str(exc_info.value) == "No outputs found" @@ -337,14 +310,10 @@ def test_freeze_outputs(self, wallet: MoneroWallet) -> None: assert is_frozen is False # test querying - output_query = MoneroOutputQuery() - output_query.is_frozen = True + output_query = MoneroOutputQuery(is_frozen=True) assert num_frozen_before == len(wallet.get_outputs(output_query)) - output_query = MoneroOutputQuery() - output_query.key_image = MoneroKeyImage() - output_query.key_image.hex = output.key_image.hex - output_query.is_frozen = True + output_query = MoneroOutputQuery(key_image=MoneroKeyImage(hex=output.key_image.hex), is_frozen=True) outputs = wallet.get_outputs(output_query) assert len(outputs) == 0 @@ -369,8 +338,7 @@ def test_input_key_images(self, wallet: MoneroWallet) -> None: subaddress_index: int = subaddress.index # test unrelayed single transaction - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = account_index + tx_config: MoneroTxConfig = MoneroTxConfig(account_index=account_index) tx_config.destinations.append(MoneroDestination(wallet.get_primary_address(), TxWalletUtils.MAX_FEE)) spend_tx: MoneroTxWallet = wallet.create_tx(tx_config) TxWalletUtils.test_spend_tx(spend_tx) @@ -391,12 +359,10 @@ def test_input_key_images(self, wallet: MoneroWallet) -> None: dust_key_images.append(tx_input.key_image.hex) # get available outputs above min amount - output_query: MoneroOutputQuery = MoneroOutputQuery() - output_query.account_index = account_index - output_query.subaddress_index = subaddress_index - output_query.is_spent = False - output_query.is_frozen = False - output_query.min_amount = TxWalletUtils.MAX_FEE + output_query: MoneroOutputQuery = MoneroOutputQuery( + account_index=account_index, subaddress_index=subaddress_index, is_spent=False, is_frozen=False, + min_amount=TxWalletUtils.MAX_FEE + ) output_query.set_tx_query(MoneroTxQuery(), True) assert output_query.tx_query is not None output_query.tx_query.is_locked = False @@ -422,8 +388,7 @@ def test_input_key_images(self, wallet: MoneroWallet) -> None: logger.debug(f"Using {len(outputs)} available outputs") # test unrelayed sweep output - tx_config = MoneroTxConfig() - tx_config.address = wallet.get_primary_address() + tx_config = MoneroTxConfig(address=wallet.get_primary_address()) output_key_image: MoneroKeyImage | None = outputs[0].key_image assert output_key_image is not None tx_config.key_image = output_key_image.hex @@ -437,8 +402,7 @@ def test_input_key_images(self, wallet: MoneroWallet) -> None: assert output.key_image.hex is not None available_key_images.add(output.key_image.hex) swept_key_images: set[str] = set() - tx_config = MoneroTxConfig() - tx_config.account_index = account_index + tx_config = MoneroTxConfig(account_index=account_index) tx_config.subaddress_indices.append(subaddress_index) tx_config.address = wallet.get_primary_address() txs = wallet.sweep_unlocked(tx_config) @@ -511,9 +475,7 @@ def test_import_key_images(self, wallet: MoneroWallet) -> None: assert result.height is not None and result.height > 0 # determine if non-zero spent and unspent amounts are expected - query: MoneroTxQuery = MoneroTxQuery() - query.is_outgoing = True - query.is_confirmed = True + query: MoneroTxQuery = MoneroTxQuery(is_outgoing=True, is_confirmed=True) txs: list[MoneroTxWallet] = wallet.get_txs(query) balance: int = wallet.get_balance() has_spent: bool = len(txs) > 0 diff --git a/tests/wallet/test_proofs.py b/tests/wallet/test_proofs.py index 8579bdd8..569eda0e 100644 --- a/tests/wallet/test_proofs.py +++ b/tests/wallet/test_proofs.py @@ -115,9 +115,7 @@ def test_check_tx_proof(self, wallet: MoneroWallet) -> None: # get random txs with outgoing destinations txs: list[MoneroTxWallet] = [] try: - query: MoneroTxQuery = MoneroTxQuery() - query.transfer_query = MoneroTransferQuery() - query.transfer_query.has_destinations = True + query: MoneroTxQuery = MoneroTxQuery(transfer_query=MoneroTransferQuery(has_destinations=True)) txs = WalletTxsUtils.get_random_transactions(wallet, query, 2, WalletUtils.MAX_TX_PROOFS) except Exception as e: if "found with" in str(e): @@ -188,10 +186,7 @@ def test_check_tx_proof(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_check_spend_proof(self, wallet: MoneroWallet) -> None: # get random confirmed outgoing txs - query: MoneroTxQuery = MoneroTxQuery() - query.is_incoming = False - query.in_tx_pool = False - query.is_failed = False + query: MoneroTxQuery = MoneroTxQuery(is_incoming=False, in_tx_pool=False, is_failed=False) txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, query, 2, WalletUtils.MAX_TX_PROOFS) for tx in txs: assert tx.is_confirmed is True @@ -247,8 +242,7 @@ def test_get_reserve_proof_wallet(self, wallet: MoneroWallet) -> None: balance: int = wallet.get_balance() if balance != check.total_amount: # TODO monero-wallet-rpc: this check fails with unconfirmed txs - query: MoneroTxQuery = MoneroTxQuery() - query.in_tx_pool = True + query: MoneroTxQuery = MoneroTxQuery(in_tx_pool=True) unconfirmed_txs: list[MoneroTxWallet] = wallet.get_txs(query) assert len(unconfirmed_txs) > 0, "Reserve amount must equal balance unless wallet has unconfirmed txs" @@ -348,8 +342,7 @@ def test_prove_unrelayed_txs(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet address1: str = WalletTestUtils.get_external_wallet_address() address2: str = wallet.get_address(0, 0) address3: str = wallet.get_address(1, 0) - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = 0 + tx_config: MoneroTxConfig = MoneroTxConfig(account_index=0) tx_config.destinations.append(MoneroDestination(address1, TxWalletUtils.MAX_FEE)) tx_config.destinations.append(MoneroDestination(address2, TxWalletUtils.MAX_FEE * 2)) tx_config.destinations.append(MoneroDestination(address3, TxWalletUtils.MAX_FEE * 3)) diff --git a/tests/wallet/test_send.py b/tests/wallet/test_send.py index b94d1015..3c5445fd 100644 --- a/tests/wallet/test_send.py +++ b/tests/wallet/test_send.py @@ -58,8 +58,7 @@ def test_send_to_self(self, wallet: MoneroWallet) -> None: # TODO (monero-project): sending funds to self # with integrated subaddress throws error: https://github.com/monero-project/monero/issues/8380 - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = 0 + tx_config: MoneroTxConfig = MoneroTxConfig(account_index=0) subaddress: MoneroSubaddress = wallet.get_subaddress(0, 1) assert subaddress.address is not None address: str = subaddress.address @@ -122,8 +121,7 @@ def test_send_to_external(self, wallet: MoneroWallet) -> None: expected_balance: int = balance1 - tx.get_outgoing_amount() - tx.fee assert expected_balance == balance2, "Balance after send was not balance before - net tx amount - fee (5 - 1 != 4 test)" - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_confirmed = False + tx_query: MoneroTxQuery = MoneroTxQuery(is_confirmed=False) txs: list[MoneroTxWallet] = wallet.get_txs(tx_query) assert len(txs) > 0 diff --git a/tests/wallet/test_support.py b/tests/wallet/test_support.py index f4537bcf..3f86972b 100644 --- a/tests/wallet/test_support.py +++ b/tests/wallet/test_support.py @@ -41,8 +41,7 @@ def wallets(cls) -> dict[str, MoneroWallet]: full_config.path = "" full_config.password = Utils.WALLET_PASSWORD full_config.network_type = Utils.NETWORK_TYPE - keys_config: MoneroWalletConfig = MoneroWalletConfig() - keys_config.network_type = Utils.NETWORK_TYPE + keys_config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) return { "full": MoneroWalletFull.create_wallet(full_config), "rpc": MoneroWalletRpc(), diff --git a/tests/wallet/test_sweep.py b/tests/wallet/test_sweep.py index 62a0aa70..36b816e6 100644 --- a/tests/wallet/test_sweep.py +++ b/tests/wallet/test_sweep.py @@ -34,10 +34,8 @@ def test_sweep_outputs(self, wallet: MoneroWallet) -> None: num_outputs: int = 3 # get outputs to sweep (not spent, unlocked, and amount >= fee) - query: MoneroOutputQuery = MoneroOutputQuery() - query.is_spent = False - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_locked = False + query: MoneroOutputQuery = MoneroOutputQuery(is_spent=False) + tx_query: MoneroTxQuery = MoneroTxQuery(is_locked=False) query.set_tx_query(tx_query, True) spendable_unlocked_outputs: list[MoneroOutputWallet] = wallet.get_outputs(query) outputs_to_sweep: list[MoneroOutputWallet] = [] @@ -68,10 +66,7 @@ def test_sweep_outputs(self, wallet: MoneroWallet) -> None: assert output.key_image is not None assert output.key_image.hex is not None address: str = wallet.get_address(output.account_index, output.subaddress_index) - config: MoneroTxConfig = MoneroTxConfig() - config.address = address - config.key_image = output.key_image.hex - config.relay = True + config: MoneroTxConfig = MoneroTxConfig(address=address, key_image=output.key_image.hex, relay=True) tx: MoneroTxWallet = wallet.sweep_output(config) # test result tx @@ -127,8 +122,7 @@ def test_sweep_dust_no_relay(self, wallet: MoneroWallet) -> None: assert len(tx_hash) == 64 # fetch and test txs - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hashes = tx_hashes + tx_query: MoneroTxQuery = MoneroTxQuery(hashes=tx_hashes) txs = wallet.get_txs(tx_query) ctx.config.relay = True for tx in txs: @@ -183,8 +177,7 @@ def test_sweep_subaddresses(self, wallet: MoneroWallet) -> None: for i in range(NUM_SUBADDRESSES_TO_SWEEP): # sweep unlocked account unlocked_subaddress: MoneroSubaddress = subaddresses_unlocked[i] - config: MoneroTxConfig = MoneroTxConfig() - config.address = wallet.get_primary_address() + config: MoneroTxConfig = MoneroTxConfig(address=wallet.get_primary_address()) assert unlocked_subaddress.account_index is not None assert unlocked_subaddress.index is not None config.account_index = unlocked_subaddress.account_index diff --git a/tests/wallet/test_sync.py b/tests/wallet/test_sync.py index 0aa01dd5..9f09c243 100644 --- a/tests/wallet/test_sync.py +++ b/tests/wallet/test_sync.py @@ -95,9 +95,7 @@ def test_get_height_by_date(self, wallet: MoneroWallet) -> None: # Can scan transactions by id @pytest.mark.skipif(TestUtils.TEST_RESETS is False, reason="TEST_RESETS disabled") def test_scan_txs(self, wallet: MoneroWallet) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.seed = wallet.get_seed() - config.restore_height = 0 + config: MoneroWalletConfig = MoneroWalletConfig(seed=wallet.get_seed(), restore_height=0) scan_wallet: MoneroWallet = self._create_wallet(config) logger.debug("Created scan wallet") WalletTxsUtils.test_scan_txs(wallet, scan_wallet) @@ -182,8 +180,7 @@ def test_sync_random(self, daemon: MoneroDaemonRpc) -> None: wallet.close() # attempt to sync unconnected wallet - config: MoneroWalletConfig = MoneroWalletConfig() - config.server = MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + config: MoneroWalletConfig = MoneroWalletConfig(server=MoneroRpcConnection(Utils.OFFLINE_SERVER_URI)) wallet = self._create_wallet(config) try: with pytest.raises(Exception) as exc_info: @@ -320,10 +317,7 @@ def test_start_stop_syncing(self, daemon: MoneroDaemonRpc) -> None: # test that sync starts automatically restore_height: int = daemon.get_height() - 100 - config = MoneroWalletConfig() - config.path = Utils.get_random_wallet_path() - config.seed = Utils.SEED - config.restore_height = restore_height + config = MoneroWalletConfig(path=Utils.get_random_wallet_path(), seed=Utils.SEED, restore_height=restore_height) wallet = self._create_wallet(config, False) try: # start syncing diff --git a/tests/wallet/test_transfers.py b/tests/wallet/test_transfers.py index 9863a71b..c5bd7f4c 100644 --- a/tests/wallet/test_transfers.py +++ b/tests/wallet/test_transfers.py @@ -33,8 +33,7 @@ def test_get_transfers(self, wallet: MoneroWallet) -> None: # get transfers by account index non_default_incoming: bool = False for account in wallet.get_accounts(True): - transfer_query: MoneroTransferQuery = MoneroTransferQuery() - transfer_query.account_index = account.index + transfer_query: MoneroTransferQuery = MoneroTransferQuery(account_index=account.index) account_transfers: list[MoneroTransfer] = WalletTransfersUtils.get_and_test_transfers(wallet, transfer_query, None, None) for transfer in account_transfers: assert transfer.account_index == account.index @@ -95,8 +94,7 @@ def test_get_transfers(self, wallet: MoneroWallet) -> None: subaddress_indices.add(idx) # get and test transfers by subaddress indices - transfer_query = MoneroTransferQuery() - transfer_query.account_index = account.index + transfer_query = MoneroTransferQuery(account_index=account.index) for idx in subaddress_indices: transfer_query.subaddress_indices.append(idx) @@ -122,24 +120,19 @@ def test_get_transfers(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_transfers_with_query(self, wallet: MoneroWallet) -> None: # get incoming transfers - query: MoneroTransferQuery = MoneroTransferQuery() - query.incoming = True + query: MoneroTransferQuery = MoneroTransferQuery(incoming=True) transfers: list[MoneroTransfer] = WalletTransfersUtils.get_and_test_transfers(wallet, query, None, True) for transfer in transfers: assert transfer.is_incoming() # get outgoing transfers - query = MoneroTransferQuery() - query.outgoing = True + query = MoneroTransferQuery(outgoing=True) transfers = WalletTransfersUtils.get_and_test_transfers(wallet, query, None, True) for transfer in transfers: assert transfer.is_outgoing() # get confirmed transfers to account 0 - query = MoneroTransferQuery() - query.account_index = 0 - query.tx_query = MoneroTxQuery() - query.tx_query.is_confirmed = True + query = MoneroTransferQuery(account_index=0, tx_query=MoneroTxQuery(is_confirmed=True)) transfers = WalletTransfersUtils.get_and_test_transfers(wallet, query, None, True) for transfer in transfers: assert transfer.account_index == 0 @@ -147,11 +140,7 @@ def test_get_transfers_with_query(self, wallet: MoneroWallet) -> None: assert transfer.tx.is_confirmed is True # get confirmed transfers to (1, 2) - query = MoneroTransferQuery() - query.account_index = 1 - query.subaddress_index = 2 - query.tx_query = MoneroTxQuery() - query.tx_query.is_confirmed = True + query = MoneroTransferQuery(account_index=1, subaddress_index=2, tx_query=MoneroTxQuery(is_confirmed=True)) transfers = WalletTransfersUtils.get_and_test_transfers(wallet, query, None, True) for transfer in transfers: assert transfer.account_index == 1 @@ -166,9 +155,7 @@ def test_get_transfers_with_query(self, wallet: MoneroWallet) -> None: assert transfer.tx.is_confirmed is True # get transfers in the tx pool - query = MoneroTransferQuery() - query.tx_query = MoneroTxQuery() - query.tx_query.in_tx_pool = True + query = MoneroTransferQuery(tx_query=MoneroTxQuery(in_tx_pool=True)) transfers = WalletTransfersUtils.get_and_test_transfers(wallet, query, None, None) for transfer in transfers: assert transfer.tx is not None @@ -182,18 +169,14 @@ def test_get_transfers_with_query(self, wallet: MoneroWallet) -> None: for tx in txs: assert tx.hash is not None tx_hashes.append(tx.hash) - query = MoneroTransferQuery() - query.tx_query = MoneroTxQuery() - query.tx_query.hash = tx.hash + query = MoneroTransferQuery(tx_query=MoneroTxQuery(hash=tx.hash)) transfers = WalletTransfersUtils.get_and_test_transfers(wallet, query, None, True) for transfer in transfers: assert transfer.tx is not None assert tx.hash == transfer.tx.hash # get transfers with tx hashes - query = MoneroTransferQuery() - query.tx_query = MoneroTxQuery() - query.tx_query.hashes = tx_hashes + query = MoneroTransferQuery(tx_query=MoneroTxQuery(hashes=tx_hashes)) transfers = WalletTransfersUtils.get_and_test_transfers(wallet, query, None, True) for transfer in transfers: assert transfer.tx is not None @@ -204,11 +187,9 @@ def test_get_transfers_with_query(self, wallet: MoneroWallet) -> None: # TODO test transfers destinations # get transfers with pre-built query that are confirmed and have outgoing destinations - transfer_query: MoneroTransferQuery = MoneroTransferQuery() - transfer_query.outgoing = True - transfer_query.has_destinations = True - transfer_query.tx_query = MoneroTxQuery() - transfer_query.tx_query.is_confirmed = True + transfer_query: MoneroTransferQuery = MoneroTransferQuery( + outgoing=True, has_destinations=True, tx_query=MoneroTxQuery(is_confirmed=True) + ) transfers = WalletTransfersUtils.get_and_test_transfers(wallet, transfer_query, None, None) for transfer in transfers: assert transfer.is_outgoing() is True @@ -218,11 +199,7 @@ def test_get_transfers_with_query(self, wallet: MoneroWallet) -> None: assert transfer.tx.is_confirmed is True # get incoming transfers to account 0 which has outgoing transfers (i.e. originated from the same wallet) - query = MoneroTransferQuery() - query.account_index = 1 - query.incoming = True - query.tx_query = MoneroTxQuery() - query.tx_query.is_outgoing = True + query = MoneroTransferQuery(account_index=1, incoming=True, tx_query=MoneroTxQuery(is_outgoing=True)) transfers = wallet.get_transfers(query) assert len(transfers) > 0 for transfer in transfers: @@ -234,9 +211,7 @@ def test_get_transfers_with_query(self, wallet: MoneroWallet) -> None: # get incoming transfers to a specific address subaddress: str = wallet.get_address(1, 0) - query = MoneroTransferQuery() - query.incoming = True - query.address = subaddress + query = MoneroTransferQuery(incoming=True, address=subaddress) transfers = wallet.get_transfers(query) assert len(transfers) > 0 for transfer in transfers: @@ -277,8 +252,7 @@ def test_get_incoming_outgoing_transfers(self, wallet: MoneroWallet) -> None: TransferUtils.test_transfer(in_transfer, None) # get incoming transfers with contradictory query - query = MoneroTransferQuery() - query.incoming = False + query = MoneroTransferQuery(incoming=False) with pytest.raises(Exception) as exc_info: wallet.get_incoming_transfers(query) assert str(exc_info.value) == "Transfer query contradicts getting incoming transfers" @@ -291,9 +265,7 @@ def test_get_incoming_outgoing_transfers(self, wallet: MoneroWallet) -> None: TransferUtils.test_transfer(out_transfer, None) # get outgoing transfers with query - query = MoneroTransferQuery() - query.account_index = account_idx - query.subaddress_index = subaddress_idx + query = MoneroTransferQuery(account_index=account_idx, subaddress_index=subaddress_idx) out_transfers = wallet.get_outgoing_transfers(query) assert len(out_transfers) > 0 for out_transfer in out_transfers: @@ -303,8 +275,7 @@ def test_get_incoming_outgoing_transfers(self, wallet: MoneroWallet) -> None: TransferUtils.test_transfer(out_transfer, None) # get outgoing transfers with contradictory query - query = MoneroTransferQuery() - query.outgoing = False + query = MoneroTransferQuery(outgoing=False) with pytest.raises(Exception) as exc_info: wallet.get_outgoing_transfers(query) assert str(exc_info.value) == "Transfer query contradicts getting outgoing transfers" @@ -337,14 +308,12 @@ def test_validate_inputs_get_transfers(self, wallet: MoneroWallet) -> None: assert transfer.tx is tx # test unused subaddress indices - transfer_query = MoneroTransferQuery() - transfer_query.account_index = 0 + transfer_query = MoneroTransferQuery(account_index=0) transfer_query.subaddress_indices.append(1234907) transfers = wallet.get_transfers(transfer_query) # test invalid subaddress index - transfer_query = MoneroTransferQuery() - transfer_query.account_index = 0 + transfer_query = MoneroTransferQuery(account_index=0) with pytest.raises(Exception): transfer_query.subaddress_index = -1 wallet.get_transfers(transfer_query) diff --git a/tests/wallet/test_txs.py b/tests/wallet/test_txs.py index 9dfafd1b..859c19cb 100644 --- a/tests/wallet/test_txs.py +++ b/tests/wallet/test_txs.py @@ -158,8 +158,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: for random_tx in random_txs: assert random_tx.hash is not None tx_hashes.append(random_tx.hash) - query: MoneroTxQuery = MoneroTxQuery() - query.hash = random_tx.hash + query: MoneroTxQuery = MoneroTxQuery(hash=random_tx.hash) txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(wallet, query, None, True, TestUtils.REGTEST) assert len(txs) == 1 # txs change with chain so check mergeability @@ -168,8 +167,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: TxWalletUtils.test_tx_wallet(merged) # get transactions by hashes - query = MoneroTxQuery() - query.hashes = tx_hashes + query = MoneroTxQuery(hashes=tx_hashes) txs = WalletTxsUtils.get_and_test_txs(wallet, query, None, None, TestUtils.REGTEST) assert len(txs) == len(random_txs) for tx in txs: @@ -178,8 +176,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # get transactions with an outgoing transfer ctx: TxContext = TxContext() ctx.has_outgoing_transfer = True - query = MoneroTxQuery() - query.is_outgoing = True + query = MoneroTxQuery(is_outgoing=True) txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) for tx in txs: assert tx.is_outgoing is True @@ -188,8 +185,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # get transactions without an outgoing transfer ctx.has_outgoing_transfer = False - query = MoneroTxQuery() - query.is_outgoing = False + query = MoneroTxQuery(is_outgoing=False) txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) for tx in txs: assert tx.outgoing_transfer is None @@ -197,8 +193,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # get transactions with incoming transfers ctx = TxContext() ctx.has_incoming_transfers = True - query = MoneroTxQuery() - query.is_incoming = True + query = MoneroTxQuery(is_incoming=True) txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) for tx in txs: assert tx.is_incoming is True @@ -208,8 +203,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # get transactions without incoming transfers ctx.has_incoming_transfers = False - query = MoneroTxQuery() - query.is_incoming = False + query = MoneroTxQuery(is_incoming=False) txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) for tx in txs: assert tx.is_incoming is False @@ -217,9 +211,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # get transactions associated with an account account_idx: int = 1 - query = MoneroTxQuery() - query.transfer_query = MoneroTransferQuery() - query.transfer_query.account_index = account_idx + query = MoneroTxQuery(transfer_query=MoneroTransferQuery(account_index=account_idx)) txs = wallet.get_txs(query) for tx in txs: @@ -237,11 +229,9 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # get txs with manually built query that are confirmed and have an outgoing transfer from account 0 ctx = TxContext() ctx.has_outgoing_transfer = True - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_confirmed = True - tx_query.transfer_query = MoneroTransferQuery() - tx_query.transfer_query.account_index = 0 - tx_query.transfer_query.outgoing = True + tx_query: MoneroTxQuery = MoneroTxQuery( + is_confirmed=True, transfer_query=MoneroTransferQuery(account_index=0, outgoing=True) + ) txs = WalletTxsUtils.get_and_test_txs(wallet, tx_query, ctx, True, TestUtils.REGTEST) for tx in txs: if tx.is_confirmed is not True: @@ -252,11 +242,9 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: assert tx.outgoing_transfer.account_index == 0 # get txs with outgoing transfers that have destinations to account 1 - tx_query = MoneroTxQuery() - tx_query.is_confirmed = True - tx_query.transfer_query = MoneroTransferQuery() - tx_query.transfer_query.account_index = 0 - tx_query.transfer_query.has_destinations = True + tx_query = MoneroTxQuery( + is_confirmed=True, transfer_query=MoneroTransferQuery(account_index=0, has_destinations=True) + ) txs = WalletTxsUtils.get_and_test_txs(wallet, tx_query, None, None, TestUtils.REGTEST) for tx in txs: @@ -267,8 +255,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # include outputs with transactions ctx = TxContext() ctx.include_outputs = True - tx_query = MoneroTxQuery() - tx_query.include_outputs = True + tx_query = MoneroTxQuery(include_outputs=True) txs = WalletTxsUtils.get_and_test_txs(wallet, tx_query, ctx, True, TestUtils.REGTEST) found: bool = False for tx in txs: @@ -284,11 +271,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # TODO no inputs returned to filter # get txs with output query - tx_query = MoneroTxQuery() - tx_query.output_query = MoneroOutputQuery() - tx_query.output_query.is_spent = False - tx_query.output_query.account_index = 1 - tx_query.output_query.subaddress_index = 2 + tx_query = MoneroTxQuery(output_query=MoneroOutputQuery(is_spent=False, account_index=1, subaddress_index=2)) txs = wallet.get_txs(tx_query) assert len(txs) > 0 for tx in txs: @@ -303,8 +286,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: raise Exception("Tx does not contain specified output") # get unlocked txs - tx_query = MoneroTxQuery() - tx_query.is_locked = False + tx_query = MoneroTxQuery(is_locked=False) txs = wallet.get_txs(tx_query) assert len(txs) > 0 for tx in txs: @@ -312,13 +294,10 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: # get confirmed transactions sent from/to same wallet with a transfer with destinations - tx_query = MoneroTxQuery() - tx_query.is_incoming = True - tx_query.is_outgoing = True - tx_query.include_outputs = True - tx_query.is_confirmed = True - tx_query.transfer_query = MoneroTransferQuery() - tx_query.transfer_query.has_destinations = True + tx_query = MoneroTxQuery( + is_incoming=True, is_outgoing=True, include_outputs=True, is_confirmed=True, + transfer_query=MoneroTransferQuery(has_destinations=True) + ) txs = wallet.get_txs(tx_query) assert len(txs) > 0, "Wallet has no incoming/outgoing txs to test; run send from/to tests" @@ -334,8 +313,7 @@ def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_txs_by_height(self, wallet: MoneroWallet) -> None: # get all confirmed txs for testing - query: MoneroTxQuery = MoneroTxQuery() - query.is_confirmed = True + query: MoneroTxQuery = MoneroTxQuery(is_confirmed=True) txs: list[MoneroTxWallet] = wallet.get_txs(query) # collect all tx heights @@ -352,8 +330,7 @@ def test_get_txs_by_height(self, wallet: MoneroWallet) -> None: mode_height: int = next(iter(height_modes)) # fetch txs at mode height - query = MoneroTxQuery() - query.height = mode_height + query = MoneroTxQuery(height=mode_height) logger.debug(f"Getting mode txs by height; mode height {mode_height}") mode_txs: list[MoneroTxWallet] = wallet.get_txs(query) assert height_counts[mode_height] == len(mode_txs) @@ -361,26 +338,21 @@ def test_get_txs_by_height(self, wallet: MoneroWallet) -> None: assert mode_height == tx.get_height() # fetch txs at mode height by range - query = MoneroTxQuery() - query.min_height = mode_height - query.max_height = mode_height + query = MoneroTxQuery(min_height=mode_height, max_height=mode_height) logger.debug(f"Getting mode txs by range; mode height {mode_height}") mode_txs_by_range: list[MoneroTxWallet] = wallet.get_txs(query) # TODO test txs order is failing TxWalletUtils.assert_list_txs_equals(mode_txs, mode_txs_by_range) # fetch all txs by range - query = MoneroTxQuery() - query.min_height = txs[0].get_height() - query.max_height = txs[-1].get_height() + query = MoneroTxQuery(min_height=txs[0].get_height(), max_height=txs[-1].get_height()) all_txs: list[MoneroTxWallet] = wallet.get_txs(query) # TODO test txs order is failing TxWalletUtils.assert_list_txs_equals(txs, all_txs) # test some filtered by range try: - query = MoneroTxQuery() - query.is_confirmed = True + query = MoneroTxQuery(is_confirmed=True) txs = wallet.get_txs(query) assert len(txs) > 0, "No transactions; run send to multiple test" @@ -405,9 +377,7 @@ def test_get_txs_by_height(self, wallet: MoneroWallet) -> None: # assert some transactions filtered unfiltered_count: int = len(txs) - query = MoneroTxQuery() - query.min_height = min_height - query.max_height = max_height + query = MoneroTxQuery(min_height=min_height, max_height=max_height) txs = WalletTxsUtils.get_and_test_txs(wallet, query, None, True, TestUtils.REGTEST) assert len(txs) < unfiltered_count for tx in txs: @@ -423,8 +393,7 @@ def test_get_txs_by_height(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False or TestUtils.LITE_MODE, reason="TEST_NON_RELAYS disabled or LITE_MODE enabled") def test_get_txs_with_payment_ids(self, wallet: MoneroWallet) -> None: # get random transactions with payment ids for testing - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.has_payment_id = True + tx_query: MoneroTxQuery = MoneroTxQuery(has_payment_id=True) random_txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, tx_query, 2, 5) assert len(random_txs) > 0, "No txs with payment ids to test" for random_tx in random_txs: @@ -438,8 +407,7 @@ def test_get_txs_with_payment_ids(self, wallet: MoneroWallet) -> None: assert len(payment_ids) > 1 for payment_id in payment_ids: - tx_query = MoneroTxQuery() - tx_query.payment_id = payment_id + tx_query = MoneroTxQuery(payment_id=payment_id) txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(wallet, tx_query, None, None, TestUtils.REGTEST) assert len(txs) > 0 first_payment_id: Optional[str] = txs[0].payment_id @@ -447,8 +415,7 @@ def test_get_txs_with_payment_ids(self, wallet: MoneroWallet) -> None: MoneroUtils.validate_payment_id(first_payment_id) # get transactions by payment hashes - tx_query = MoneroTxQuery() - tx_query.payment_ids = payment_ids + tx_query = MoneroTxQuery(payment_ids=payment_ids) txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(wallet, tx_query, None, None, TestUtils.REGTEST) for tx in txs: assert tx.payment_id is not None @@ -458,8 +425,7 @@ def test_get_txs_with_payment_ids(self, wallet: MoneroWallet) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_get_txs_fields_with_filtering(self, wallet: MoneroWallet) -> None: # fetch wallet txs - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.is_confirmed = True + tx_query: MoneroTxQuery = MoneroTxQuery(is_confirmed=True) txs: list[MoneroTxWallet] = wallet.get_txs(tx_query) for tx in txs: @@ -504,8 +470,7 @@ def test_validate_inputs_get_txs(self, wallet: MoneroWallet) -> None: assert fetched_tx is None # fetch unknown tx hash using query - tx_query: MoneroTxQuery = MoneroTxQuery() - tx_query.hash = unknown_hash1 + tx_query: MoneroTxQuery = MoneroTxQuery(hash=unknown_hash1) fetched_txs: list[MoneroTxWallet] = wallet.get_txs(tx_query) assert len(fetched_txs) == 0 @@ -534,8 +499,7 @@ def test_validate_inputs_get_txs(self, wallet: MoneroWallet) -> None: assert txs[0].hash == tx_hash # test collection of invalid hashes - tx_query = MoneroTxQuery() - tx_query.hashes = [tx_hash, invalid_hash, "invalid_hash_2"] + tx_query = MoneroTxQuery(hashes=[tx_hash, invalid_hash, "invalid_hash_2"]) txs = wallet.get_txs(tx_query) assert len(txs) == 1 From 38963c95bd16bbe134b35468374f21f192da1d66 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 29 Nov 2026 22:34:36 +0100 Subject: [PATCH 07/11] docs: construct the configs and queries of the examples from keywords --- README.md | 26 ++++++----- docs/mkdocs/docs/en/api/errors.md | 3 +- docs/mkdocs/docs/en/api/wallet_full.md | 15 +++--- docs/mkdocs/docs/en/api/wallet_keys.md | 3 +- docs/mkdocs/docs/en/api/wallet_rpc.md | 9 ++-- .../basics/create_local_full_wallet.md | 33 +++++++------ .../basics/interact_with_wallet_rpc.md | 7 +-- .../docs/en/examples/basics/multisig.md | 4 +- .../examples/basics/proofs_and_signatures.md | 3 +- .../basics/query_wallet_txs_and_transfers.md | 46 +++++++++---------- .../en/examples/basics/sending_payments.md | 39 ++++++++-------- .../examples/basics/using_keys_only_wallet.md | 23 +++++----- .../examples/scenarios/accepting_payments.md | 15 +++--- .../examples/scenarios/backup_and_recovery.md | 22 +++++---- .../examples/scenarios/batch_withdrawals.md | 11 +++-- .../en/examples/scenarios/cold_signing.md | 35 +++++++------- .../scenarios/developing_on_regtest.md | 22 +++++---- .../scenarios/escrow_with_multisig.md | 7 +-- .../docs/en/examples/scenarios/sign_in.md | 3 +- 19 files changed, 166 insertions(+), 160 deletions(-) diff --git a/README.md b/README.md index 9d4c399a..714b7e91 100644 --- a/README.md +++ b/README.md @@ -55,13 +55,14 @@ txs_in_pool: list[MoneroTx] = daemon.get_tx_pool() # get transactions in the poo # create wallet from mnemonic phrase using Python bindings to monero-project -wallet_config = MoneroWalletConfig() -wallet_config.path = "sample_wallet_full" -wallet_config.password = "supersecretpassword123" -wallet_config.network_type = MoneroNetworkType.STAGENET -wallet_config.server = MoneroRpcConnection("http://localhost:38081", "superuser", "abctesting123") -wallet_config.seed = "hefty value scenic..." -wallet_config.restore_height = 573936 +wallet_config = MoneroWalletConfig( + path="sample_wallet_full", + password="supersecretpassword123", + network_type=MoneroNetworkType.STAGENET, + server=MoneroRpcConnection("http://localhost:38081", "superuser", "abctesting123"), + seed="hefty value scenic...", + restore_height=573936, +) wallet_full: MoneroWallet = MoneroWalletFull.create_wallet(wallet_config) listener: MoneroWalletListener = MyWalletListener() @@ -83,11 +84,12 @@ balance: int = wallet_rpc.get_balance() # 533648366742 txs: list[MoneroTxWallet] = wallet_rpc.get_txs() # get transactions containing transfers to/from the wallet # send funds from RPC wallet to full wallet -tx_config = MoneroTxConfig() -tx_config.account_index = 0 -tx_config.address = wallet_full.get_address(1, 0) -tx_config.amount = 250000000000 # send 0.25 XMR (denominated in atomic units) -tx_config.relay = False # create transaction and relay to the network if true +tx_config = MoneroTxConfig( + account_index=0, + address=wallet_full.get_address(1, 0), + amount=250000000000, # send 0.25 XMR (denominated in atomic units) + relay=False, # create transaction and relay to the network if true +) created_tx: MoneroTxWallet = wallet_rpc.create_tx(tx_config) fee: int | None = created_tx.fee # "Are you sure you want to send... ?" diff --git a/docs/mkdocs/docs/en/api/errors.md b/docs/mkdocs/docs/en/api/errors.md index a615424c..1bb8ba0f 100644 --- a/docs/mkdocs/docs/en/api/errors.md +++ b/docs/mkdocs/docs/en/api/errors.md @@ -31,8 +31,7 @@ except MoneroError as e: print(f"it failed: {e}") # a method that a wallet does not support raises a MoneroError that says so -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.MAINNET +config = MoneroWalletConfig(network_type=MoneroNetworkType.MAINNET) keys = MoneroWalletKeys.create_wallet_random(config) try: keys.get_height() diff --git a/docs/mkdocs/docs/en/api/wallet_full.md b/docs/mkdocs/docs/en/api/wallet_full.md index 6923b403..64585cd6 100644 --- a/docs/mkdocs/docs/en/api/wallet_full.md +++ b/docs/mkdocs/docs/en/api/wallet_full.md @@ -22,13 +22,14 @@ and how depends on what the config has: ```python from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull -config = MoneroWalletConfig() -config.path = "wallets/main" -config.password = "supersecretpassword123" -config.network_type = MoneroNetworkType.STAGENET -config.server = MoneroRpcConnection("http://localhost:38081") -config.seed = "hefty value scenic..." -config.restore_height = 573936 # the height to sync from: without it a restored wallet syncs from the first block +config = MoneroWalletConfig( + path="wallets/main", + password="supersecretpassword123", + network_type=MoneroNetworkType.STAGENET, + server=MoneroRpcConnection("http://localhost:38081"), + seed="hefty value scenic...", + restore_height=573936, # the height to sync from: without it a restored wallet syncs from the first block +) wallet = MoneroWalletFull.create_wallet(config) ``` diff --git a/docs/mkdocs/docs/en/api/wallet_keys.md b/docs/mkdocs/docs/en/api/wallet_keys.md index 00c533dc..fab875ee 100644 --- a/docs/mkdocs/docs/en/api/wallet_keys.md +++ b/docs/mkdocs/docs/en/api/wallet_keys.md @@ -23,8 +23,7 @@ Each way of making it has its own function, which takes a [`MoneroWalletConfig`] ```python from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.MAINNET +config = MoneroWalletConfig(network_type=MoneroNetworkType.MAINNET) wallet = MoneroWalletKeys.create_wallet_random(config) print(wallet.get_seed()) diff --git a/docs/mkdocs/docs/en/api/wallet_rpc.md b/docs/mkdocs/docs/en/api/wallet_rpc.md index 35540343..e8bf6124 100644 --- a/docs/mkdocs/docs/en/api/wallet_rpc.md +++ b/docs/mkdocs/docs/en/api/wallet_rpc.md @@ -35,10 +35,11 @@ wallet = MoneroWalletRpc("http://localhost:38083", "rpc_user", "abc123") wallet.open_wallet("main", "supersecretpassword123") # or a new one, there: the config is the one of a full wallet, its path is the name of the wallet in the folder -config = MoneroWalletConfig() -config.path = "other" -config.password = "supersecretpassword123" -config.network_type = MoneroNetworkType.STAGENET +config = MoneroWalletConfig( + path="other", + password="supersecretpassword123", + network_type=MoneroNetworkType.STAGENET, +) wallet.create_wallet(config) ``` diff --git a/docs/mkdocs/docs/en/examples/basics/create_local_full_wallet.md b/docs/mkdocs/docs/en/examples/basics/create_local_full_wallet.md index bad44a79..8fa9a2ab 100644 --- a/docs/mkdocs/docs/en/examples/basics/create_local_full_wallet.md +++ b/docs/mkdocs/docs/en/examples/basics/create_local_full_wallet.md @@ -12,11 +12,12 @@ how it works. ```python from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull -config = MoneroWalletConfig() -config.path = "test_wallet_full" # test_wallet_full and test_wallet_full.keys -config.password = "supersecretpassword123" -config.network_type = MoneroNetworkType.TESTNET -config.server = MoneroRpcConnection("http://localhost:28081") +config = MoneroWalletConfig( + path="test_wallet_full", # test_wallet_full and test_wallet_full.keys + password="supersecretpassword123", + network_type=MoneroNetworkType.TESTNET, + server=MoneroRpcConnection("http://localhost:28081"), +) wallet = MoneroWalletFull.create_wallet(config) print(wallet.get_seed()) # write it down: it is the wallet @@ -27,13 +28,14 @@ print(wallet.get_seed()) # write it down: it is the w ```python from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull -config = MoneroWalletConfig() -config.path = "restored_wallet" -config.password = "supersecretpassword123" -config.network_type = MoneroNetworkType.TESTNET -config.server = MoneroRpcConnection("http://localhost:28081") -config.seed = "...the 25 words..." -config.restore_height = 2500000 # a height before the first payment to the wallet +config = MoneroWalletConfig( + path="restored_wallet", + password="supersecretpassword123", + network_type=MoneroNetworkType.TESTNET, + server=MoneroRpcConnection("http://localhost:28081"), + seed="...the 25 words...", + restore_height=2500000, # a height before the first payment to the wallet +) wallet = MoneroWalletFull.create_wallet(config) wallet.sync() @@ -72,9 +74,10 @@ A wallet with no `path` is not written to disk: its data are taken with ```python from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletFull -config = MoneroWalletConfig() -config.password = "supersecretpassword123" -config.network_type = MoneroNetworkType.TESTNET +config = MoneroWalletConfig( + password="supersecretpassword123", + network_type=MoneroNetworkType.TESTNET, +) wallet = MoneroWalletFull.create_wallet(config) keys_data: bytes = wallet.get_keys_file_buffer("supersecretpassword123", False) diff --git a/docs/mkdocs/docs/en/examples/basics/interact_with_wallet_rpc.md b/docs/mkdocs/docs/en/examples/basics/interact_with_wallet_rpc.md index f05678c0..7aa69c8f 100644 --- a/docs/mkdocs/docs/en/examples/basics/interact_with_wallet_rpc.md +++ b/docs/mkdocs/docs/en/examples/basics/interact_with_wallet_rpc.md @@ -33,9 +33,10 @@ A new wallet, in the `--wallet-dir` of the server: from monero import MoneroWalletConfig # build wallet configuration -config = MoneroWalletConfig() -config.path = "wallet_name" # the name of its file, in the folder of the server -config.password = "wallet_password" +config = MoneroWalletConfig( + path="wallet_name", # the name of its file, in the folder of the server + password="wallet_password", +) # create new wallet file in rpc server wallet.create_wallet(config) diff --git a/docs/mkdocs/docs/en/examples/basics/multisig.md b/docs/mkdocs/docs/en/examples/basics/multisig.md index bf4188b1..608bf5eb 100644 --- a/docs/mkdocs/docs/en/examples/basics/multisig.md +++ b/docs/mkdocs/docs/en/examples/basics/multisig.md @@ -70,9 +70,7 @@ def send(participants: list[MoneroWallet], m: int, address: str, amount: int) -> share_multisig_info(participants) # one participant creates the transaction, which is not signed enough to be relayed - config = MoneroTxConfig() - config.address = address - config.amount = amount + config = MoneroTxConfig(address=address, amount=amount) tx = participants[0].create_tx(config) assert tx.tx_set is not None and tx.tx_set.multisig_tx_hex is not None tx_hex: str = tx.tx_set.multisig_tx_hex diff --git a/docs/mkdocs/docs/en/examples/basics/proofs_and_signatures.md b/docs/mkdocs/docs/en/examples/basics/proofs_and_signatures.md index c8e34c37..8236f182 100644 --- a/docs/mkdocs/docs/en/examples/basics/proofs_and_signatures.md +++ b/docs/mkdocs/docs/en/examples/basics/proofs_and_signatures.md @@ -13,8 +13,7 @@ A message signed with an address proves that whoever signed it has the keys of t ```python from monero import MoneroMessageSignatureType, MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.MAINNET +config = MoneroWalletConfig(network_type=MoneroNetworkType.MAINNET) wallet = MoneroWalletKeys.create_wallet_random(config) message = "I am the owner of this address" diff --git a/docs/mkdocs/docs/en/examples/basics/query_wallet_txs_and_transfers.md b/docs/mkdocs/docs/en/examples/basics/query_wallet_txs_and_transfers.md index 8a2e85d4..0e6eaf31 100644 --- a/docs/mkdocs/docs/en/examples/basics/query_wallet_txs_and_transfers.md +++ b/docs/mkdocs/docs/en/examples/basics/query_wallet_txs_and_transfers.md @@ -25,18 +25,16 @@ wallet = MoneroWalletRpc("http://wallet_rpc_uri:18083") wallet.open_wallet("wallet_name", "wallet_password") # create and setup a new tx query to filter txs with -query = MoneroTxQuery() - -# fetch only outgoing txs -query.is_incoming = False -query.is_outgoing = True - -# include outputs in tx data -query.include_outputs = True - -# filter tx by height range -query.min_height = 150000 -query.max_height = 300000 +query = MoneroTxQuery( + # fetch only outgoing txs + is_incoming=False, + is_outgoing=True, + # include outputs in tx data + include_outputs=True, + # filter tx by height range + min_height=150000, + max_height=300000, +) # fetch the txs that match the query txs: list[MoneroTxWallet] = wallet.get_txs(query) @@ -59,14 +57,13 @@ wallet = MoneroWalletRpc("http://wallet_rpc_uri:18083") wallet.open_wallet("wallet_name", "wallet_password") # create and setup a new transfer query -query = MoneroTransferQuery() - -# fetch only incoming transfers -query.incoming = True - -# filter by account and subaddress index -query.account_index = 1 -query.subaddress_indices = [0, 1, 2, 3] +query = MoneroTransferQuery( + # fetch only incoming transfers + incoming=True, + # filter by account and subaddress index + account_index=1, + subaddress_indices=[0, 1, 2, 3], +) # fetch the transfers that match the query transfers: list[MoneroTransfer] = wallet.get_transfers(query) @@ -81,10 +78,11 @@ Example of fetching the outputs of the wallet with a `MoneroOutputQuery`, the on ```python from monero import MoneroOutputQuery, MoneroOutputWallet, MoneroUtils -query = MoneroOutputQuery() -query.is_spent = False -query.is_frozen = False -query.account_index = 0 +query = MoneroOutputQuery( + is_spent=False, + is_frozen=False, + account_index=0, +) outputs: list[MoneroOutputWallet] = wallet.get_outputs(query) for output in outputs: diff --git a/docs/mkdocs/docs/en/examples/basics/sending_payments.md b/docs/mkdocs/docs/en/examples/basics/sending_payments.md index 3cd611e3..b26a78c6 100644 --- a/docs/mkdocs/docs/en/examples/basics/sending_payments.md +++ b/docs/mkdocs/docs/en/examples/basics/sending_payments.md @@ -13,17 +13,15 @@ wallet = MoneroWalletRpc("http://wallet_rpc_uri:18083") wallet.open_wallet("wallet_name", "wallet_password") # create and setup transaction configuration -tx_config = MoneroTxConfig() - -# specify source account index -tx_config.account_index = 0 - -# specify address and destination amount -tx_config.address = "...destination address..." -tx_config.amount = 1000000000 - -# relay tx to the network -tx_config.relay = True +tx_config = MoneroTxConfig( + # specify source account index + account_index=0, + # specify address and destination amount + address="...destination address...", + amount=1000000000, + # relay tx to the network + relay=True, +) # create txs with configuration txs: list[MoneroTxWallet] = wallet.create_txs(tx_config) @@ -41,15 +39,16 @@ A transaction can pay more destinations at once, up to 15: a transaction has at ```python from monero import MoneroDestination, MoneroTxConfig -batch = MoneroTxConfig() -batch.account_index = 0 -batch.destinations = [ - MoneroDestination("...destination address 1...", 1000000000), - MoneroDestination("...destination address 2...", 2500000000), - MoneroDestination("...destination address 3...", 500000000), -] -batch.can_split = True # more transactions, if one is not enough -batch.relay = True +batch = MoneroTxConfig( + account_index=0, + destinations=[ + MoneroDestination("...destination address 1...", 1000000000), + MoneroDestination("...destination address 2...", 2500000000), + MoneroDestination("...destination address 3...", 500000000), + ], + can_split=True, # more transactions, if one is not enough + relay=True, +) txs = wallet.create_txs(batch) ``` diff --git a/docs/mkdocs/docs/en/examples/basics/using_keys_only_wallet.md b/docs/mkdocs/docs/en/examples/basics/using_keys_only_wallet.md index 5c591bbd..9845f631 100644 --- a/docs/mkdocs/docs/en/examples/basics/using_keys_only_wallet.md +++ b/docs/mkdocs/docs/en/examples/basics/using_keys_only_wallet.md @@ -13,9 +13,10 @@ A new wallet, with a random seed: ```python from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.TESTNET -config.language = "English" # the language of the words of the seed +config = MoneroWalletConfig( + network_type=MoneroNetworkType.TESTNET, + language="English", # the language of the words of the seed +) wallet = MoneroWalletKeys.create_wallet_random(config) print(wallet.get_seed()) @@ -26,9 +27,7 @@ The same wallet, restored from its seed: ```python from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.TESTNET -config.seed = "...wallet seed..." +config = MoneroWalletConfig(network_type=MoneroNetworkType.TESTNET, seed="...wallet seed...") wallet = MoneroWalletKeys.create_wallet_from_seed(config) ``` @@ -38,10 +37,11 @@ Or from its keys: with the view key and no spend key it is a view-only wallet: ```python from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.TESTNET -config.primary_address = "...wallet primary address..." -config.private_view_key = "...wallet private view key..." +config = MoneroWalletConfig( + network_type=MoneroNetworkType.TESTNET, + primary_address="...wallet primary address...", + private_view_key="...wallet private view key...", +) wallet = MoneroWalletKeys.create_wallet_from_keys(config) print(wallet.is_view_only()) # True @@ -52,8 +52,7 @@ print(wallet.is_view_only()) # True ```python from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.TESTNET +config = MoneroWalletConfig(network_type=MoneroNetworkType.TESTNET) wallet = MoneroWalletKeys.create_wallet_random(config) print(wallet.get_primary_address()) diff --git a/docs/mkdocs/docs/en/examples/scenarios/accepting_payments.md b/docs/mkdocs/docs/en/examples/scenarios/accepting_payments.md index 27008598..82f91a1d 100644 --- a/docs/mkdocs/docs/en/examples/scenarios/accepting_payments.md +++ b/docs/mkdocs/docs/en/examples/scenarios/accepting_payments.md @@ -35,11 +35,12 @@ def new_order(wallet: MoneroWallet, order_id: str, price_xmr: float) -> tuple[Or order = Order(order_id, MoneroUtils.xmr_to_atomic_units(price_xmr), subaddress.index, subaddress.address) # monero:
?tx_amount=...&recipient_name=...&tx_description=... - request = MoneroTxConfig() - request.address = order.address - request.amount = order.amount - request.recipient_name = "The Shop" - request.note = f"order {order_id}" + request = MoneroTxConfig( + address=order.address, + amount=order.amount, + recipient_name="The Shop", + note=f"order {order_id}", + ) return order, wallet.get_payment_uri(request) ``` @@ -104,9 +105,7 @@ class Paid: def amount_paid(wallet: MoneroWallet, order: Order) -> Paid: """What the order received, by state.""" - query = MoneroTransferQuery() - query.account_index = ACCOUNT - query.subaddress_index = order.subaddress_index + query = MoneroTransferQuery(account_index=ACCOUNT, subaddress_index=order.subaddress_index) transfers: list[MoneroIncomingTransfer] = wallet.get_incoming_transfers(query) paid = Paid() diff --git a/docs/mkdocs/docs/en/examples/scenarios/backup_and_recovery.md b/docs/mkdocs/docs/en/examples/scenarios/backup_and_recovery.md index 48234af3..89db4724 100644 --- a/docs/mkdocs/docs/en/examples/scenarios/backup_and_recovery.md +++ b/docs/mkdocs/docs/en/examples/scenarios/backup_and_recovery.md @@ -34,13 +34,14 @@ payments before it, one that is too low only takes longer. ```python from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull -config = MoneroWalletConfig() -config.path = "wallets/restored" -config.password = "a new password" -config.network_type = MoneroNetworkType.MAINNET -config.server = MoneroRpcConnection("http://localhost:18081") -config.seed = "...the 25 words..." -config.restore_height = 3200000 +config = MoneroWalletConfig( + path="wallets/restored", + password="a new password", + network_type=MoneroNetworkType.MAINNET, + server=MoneroRpcConnection("http://localhost:18081"), + seed="...the 25 words...", + restore_height=3200000, +) wallet = MoneroWalletFull.create_wallet(config) ``` @@ -79,9 +80,10 @@ made from it, offline, has the same primary address. ```python from monero import MoneroNetworkType, MoneroWalletConfig, MoneroWalletKeys -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.MAINNET -config.seed = "...the 25 words, as written in the backup..." +config = MoneroWalletConfig( + network_type=MoneroNetworkType.MAINNET, + seed="...the 25 words, as written in the backup...", +) check = MoneroWalletKeys.create_wallet_from_seed(config) assert check.get_primary_address() == wallet.get_primary_address(), "the seed of the backup is not the one of the wallet" ``` diff --git a/docs/mkdocs/docs/en/examples/scenarios/batch_withdrawals.md b/docs/mkdocs/docs/en/examples/scenarios/batch_withdrawals.md index 29fdc179..9a5ed33d 100644 --- a/docs/mkdocs/docs/en/examples/scenarios/batch_withdrawals.md +++ b/docs/mkdocs/docs/en/examples/scenarios/batch_withdrawals.md @@ -66,11 +66,12 @@ wallet.open_wallet("hot", "supersecretpassword123") def pay(batch: list[Withdrawal]) -> list[str]: """Pays a batch in one transaction, and returns its hash.""" - config = MoneroTxConfig() - config.account_index = 0 - config.destinations = [MoneroDestination(w.address, w.amount) for w in batch] - config.priority = MoneroTxPriority.UNIMPORTANT - config.relay = True + config = MoneroTxConfig( + account_index=0, + destinations=[MoneroDestination(w.address, w.amount) for w in batch], + priority=MoneroTxPriority.UNIMPORTANT, + relay=True, + ) tx = wallet.create_tx(config) assert tx.hash is not None diff --git a/docs/mkdocs/docs/en/examples/scenarios/cold_signing.md b/docs/mkdocs/docs/en/examples/scenarios/cold_signing.md index f43adc93..43bf05b7 100644 --- a/docs/mkdocs/docs/en/examples/scenarios/cold_signing.md +++ b/docs/mkdocs/docs/en/examples/scenarios/cold_signing.md @@ -22,23 +22,25 @@ view-only wallet on the online one: from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletFull # on the offline machine -cold_config = MoneroWalletConfig() -cold_config.path = "wallets/cold" -cold_config.password = "supersecretpassword123" -cold_config.network_type = MoneroNetworkType.STAGENET -cold_config.seed = "...the 25 words..." +cold_config = MoneroWalletConfig( + path="wallets/cold", + password="supersecretpassword123", + network_type=MoneroNetworkType.STAGENET, + seed="...the 25 words...", +) cold = MoneroWalletFull.create_wallet(cold_config) print(cold.get_primary_address(), cold.get_private_view_key()) # copy them to the online machine # on the online machine -online_config = MoneroWalletConfig() -online_config.path = "wallets/view_only" -online_config.password = "supersecretpassword123" -online_config.network_type = MoneroNetworkType.STAGENET -online_config.server = MoneroRpcConnection("http://localhost:38081") -online_config.primary_address = "..." # the address of the cold wallet -online_config.private_view_key = "..." # and its view key -online_config.restore_height = 1500000 # before its first payment +online_config = MoneroWalletConfig( + path="wallets/view_only", + password="supersecretpassword123", + network_type=MoneroNetworkType.STAGENET, + server=MoneroRpcConnection("http://localhost:38081"), + primary_address="...", # the address of the cold wallet + private_view_key="...", # and its view key + restore_height=1500000, # before its first payment +) online = MoneroWalletFull.create_wallet(online_config) assert online.is_view_only() ``` @@ -81,9 +83,10 @@ The view-only wallet makes the transaction, which it can not sign: ```python from monero import MoneroTxConfig -config = MoneroTxConfig() -config.address = "..." # where the payment goes -config.amount = 250000000000 # 0.25 XMR +config = MoneroTxConfig( + address="...", # where the payment goes + amount=250000000000, # 0.25 XMR +) unsigned = online.create_tx(config) assert unsigned.tx_set is not None and unsigned.tx_set.unsigned_tx_hex is not None unsigned_tx_hex: str = unsigned.tx_set.unsigned_tx_hex diff --git a/docs/mkdocs/docs/en/examples/scenarios/developing_on_regtest.md b/docs/mkdocs/docs/en/examples/scenarios/developing_on_regtest.md index 8446217d..18f9946e 100644 --- a/docs/mkdocs/docs/en/examples/scenarios/developing_on_regtest.md +++ b/docs/mkdocs/docs/en/examples/scenarios/developing_on_regtest.md @@ -29,12 +29,13 @@ from monero import MoneroDaemonRpc, MoneroNetworkType, MoneroRpcConnection, Mone daemon = MoneroDaemonRpc("http://localhost:18081") -config = MoneroWalletConfig() -config.path = "regtest/miner" -config.password = "supersecretpassword123" -config.network_type = MoneroNetworkType.MAINNET -config.regtest = True -config.server = MoneroRpcConnection("http://localhost:18081") +config = MoneroWalletConfig( + path="regtest/miner", + password="supersecretpassword123", + network_type=MoneroNetworkType.MAINNET, + regtest=True, + server=MoneroRpcConnection("http://localhost:18081"), +) miner = MoneroWalletFull.create_wallet(config) daemon.generate_blocks(miner.get_primary_address(), 100) # 100 rewards @@ -54,10 +55,11 @@ from monero import MoneroTxConfig, MoneroUtils config.path = "regtest/customer" customer = MoneroWalletFull.create_wallet(config) -payment = MoneroTxConfig() -payment.address = customer.get_primary_address() -payment.amount = MoneroUtils.xmr_to_atomic_units(1.5) -payment.relay = True +payment = MoneroTxConfig( + address=customer.get_primary_address(), + amount=MoneroUtils.xmr_to_atomic_units(1.5), + relay=True, +) tx = miner.create_tx(payment) # the payment is in the pool: the wallet sees the transaction, the balance does not count it yet diff --git a/docs/mkdocs/docs/en/examples/scenarios/escrow_with_multisig.md b/docs/mkdocs/docs/en/examples/scenarios/escrow_with_multisig.md index 4e9a2f09..57a4d59e 100644 --- a/docs/mkdocs/docs/en/examples/scenarios/escrow_with_multisig.md +++ b/docs/mkdocs/docs/en/examples/scenarios/escrow_with_multisig.md @@ -69,9 +69,10 @@ def settle(creator: MoneroWallet, cosigner: MoneroWallet, to_address: str) -> li cosigner.import_multisig_hex([creator_info]) # the creator makes the transaction: everything that is unlocked, to the address - config = MoneroTxConfig() - config.address = to_address - config.account_index = 0 # the account that the buyer paid + config = MoneroTxConfig( + address=to_address, + account_index=0, # the account that the buyer paid + ) txs = creator.sweep_unlocked(config) tx_set = txs[0].tx_set assert tx_set is not None and tx_set.multisig_tx_hex is not None diff --git a/docs/mkdocs/docs/en/examples/scenarios/sign_in.md b/docs/mkdocs/docs/en/examples/scenarios/sign_in.md index 7f8180ad..bdf204a4 100644 --- a/docs/mkdocs/docs/en/examples/scenarios/sign_in.md +++ b/docs/mkdocs/docs/en/examples/scenarios/sign_in.md @@ -47,8 +47,7 @@ address = user.get_primary_address() from monero import MoneroMessageSignatureType, MoneroNetworkType, MoneroUtils, MoneroWalletConfig, MoneroWalletKeys # any wallet checks a signature: a keys-only one, made once when the site starts -config = MoneroWalletConfig() -config.network_type = MoneroNetworkType.MAINNET +config = MoneroWalletConfig(network_type=MoneroNetworkType.MAINNET) verifier = MoneroWalletKeys.create_wallet_random(config) From c62a5a6959b61af7ba37cdeb0a6fb419686c54ff Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Tue, 1 Dec 2026 22:31:36 +0100 Subject: [PATCH 08/11] tests: add a harness for malicious rpc servers --- tests/common/test_malicious_server.py | 71 ++++++++++++ tests/utils/__init__.py | 8 +- tests/utils/malicious_server.py | 154 ++++++++++++++++++++++++++ 3 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 tests/common/test_malicious_server.py create mode 100644 tests/utils/malicious_server.py diff --git a/tests/common/test_malicious_server.py b/tests/common/test_malicious_server.py new file mode 100644 index 00000000..570fe7cc --- /dev/null +++ b/tests/common/test_malicious_server.py @@ -0,0 +1,71 @@ +from __future__ import annotations + +import logging +import os +import time + +import pytest +from monero import MoneroDaemonRpc, MoneroWalletRpc + +from utils import BaseTestClass, MaliciousDaemonServer, MaliciousWalletRpcServer, Verdict + +logger: logging.Logger = logging.getLogger("TestMaliciousServer") + + +def _get_height(uri: str) -> None: + """A call to test: run by `MaliciousRpcServer.run` in its own process, given the uri of the server.""" + MoneroDaemonRpc(uri).get_height() + + +def _get_balance(uri: str) -> None: + """Same, for the wallet rpc client.""" + MoneroWalletRpc(uri).get_balance() + + +def _exit_without_reporting(uri: str) -> None: + """Does not call any client: ends the process the way a crash would, before it can report an outcome.""" + os._exit(1) + + +@pytest.mark.unit +class TestMaliciousServer(BaseTestClass): + """Unit tests of the MaliciousRpcServer harness itself: whether it correctly tells apart a call that raises MoneroError, one + that returns normally, one whose process ends without reporting, and one that takes too long. Scenarios with the inputs that a + real daemon or wallet rpc server can send belong in the tests of those clients, not here.""" + + # A well formed response does not make the client raise + def test_normal_response_does_not_raise(self) -> None: + with MaliciousDaemonServer() as server: + server.set_json_rpc_response({"status": "OK", "count": 100}) + result = server.run(_get_height) + assert result.verdict is Verdict.OK, result.detail + + # An error status is already handled correctly: a baseline for the harness, not a finding + def test_error_status_raises_moneroerror(self) -> None: + with MaliciousDaemonServer() as server: + server.set_json_rpc_response({"status": "Error"}) + result = server.run(_get_height) + assert result.verdict is Verdict.RAISED, result.detail + + # Invalid JSON is already rejected correctly too + def test_invalid_json_raises_moneroerror(self) -> None: + with MaliciousWalletRpcServer() as server: + server.set_response("/json_rpc", b"not json") + result = server.run(_get_balance) + assert result.verdict is Verdict.RAISED, result.detail + + # run() kills the process and reports a timeout, instead of waiting for a slow server + def test_slow_response_times_out(self) -> None: + with MaliciousDaemonServer(response_delay=2.0) as server: + server.set_json_rpc_response({"status": "OK", "count": 100}) + start: float = time.monotonic() + result = server.run(_get_height, timeout=0.3) + elapsed: float = time.monotonic() - start + assert result.verdict is Verdict.TIMED_OUT + assert elapsed < 2.0, f"run() waited {elapsed:.1f} s instead of killing the process at its own timeout" + + # A process that ends without reporting (a real crash would do the same) is told apart from a timeout or a raised error + def test_process_that_exits_without_reporting_is_a_crash(self) -> None: + with MaliciousDaemonServer() as server: + result = server.run(_exit_without_reporting) + assert result.verdict is Verdict.CRASHED, result.detail diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index 440c3f8a..651909c6 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -39,6 +39,7 @@ from .fake_daemon_rpc_server import FakeDaemonRpcServer from .fake_wallet_rpc_server import FakeWalletRpcServer from .fake_raw_rpc_server import FakeRawRpcServer +from .malicious_server import MaliciousCallResult, MaliciousDaemonServer, MaliciousRpcServer, MaliciousWalletRpcServer, Verdict from .wallet_notification_collector import WalletNotificationCollector from .wallet_notifications_tester import WalletNotificationsTester from .submit_then_relay_tx_tester import SubmitThenRelayTxTester @@ -113,5 +114,10 @@ 'DaemonNotificationCollector', 'FakeDaemonRpcServer', 'FakeWalletRpcServer', - 'FakeRawRpcServer' + 'FakeRawRpcServer', + 'MaliciousCallResult', + 'MaliciousDaemonServer', + 'MaliciousRpcServer', + 'MaliciousWalletRpcServer', + 'Verdict' ] diff --git a/tests/utils/malicious_server.py b/tests/utils/malicious_server.py new file mode 100644 index 00000000..4310e846 --- /dev/null +++ b/tests/utils/malicious_server.py @@ -0,0 +1,154 @@ +from __future__ import annotations + +import multiprocessing +import queue +import sys + +from dataclasses import dataclass +from enum import Enum +from multiprocessing.context import SpawnContext +from multiprocessing.process import BaseProcess +from typing import Callable, Optional +from typing_extensions import Self, override + +from .fake_raw_rpc_server import FakeRawRpcServer + +if sys.platform != "win32": + import resource + +# spawn, on every platform: the process that runs a call gets a fresh interpreter of its own, instead of a fork of this one, which +# may already have the bindings loaded, with threads and C++ state of their own (this module's own server runs in a background +# thread, and so does the poller of a client that an earlier test left running) +_CONTEXT: SpawnContext = multiprocessing.get_context("spawn") + + +class Verdict(Enum): + """What happened when a call was run against a malicious server, in its own process.""" + + OK = "ok" + """The call returned normally, without raising.""" + + RAISED = "raised" + """The call raised `monero.MoneroError`: the one a client should raise against a server it does not trust.""" + + OTHER_EXCEPTION = "other_exception" + """The call raised an exception that is not `monero.MoneroError`.""" + + CRASHED = "crashed" + """The process ended before it could report an outcome: a signal, a native crash, or a call to `os._exit()`.""" + + TIMED_OUT = "timed_out" + """The call did not end within the time given to `MaliciousRpcServer.run`, and was killed.""" + + +@dataclass +class MaliciousCallResult: + """What happened when a call was run against a malicious server.""" + + verdict: Verdict + """What happened.""" + + detail: Optional[str] + """The message of the exception, for `RAISED` and `OTHER_EXCEPTION`; the exit code of the process, for `CRASHED`; `None` for + `OK` and `TIMED_OUT`.""" + + +def _run_call( + call: Callable[[str], None], uri: str, memory_limit_mb: int, outcome: "multiprocessing.Queue[tuple[Verdict, Optional[str]]]" +) -> None: + """Runs `call(uri)`, with a limit on the memory of this process, and puts its outcome in `outcome`. Run in its own process by + `MaliciousRpcServer.run`, so that a crash here does not take the rest of the tests down with it. + + :param Callable[[str], None] call: a function at module level, that makes one client of the server and does one call with it. + :param str uri: uri of the malicious server, given to `call`. + :param int memory_limit_mb: limit on the address space of this process, in MB; not enforced on Windows. + :param multiprocessing.Queue outcome: where the verdict and its detail are put. + """ + if sys.platform != "win32": + limit: int = memory_limit_mb * 1024 * 1024 + resource.setrlimit(resource.RLIMIT_AS, (limit, limit)) + # imported here: the parent process, which only starts this one, does not need the bindings + from monero import MoneroError + + try: + call(uri) + outcome.put((Verdict.OK, None)) + except MoneroError as e: + outcome.put((Verdict.RAISED, str(e))) + except Exception as e: + outcome.put((Verdict.OTHER_EXCEPTION, f"{type(e).__name__}: {e}")) + + +class MaliciousRpcServer(FakeRawRpcServer): + """A rpc server for tests of how a client reacts to one that is malicious, or just broken: wrong fields, missing ones, extreme + values, or anything else that `set_response` or `set_json_rpc_response` can send back. `run` makes the call to test in its own + process, with a limit on its memory and on how long it can take, so that a client which crashes or hangs on a bad response does + not take the rest of the tests down with it. + + `MoneroDaemonRpc` and `MoneroWalletRpc` need different setup: use `MaliciousDaemonServer` and `MaliciousWalletRpcServer`. + + Use it as a context manager. + """ + + @override + def __enter__(self) -> Self: + # FakeRawRpcServer.__enter__ is typed to return a FakeRawRpcServer, which would hide the methods of this class and of its + # subclasses from a type checker + super().__enter__() + return self + + def set_json_rpc_response(self, result: object, status: int = 200) -> None: + """Set the result that every call to the json rpc endpoint (`/json_rpc`) gets, whatever its method: enough for a test that + has the client call one method. A call that goes to another path needs `set_response` (inherited) instead. + + :param object result: the `result` of the json rpc response. + :param int status: http status of the response. + """ + self.set_response("/json_rpc", {"jsonrpc": "2.0", "id": "0", "result": result}, status) + + def run(self, call: Callable[[str], None], timeout: float = 5.0, memory_limit_mb: int = 300) -> MaliciousCallResult: + """Run `call(self.uri)` in its own process, and report what happened to it. + + :param Callable[[str], None] call: a function at module level (`multiprocessing` has to pickle it to start the process with + it, so a lambda, a closure or a local function do not work): makes one client of the server and does one call with it. + :param float timeout: seconds to wait for the call before killing its process and reporting it as timed out. + :param int memory_limit_mb: limit on the address space of the process that runs the call, in MB; not enforced on Windows. + :returns MaliciousCallResult: what happened. + """ + outcome: "multiprocessing.Queue[tuple[Verdict, Optional[str]]]" = _CONTEXT.Queue() + process: BaseProcess = _CONTEXT.Process(target=_run_call, args=(call, self.uri, memory_limit_mb, outcome)) + process.start() + process.join(timeout) + + if process.is_alive(): + process.terminate() + process.join(2) + if process.is_alive(): + process.kill() + process.join() + return MaliciousCallResult(Verdict.TIMED_OUT, None) + + try: + verdict, detail = outcome.get_nowait() + except queue.Empty: + # the process ended before it could report an outcome: a signal (a negative exit code, where the platform has one) or + # a call to os._exit() + return MaliciousCallResult(Verdict.CRASHED, f"exit code {process.exitcode}") + + return MaliciousCallResult(verdict, detail) + + +class MaliciousDaemonServer(MaliciousRpcServer): + """A malicious or broken daemon rpc server: for tests that `MoneroDaemonRpc` raises `monero.MoneroError` against inputs that it + should not trust, instead of crashing or hanging. + + Use it as a context manager. + """ + + +class MaliciousWalletRpcServer(MaliciousRpcServer): + """A malicious or broken wallet rpc server: for tests that `MoneroWalletRpc` raises `monero.MoneroError` against inputs that it + should not trust, instead of crashing or hanging. + + Use it as a context manager. + """ From 3e0960463c5d5a5bd01f8a0c49d405e049616ef3 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Tue, 1 Dec 2026 23:11:49 +0100 Subject: [PATCH 09/11] tests: explain why the rpc public key tests fail --- tests/wallet/test_keys_and_addresses.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/wallet/test_keys_and_addresses.py b/tests/wallet/test_keys_and_addresses.py index 1904aea1..1e1b08a5 100644 --- a/tests/wallet/test_keys_and_addresses.py +++ b/tests/wallet/test_keys_and_addresses.py @@ -288,6 +288,13 @@ class TestMoneroWalletFullKeysAndAddresses(FullWalletSupport, BaseTestMoneroWall """Full wallet keys and addresses integration tests.""" +_NO_PUBLIC_KEY_QUERY: str = ( + "TODO monero-cpp: the query_key method of monero-wallet-rpc only knows the mnemonic, view_key and spend_key key types, and answers " + "'key_type ... not found' for public_view_key and public_spend_key, which monero-cpp asks for. " + "It could derive them from the primary address" +) + + @pytest.mark.integration class TestMoneroWalletRpcKeysAndAddresses(RpcWalletSupport, BaseTestMoneroWalletKeysAndAddresses): """Rpc wallet keys and addresses integration tests.""" @@ -306,12 +313,12 @@ def test_get_subaddress_address_out_of_range(self, wallet: MoneroWallet) -> None def test_get_seed_language(self, wallet: MoneroWallet) -> None: return super().test_get_seed_language(wallet) - @pytest.mark.xfail(reason="TODO monero-project") + @pytest.mark.xfail(reason=_NO_PUBLIC_KEY_QUERY) @override def test_get_public_view_key(self, wallet: MoneroWallet) -> None: return super().test_get_public_view_key(wallet) - @pytest.mark.xfail(reason="TODO monero-project") + @pytest.mark.xfail(reason=_NO_PUBLIC_KEY_QUERY) @override def test_get_public_spend_key(self, wallet: MoneroWallet) -> None: return super().test_get_public_spend_key(wallet) From c4cf980b22e1b2fcc2919496e7b37c233b646959 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Tue, 1 Dec 2026 23:11:49 +0100 Subject: [PATCH 10/11] tests: ignore a refused memory limit in the harness --- tests/common/test_malicious_server.py | 25 +++++++++++++++++++++++++ tests/utils/malicious_server.py | 25 ++++++++++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/common/test_malicious_server.py b/tests/common/test_malicious_server.py index 570fe7cc..35fecdb7 100644 --- a/tests/common/test_malicious_server.py +++ b/tests/common/test_malicious_server.py @@ -2,12 +2,14 @@ import logging import os +import sys import time import pytest from monero import MoneroDaemonRpc, MoneroWalletRpc from utils import BaseTestClass, MaliciousDaemonServer, MaliciousWalletRpcServer, Verdict +from utils.malicious_server import limit_memory logger: logging.Logger = logging.getLogger("TestMaliciousServer") @@ -27,6 +29,11 @@ def _exit_without_reporting(uri: str) -> None: os._exit(1) +def _allocate_500_mb(uri: str) -> None: + """Does not call any client: asks for more memory than the limit that the tests give to `run`.""" + bytearray(500 * 1024 * 1024) + + @pytest.mark.unit class TestMaliciousServer(BaseTestClass): """Unit tests of the MaliciousRpcServer harness itself: whether it correctly tells apart a call that raises MoneroError, one @@ -69,3 +76,21 @@ def test_process_that_exits_without_reporting_is_a_crash(self) -> None: with MaliciousDaemonServer() as server: result = server.run(_exit_without_reporting) assert result.verdict is Verdict.CRASHED, result.detail + + # A call that asks for more memory than its limit fails, instead of taking the memory of the machine + @pytest.mark.skipif(sys.platform != "linux", reason="the limit on the address space is enforced on Linux") + def test_memory_limit_is_enforced(self) -> None: + with MaliciousDaemonServer() as server: + result = server.run(_allocate_500_mb, memory_limit_mb=300) + assert result.verdict is Verdict.OTHER_EXCEPTION, result.detail + assert result.detail is not None and result.detail.startswith("MemoryError"), result.detail + + # A platform that refuses the limit (macOS may) does not stop the call: it runs without it, bound by the timeout + @pytest.mark.skipif(sys.platform == "win32", reason="the limit is not set on Windows") + @pytest.mark.parametrize("error", [ValueError("current limit exceeds maximum limit"), OSError("operation not permitted")]) + def test_refused_memory_limit_is_ignored(self, monkeypatch: pytest.MonkeyPatch, error: Exception) -> None: + def refuse(which: int, limits: tuple[int, int]) -> None: + raise error + + monkeypatch.setattr("utils.malicious_server.resource.setrlimit", refuse) + limit_memory(300) diff --git a/tests/utils/malicious_server.py b/tests/utils/malicious_server.py index 4310e846..6b913e7b 100644 --- a/tests/utils/malicious_server.py +++ b/tests/utils/malicious_server.py @@ -53,6 +53,21 @@ class MaliciousCallResult: `OK` and `TIMED_OUT`.""" +def limit_memory(memory_limit_mb: int) -> None: + """Limits the address space of this process, where the platform takes the limit. One that refuses it (macOS may) leaves the + process as it is, and the call that it runs is still bound by the timeout of `MaliciousRpcServer.run`. + + :param int memory_limit_mb: limit on the address space of this process, in MB. + """ + if sys.platform == "win32": + return + limit: int = memory_limit_mb * 1024 * 1024 + try: + resource.setrlimit(resource.RLIMIT_AS, (limit, limit)) + except (ValueError, OSError): + pass + + def _run_call( call: Callable[[str], None], uri: str, memory_limit_mb: int, outcome: "multiprocessing.Queue[tuple[Verdict, Optional[str]]]" ) -> None: @@ -61,12 +76,11 @@ def _run_call( :param Callable[[str], None] call: a function at module level, that makes one client of the server and does one call with it. :param str uri: uri of the malicious server, given to `call`. - :param int memory_limit_mb: limit on the address space of this process, in MB; not enforced on Windows. + :param int memory_limit_mb: limit on the address space of this process, in MB; not enforced on Windows, nor where the platform + refuses it. :param multiprocessing.Queue outcome: where the verdict and its detail are put. """ - if sys.platform != "win32": - limit: int = memory_limit_mb * 1024 * 1024 - resource.setrlimit(resource.RLIMIT_AS, (limit, limit)) + limit_memory(memory_limit_mb) # imported here: the parent process, which only starts this one, does not need the bindings from monero import MoneroError @@ -112,7 +126,8 @@ def run(self, call: Callable[[str], None], timeout: float = 5.0, memory_limit_mb :param Callable[[str], None] call: a function at module level (`multiprocessing` has to pickle it to start the process with it, so a lambda, a closure or a local function do not work): makes one client of the server and does one call with it. :param float timeout: seconds to wait for the call before killing its process and reporting it as timed out. - :param int memory_limit_mb: limit on the address space of the process that runs the call, in MB; not enforced on Windows. + :param int memory_limit_mb: limit on the address space of the process that runs the call, in MB; not enforced on Windows, + nor where the platform refuses it. :returns MaliciousCallResult: what happened. """ outcome: "multiprocessing.Queue[tuple[Verdict, Optional[str]]]" = _CONTEXT.Queue() From 247e893d8ee1bf580b1aa537b5067e6e319244bc Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Tue, 1 Dec 2026 23:11:49 +0100 Subject: [PATCH 11/11] tests: construct more objects from keywords --- tests/common/test_block_generation.py | 8 +- tests/utils/test_utils.py | 38 +++----- tests/utils/to_multiple_tx_sender.py | 8 +- .../view_only_and_offline_wallet_tester.py | 5 +- tests/utils/wallet_notifications_tester.py | 14 ++- tests/utils/wallet_sweeper.py | 16 ++-- tests/utils/wallet_txs_utils.py | 7 +- tests/utils/wallet_utils.py | 8 +- tests/wallet/test_creation.py | 86 ++++++++----------- tests/wallet/test_equality.py | 5 +- tests/wallet/test_full_offline.py | 14 ++- tests/wallet/test_listeners.py | 8 +- tests/wallet/test_multisig.py | 26 ++---- tests/wallet/test_outputs.py | 6 +- tests/wallet/test_pool.py | 31 +++---- tests/wallet/test_proofs.py | 3 +- tests/wallet/test_send.py | 23 ++--- tests/wallet/test_support.py | 7 +- tests/wallet/test_sweep.py | 7 +- tests/wallet/test_sync.py | 20 ++--- tests/wallet/test_transfers.py | 13 ++- tests/wallet/test_update_locked.py | 38 +++----- 22 files changed, 154 insertions(+), 237 deletions(-) diff --git a/tests/common/test_block_generation.py b/tests/common/test_block_generation.py index cf3f86e4..a8ff252e 100644 --- a/tests/common/test_block_generation.py +++ b/tests/common/test_block_generation.py @@ -20,10 +20,10 @@ def __init__(self, difficulty: int, is_regtest: bool | None = True, fails: bool def get_info(self) -> MoneroDaemonInfo: if self._fails: raise RuntimeError("no node") - info: MoneroDaemonInfo = MoneroDaemonInfo() - info.difficulty_low = self._difficulty & ((1 << 64) - 1) - info.difficulty_high = self._difficulty >> 64 - info.is_regtest = self._is_regtest + info: MoneroDaemonInfo = MoneroDaemonInfo( + difficulty_low=self._difficulty & ((1 << 64) - 1), difficulty_high=self._difficulty >> 64, + is_regtest=self._is_regtest + ) return info diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index c63c1175..9026d1fa 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -377,14 +377,10 @@ def get_wallet_full_config(cls, daemon_connection: MoneroRpcConnection) -> Moner :param MoneroRpcConnection daemon_connection: rpc daemon connection. :returns MoneroWalletConfig: full wallet test configuration. """ - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = cls.WALLET_FULL_PATH - config.password = cls.WALLET_PASSWORD - config.network_type = cls.NETWORK_TYPE - config.seed = cls.SEED - config.server = daemon_connection - config.restore_height = cls.FIRST_RECEIVE_HEIGHT - config.regtest = cls.REGTEST + config: MoneroWalletConfig = MoneroWalletConfig( + path=cls.WALLET_FULL_PATH, password=cls.WALLET_PASSWORD, network_type=cls.NETWORK_TYPE, seed=cls.SEED, + server=daemon_connection, restore_height=cls.FIRST_RECEIVE_HEIGHT, regtest=cls.REGTEST + ) return config @@ -443,10 +439,7 @@ def get_wallet_full_offline(cls) -> MoneroWalletFull: :returns MoneroWalletFull: disconnected full test wallet. """ if cls._WALLET_FULL_OFFLINE is None or cls._WALLET_FULL_OFFLINE.is_closed(): - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = "" - config.password = cls.WALLET_PASSWORD - config.network_type = cls.NETWORK_TYPE + config: MoneroWalletConfig = MoneroWalletConfig(path="", password=cls.WALLET_PASSWORD, network_type=cls.NETWORK_TYPE) cls._WALLET_FULL_OFFLINE = MoneroWalletFull.create_wallet(config) return cls._WALLET_FULL_OFFLINE @@ -533,11 +526,10 @@ def get_wallet_rpc(cls) -> MoneroWalletRpc: # -1 returned when wallet does not exist or fails to open e.g. it's already open by another application if e.code == -1: # create wallet - config = MoneroWalletConfig() - config.path = cls.WALLET_NAME - config.password = cls.WALLET_PASSWORD - config.seed = cls.SEED - config.restore_height = cls.FIRST_RECEIVE_HEIGHT + config = MoneroWalletConfig( + path=cls.WALLET_NAME, password=cls.WALLET_PASSWORD, seed=cls.SEED, + restore_height=cls.FIRST_RECEIVE_HEIGHT + ) cls._WALLET_RPC.create_wallet(config) else: raise @@ -627,14 +619,10 @@ def create_wallet_ground_truth( # create ground truth wallet daemon_connection: MoneroRpcConnection = MoneroRpcConnection(cls.DAEMON_RPC_URI, cls.DAEMON_RPC_USERNAME, cls.DAEMON_RPC_PASSWORD) path: str = cls.TEST_WALLETS_DIR + "/gt_wallet_" + GenUtils.current_timestamp_str() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path - config.password = cls.WALLET_PASSWORD - config.network_type = network_type - config.seed = seed - config.server = daemon_connection - config.restore_height = restore_height - config.regtest = cls.REGTEST + config: MoneroWalletConfig = MoneroWalletConfig( + path=path, password=cls.WALLET_PASSWORD, network_type=network_type, seed=seed, server=daemon_connection, + restore_height=restore_height, regtest=cls.REGTEST + ) if start_height is None: start_height = 0 if restore_height is None else restore_height diff --git a/tests/utils/to_multiple_tx_sender.py b/tests/utils/to_multiple_tx_sender.py index 6ace6f68..47d27b22 100644 --- a/tests/utils/to_multiple_tx_sender.py +++ b/tests/utils/to_multiple_tx_sender.py @@ -150,11 +150,9 @@ def _build_tx_config(self, src_account: MoneroAccount, send_amount_per_subaddres :param list[str] destination_addresses: addresses to send funds to. :returns MoneroTxConfig: transaction configuration. """ - config: MoneroTxConfig = MoneroTxConfig() - config.account_index = src_account.index - config.relay = True - config.can_split = self._can_split - config.priority = MoneroTxPriority.NORMAL + config: MoneroTxConfig = MoneroTxConfig( + account_index=src_account.index, relay=True, can_split=self._can_split, priority=MoneroTxPriority.NORMAL + ) subtract_fee_from: list[int] = [] for i, address in enumerate(destination_addresses): diff --git a/tests/utils/view_only_and_offline_wallet_tester.py b/tests/utils/view_only_and_offline_wallet_tester.py index c9b09558..cea009bb 100644 --- a/tests/utils/view_only_and_offline_wallet_tester.py +++ b/tests/utils/view_only_and_offline_wallet_tester.py @@ -128,10 +128,7 @@ def test(self) -> None: assert self._wallet.get_balance() == self._view_only_wallet.get_balance() # create unsigned tx using view-only wallet - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = 0 - tx_config.address = primary_address - tx_config.amount = TxWalletUtils.MAX_FEE * 3 + tx_config: MoneroTxConfig = MoneroTxConfig(account_index=0, address=primary_address, amount=TxWalletUtils.MAX_FEE * 3) unsigned_tx: MoneroTxWallet = self._view_only_wallet.create_tx(tx_config) assert unsigned_tx.tx_set is not None assert unsigned_tx.tx_set.unsigned_tx_hex is not None diff --git a/tests/utils/wallet_notifications_tester.py b/tests/utils/wallet_notifications_tester.py index 393b7fb0..e147e332 100644 --- a/tests/utils/wallet_notifications_tester.py +++ b/tests/utils/wallet_notifications_tester.py @@ -177,10 +177,9 @@ def _run(self) -> None: if self.sweep_output: ctx.is_sweep_response = True ctx.is_sweep_output_response = True - output_query: MoneroOutputQuery = MoneroOutputQuery() - output_query.is_spent = False - output_query.account_index = 0 - output_query.min_amount = TxWalletUtils.MAX_FEE * 5 + output_query: MoneroOutputQuery = MoneroOutputQuery( + is_spent=False, account_index=0, min_amount=TxWalletUtils.MAX_FEE * 5 + ) unlocked_query: MoneroTxQuery = MoneroTxQuery(is_locked=False) output_query.set_tx_query(unlocked_query, True) outputs: list[MoneroOutputWallet] = sender.get_outputs(output_query) @@ -530,10 +529,9 @@ def issues_to_str(issues: list[str]) -> str: @staticmethod def _output(amount: int, account_index: int, subaddress_index: int) -> MoneroOutputWallet: - output: MoneroOutputWallet = MoneroOutputWallet() - output.amount = amount - output.account_index = account_index - output.subaddress_index = subaddress_index + output: MoneroOutputWallet = MoneroOutputWallet( + amount=amount, account_index=account_index, subaddress_index=subaddress_index + ) return output @staticmethod diff --git a/tests/utils/wallet_sweeper.py b/tests/utils/wallet_sweeper.py index 666ed832..2745ac29 100644 --- a/tests/utils/wallet_sweeper.py +++ b/tests/utils/wallet_sweeper.py @@ -71,10 +71,9 @@ def sweep(self) -> None: # sweep funds destination: str = self._wallet.get_primary_address() - config: MoneroTxConfig = MoneroTxConfig() - config.address = destination - config.sweep_each_subaddress = self._sweep_each_subaddress - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + address=destination, sweep_each_subaddress=self._sweep_each_subaddress, relay=True + ) copy: MoneroTxConfig = config.copy() txs: list[MoneroTxWallet] = self._wallet.sweep_unlocked(config) # config is unchanged @@ -89,11 +88,10 @@ def sweep(self) -> None: assert len(txs) > 0 for tx in txs: assert tx.outgoing_transfer is not None - config = MoneroTxConfig() - config.address = destination - config.account_index = tx.outgoing_transfer.account_index - config.sweep_each_subaddress = self._sweep_each_subaddress - config.relay = True + config = MoneroTxConfig( + address=destination, account_index=tx.outgoing_transfer.account_index, + sweep_each_subaddress=self._sweep_each_subaddress, relay=True + ) ctx: TxContext = TxContext() ctx.wallet = self._wallet diff --git a/tests/utils/wallet_txs_utils.py b/tests/utils/wallet_txs_utils.py index bc3cbf6a..b570bf89 100644 --- a/tests/utils/wallet_txs_utils.py +++ b/tests/utils/wallet_txs_utils.py @@ -95,10 +95,9 @@ def get_unrelayed_tx(cls, wallet: MoneroWallet, account_idx: int) -> MoneroTxWal """ # TODO monero-project assert account_idx > 0, "Txs sent from/to same account are not properly synced from the pool" - config: MoneroTxConfig = MoneroTxConfig() - config.account_index = account_idx - config.address = wallet.get_primary_address() - config.amount = TxWalletUtils.MAX_FEE + config: MoneroTxConfig = MoneroTxConfig( + account_index=account_idx, address=wallet.get_primary_address(), amount=TxWalletUtils.MAX_FEE + ) tx: MoneroTxWallet = wallet.create_tx(config) assert (tx.full_hex is None or tx.full_hex == "") is False diff --git a/tests/utils/wallet_utils.py b/tests/utils/wallet_utils.py index f1de9b4a..835be5b1 100644 --- a/tests/utils/wallet_utils.py +++ b/tests/utils/wallet_utils.py @@ -237,11 +237,9 @@ def build_payment_uri_config(cls, address: str) -> MoneroTxConfig: :param str address: destination address for the tx configuration. :returns MoneroTxConfig: sample tx configuration for payment URI tests. """ - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.address = address - tx_config.amount = 250000000000 - tx_config.recipient_name = "John Doe" - tx_config.note = "My transfer to wallet" + tx_config: MoneroTxConfig = MoneroTxConfig( + address=address, amount=250000000000, recipient_name="John Doe", note="My transfer to wallet" + ) return tx_config diff --git a/tests/wallet/test_creation.py b/tests/wallet/test_creation.py index 042ab395..c012e002 100644 --- a/tests/wallet/test_creation.py +++ b/tests/wallet/test_creation.py @@ -84,9 +84,7 @@ def test_create_wallet_from_seed(self, wallet: MoneroWallet, test_config: BaseTe private_spend_key: str = wallet.get_private_spend_key() # recreate test wallet from seed - config: MoneroWalletConfig = MoneroWalletConfig() - config.seed = TestUtils.SEED - config.restore_height = TestUtils.FIRST_RECEIVE_HEIGHT + config: MoneroWalletConfig = MoneroWalletConfig(seed=TestUtils.SEED, restore_height=TestUtils.FIRST_RECEIVE_HEIGHT) w: MoneroWallet = self._create_wallet(config) path: str = w.get_path() @@ -116,10 +114,9 @@ def test_create_wallet_from_seed(self, wallet: MoneroWallet, test_config: BaseTe @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") def test_create_wallet_from_seed_with_offset(self) -> None: # create test wallet with offset - config: MoneroWalletConfig = MoneroWalletConfig() - config.seed = TestUtils.SEED - config.restore_height = TestUtils.FIRST_RECEIVE_HEIGHT - config.seed_offset = "my secret offset!" + config: MoneroWalletConfig = MoneroWalletConfig( + seed=TestUtils.SEED, restore_height=TestUtils.FIRST_RECEIVE_HEIGHT, seed_offset="my secret offset!" + ) wallet: MoneroWallet = self._create_wallet(config) try: MoneroUtils.validate_mnemonic(wallet.get_seed()) @@ -141,11 +138,10 @@ def test_create_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWa private_spend_key: str = wallet.get_private_spend_key() # recreate test wallet from keys - config: MoneroWalletConfig = MoneroWalletConfig() - config.primary_address = primary_address - config.private_view_key = private_view_key - config.private_spend_key = private_spend_key - config.restore_height = daemon.get_height() + config: MoneroWalletConfig = MoneroWalletConfig( + primary_address=primary_address, private_view_key=private_view_key, private_spend_key=private_spend_key, + restore_height=daemon.get_height() + ) w: MoneroWallet = self._create_wallet(config) path: str = w.get_path() @@ -324,18 +320,17 @@ def test_save_and_close(self) -> None: @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False and TestUtils.TEST_RELAYS is False, reason="TEST_NON_RELAYS and TEST_RELAYS disabled") def test_view_only_and_offline_wallets(self, wallet: MoneroWallet) -> None: # create view-only and offline wallets - config: MoneroWalletConfig = MoneroWalletConfig() - config.primary_address = wallet.get_primary_address() - config.private_view_key = wallet.get_private_view_key() - config.restore_height = TestUtils.FIRST_RECEIVE_HEIGHT + config: MoneroWalletConfig = MoneroWalletConfig( + primary_address=wallet.get_primary_address(), private_view_key=wallet.get_private_view_key(), + restore_height=TestUtils.FIRST_RECEIVE_HEIGHT + ) view_only_wallet: MoneroWallet = self._create_wallet(config) - config = MoneroWalletConfig() - config.primary_address = wallet.get_primary_address() - config.private_view_key = wallet.get_private_view_key() - config.private_spend_key = wallet.get_private_spend_key() - config.server = MoneroRpcConnection(TestUtils.OFFLINE_SERVER_URI) - config.restore_height = 0 + config = MoneroWalletConfig( + primary_address=wallet.get_primary_address(), private_view_key=wallet.get_private_view_key(), + private_spend_key=wallet.get_private_spend_key(), server=MoneroRpcConnection(TestUtils.OFFLINE_SERVER_URI), + restore_height=0 + ) offline_wallet: MoneroWallet = self._create_wallet(config) assert offline_wallet.is_connected_to_daemon() is False view_only_wallet.sync() @@ -377,10 +372,9 @@ class TestMoneroWalletFullCreation(FullWalletSupport, BaseTestMoneroWalletCreati def test_create_wallet_random_full(self, daemon: MoneroDaemonRpc) -> None: # create random wallet with defaults path: str = Utils.get_random_wallet_path() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path - config.network_type = MoneroNetworkType.MAINNET - config.server = MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + config: MoneroWalletConfig = MoneroWalletConfig( + path=path, network_type=MoneroNetworkType.MAINNET, server=MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + ) wallet: MoneroWalletFull = self._create_wallet(config) MoneroUtils.validate_mnemonic(wallet.get_seed()) MoneroUtils.validate_address(wallet.get_primary_address(), MoneroNetworkType.MAINNET) @@ -434,10 +428,9 @@ def test_create_wallet_random_full(self, daemon: MoneroDaemonRpc) -> None: def test_create_wallet_from_seed_full(self, daemon: MoneroDaemonRpc) -> None: # create unconnected wallet with seed path: str = Utils.get_random_wallet_path() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path - config.seed = Utils.SEED - config.server = MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + config: MoneroWalletConfig = MoneroWalletConfig( + path=path, seed=Utils.SEED, server=MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + ) wallet: MoneroWalletFull = self._create_wallet(config) assert wallet.get_seed() == Utils.SEED assert wallet.get_primary_address() == Utils.ADDRESS @@ -475,11 +468,9 @@ def test_create_wallet_from_seed_full(self, daemon: MoneroDaemonRpc) -> None: # create wallet with seed, no connection, and restore height restore_height: int = 10000 path = Utils.get_random_wallet_path() - config = MoneroWalletConfig() - config.path = path - config.seed = Utils.SEED - config.restore_height = restore_height - config.server = MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + config = MoneroWalletConfig( + path=path, seed=Utils.SEED, restore_height=restore_height, server=MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + ) wallet = self._create_wallet(config) assert wallet.get_seed() == Utils.SEED assert wallet.get_primary_address() == Utils.ADDRESS @@ -668,10 +659,7 @@ def test_create_wallet_random_rpc(self) -> None: def test_create_wallet_from_seed_rpc(self, daemon: MoneroDaemonRpc) -> None: # create wallet with seed and defaults path: str = StringUtils.get_random_string() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path - config.seed = Utils.SEED - config.restore_height = Utils.FIRST_RECEIVE_HEIGHT + config: MoneroWalletConfig = MoneroWalletConfig(path=path, seed=Utils.SEED, restore_height=Utils.FIRST_RECEIVE_HEIGHT) wallet: MoneroWalletRpc = self._create_wallet(config) # validate wallet @@ -908,10 +896,9 @@ def test_create_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWa private_spend_key: str = wallet.get_private_spend_key() # recreate test wallet from keys - config: MoneroWalletConfig = MoneroWalletConfig() - config.primary_address = primary_address - config.private_view_key = private_view_key - config.private_spend_key = private_spend_key + config: MoneroWalletConfig = MoneroWalletConfig( + primary_address=primary_address, private_view_key=private_view_key, private_spend_key=private_spend_key + ) w: MoneroWallet = self._create_wallet(config) WalletUtils.test_wallet_keys(primary_address, private_view_key, private_spend_key, w) assert w.get_network_type() == Utils.NETWORK_TYPE @@ -954,9 +941,9 @@ def test_create_wallet_from_keys_invalid_spend_key(self) -> None: """ create_wallet_from_keys() must fail to parse a malformed private spend key. """ - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE - config.private_spend_key = "not-a-valid-hex-secret-key" + config: MoneroWalletConfig = MoneroWalletConfig( + network_type=Utils.NETWORK_TYPE, private_spend_key="not-a-valid-hex-secret-key" + ) with pytest.raises(RuntimeError, match="failed to parse secret spend key"): MoneroWalletKeys.create_wallet_from_keys(config) @@ -965,10 +952,9 @@ def test_create_wallet_from_keys_invalid_view_key(self) -> None: """ create_wallet_from_keys() must fail to parse a malformed private view key. """ - config: MoneroWalletConfig = MoneroWalletConfig() - config.network_type = Utils.NETWORK_TYPE - config.primary_address = Utils.ADDRESS - config.private_view_key = "not-a-valid-hex-secret-key" + config: MoneroWalletConfig = MoneroWalletConfig( + network_type=Utils.NETWORK_TYPE, primary_address=Utils.ADDRESS, private_view_key="not-a-valid-hex-secret-key" + ) with pytest.raises(RuntimeError, match="failed to parse secret view key"): MoneroWalletKeys.create_wallet_from_keys(config) diff --git a/tests/wallet/test_equality.py b/tests/wallet/test_equality.py index 9b14d485..4f9a411a 100644 --- a/tests/wallet/test_equality.py +++ b/tests/wallet/test_equality.py @@ -106,10 +106,7 @@ def test_accounting(self, wallet: MoneroWallet) -> None: # subaddress balances are sum of their unspent outputs for subaddress in account.subaddresses: subaddress_sum: int = 0 - output_query = MoneroOutputQuery() - output_query.account_index = account.index - output_query.subaddress_index = subaddress.index - output_query.is_spent = False + output_query = MoneroOutputQuery(account_index=account.index, subaddress_index=subaddress.index, is_spent=False) subaddress_outputs: list[MoneroOutputWallet] = wallet.get_outputs(output_query) for output in subaddress_outputs: assert output.amount is not None diff --git a/tests/wallet/test_full_offline.py b/tests/wallet/test_full_offline.py index ea858f0b..f74c0461 100644 --- a/tests/wallet/test_full_offline.py +++ b/tests/wallet/test_full_offline.py @@ -55,10 +55,9 @@ def test_import_key_images_signature_not_defined(self, wallet: MoneroWalletFull) # Can be moved def test_move_to(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = "" - config.password = Utils.WALLET_PASSWORD - config.network_type = MoneroNetworkType.MAINNET + config: MoneroWalletConfig = MoneroWalletConfig( + path="", password=Utils.WALLET_PASSWORD, network_type=MoneroNetworkType.MAINNET + ) wallet: MoneroWalletFull = MoneroWalletFull.create_wallet(config) try: seed: str = wallet.get_seed() @@ -95,10 +94,9 @@ def test_move_to(self) -> None: # Can export and import wallet files def test_export_and_import_wallet_files(self) -> None: - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = "" - config.password = Utils.WALLET_PASSWORD - config.network_type = MoneroNetworkType.MAINNET + config: MoneroWalletConfig = MoneroWalletConfig( + path="", password=Utils.WALLET_PASSWORD, network_type=MoneroNetworkType.MAINNET + ) wallet: MoneroWalletFull = MoneroWalletFull.create_wallet(config) from_keys: MoneroWalletFull | None = None from_both: MoneroWalletFull | None = None diff --git a/tests/wallet/test_listeners.py b/tests/wallet/test_listeners.py index 4ccf046b..c9d427c1 100644 --- a/tests/wallet/test_listeners.py +++ b/tests/wallet/test_listeners.py @@ -59,11 +59,9 @@ def test_create_and_receive(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) TestUtils.WALLET_TX_TRACKER.wait_for_unlocked_balance(wallet, 0, None, TxWalletUtils.MAX_FEE) # send funds to the receiver - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = 0 - tx_config.address = receiver.get_primary_address() - tx_config.amount = TxWalletUtils.MAX_FEE - tx_config.relay = True + tx_config: MoneroTxConfig = MoneroTxConfig( + account_index=0, address=receiver.get_primary_address(), amount=TxWalletUtils.MAX_FEE, relay=True + ) sent_tx: MoneroTxWallet = wallet.create_tx(tx_config) assert sent_tx.hash is not None diff --git a/tests/wallet/test_multisig.py b/tests/wallet/test_multisig.py index 322d57e5..4f5eba64 100644 --- a/tests/wallet/test_multisig.py +++ b/tests/wallet/test_multisig.py @@ -90,11 +90,10 @@ def _test_multisig_participants( # create txs to send funds from a subaddress in the multisig wallet logger.info("Sending") - config: MoneroTxConfig = MoneroTxConfig() - config.address = wallet.get_address(account_idx, 0) - config.amount = TxWalletUtils.MAX_FEE - config.account_index = account_idx - config.subaddress_indices = [0] + config: MoneroTxConfig = MoneroTxConfig( + address=wallet.get_address(account_idx, 0), amount=TxWalletUtils.MAX_FEE, account_index=account_idx, + subaddress_indices=[0] + ) txs: list[MoneroTxWallet] = participant.create_txs(config) assert len(txs) > 0 tx_set: MoneroTxSet | None = txs[0].tx_set @@ -124,10 +123,7 @@ def _test_multisig_participants( assert len(outputs) > 0 assert outputs[0].is_spent is False assert outputs[0].key_image is not None - sweep_config: MoneroTxConfig = MoneroTxConfig() - sweep_config.address = return_address - sweep_config.key_image = outputs[0].key_image.hex - sweep_config.relay = True + sweep_config: MoneroTxConfig = MoneroTxConfig(address=return_address, key_image=outputs[0].key_image.hex, relay=True) tx_set = participant.sweep_output(sweep_config).tx_set assert tx_set is not None self._test_multisig_tx_set(tx_set) @@ -262,10 +258,7 @@ def _init_multisig_wallets( # restore participant from multisig seed self._close_wallet(participant) - restore_config: MoneroWalletConfig = MoneroWalletConfig() - restore_config.restore_height = daemon.get_height() - restore_config.seed = seed - restore_config.is_multisig = True + restore_config: MoneroWalletConfig = MoneroWalletConfig(restore_height=daemon.get_height(), seed=seed, is_multisig=True) participant = self._create_wallet(restore_config) participants[0] = participant MoneroUtils.validate_address(participant.get_primary_address(), Utils.NETWORK_TYPE) @@ -354,10 +347,9 @@ def _init_multisig_wallets( # attempt creating and relaying transaction without synchronizing with participants return_address: str = wallet.get_primary_address() # funds will be returned to this address from the multisig wallet - unsynced_config: MoneroTxConfig = MoneroTxConfig() - unsynced_config.account_index = account_idx - unsynced_config.address = return_address - unsynced_config.amount = TxWalletUtils.MAX_FEE * 3 + unsynced_config: MoneroTxConfig = MoneroTxConfig( + account_index=account_idx, address=return_address, amount=TxWalletUtils.MAX_FEE * 3 + ) with pytest.raises(Exception) as exc_info: participant.create_txs(unsynced_config) assert str(exc_info.value) == "No transaction created" diff --git a/tests/wallet/test_outputs.py b/tests/wallet/test_outputs.py index 2ec482ee..ac0957aa 100644 --- a/tests/wallet/test_outputs.py +++ b/tests/wallet/test_outputs.py @@ -57,9 +57,9 @@ def test_get_outputs(self, wallet: MoneroWallet) -> None: # get outputs by subaddress index subaddress_outputs: list[MoneroOutputWallet] = [] for subaddress in account.subaddresses: - subaddr_query: MoneroOutputQuery = MoneroOutputQuery() - subaddr_query.account_index = account.index - subaddr_query.subaddress_index = subaddress.index + subaddr_query: MoneroOutputQuery = MoneroOutputQuery( + account_index=account.index, subaddress_index=subaddress.index + ) outputs: list[MoneroOutputWallet] = OutputUtils.get_and_test_outputs(wallet, subaddr_query, subaddress.is_used) for output in outputs: assert subaddress.account_index == output.account_index diff --git a/tests/wallet/test_pool.py b/tests/wallet/test_pool.py index 4c132ec1..090be69a 100644 --- a/tests/wallet/test_pool.py +++ b/tests/wallet/test_pool.py @@ -20,11 +20,9 @@ class BaseTestMoneroWalletPool(BaseTestMoneroWallet): # TODO this test fails because wallet does not recognize pool tx sent from/to same account @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled") def test_sync_with_pool_same_accounts(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: - config: MoneroTxConfig = MoneroTxConfig() - config.account_index = 0 - config.address = wallet.get_primary_address() - config.amount = TxWalletUtils.MAX_FEE * 5 - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + account_index=0, address=wallet.get_primary_address(), amount=TxWalletUtils.MAX_FEE * 5, relay=True + ) WalletSendUtils.test_sync_with_pool_submit(daemon, wallet, config) # Can sync with txs submitted and flushed from the pool @@ -33,22 +31,18 @@ def test_sync_with_pool_same_accounts(self, daemon: MoneroDaemonRpc, wallet: Mon @pytest.mark.skipif(TestUtils.CI, reason="CI is too slow to catchup failed txs (see wallet2::process_unconfirmed_transfer)") def test_sync_with_pool_submit_and_flush(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: logger.warning("This test takes at least 500 seconds (~8 minutes) to catchup failed txs (see wallet2::process_unconfirmed_transfer).") - config: MoneroTxConfig = MoneroTxConfig() - config.account_index = 2 - config.address = wallet.get_primary_address() - config.amount = TxWalletUtils.MAX_FEE * 5 - config.relay = False + config: MoneroTxConfig = MoneroTxConfig( + account_index=2, address=wallet.get_primary_address(), amount=TxWalletUtils.MAX_FEE * 5, relay=False + ) WalletSendUtils.test_sync_with_pool_submit(daemon, wallet, config) # Can sync with txs submitted and relayed from the pool @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled") @pytest.mark.skipif(TestUtils.LITE_MODE, reason="LITE_MODE enabled") def test_sync_with_pool_submit_and_relay(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: - config: MoneroTxConfig = MoneroTxConfig() - config.account_index = 2 - config.address = wallet.get_primary_address() - config.amount = TxWalletUtils.MAX_FEE * 5 - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + account_index=2, address=wallet.get_primary_address(), amount=TxWalletUtils.MAX_FEE * 5, relay=True + ) WalletSendUtils.test_sync_with_pool_submit(daemon, wallet, config) # can sync with txs relayed to the pool @@ -63,10 +57,9 @@ def test_sync_with_pool_relay(self, daemon: MoneroDaemonRpc, wallet: MoneroWalle unlocked_balance_before: int = wallet.get_unlocked_balance() # create config - config: MoneroTxConfig = MoneroTxConfig() - config.account_index = 2 - config.address = wallet.get_primary_address() - config.amount = TxWalletUtils.MAX_FEE * 5 + config: MoneroTxConfig = MoneroTxConfig( + account_index=2, address=wallet.get_primary_address(), amount=TxWalletUtils.MAX_FEE * 5 + ) # create tx to relay tx: MoneroTxWallet = wallet.create_tx(config) diff --git a/tests/wallet/test_proofs.py b/tests/wallet/test_proofs.py index 569eda0e..9f88338f 100644 --- a/tests/wallet/test_proofs.py +++ b/tests/wallet/test_proofs.py @@ -37,8 +37,7 @@ def test_check_tx_key(self, wallet: MoneroWallet) -> None: # get random txs that are confirmed and have outgoing destinations txs: list[MoneroTxWallet] = [] try: - query: MoneroTxQuery = MoneroTxQuery() - query.is_confirmed = True + query: MoneroTxQuery = MoneroTxQuery(is_confirmed=True) query.transfer_query = MoneroTransferQuery() query.transfer_query.has_destinations = True txs = WalletTxsUtils.get_random_transactions(wallet, query, 1, WalletUtils.MAX_TX_PROOFS) diff --git a/tests/wallet/test_send.py b/tests/wallet/test_send.py index 3c5445fd..eb69615e 100644 --- a/tests/wallet/test_send.py +++ b/tests/wallet/test_send.py @@ -34,10 +34,7 @@ class BaseTestMoneroWalletSend(BaseTestMoneroWallet): @pytest.mark.flaky(reruns=5, reruns_delay=5, only_rerun=[]) def test_validate_inputs_sending_funds(self, wallet: MoneroWallet) -> None: # try sending with invalid address - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.address = "my invalid address" - tx_config.account_index = 0 - tx_config.amount = TxWalletUtils.MAX_FEE + tx_config: MoneroTxConfig = MoneroTxConfig(address="my invalid address", account_index=0, amount=TxWalletUtils.MAX_FEE) with pytest.raises(Exception) as exc_info: wallet.create_tx(tx_config) assert str(exc_info.value) == "Invalid destination address" @@ -69,11 +66,9 @@ def test_send_to_self(self, wallet: MoneroWallet) -> None: wallet.create_tx(tx_config) # send funds to self - tx_config = MoneroTxConfig() - tx_config.account_index = 0 - tx_config.address = wallet.get_integrated_address().integrated_address - tx_config.amount = amount - tx_config.relay = True + tx_config = MoneroTxConfig( + account_index=0, address=wallet.get_integrated_address().integrated_address, amount=amount, relay=True + ) tx: MoneroTxWallet = wallet.create_tx(tx_config) @@ -104,11 +99,11 @@ def test_send_to_external(self, wallet: MoneroWallet) -> None: unlocked_balance1: int = wallet.get_unlocked_balance() # send funds to recipient - tx_config: MoneroTxConfig = MoneroTxConfig() - tx_config.account_index = 0 - tx_config.address = wallet.get_integrated_address(recipient.get_primary_address(), "54491f3bb3572a37").integrated_address - tx_config.amount = amount - tx_config.relay = True + tx_config: MoneroTxConfig = MoneroTxConfig( + account_index=0, + address=wallet.get_integrated_address(recipient.get_primary_address(), "54491f3bb3572a37").integrated_address, + amount=amount, relay=True + ) tx: MoneroTxWallet = wallet.create_tx(tx_config) # test sender balances after diff --git a/tests/wallet/test_support.py b/tests/wallet/test_support.py index 3f86972b..cad6a57e 100644 --- a/tests/wallet/test_support.py +++ b/tests/wallet/test_support.py @@ -37,10 +37,9 @@ def support(cls) -> dict[str, dict[str, str]]: def wallets(cls) -> dict[str, MoneroWallet]: """A wallet of each type, of its own: the calls change and close them. None of them reaches the network: the full one has no daemon and the rpc one has no server, so their calls fail at once when they are implemented.""" - full_config: MoneroWalletConfig = MoneroWalletConfig() - full_config.path = "" - full_config.password = Utils.WALLET_PASSWORD - full_config.network_type = Utils.NETWORK_TYPE + full_config: MoneroWalletConfig = MoneroWalletConfig( + path="", password=Utils.WALLET_PASSWORD, network_type=Utils.NETWORK_TYPE + ) keys_config: MoneroWalletConfig = MoneroWalletConfig(network_type=Utils.NETWORK_TYPE) return { "full": MoneroWalletFull.create_wallet(full_config), diff --git a/tests/wallet/test_sweep.py b/tests/wallet/test_sweep.py index 36b816e6..f0b56575 100644 --- a/tests/wallet/test_sweep.py +++ b/tests/wallet/test_sweep.py @@ -264,10 +264,9 @@ def test_sweep_accounts(self, wallet: MoneroWallet) -> None: # sweep unlocked account unlocked_account: MoneroAccount = accounts_unlocked[i] assert unlocked_account.index is not None - config: MoneroTxConfig = MoneroTxConfig() - config.address = wallet.get_primary_address() - config.account_index = unlocked_account.index - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + address=wallet.get_primary_address(), account_index=unlocked_account.index, relay=True + ) txs: list[MoneroTxWallet] = wallet.sweep_unlocked(config) # test transactions diff --git a/tests/wallet/test_sync.py b/tests/wallet/test_sync.py index 9f09c243..7f905a65 100644 --- a/tests/wallet/test_sync.py +++ b/tests/wallet/test_sync.py @@ -225,12 +225,10 @@ def test_sync_seed_start_height_gt_restore_height(self, daemon: MoneroDaemonRpc, def test_sync_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWalletFull) -> None: # recreate test wallet from keys path: str = Utils.get_random_wallet_path() - config: MoneroWalletConfig = MoneroWalletConfig() - config.path = path - config.primary_address = wallet.get_primary_address() - config.private_view_key = wallet.get_private_view_key() - config.private_spend_key = wallet.get_private_spend_key() - config.restore_height = Utils.FIRST_RECEIVE_HEIGHT + config: MoneroWalletConfig = MoneroWalletConfig( + path=path, primary_address=wallet.get_primary_address(), private_view_key=wallet.get_private_view_key(), + private_spend_key=wallet.get_private_spend_key(), restore_height=Utils.FIRST_RECEIVE_HEIGHT + ) wallet_keys: MoneroWalletFull = self._create_wallet(config, False) # create ground truth wallet for comparison @@ -280,9 +278,9 @@ def test_sync_wallet_from_keys(self, daemon: MoneroDaemonRpc, wallet: MoneroWall @pytest.mark.skipif(Utils.LITE_MODE, reason="LITE_MODE enabled") def test_start_stop_syncing(self, daemon: MoneroDaemonRpc) -> None: # test unconnected wallet - config: MoneroWalletConfig = MoneroWalletConfig() - config.server = MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) - config.path = Utils.get_random_wallet_path() + config: MoneroWalletConfig = MoneroWalletConfig( + server=MoneroRpcConnection(Utils.OFFLINE_SERVER_URI), path=Utils.get_random_wallet_path() + ) wallet: MoneroWalletFull = self._create_wallet(config) try: assert len(wallet.get_seed()) > 0 @@ -293,9 +291,7 @@ def test_start_stop_syncing(self, daemon: MoneroDaemonRpc) -> None: wallet.close() # test connecting wallet - config = MoneroWalletConfig() - config.path = Utils.get_random_wallet_path() - config.server = MoneroRpcConnection(Utils.OFFLINE_SERVER_URI) + config = MoneroWalletConfig(path=Utils.get_random_wallet_path(), server=MoneroRpcConnection(Utils.OFFLINE_SERVER_URI)) wallet = self._create_wallet(config) try: assert len(wallet.get_seed()) > 0 diff --git a/tests/wallet/test_transfers.py b/tests/wallet/test_transfers.py index c5bd7f4c..c83e8b42 100644 --- a/tests/wallet/test_transfers.py +++ b/tests/wallet/test_transfers.py @@ -41,9 +41,9 @@ def test_get_transfers(self, wallet: MoneroWallet) -> None: # get transfers by subaddress index subaddress_transfers: list[MoneroTransfer] = [] for subaddress in account.subaddresses: - subaddress_query: MoneroTransferQuery = MoneroTransferQuery() - subaddress_query.account_index = subaddress.account_index - subaddress_query.subaddress_index = subaddress.index + subaddress_query: MoneroTransferQuery = MoneroTransferQuery( + account_index=subaddress.account_index, subaddress_index=subaddress.index + ) transfers: list[MoneroTransfer] = WalletTransfersUtils.get_and_test_transfers(wallet, subaddress_query, None, None) for transfer in transfers: @@ -236,10 +236,9 @@ def test_get_incoming_outgoing_transfers(self, wallet: MoneroWallet) -> None: subaddress_idx: int | None = in_transfers[0].subaddress_index assert account_idx is not None assert subaddress_idx is not None - query: MoneroTransferQuery = MoneroTransferQuery() - query.amount = amount - query.account_index = account_idx - query.subaddress_index = subaddress_idx + query: MoneroTransferQuery = MoneroTransferQuery( + amount=amount, account_index=account_idx, subaddress_index=subaddress_idx + ) query.tx_query = MoneroTxQuery() query.tx_query.is_confirmed = True in_transfers = wallet.get_incoming_transfers(query) diff --git a/tests/wallet/test_update_locked.py b/tests/wallet/test_update_locked.py index 28050e99..7acd2140 100644 --- a/tests/wallet/test_update_locked.py +++ b/tests/wallet/test_update_locked.py @@ -22,12 +22,9 @@ class BaseTestMoneroWalletUpdateLocked(BaseTestMoneroWallet): @pytest.mark.skipif(TestUtils.TEST_NOTIFICATIONS is False, reason="TEST_NOTIFICATIONS disabled") @pytest.mark.flaky(reruns=5, reruns_delay=10, only_rerun=["Daemon is busy", r"Cannot reconcile integrals:.*m_is_incoming"]) def test_update_locked_same_account(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: - config: MoneroTxConfig = MoneroTxConfig() - config.address = wallet.get_primary_address() - config.amount = TxWalletUtils.MAX_FEE - config.account_index = 0 - config.can_split = False - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + address=wallet.get_primary_address(), amount=TxWalletUtils.MAX_FEE, account_index=0, can_split=False, relay=True + ) WalletSendUtils.test_send_and_update_txs(daemon, wallet, config) # Can update split locked txs sent from/to the same account as blocks are added to the chain @@ -36,12 +33,9 @@ def test_update_locked_same_account(self, daemon: MoneroDaemonRpc, wallet: Moner @pytest.mark.skipif(TestUtils.LITE_MODE, reason="LITE_MODE enabled") @pytest.mark.flaky(reruns=5, reruns_delay=10, only_rerun=["Daemon is busy", r"Cannot reconcile integrals:.*m_is_incoming"]) def test_update_locked_same_account_split(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: - config: MoneroTxConfig = MoneroTxConfig() - config.address = wallet.get_primary_address() - config.amount = TxWalletUtils.MAX_FEE - config.account_index = 0 - config.can_split = True - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + address=wallet.get_primary_address(), amount=TxWalletUtils.MAX_FEE, account_index=0, can_split=True, relay=True + ) WalletSendUtils.test_send_and_update_txs(daemon, wallet, config) # TODO on wallet full is flaky due to `Cannot reconcile integrals: 0 vs 1. tx wallet m_is_incoming` error @@ -51,12 +45,10 @@ def test_update_locked_same_account_split(self, daemon: MoneroDaemonRpc, wallet: @pytest.mark.skipif(TestUtils.LITE_MODE, reason="LITE_MODE enabled") @pytest.mark.flaky(reruns=5, reruns_delay=10, only_rerun=["Daemon is busy", r"Cannot reconcile integrals:.*m_is_incoming"]) def test_update_locked_different_accounts(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: - config: MoneroTxConfig = MoneroTxConfig() - config.address = wallet.get_subaddress(1, 0).address - config.amount = TxWalletUtils.MAX_FEE - config.account_index = 0 - config.can_split = False - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + address=wallet.get_subaddress(1, 0).address, amount=TxWalletUtils.MAX_FEE, account_index=0, can_split=False, + relay=True + ) WalletSendUtils.test_send_and_update_txs(daemon, wallet, config) # Can update locked, split txs sent from/to different accounts as blocks are added to the chain @@ -65,12 +57,10 @@ def test_update_locked_different_accounts(self, daemon: MoneroDaemonRpc, wallet: @pytest.mark.skipif(TestUtils.LITE_MODE, reason="LITE_MODE enabled") @pytest.mark.flaky(reruns=5, reruns_delay=10, only_rerun=["Daemon is busy", r"Cannot reconcile integrals:.*m_is_incoming"]) def test_update_locked_different_accounts_split(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: - config: MoneroTxConfig = MoneroTxConfig() - config.address = wallet.get_subaddress(1, 0).address - config.amount = TxWalletUtils.MAX_FEE - config.account_index = 0 - config.can_split = True - config.relay = True + config: MoneroTxConfig = MoneroTxConfig( + address=wallet.get_subaddress(1, 0).address, amount=TxWalletUtils.MAX_FEE, account_index=0, can_split=True, + relay=True + ) WalletSendUtils.test_send_and_update_txs(daemon, wallet, config)