Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Sep 7, 2022
1 parent cfc64f7 commit 580c717
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 deletions.
5 changes: 3 additions & 2 deletions mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl JsonRpcClient for NativeClientImpl {
if res.0 != StatusCode::OK {
let res_value = serde_json::from_slice(&res.2)
.map_err(|e| JsonRpcErrorType::parse_error(&uri, e.to_string()))?;
return Err(JsonRpcErrorType::Response(res.0.as_str().to_string().into(), res_value));
return Err(JsonRpcErrorType::Response(uri.into(), res_value));
}

let response = json::from_str(body).map_err(|e| JsonRpcErrorType::parse_error(&uri, e.to_string()))?;
Expand Down Expand Up @@ -2726,7 +2726,8 @@ fn electrum_connect(
}
}

// electrum_request should always return JsonRpcErrorType::Transport Error
/// # Important
/// electrum_request should always return JsonRpcErrorType::Transport Error
fn electrum_request(
mut req_json: String,
rpc_id: JsonRpcId,
Expand Down
21 changes: 5 additions & 16 deletions mm2src/coins/utxo/utxo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3876,29 +3876,18 @@ fn test_electrum_display_balances() {

#[test]
fn test_for_non_existent_tx_hex_utxo_electrum() {
// This test shouldn't wait till timeout!
let timeout = (now_ms() / 1000) + 120;
let client = electrum_client_for_test(RICK_ELECTRUM_ADDRS);
let coin = utxo_coin_for_test(
client.into(),
Some("spice describe gravity federal blast come thank unfair canal monkey style afraid"),
false,
);
let tx = vec![
4, 0, 0, 128, 133, 32, 47, 137, 1, 81, 146, 94, 240, 227, 116, 153, 194, 232, 25, 255, 192, 110, 155, 208, 14,
157, 197, 189, 65, 107, 229, 129, 124, 136, 215, 10, 63, 13, 218, 183, 206, 1, 0, 0, 0, 107, 72, 48, 69, 2, 33,
0, 255, 148, 80, 199, 101, 182, 102, 18, 1, 46, 26, 48, 212, 144, 162, 81, 21, 157, 233, 80, 159, 130, 184, 56,
98, 183, 189, 115, 233, 233, 30, 60, 2, 32, 124, 220, 236, 219, 101, 75, 139, 241, 185, 174, 16, 112, 127, 128,
159, 9, 104, 156, 39, 2, 81, 187, 198, 209, 255, 79, 84, 61, 238, 53, 243, 35, 1, 33, 3, 192, 45, 65, 142, 227,
32, 245, 206, 82, 10, 140, 237, 131, 171, 113, 63, 246, 56, 118, 88, 57, 29, 11, 37, 227, 59, 106, 136, 90,
252, 3, 72, 255, 255, 255, 255, 3, 0, 225, 245, 5, 0, 0, 0, 0, 23, 169, 20, 27, 130, 67, 246, 162, 41, 162,
144, 64, 214, 12, 227, 165, 136, 151, 82, 145, 176, 74, 245, 135, 0, 0, 0, 0, 0, 0, 0, 0, 22, 106, 20, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 3, 129, 66, 23, 0, 0, 0, 25, 118, 169, 20, 158, 220,
162, 160, 79, 133, 71, 112, 148, 22, 186, 113, 239, 163, 18, 241, 138, 161, 220, 132, 136, 172, 174, 23, 247,
98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]; // Bad transaction hex
let timeout = (now_ms() / 1000) + 120;

let tx_str = "0400008085202f8902bf17bf7d1daace52e08f732a6b8771743ca4b1cb765a187e72fd091a0aabfd52000000006a47304402203eaaa3c4da101240f80f9c5e9de716a22b1ec6d66080de6a0cca32011cd77223022040d9082b6242d6acf9a1a8e658779e1c655d708379862f235e8ba7b8ca4e69c6012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffffff023ca13c0e9e085dd13f481f193e8a3e8fd609020936e98b5587342d994f4d020000006b483045022100c0ba56adb8de923975052312467347d83238bd8d480ce66e8b709a7997373994022048507bcac921fdb2302fa5224ce86e41b7efc1a2e20ae63aa738dfa99b7be826012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0300e1f5050000000017a9141ee6d4c38a3c078eab87ad1a5e4b00f21259b10d870000000000000000166a1400000000000000000000000000000000000000001b94d736000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac2d08e35e000000000000000000000000000000"; // nonexistent transaction hex
let tx: UtxoTx = tx_str.into();
let actual = coin
.wait_for_confirmations(&tx, 1, false, timeout, 1)
.wait_for_confirmations(&tx.tx_hash(), 1, false, timeout, 1)
.wait()
.err()
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions mm2src/common/jsonrpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ pub enum JsonRpcErrorType {

impl JsonRpcErrorType {
pub fn parse_error(remote_addr: &str, err: String) -> Self { Self::Parse(remote_addr.to_string().into(), err) }

/// Whether the error type is [`JsonRpcErrorType::Transport`].
#[inline]
pub fn is_transport(&self) -> bool { matches!(self, JsonRpcErrorType::Transport(_)) }
Expand Down
6 changes: 2 additions & 4 deletions mm2src/mm2_core/src/mm_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use futures::future::AbortHandle;
use gstuff::{try_s, Constructible, ERR, ERRL};
use keys::KeyPair;
use lazy_static::lazy_static;
#[cfg(not(target_arch = "wasm32"))]
use mm2_metrics::MmMetricsError;
use mm2_metrics::{MetricsArc, MetricsOps};
use primitives::hash::H160;
use rand::Rng;
Expand All @@ -20,7 +18,6 @@ use std::any::Any;
use std::collections::hash_map::{Entry, HashMap};
use std::collections::HashSet;
use std::fmt;
#[cfg(not(target_arch = "wasm32"))] use std::net::AddrParseError;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
Expand All @@ -32,8 +29,9 @@ cfg_wasm32! {

cfg_native! {
use mm2_metrics::prometheus;
use mm2_metrics::MmMetricsError;
use db_common::sqlite::rusqlite::Connection;
use std::net::{IpAddr, SocketAddr};
use std::net::{IpAddr, SocketAddr, AddrParseError};
use std::sync::MutexGuard;
}

Expand Down
19 changes: 3 additions & 16 deletions mm2src/mm2_main/src/docker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,26 +447,13 @@ mod docker_tests {
// This test shouldn't wait till timeout!
let timeout = (now_ms() / 1000) + 120;
let (_ctx, coin, _) = generate_utxo_coin_with_random_privkey("MYCOIN", 1000u64.into());
let hex = vec![
4, 0, 0, 128, 133, 32, 47, 137, 1, 81, 146, 94, 240, 227, 116, 153, 194, 232, 25, 255, 192, 110, 155, 208,
14, 157, 197, 189, 65, 107, 229, 129, 124, 136, 215, 10, 63, 13, 218, 183, 206, 1, 0, 0, 0, 107, 72, 48,
69, 2, 33, 0, 255, 148, 80, 199, 101, 182, 102, 18, 1, 46, 26, 48, 212, 144, 162, 81, 21, 157, 233, 80,
159, 130, 184, 56, 98, 183, 189, 115, 233, 233, 30, 60, 2, 32, 124, 220, 236, 219, 101, 75, 139, 241, 185,
174, 16, 112, 127, 128, 159, 9, 104, 156, 39, 2, 81, 187, 198, 209, 255, 79, 84, 61, 238, 53, 243, 35, 1,
33, 3, 192, 45, 65, 142, 227, 32, 245, 206, 82, 10, 140, 237, 131, 171, 113, 63, 246, 56, 118, 88, 57, 29,
11, 37, 227, 59, 106, 136, 90, 252, 3, 72, 255, 255, 255, 255, 3, 0, 225, 245, 5, 0, 0, 0, 0, 23, 169, 20,
27, 130, 67, 246, 162, 41, 162, 144, 64, 214, 12, 227, 165, 136, 151, 82, 145, 176, 74, 245, 135, 0, 0, 0,
0, 0, 0, 0, 0, 22, 106, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 3, 129, 66, 23,
0, 0, 0, 25, 118, 169, 20, 158, 220, 162, 160, 79, 133, 71, 112, 148, 22, 186, 113, 239, 163, 18, 241, 138,
161, 220, 132, 136, 172, 174, 23, 247, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];

let tx_str = "0400008085202f8902bf17bf7d1daace52e08f732a6b8771743ca4b1cb765a187e72fd091a0aabfd52000000006a47304402203eaaa3c4da101240f80f9c5e9de716a22b1ec6d66080de6a0cca32011cd77223022040d9082b6242d6acf9a1a8e658779e1c655d708379862f235e8ba7b8ca4e69c6012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffffff023ca13c0e9e085dd13f481f193e8a3e8fd609020936e98b5587342d994f4d020000006b483045022100c0ba56adb8de923975052312467347d83238bd8d480ce66e8b709a7997373994022048507bcac921fdb2302fa5224ce86e41b7efc1a2e20ae63aa738dfa99b7be826012102031d4256c4bc9f99ac88bf3dba21773132281f65f9bf23a59928bce08961e2f3ffffffff0300e1f5050000000017a9141ee6d4c38a3c078eab87ad1a5e4b00f21259b10d870000000000000000166a1400000000000000000000000000000000000000001b94d736000000001976a91405aab5342166f8594baf17a7d9bef5d56744332788ac2d08e35e000000000000000000000000000000"; // nonexistent transaction hex
let tx: chain::Transaction = tx_str.into();
let actual = coin
.wait_for_confirmations(&hex, 1, false, timeout, 1)
.wait_for_confirmations(&tx.tx_hash(), 1, false, timeout, 1)
.wait()
.err()
.unwrap();

assert!(actual
.contains("Tx b4f8d0f3665ccb7a7e1d98cfaba9c77ed4cbe245deaf529a5578b6977d91253c is not on chain anymore"))
}
Expand Down

0 comments on commit 580c717

Please sign in to comment.