Skip to content

Commit

Permalink
fix(tests): refactor tbch electrums list and remove non working ones (K…
Browse files Browse the repository at this point in the history
  • Loading branch information
shamardy authored Oct 24, 2023
1 parent 5df7db3 commit 222a851
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 79 deletions.
4 changes: 2 additions & 2 deletions mm2src/coins/utxo/bch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ pub fn tbch_coin_for_test() -> (MmArc, BchCoin) {
use common::block_on;
use crypto::privkey::key_pair_from_seed;
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::BCHD_TESTNET_URLS;
use mm2_test_helpers::for_tests::{electrum_servers_rpc, BCHD_TESTNET_URLS, T_BCH_ELECTRUMS};

let ctx = MmCtxBuilder::default().into_mm_arc();
let keypair = key_pair_from_seed("BCH SLP test").unwrap();
Expand All @@ -1411,7 +1411,7 @@ pub fn tbch_coin_for_test() -> (MmArc, BchCoin) {
let req = json!({
"method": "electrum",
"coin": "BCH",
"servers": [{"url":"blackie.c3-soft.com:60001"},{"url":"testnet.imaginary.cash:50001"},{"url":"tbch.loping.net:60001"},{"url":"electroncash.de:50003"}],
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
"bchd_urls": BCHD_TESTNET_URLS,
"allow_slp_unsafe_conf": false,
});
Expand Down
41 changes: 6 additions & 35 deletions mm2src/coins/utxo/utxo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ use futures::future::join_all;
use futures::TryFutureExt;
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_number::bigdecimal::{BigDecimal, Signed};
use mm2_test_helpers::for_tests::{mm_ctx_with_custom_db, DOC_ELECTRUM_ADDRS, MORTY_ELECTRUM_ADDRS, RICK_ELECTRUM_ADDRS};
use mm2_test_helpers::for_tests::{electrum_servers_rpc, mm_ctx_with_custom_db, DOC_ELECTRUM_ADDRS,
MORTY_ELECTRUM_ADDRS, RICK_ELECTRUM_ADDRS, T_BCH_ELECTRUMS};
use mocktopus::mocking::*;
use rpc::v1::types::H256 as H256Json;
use serialization::{deserialize, CoinVariant};
Expand Down Expand Up @@ -1371,15 +1372,7 @@ fn test_cashaddresses_in_tx_details_by_hash() {
});
let req = json!({
"method": "electrum",
"servers": [
{"url":"bch0.kister.net:51002","protocol":"SSL"},
{"url":"tbch.loping.net:60002","protocol":"SSL"},
{"url":"electroncash.de:50003"},
{"url":"tbch.loping.net:60001"},
{"url":"blackie.c3-soft.com:60001"},
{"url":"bch0.kister.net:51001"},
{"url":"testnet.imaginary.cash:50001"}
],
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
});

let ctx = MmCtxBuilder::new().into_mm_arc();
Expand Down Expand Up @@ -1412,15 +1405,7 @@ fn test_address_from_str_with_cashaddress_activated() {
});
let req = json!({
"method": "electrum",
"servers": [
{"url":"bch0.kister.net:51002","protocol":"SSL"},
{"url":"tbch.loping.net:60002","protocol":"SSL"},
{"url":"electroncash.de:50003"},
{"url":"tbch.loping.net:60001"},
{"url":"blackie.c3-soft.com:60001"},
{"url":"bch0.kister.net:51001"},
{"url":"testnet.imaginary.cash:50001"}
],
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
});

let ctx = MmCtxBuilder::new().into_mm_arc();
Expand Down Expand Up @@ -1452,15 +1437,7 @@ fn test_address_from_str_with_legacy_address_activated() {
});
let req = json!({
"method": "electrum",
"servers": [
{"url":"bch0.kister.net:51002","protocol":"SSL"},
{"url":"tbch.loping.net:60002","protocol":"SSL"},
{"url":"electroncash.de:50003"},
{"url":"tbch.loping.net:60001"},
{"url":"blackie.c3-soft.com:60001"},
{"url":"bch0.kister.net:51001"},
{"url":"testnet.imaginary.cash:50001"}
],
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
});

