Skip to content

Commit cf5bb74

Browse files
Add prove unrelayed txs test
1 parent 9f83925 commit cf5bb74

2 files changed

Lines changed: 61 additions & 9 deletions

File tree

‎src/cpp/wallet/py_monero_wallet_rpc.cpp‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,14 +1264,15 @@ std::string PyMoneroWalletRpc::get_tx_key(const std::string& tx_hash) const {
12641264

12651265
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 {
12661266
try {
1267-
auto params = std::make_shared<PyMoneroCheckTxKeyParams>(tx_hash, tx_key, address);
1268-
PyMoneroJsonRequest request("check_tx_key", params);
1269-
auto response = m_rpc->send_json_request(request);
1270-
if (response->m_result == boost::none) throw std::runtime_error("Invalid Monero JSONRPC response");
1271-
auto node = response->m_result.get();
1272-
auto check = std::make_shared<monero::monero_check_tx>();
1273-
PyMoneroCheckTxProof::from_property_tree(node, check);
1274-
return check;
1267+
auto params = std::make_shared<PyMoneroCheckTxKeyParams>(tx_hash, tx_key, address);
1268+
PyMoneroJsonRequest request("check_tx_key", params);
1269+
auto response = m_rpc->send_json_request(request);
1270+
if (response->m_result == boost::none) throw std::runtime_error("Invalid Monero JSONRPC response");
1271+
auto node = response->m_result.get();
1272+
auto check = std::make_shared<monero::monero_check_tx>();
1273+
check->m_is_good = true;
1274+
PyMoneroCheckTxProof::from_property_tree(node, check);
1275+
return check;
12751276
} catch (const PyMoneroRpcError& ex) {
12761277
if (ex.code == -8 && ex.what() == std::string("TX ID has invalid format")) {
12771278
// normalize error message

‎tests/test_monero_wallet_common.py‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
MoneroOutputQuery, MoneroTransfer, MoneroIncomingTransfer, MoneroOutgoingTransfer,
1717
MoneroTxWallet, MoneroOutputWallet, MoneroTx, MoneroAccount, MoneroSubaddress,
1818
MoneroMessageSignatureType, MoneroTxPriority, MoneroFeeEstimate,
19-
MoneroIntegratedAddress, MoneroCheckTx, MoneroCheckReserve
19+
MoneroIntegratedAddress, MoneroCheckTx, MoneroCheckReserve, MoneroSubmitTxResult
2020
)
2121
from utils import (
2222
TestUtils, WalletEqualityUtils,
@@ -3318,6 +3318,57 @@ def test_input_key_images(self, wallet: MoneroWallet) -> None:
33183318
assert max_skipped_output.amount is not None
33193319
assert max_skipped_output.amount < TxUtils.MAX_FEE
33203320

3321+
# Can prove unrelayed txs
3322+
@pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
3323+
def test_prove_unrelayed_txs(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None:
3324+
# create unrelayed tx to verify
3325+
address1: str = WalletUtils.get_external_wallet_address()
3326+
address2: str = wallet.get_address(0, 0)
3327+
address3: str = wallet.get_address(1, 0)
3328+
tx_config: MoneroTxConfig = MoneroTxConfig()
3329+
tx_config.account_index = 0
3330+
tx_config.destinations.append(MoneroDestination(address1, TxUtils.MAX_FEE))
3331+
tx_config.destinations.append(MoneroDestination(address2, TxUtils.MAX_FEE * 2))
3332+
tx_config.destinations.append(MoneroDestination(address3, TxUtils.MAX_FEE * 3))
3333+
tx: MoneroTxWallet = wallet.create_tx(tx_config)
3334+
assert tx.full_hex is not None
3335+
assert tx.hash is not None
3336+
assert tx.key is not None
3337+
3338+
# submit tx to daemon but do not relay
3339+
result: MoneroSubmitTxResult = daemon.submit_tx_hex(tx.full_hex, True)
3340+
assert result.is_good
3341+
3342+
# create random wallet to verify transfers
3343+
verifying_wallet: MoneroWallet = self._create_wallet(MoneroWalletConfig())
3344+
3345+
# verify transfer 1
3346+
check: MoneroCheckTx = verifying_wallet.check_tx_key(tx.hash, tx.key, address1)
3347+
assert check.is_good
3348+
assert check.in_tx_pool is True
3349+
assert check.num_confirmations == 0
3350+
assert check.received_amount == TxUtils.MAX_FEE
3351+
3352+
# verify transfer 2
3353+
check = verifying_wallet.check_tx_key(tx.hash, tx.key, address2)
3354+
assert check.is_good
3355+
assert check.in_tx_pool is True
3356+
assert check.num_confirmations == 0
3357+
# + change amount
3358+
assert check.received_amount is not None
3359+
assert check.received_amount >= TxUtils.MAX_FEE * 2
3360+
3361+
# verify transfer 3
3362+
check = verifying_wallet.check_tx_key(tx.hash, tx.key, address3)
3363+
assert check.is_good
3364+
assert check.in_tx_pool is True
3365+
assert check.num_confirmations == 0
3366+
assert TxUtils.MAX_FEE * 3 == check.received_amount
3367+
3368+
# cleanup
3369+
daemon.flush_tx_pool(tx.hash)
3370+
self._close_wallet(verifying_wallet)
3371+
33213372
# Can get the default fee priority
33223373
@pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
33233374
def test_get_default_fee_priority(self, wallet: MoneroWallet) -> None:

0 commit comments

Comments
 (0)