|
8 | 8 | MoneroWalletConfig, MoneroDestination, MoneroUtils, |
9 | 9 | MoneroTxConfig, MoneroSubaddress, MoneroAccount, MoneroTxWallet, |
10 | 10 | MoneroOutputWallet, MoneroKeyImage, MoneroIntegratedAddress, |
11 | | - MoneroKeyImageImportResult, MoneroMessageSignatureResult, |
12 | | - MoneroMessageSignatureType, MoneroCheckTx, MoneroCheckReserve, |
| 11 | + MoneroKeyImageImportResult, MoneroKeyImageExportResult, MoneroMessageSignatureResult, |
| 12 | + MoneroMessageSignatureType, MoneroCheck, MoneroCheckTx, MoneroCheckReserve, |
13 | 13 | MoneroMultisigInfo, MoneroMultisigInitResult, MoneroMultisigSignResult, |
14 | 14 | MoneroAddressBookEntry, MoneroAccountTag, MoneroIncomingTransfer, |
15 | 15 | MoneroOutgoingTransfer, IncomingTransferComparator, OutputComparator, MoneroTx, |
16 | | - MoneroTxSet |
| 16 | + MoneroTxSet, MoneroSyncResult, MoneroDecodedAddress, |
| 17 | + MoneroAddressType, MoneroNetworkType |
17 | 18 | ) |
18 | 19 | from utils import BaseTestClass, TestUtils, AssertUtils |
19 | 20 |
|
@@ -189,6 +190,11 @@ def test_wallet_config(self) -> None: |
189 | 190 | logger.debug(f"Deserialized config: {deserialized_config.serialize()}") |
190 | 191 | AssertUtils.assert_equals(config, deserialized_config) |
191 | 192 |
|
| 193 | + @pytest.mark.parametrize("json_fragment", ['{"networkType":-1}', '{"networkType":3}']) |
| 194 | + def test_wallet_config_invalid_network_type(self, json_fragment: str) -> None: |
| 195 | + with pytest.raises(Exception, match="Invalid network type"): |
| 196 | + MoneroWalletConfig.deserialize(json_fragment) |
| 197 | + |
192 | 198 | def test_tx_config(self) -> None: |
193 | 199 | config: MoneroTxConfig = MoneroTxConfig() |
194 | 200 | config.set_address(TestUtils.ADDRESS) |
@@ -507,6 +513,60 @@ def test_tx_set_signed_tx_hex_deserialize(self) -> None: |
507 | 513 | tx_set.signed_tx_hex = "deadbeef" |
508 | 514 | AssertUtils.assert_serialization_integrity(tx_set) |
509 | 515 |
|
| 516 | + def test_sync_result_deserialize(self) -> None: |
| 517 | + result: MoneroSyncResult = MoneroSyncResult() |
| 518 | + result.num_blocks_fetched = 42 |
| 519 | + result.received_money = True |
| 520 | + AssertUtils.assert_serialization_integrity(result) |
| 521 | + |
| 522 | + def test_check_deserialize(self) -> None: |
| 523 | + check: MoneroCheck = MoneroCheck() |
| 524 | + check.is_good = True |
| 525 | + AssertUtils.assert_serialization_integrity(check) |
| 526 | + |
| 527 | + def test_incoming_transfer_deserialize(self) -> None: |
| 528 | + transfer: MoneroIncomingTransfer = MoneroIncomingTransfer() |
| 529 | + transfer.amount = 500000 |
| 530 | + transfer.account_index = 0 |
| 531 | + transfer.subaddress_index = 1 |
| 532 | + transfer.address = TestUtils.ADDRESS |
| 533 | + transfer.num_suggested_confirmations = 10 |
| 534 | + AssertUtils.assert_serialization_integrity(transfer) |
| 535 | + |
| 536 | + def test_outgoing_transfer_deserialize(self) -> None: |
| 537 | + transfer: MoneroOutgoingTransfer = MoneroOutgoingTransfer() |
| 538 | + transfer.amount = 500000 |
| 539 | + transfer.account_index = 0 |
| 540 | + transfer.subaddress_indices = [0, 1] |
| 541 | + transfer.addresses = [TestUtils.ADDRESS] |
| 542 | + transfer.destinations = [MoneroDestination(TestUtils.ADDRESS, 500000)] |
| 543 | + AssertUtils.assert_serialization_integrity(transfer) |
| 544 | + |
| 545 | + def test_decoded_address_deserialize(self) -> None: |
| 546 | + address: MoneroDecodedAddress = MoneroDecodedAddress( |
| 547 | + TestUtils.ADDRESS, MoneroAddressType.PRIMARY_ADDRESS, MoneroNetworkType.MAINNET |
| 548 | + ) |
| 549 | + AssertUtils.assert_serialization_integrity(address) |
| 550 | + |
| 551 | + @pytest.mark.parametrize("json_fragment", [ |
| 552 | + '{"networkType":-1}', |
| 553 | + '{"networkType":3}', |
| 554 | + '{"addressType":-1}', |
| 555 | + '{"addressType":3}', |
| 556 | + ]) |
| 557 | + def test_decoded_address_invalid_enum_range(self, json_fragment: str) -> None: |
| 558 | + with pytest.raises(Exception, match="Invalid (network|address) type"): |
| 559 | + MoneroDecodedAddress.deserialize(json_fragment) |
| 560 | + |
| 561 | + def test_key_image_export_result_deserialize(self) -> None: |
| 562 | + result: MoneroKeyImageExportResult = MoneroKeyImageExportResult() |
| 563 | + result.offset = 3 |
| 564 | + key_image: MoneroKeyImage = MoneroKeyImage() |
| 565 | + key_image.hex = "a" * 64 |
| 566 | + key_image.signature = "b" * 128 |
| 567 | + result.key_images = [key_image] |
| 568 | + AssertUtils.assert_serialization_integrity(result) |
| 569 | + |
510 | 570 | #endregion |
511 | 571 |
|
512 | 572 | #region Copy / merge / comparators |
@@ -621,38 +681,28 @@ def test_outgoing_transfer_merge(self) -> None: |
621 | 681 | assert a.subaddress_indices == [0] |
622 | 682 | assert len(a.destinations) == 1 |
623 | 683 |
|
624 | | - @pytest.mark.xfail(reason="monero_outgoing_transfer::merge() dereferences destination address/amount unconditionally", strict=True) |
625 | 684 | def test_outgoing_transfer_merge_destinations_with_unset_fields(self) -> None: |
626 | | - script: str = ( |
627 | | - "import monero, sys\n" |
628 | | - # dirty the heap first: a clean freshly-started interpreter doesn't reliably |
629 | | - # reproduce the crash, but a heap with realistic allocation churn (much closer to |
630 | | - # a real test run or application) does, consistently |
631 | | - "garbage = []\n" |
632 | | - "for i in range(500):\n" |
633 | | - " tx = monero.MoneroTxWallet()\n" |
634 | | - " tx.hash = 'b' * 64 + str(i)\n" |
635 | | - " tx.note = 'x' * (i % 200)\n" |
636 | | - " garbage.append(tx)\n" |
637 | | - "del garbage\n" |
638 | | - "a = monero.MoneroOutgoingTransfer()\n" |
639 | | - "a.amount = 500000\n" |
640 | | - "a.account_index = 0\n" |
641 | | - "a.destinations = [monero.MoneroDestination()]\n" |
642 | | - "b = a.copy()\n" |
643 | | - "b.destinations = [monero.MoneroDestination()]\n" |
644 | | - "try:\n" |
645 | | - " a.merge(b)\n" |
646 | | - " sys.exit('merge() did not raise')\n" |
647 | | - "except RuntimeError as e:\n" |
648 | | - " sys.exit(0 if str(e) == 'Destination vectors are different' else f'wrong message: {e}')\n" |
649 | | - ) |
650 | | - result: subprocess.CompletedProcess[str] = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True, timeout=30) |
651 | | - logger.debug(f"subprocess exit code: {result.returncode}, stderr: {result.stderr.strip()}") |
652 | | - assert result.returncode == 0, ( |
653 | | - f"outgoing_transfer.merge() did not cleanly raise 'Destination vectors are different' " |
654 | | - f"(exit code {result.returncode}): {result.stderr.strip()[-300:]}" |
655 | | - ) |
| 685 | + # destinations with unset address/amount are a reachable state; merge() |
| 686 | + # must compare them without dereferencing the empty optionals |
| 687 | + a: MoneroOutgoingTransfer = MoneroOutgoingTransfer() |
| 688 | + a.amount = 500000 |
| 689 | + a.account_index = 0 |
| 690 | + a.destinations = [MoneroDestination()] |
| 691 | + b: MoneroOutgoingTransfer = a.copy() |
| 692 | + b.destinations = [MoneroDestination()] |
| 693 | + a.merge(b) # equal (empty) destinations -> no error |
| 694 | + assert len(a.destinations) == 1 |
| 695 | + |
| 696 | + def test_outgoing_transfer_merge_conflicting_destinations_raises(self) -> None: |
| 697 | + a: MoneroOutgoingTransfer = MoneroOutgoingTransfer() |
| 698 | + a.amount = 500000 |
| 699 | + a.account_index = 0 |
| 700 | + a.destinations = [MoneroDestination(TestUtils.ADDRESS, 1)] |
| 701 | + b: MoneroOutgoingTransfer = a.copy() |
| 702 | + b.destinations = [MoneroDestination(TestUtils.ADDRESS, 2)] |
| 703 | + with pytest.raises(RuntimeError) as exc_info: |
| 704 | + a.merge(b) |
| 705 | + assert str(exc_info.value) == "Destination vectors are different" |
656 | 706 |
|
657 | 707 | def test_output_wallet_copy(self) -> None: |
658 | 708 | output: MoneroOutputWallet = MoneroOutputWallet() |
|
0 commit comments