let ctx = MmCtxBuilder::new().into_mm_arc();
Expand Down Expand Up @@ -2971,13 +2948,7 @@ fn test_tx_details_kmd_rewards_claimed_by_other() {
fn test_tx_details_bch_no_rewards() {
const TX_HASH: &str = "eb13d926f15cbb896e0bcc7a1a77a4ec63504e57a1524c13a7a9b80f43ecb05c";

let electrum = electrum_client_for_test(&[
"electroncash.de:50003",
"tbch.loping.net:60001",
"blackie.c3-soft.com:60001",
"bch0.kister.net:51001",
"testnet.imaginary.cash:50001",
]);
let electrum = electrum_client_for_test(T_BCH_ELECTRUMS);
let coin = utxo_coin_for_test(electrum.into(), None, false);

let tx_details = get_tx_details_eq_for_both_versions(&coin, TX_HASH);
Expand Down
34 changes: 8 additions & 26 deletions mm2src/mm2_main/tests/mm2_tests/bch_and_slp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,18 @@ use common::{block_on, log, repeatable};
use crypto::StandardHDCoinAddress;
use http::StatusCode;
use itertools::Itertools;
use mm2_test_helpers::for_tests::{disable_coin, enable_bch_with_tokens, enable_slp, my_tx_history_v2, sign_message,
tbch_for_slp_conf, tbch_usdf_conf, verify_message, MarketMakerIt, Mm2TestConf,
UtxoRpcMode};
use mm2_test_helpers::for_tests::{disable_coin, electrum_servers_rpc, enable_bch_with_tokens, enable_slp,
my_tx_history_v2, sign_message, tbch_for_slp_conf, tbch_usdf_conf, verify_message,
MarketMakerIt, Mm2TestConf, UtxoRpcMode, T_BCH_ELECTRUMS};
use mm2_test_helpers::structs::{EnableBchWithTokensResponse, RpcV2Response, SignatureResponse, StandardHistoryV2Res,
UtxoFeeDetails, VerificationResponse};
use serde_json::{self as json, json, Value as Json};
use std::env;
use std::thread;
use std::time::Duration;

#[cfg(not(target_arch = "wasm32"))]
const T_BCH_ELECTRUMS: &[&str] = &[
"electroncash.de:50003",
"tbch.loping.net:60001",
"blackie.c3-soft.com:60001",
"bch0.kister.net:51001",
"testnet.imaginary.cash:50001",
];

#[cfg(target_arch = "wasm32")]
const T_BCH_ELECTRUMS: &[&str] = &[
"electroncash.de:60003",
"electroncash.de:60004",
"blackie.c3-soft.com:60004",
];

const BIP39_PASSPHRASE: &str = "tank abandon bind salon remove wisdom net size aspect direct source fossil";

fn t_bch_electrums_legacy_json() -> Vec<Json> { T_BCH_ELECTRUMS.iter().map(|url| json!({ "url": url })).collect() }

#[test]
#[cfg(not(target_arch = "wasm32"))]
fn test_withdraw_cashaddresses() {
Expand Down Expand Up @@ -63,7 +45,7 @@ fn test_withdraw_cashaddresses() {
"userpass": mm.userpass,
"method": "electrum",
"coin": "BCH",
"servers": t_bch_electrums_legacy_json(),
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
"mm2": 1,
})))
.unwrap();
Expand Down Expand Up @@ -177,7 +159,7 @@ fn test_withdraw_cashaddresses() {
"userpass": mm.userpass,
"method": "electrum",
"coin": "BCH",
"servers": t_bch_electrums_legacy_json(),
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
"address_format":{"format":"standard"},
"mm2": 1,
})))
Expand Down Expand Up @@ -267,7 +249,7 @@ fn test_withdraw_to_different_cashaddress_network_should_fail() {
"userpass": mm.userpass,
"method": "electrum",
"coin": "BCH",
"servers": t_bch_electrums_legacy_json(),
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
"mm2": 1,
})))
.unwrap();
Expand Down Expand Up @@ -330,7 +312,7 @@ fn test_common_cashaddresses() {
"userpass": mm.userpass,
"method": "electrum",
"coin": "BCH",
"servers": t_bch_electrums_legacy_json(),
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
"mm2": 1,
})))
.unwrap();
Expand Down Expand Up @@ -531,7 +513,7 @@ fn test_sign_verify_message_bch() {
"userpass": mm.userpass,
"method": "electrum",
"coin": "BCH",
"servers": t_bch_electrums_legacy_json(),
"servers": electrum_servers_rpc(T_BCH_ELECTRUMS),
"mm2": 1,
})))
.unwrap();
Expand Down
16 changes: 2 additions & 14 deletions mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use mm2_test_helpers::for_tests::{btc_segwit_conf, btc_with_spv_conf, btc_with_s
MarketMakerIt, Mm2InitPrivKeyPolicy, Mm2TestConf, Mm2TestConfForSwap, RaiiDump,
ETH_DEV_NODES, ETH_DEV_SWAP_CONTRACT, ETH_DEV_TOKEN_CONTRACT, ETH_MAINNET_NODE,
ETH_MAINNET_SWAP_CONTRACT, MORTY, QRC20_ELECTRUMS, RICK, RICK_ELECTRUM_ADDRS,
TBTC_ELECTRUMS};
TBTC_ELECTRUMS, T_BCH_ELECTRUMS};

