Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/cpp/wallet/py_monero_wallet_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,14 +1264,15 @@ std::string PyMoneroWalletRpc::get_tx_key(const std::string& tx_hash) const {

std::shared_ptr<monero_check_tx> PyMoneroWalletRpc::check_tx_key(const std::string& tx_hash, const std::string& tx_key, const std::string& address) const {
try {
auto params = std::make_shared<PyMoneroCheckTxKeyParams>(tx_hash, tx_key, address);
PyMoneroJsonRequest request("check_tx_key", params);
auto response = m_rpc->send_json_request(request);
if (response->m_result == boost::none) throw std::runtime_error("Invalid Monero JSONRPC response");
auto node = response->m_result.get();
auto check = std::make_shared<monero::monero_check_tx>();
PyMoneroCheckTxProof::from_property_tree(node, check);
return check;
auto params = std::make_shared<PyMoneroCheckTxKeyParams>(tx_hash, tx_key, address);
PyMoneroJsonRequest request("check_tx_key", params);
auto response = m_rpc->send_json_request(request);
if (response->m_result == boost::none) throw std::runtime_error("Invalid Monero JSONRPC response");
auto node = response->m_result.get();
auto check = std::make_shared<monero::monero_check_tx>();
check->m_is_good = true;
PyMoneroCheckTxProof::from_property_tree(node, check);
return check;
} catch (const PyMoneroRpcError& ex) {
if (ex.code == -8 && ex.what() == std::string("TX ID has invalid format")) {
// normalize error message
Expand Down
53 changes: 52 additions & 1 deletion tests/test_monero_wallet_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
MoneroOutputQuery, MoneroTransfer, MoneroIncomingTransfer, MoneroOutgoingTransfer,
MoneroTxWallet, MoneroOutputWallet, MoneroTx, MoneroAccount, MoneroSubaddress,
MoneroMessageSignatureType, MoneroTxPriority, MoneroFeeEstimate,
MoneroIntegratedAddress, MoneroCheckTx, MoneroCheckReserve
MoneroIntegratedAddress, MoneroCheckTx, MoneroCheckReserve, MoneroSubmitTxResult
)
from utils import (
TestUtils, WalletEqualityUtils,
Expand Down Expand Up @@ -3318,6 +3318,57 @@ def test_input_key_images(self, wallet: MoneroWallet) -> None:
assert max_skipped_output.amount is not None
assert max_skipped_output.amount < TxUtils.MAX_FEE

# Can prove unrelayed txs
@pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_prove_unrelayed_txs(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None:
# create unrelayed tx to verify
address1: str = WalletUtils.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.destinations.append(MoneroDestination(address1, TxUtils.MAX_FEE))
tx_config.destinations.append(MoneroDestination(address2, TxUtils.MAX_FEE * 2))
tx_config.destinations.append(MoneroDestination(address3, TxUtils.MAX_FEE * 3))
tx: MoneroTxWallet = wallet.create_tx(tx_config)
assert tx.full_hex is not None
assert tx.hash is not None
assert tx.key is not None

# submit tx to daemon but do not relay
result: MoneroSubmitTxResult = daemon.submit_tx_hex(tx.full_hex, True)
assert result.is_good

# create random wallet to verify transfers
verifying_wallet: MoneroWallet = self._create_wallet(MoneroWalletConfig())

# verify transfer 1
check: MoneroCheckTx = verifying_wallet.check_tx_key(tx.hash, tx.key, address1)
assert check.is_good
assert check.in_tx_pool is True
assert check.num_confirmations == 0
assert check.received_amount == TxUtils.MAX_FEE

# verify transfer 2
check = verifying_wallet.check_tx_key(tx.hash, tx.key, address2)
assert check.is_good
assert check.in_tx_pool is True
assert check.num_confirmations == 0
# + change amount
assert check.received_amount is not None
assert check.received_amount >= TxUtils.MAX_FEE * 2

# verify transfer 3
check = verifying_wallet.check_tx_key(tx.hash, tx.key, address3)
assert check.is_good
assert check.in_tx_pool is True
assert check.num_confirmations == 0
assert TxUtils.MAX_FEE * 3 == check.received_amount

# cleanup
daemon.flush_tx_pool(tx.hash)
self._close_wallet(verifying_wallet)

# Can get the default fee priority
@pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_get_default_fee_priority(self, wallet: MoneroWallet) -> None:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_monero_wallet_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,11 @@ def test_sweep_wallet_by_accounts(self, wallet: MoneroWallet) -> None:
def test_sweep_wallet_by_subaddresses(self, wallet: MoneroWallet) -> None:
return super().test_sweep_wallet_by_subaddresses(wallet)

@pytest.mark.not_supported
@override
def test_prove_unrelayed_txs(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None:
return super().test_prove_unrelayed_txs(daemon, wallet)

#endregion

#region Tests
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def get_external_wallet_address(cls) -> str:

:returns str: external wallet address
"""
network_type: MoneroNetworkType | None = TestUtils.get_daemon_rpc().get_info().network_type
network_type: MoneroNetworkType | None = TestUtils.NETWORK_TYPE

if network_type == MoneroNetworkType.STAGENET:
# subaddress
Expand Down