Skip to content

Commit 3238b37

Browse files
Wallet rpc consolidation
1 parent 16d5f13 commit 3238b37

2 files changed

Lines changed: 13 additions & 38 deletions

File tree

src/cpp/wallet/py_monero_wallet_model.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,11 @@ void PyMoneroTxWallet::from_property_tree_with_transfer(const boost::property_tr
603603
}
604604
}
605605
else if (key == std::string("amount_in")) tx->m_input_sum = it->second.get_value<uint64_t>();
606-
else if (key == std::string("amount_out")) tx->m_input_sum = it->second.get_value<uint64_t>();
606+
else if (key == std::string("amount_out")) tx->m_output_sum = it->second.get_value<uint64_t>();
607607
else if (key == std::string("change_address") && !it->second.data().empty()) tx->m_change_address = it->second.data();
608608
else if (key == std::string("change_amount")) tx->m_change_amount = it->second.get_value<uint64_t>();
609609
else if (key == std::string("dummy_outputs")) tx->m_num_dummy_outputs = it->second.get_value<uint64_t>();
610-
//else if (key == std::string("extra")) tx->m_extra = it->second.data();
610+
else if (key == std::string("extra")) tx->m_extra_hex = it->second.data();
611611
else if (key == std::string("ring_size")) tx->m_ring_size = it->second.get_value<uint32_t>();
612612
else if (key == std::string("spent_key_images")) {
613613
auto node2 = it->second;
@@ -714,14 +714,14 @@ void PyMoneroTxWallet::from_property_tree_with_output(const boost::property_tree
714714
tx->m_in_tx_pool = false;
715715

716716
auto output = std::make_shared<monero::monero_output_wallet>();
717-
auto key_image = std::make_shared<monero::monero_key_image>();
718717
output->m_tx = tx;
719718

720719
for(auto it = node.begin(); it != node.end(); ++it) {
721720
std::string key = it->first;
722721
if (key == std::string("amount")) output->m_amount = it->second.get_value<uint64_t>();
723722
else if (key == std::string("spent")) output->m_is_spent = it->second.get_value<bool>();
724-
else if (key == std::string("key_image")) {
723+
else if (key == std::string("key_image") && !it->second.data().empty()) {
724+
auto key_image = std::make_shared<monero::monero_key_image>();
725725
key_image->m_hex = it->second.data();
726726
output->m_key_image = key_image;
727727
}
@@ -1440,7 +1440,7 @@ rapidjson::Value PyMoneroKeyImage::to_rapidjson_val(rapidjson::Document::Allocat
14401440

14411441
// set string values
14421442
rapidjson::Value value_str(rapidjson::kStringType);
1443-
if (m_hex != boost::none) monero_utils::add_json_member("keyImage", m_hex.get(), allocator, root, value_str);
1443+
if (m_hex != boost::none) monero_utils::add_json_member("key_image", m_hex.get(), allocator, root, value_str);
14441444
if (m_signature != boost::none) monero_utils::add_json_member("signature", m_signature.get(), allocator, root, value_str);
14451445

14461446
// return root

tests/test_monero_wallet_rpc.py

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,11 @@ def get_test_wallet(cls) -> MoneroWalletRpc:
4141

4242
@override
4343
def _open_wallet(self, config: MoneroWalletConfig | None) -> MoneroWalletRpc:
44-
try:
45-
return Utils.open_wallet_rpc(config)
46-
except Exception:
47-
Utils.free_wallet_rpc_resources()
48-
raise
44+
return Utils.open_wallet_rpc(config)
4945

5046
@override
5147
def _create_wallet(self, config: MoneroWalletConfig) -> MoneroWalletRpc:
52-
try:
53-
return Utils.create_wallet_rpc(config)
54-
except Exception:
55-
Utils.free_wallet_rpc_resources()
56-
raise
48+
return Utils.create_wallet_rpc(config)
5749

5850
@override
5951
def _close_wallet(self, wallet: MoneroWallet, save: bool = False) -> None:
@@ -123,7 +115,6 @@ def test_get_subaddress_address_out_of_range(self, wallet: MoneroWallet) -> None
123115

124116
# Can create a wallet with a randomly generated seed
125117
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
126-
@pytest.mark.xfail(reason="TODO setup another docker wallet-rpc")
127118
def test_create_wallet_random_rpc(self) -> None:
128119
# create random wallet with defaults
129120
path: str = StringUtils.get_random_string()
@@ -146,14 +137,12 @@ def test_create_wallet_random_rpc(self) -> None:
146137
wallet = self._create_wallet(config)
147138
MoneroUtils.validate_mnemonic(wallet.get_seed())
148139
assert seed != wallet.get_seed()
140+
seed = wallet.get_seed()
149141
MoneroUtils.validate_address(wallet.get_primary_address(), Utils.NETWORK_TYPE)
150142

151143
# attempt to create wallet which already exists
152144
try:
153-
config = MoneroWalletConfig()
154-
config.path = path
155-
config.language = "Spanish"
156-
self._create_wallet(config)
145+
wallet.create_wallet(config)
157146
except MoneroError as e:
158147
err_msg: str = str(e)
159148
assert err_msg == f"Wallet already exists: {path}", err_msg
@@ -209,10 +198,8 @@ def test_create_wallet_from_seed_rpc(self, daemon: MoneroDaemonRpc) -> None:
209198

210199
# Can open wallets
211200
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
212-
@pytest.mark.skip(reason="TODO setup another docker monero-wallet-rpc resource")
213201
def test_open_wallet(self)-> None:
214202
# create names of tests wallets
215-
# TODO setup more wallet-rpc instances
216203
num_test_wallets: int = 1
217204
names: list[str] = [ ]
218205
for i in range(num_test_wallets):
@@ -238,23 +225,16 @@ def test_open_wallet(self)-> None:
238225
assert seeds[i] == wallet.get_seed()
239226
wallets.append(wallet)
240227

241-
# attempt to re-open already opened wallet
242-
try:
243-
config: MoneroWalletConfig = MoneroWalletConfig()
244-
self._open_wallet(config)
245-
raise Exception("Cannot open wallet wich is already open")
246-
except MoneroError as e:
247-
# -1 indicates wallet does not exist (or is open by another app)
248-
logger.critical(str(e))
249-
250228
# attempt to open non-existent
251229
try:
252230
config: MoneroWalletConfig = MoneroWalletConfig()
253231
config.path = "btc_integrity"
254232
config.password = Utils.WALLET_PASSWORD
233+
self._open_wallet(config)
255234
raise Exception("Cannot open non-existent wallet")
256-
except MoneroError as e:
257-
logger.critical(e)
235+
except Exception as e:
236+
e_msg: str = str(e)
237+
assert e_msg != "Cannot open non-existent wallet", e_msg
258238

259239
# close wallets:
260240
for wallet in wallets:
@@ -356,9 +336,4 @@ def test_get_public_spend_key(self, wallet: MoneroWallet) -> None:
356336
def test_import_key_images(self, wallet: MoneroWallet) -> None:
357337
return super().test_import_key_images(wallet)
358338

359-
@pytest.mark.skip(reason="TODO setup another docker monero-wallet-rpc resource")
360-
@override
361-
def test_view_only_and_offline_wallets(self, wallet: MoneroWallet) -> None:
362-
return super().test_view_only_and_offline_wallets(wallet)
363-
364339
#endregion

0 commit comments

Comments
 (0)