use crypto::StandardHDCoinAddress;
use mm2_test_helpers::get_passphrase;
Expand Down Expand Up @@ -3176,19 +3176,7 @@ fn test_convert_utxo_address() {
let (_dump_log, _dump_dashboard) = mm.mm_dump();
log!("log path: {}", mm.log_path.display());

let _electrum = block_on(enable_electrum(
&mm,
"BCH",
false,
&[
"electroncash.de:50003",
"tbch.loping.net:60001",
"blackie.c3-soft.com:60001",
"bch0.kister.net:51001",
"testnet.imaginary.cash:50001",
],
None,
));
let _electrum = block_on(enable_electrum(&mm, "BCH", false, T_BCH_ELECTRUMS, None));

// test standard to cashaddress
let rc = block_on(mm.rpc(&json! ({
Expand Down
5 changes: 3 additions & 2 deletions mm2src/mm2_test_helpers/src/for_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub const QRC20_ELECTRUMS: &[&str] = &[
"electrum2.cipig.net:10071",
"electrum3.cipig.net:10071",
];
pub const T_BCH_ELECTRUMS: &[&str] = &["tbch.loping.net:60001", "bch0.kister.net:51001"];
pub const TBTC_ELECTRUMS: &[&str] = &[
"electrum1.cipig.net:10068",
"electrum2.cipig.net:10068",
Expand Down Expand Up @@ -1732,7 +1733,7 @@ pub enum UtxoRpcMode {
}

#[cfg(not(target_arch = "wasm32"))]
fn electrum_servers_rpc(servers: &[&str]) -> Vec<ElectrumRpcRequest> {
pub fn electrum_servers_rpc(servers: &[&str]) -> Vec<ElectrumRpcRequest> {
servers
.iter()
.map(|url| ElectrumRpcRequest {
Expand All @@ -1743,7 +1744,7 @@ fn electrum_servers_rpc(servers: &[&str]) -> Vec<ElectrumRpcRequest> {
}

#[cfg(target_arch = "wasm32")]
fn electrum_servers_rpc(servers: &[&str]) -> Vec<ElectrumRpcRequest> {
pub fn electrum_servers_rpc(servers: &[&str]) -> Vec<ElectrumRpcRequest> {
servers
.iter()
.map(|url| ElectrumRpcRequest {
Expand Down

0 comments on commit 222a851

Please sign in to comment.