Skip to content

Commit

Permalink
Merge branch 'dev' into fix-arrr-note-saving
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Feb 19, 2025
2 parents e4e6114 + a559236 commit 6d0871a
Show file tree
Hide file tree
Showing 22 changed files with 211 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,4 @@ jobs:
uses: ./.github/actions/build-cache

- name: Test
run: WASM_BINDGEN_TEST_TIMEOUT=480 GECKODRIVER=/bin/geckodriver wasm-pack test --firefox --headless mm2src/mm2_main
run: WASM_BINDGEN_TEST_TIMEOUT=600 GECKODRIVER=/bin/geckodriver wasm-pack test --firefox --headless mm2src/mm2_main
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cfg_native!(

use common::{now_sec, block_on_f01};
use ethkey::{Generator, Random};
use mm2_test_helpers::for_tests::{ETH_MAINNET_CHAIN_ID, ETH_MAINNET_NODE, ETH_SEPOLIA_CHAIN_ID, ETH_SEPOLIA_NODES,
use mm2_test_helpers::for_tests::{ETH_MAINNET_CHAIN_ID, ETH_MAINNET_NODES, ETH_SEPOLIA_CHAIN_ID, ETH_SEPOLIA_NODES,
ETH_SEPOLIA_TOKEN_CONTRACT};
use mocktopus::mocking::*;

Expand Down Expand Up @@ -547,7 +547,7 @@ fn test_get_fee_to_send_taker_fee_insufficient_balance() {
platform: "ETH".to_string(),
token_addr: Address::from_str("0xaD22f63404f7305e4713CcBd4F296f34770513f4").unwrap(),
},
&[ETH_MAINNET_NODE],
ETH_MAINNET_NODES,
None,
ETH_MAINNET_CHAIN_ID,
);
Expand All @@ -568,7 +568,7 @@ fn test_get_fee_to_send_taker_fee_insufficient_balance() {
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn validate_dex_fee_invalid_sender_eth() {
let (_ctx, coin) = eth_coin_for_test(EthCoinType::Eth, &[ETH_MAINNET_NODE], None, ETH_MAINNET_CHAIN_ID);
let (_ctx, coin) = eth_coin_for_test(EthCoinType::Eth, ETH_MAINNET_NODES, None, ETH_MAINNET_CHAIN_ID);
// the real dex fee sent on mainnet
// https://etherscan.io/tx/0x7e9ca16c85efd04ee5e31f2c1914b48f5606d6f9ce96ecce8c96d47d6857278f
let tx = block_on(block_on(coin.web3()).unwrap().eth().transaction(TransactionId::Hash(
Expand Down Expand Up @@ -601,7 +601,7 @@ fn validate_dex_fee_invalid_sender_erc() {
platform: "ETH".to_string(),
token_addr: Address::from_str("0xa1d6df714f91debf4e0802a542e13067f31b8262").unwrap(),
},
&[ETH_MAINNET_NODE],
ETH_MAINNET_NODES,
None,
ETH_MAINNET_CHAIN_ID,
);
Expand Down Expand Up @@ -642,7 +642,7 @@ fn sender_compressed_pub(tx: &SignedEthTx) -> [u8; 33] {
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn validate_dex_fee_eth_confirmed_before_min_block() {
let (_ctx, coin) = eth_coin_for_test(EthCoinType::Eth, &[ETH_MAINNET_NODE], None, ETH_MAINNET_CHAIN_ID);
let (_ctx, coin) = eth_coin_for_test(EthCoinType::Eth, ETH_MAINNET_NODES, None, ETH_MAINNET_CHAIN_ID);
// the real dex fee sent on mainnet
// https://etherscan.io/tx/0x7e9ca16c85efd04ee5e31f2c1914b48f5606d6f9ce96ecce8c96d47d6857278f
let tx = block_on(block_on(coin.web3()).unwrap().eth().transaction(TransactionId::Hash(
Expand Down Expand Up @@ -677,7 +677,7 @@ fn validate_dex_fee_erc_confirmed_before_min_block() {
platform: "ETH".to_string(),
token_addr: Address::from_str("0xa1d6df714f91debf4e0802a542e13067f31b8262").unwrap(),
},
&[ETH_MAINNET_NODE],
ETH_MAINNET_NODES,
None,
ETH_MAINNET_CHAIN_ID,
);
Expand Down Expand Up @@ -711,7 +711,7 @@ fn validate_dex_fee_erc_confirmed_before_min_block() {
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_negotiate_swap_contract_addr_no_fallback() {
let (_, coin) = eth_coin_for_test(EthCoinType::Eth, &[ETH_MAINNET_NODE], None, ETH_MAINNET_CHAIN_ID);
let (_, coin) = eth_coin_for_test(EthCoinType::Eth, ETH_MAINNET_NODES, None, ETH_MAINNET_CHAIN_ID);

let input = None;
let error = coin.negotiate_swap_contract_addr(input).unwrap_err().into_inner();
Expand Down Expand Up @@ -743,7 +743,7 @@ fn test_negotiate_swap_contract_addr_has_fallback() {

let (_, coin) = eth_coin_for_test(
EthCoinType::Eth,
&[ETH_MAINNET_NODE],
ETH_MAINNET_NODES,
Some(fallback),
ETH_MAINNET_CHAIN_ID,
);
Expand Down
30 changes: 19 additions & 11 deletions mm2src/coins/nft/nft_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::eth::eth_addr_to_hex;
use crate::nft::nft_structs::{Chain, NftFromMoralis, NftListFilters, NftTransferHistoryFilters,
NftTransferHistoryFromMoralis, PhishingDomainReq, PhishingDomainRes, SpamContractReq,
SpamContractRes, TransferMeta, UriMeta};
SpamContractRes, TransferMeta};
use crate::nft::storage::db_test_helpers::{get_nft_ctx, nft, nft_list, nft_transfer_history};
use crate::nft::storage::{NftListStorageOps, NftTransferHistoryStorageOps, RemoveNftResult};
use crate::nft::{check_moralis_ipfs_bafy, get_domain_from_url, is_malicious, process_metadata_for_spam_link,
Expand Down Expand Up @@ -152,16 +152,24 @@ cross_test!(test_antispam_scan_endpoints, {
assert!(phishing_res.result.get("disposal-account-case-1f677.web.app").unwrap());
});

cross_test!(test_camo, {
let hex_token_uri = hex::encode("https://tikimetadata.s3.amazonaws.com/tiki_box.json");
let uri_decode = format!("{}/url/decode/{}", BLOCKLIST_API_ENDPOINT, hex_token_uri);
let decode_res = send_request_to_uri(&uri_decode, None).await.unwrap();
let uri_meta: UriMeta = serde_json::from_value(decode_res).unwrap();
assert_eq!(
uri_meta.raw_image_url.unwrap(),
"https://tikimetadata.s3.amazonaws.com/tiki_box.png"
);
});
// Disabled on Linux: https://github.com/KomodoPlatform/komodo-defi-framework/issues/2367
cross_test!(
test_camo,
{
use crate::nft::nft_structs::UriMeta;

let hex_token_uri = hex::encode("https://tikimetadata.s3.amazonaws.com/tiki_box.json");
let uri_decode = format!("{}/url/decode/{}", BLOCKLIST_API_ENDPOINT, hex_token_uri);
let decode_res = send_request_to_uri(&uri_decode, None).await.unwrap();
let uri_meta: UriMeta = serde_json::from_value(decode_res).unwrap();
assert_eq!(
uri_meta.raw_image_url.unwrap(),
"https://tikimetadata.s3.amazonaws.com/tiki_box.png"
);
},
target_os = "macos",
target_os = "windows"
);

cross_test!(test_add_get_nfts, {
let chain = Chain::Bsc;
Expand Down
3 changes: 2 additions & 1 deletion mm2src/coins/qrc20/qrc20_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use itertools::Itertools;
use keys::Address;
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_number::bigdecimal::Zero;
use mm2_test_helpers::electrums::tqtum_electrums;
use rpc::v1::types::ToTxHash;
use std::convert::TryFrom;
use std::mem::discriminant;
Expand Down Expand Up @@ -37,7 +38,7 @@ pub fn qrc20_coin_for_test(priv_key: [u8; 32], fallback_swap: Option<&str>) -> (
});
let req = json!({
"method": "electrum",
"servers": [{"url":"electrum1.cipig.net:10071"}, {"url":"electrum2.cipig.net:10071"}, {"url":"electrum3.cipig.net:10071"}],
"servers": tqtum_electrums(),
"swap_contract_address": "0xba8b71f3544b93e2f681f996da519a98ace0107a",
"fallback_swap_contract": fallback_swap,
});
Expand Down
24 changes: 13 additions & 11 deletions mm2src/coins/z_coin/storage/blockdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ mod native_tests {
mod wasm_tests {
use crate::z_coin::storage::blockdb::block_db_storage_tests::{test_insert_block_and_get_latest_block_impl,
test_rewind_to_height_impl};
use crate::z_coin::z_rpc::{LightRpcClient, ZRpcOps};
use common::log::info;
use common::log::wasm_log::register_wasm_log;
// use crate::z_coin::z_rpc::{LightRpcClient, ZRpcOps};
// use common::log::info;
// use common::log::wasm_log::register_wasm_log;
use common::log::warn;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);
Expand All @@ -124,13 +125,14 @@ mod wasm_tests {

#[wasm_bindgen_test]
async fn test_transport() {
register_wasm_log();
let client = LightRpcClient::new(vec!["https://pirate.battlefield.earth:8581".to_string()])
.await
.unwrap();
let latest_height = client.get_block_height().await;

assert!(latest_height.is_ok());
info!("LATEST BLOCK: {latest_height:?}");
warn!("Skipping test_transport since it's failing, check https://github.com/KomodoPlatform/komodo-defi-framework/issues/2366");
// register_wasm_log();
// let client = LightRpcClient::new(vec!["https://pirate.battlefield.earth:8581".to_string()])
// .await
// .unwrap();
// let latest_height = client.get_block_height().await;
//
// assert!(latest_height.is_ok());
// info!("LATEST BLOCK: {latest_height:?}");
}
}
1 change: 1 addition & 0 deletions mm2src/coins/z_coin/tx_streaming_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use mm2_test_helpers::for_tests::{PIRATE_ELECTRUMS, PIRATE_LIGHTWALLETD_URLS};
use crate::utxo::rpc_clients::ElectrumConnectionSettings;
use crate::z_coin::{ZcoinActivationParams, ZcoinRpcMode};

#[allow(dead_code)]
fn light_zcoin_activation_params() -> ZcoinActivationParams {
ZcoinActivationParams {
mode: ZcoinRpcMode::Light {
Expand Down
140 changes: 71 additions & 69 deletions mm2src/coins/z_coin/tx_streaming_tests/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
use common::custom_futures::timeout::FutureTimerExt;
use common::{executor::Timer, Future01CompatExt};
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::{pirate_conf, ARRR};
// use common::custom_futures::timeout::FutureTimerExt;
// use common::{executor::Timer, Future01CompatExt};
// use mm2_core::mm_ctx::MmCtxBuilder;
// use mm2_test_helpers::for_tests::{pirate_conf, ARRR};
use common::log::warn;
use wasm_bindgen_test::*;

use super::light_zcoin_activation_params;
use crate::z_coin::tx_history_events::ZCoinTxHistoryEventStreamer;
use crate::z_coin::z_coin_from_conf_and_params;
use crate::z_coin::z_htlc::z_send_dex_fee;
use crate::PrivKeyBuildPolicy;
use crate::{CoinProtocol, MarketCoinOps, MmCoin};
//
// use super::light_zcoin_activation_params;
// use crate::z_coin::tx_history_events::ZCoinTxHistoryEventStreamer;
// use crate::z_coin::z_coin_from_conf_and_params;
// use crate::z_coin::z_htlc::z_send_dex_fee;
// use crate::PrivKeyBuildPolicy;
// use crate::{CoinProtocol, MarketCoinOps, MmCoin};

#[wasm_bindgen_test]
async fn test_zcoin_tx_streaming() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let conf = pirate_conf();
let params = light_zcoin_activation_params();
// Address: RQX5MnqnxEk6P33LSEAxC2vqA7DfSdWVyH
// Or: zs1n2azlwcj9pvl2eh36qvzgeukt2cpzmw44hya8wyu52j663d0dfs4d5hjx6tr04trz34jxyy433j
let priv_key_policy =
PrivKeyBuildPolicy::IguanaPrivKey("6d862798ef956fb60fb17bcc417dd6d44bfff066a4a49301cd2528e41a4a3e45".into());
let protocol_info = match serde_json::from_value::<CoinProtocol>(conf["protocol"].clone()).unwrap() {
CoinProtocol::ZHTLC(protocol_info) => protocol_info,
other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol),
};

let coin = z_coin_from_conf_and_params(&ctx, ARRR, &conf, &params, protocol_info, priv_key_policy)
.await
.unwrap();

// Wait till we are synced with the sapling state.
while !coin.is_sapling_state_synced().await {
Timer::sleep(1.).await;
}

// Query the block height to make sure our electrums are actually connected.
log!("current block = {:?}", coin.current_block().compat().await.unwrap());

// Add a new client to use it for listening to tx history events.
let client_id = 1;
let mut event_receiver = ctx.event_stream_manager.new_client(client_id).unwrap();
// Add the streamer that will stream the tx history events.
let streamer = ZCoinTxHistoryEventStreamer::new(coin.clone());
// Subscribe the client to the streamer.
ctx.event_stream_manager
.add(client_id, streamer, coin.spawner())
.await
.unwrap();

// Send a tx to have it in the tx history.
let tx = z_send_dex_fee(&coin, "0.0001".parse().unwrap(), &[1; 16])
.await
.unwrap();

// Wait for the tx history event (should be streamed next block).
let event = Box::pin(event_receiver.recv())
.timeout_secs(120.)
.await
.expect("timed out waiting for tx to showup")
.expect("tx history sender shutdown");

log!("{:?}", event.get());
let (event_type, event_data) = event.get();
// Make sure this is not an error event,
assert!(!event_type.starts_with("ERROR_"));
// from the expected streamer,
assert_eq!(
event_type,
ZCoinTxHistoryEventStreamer::derive_streamer_id(coin.ticker())
);
// and has the expected data.
assert_eq!(event_data["tx_hash"].as_str().unwrap(), tx.txid().to_string());
warn!("Skipping test_zcoin_tx_streaming since it's failing, check https://github.com/KomodoPlatform/komodo-defi-framework/issues/2366");
// let ctx = MmCtxBuilder::default().into_mm_arc();
// let conf = pirate_conf();
// let params = light_zcoin_activation_params();
// // Address: RQX5MnqnxEk6P33LSEAxC2vqA7DfSdWVyH
// // Or: zs1n2azlwcj9pvl2eh36qvzgeukt2cpzmw44hya8wyu52j663d0dfs4d5hjx6tr04trz34jxyy433j
// let priv_key_policy =
// PrivKeyBuildPolicy::IguanaPrivKey("6d862798ef956fb60fb17bcc417dd6d44bfff066a4a49301cd2528e41a4a3e45".into());
// let protocol_info = match serde_json::from_value::<CoinProtocol>(conf["protocol"].clone()).unwrap() {
// CoinProtocol::ZHTLC(protocol_info) => protocol_info,
// other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol),
// };
//
// let coin = z_coin_from_conf_and_params(&ctx, ARRR, &conf, &params, protocol_info, priv_key_policy)
// .await
// .unwrap();
//
// // Wait till we are synced with the sapling state.
// while !coin.is_sapling_state_synced().await {
// Timer::sleep(1.).await;
// }
//
// // Query the block height to make sure our electrums are actually connected.
// log!("current block = {:?}", coin.current_block().compat().await.unwrap());
//
// // Add a new client to use it for listening to tx history events.
// let client_id = 1;
// let mut event_receiver = ctx.event_stream_manager.new_client(client_id).unwrap();
// // Add the streamer that will stream the tx history events.
// let streamer = ZCoinTxHistoryEventStreamer::new(coin.clone());
// // Subscribe the client to the streamer.
// ctx.event_stream_manager
// .add(client_id, streamer, coin.spawner())
// .await
// .unwrap();
//
// // Send a tx to have it in the tx history.
// let tx = z_send_dex_fee(&coin, "0.0001".parse().unwrap(), &[1; 16])
// .await
// .unwrap();
//
// // Wait for the tx history event (should be streamed next block).
// let event = Box::pin(event_receiver.recv())
// .timeout_secs(120.)
// .await
// .expect("timed out waiting for tx to showup")
// .expect("tx history sender shutdown");
//
// log!("{:?}", event.get());
// let (event_type, event_data) = event.get();
// // Make sure this is not an error event,
// assert!(!event_type.starts_with("ERROR_"));
// // from the expected streamer,
// assert_eq!(
// event_type,
// ZCoinTxHistoryEventStreamer::derive_streamer_id(coin.ticker())
// );
// // and has the expected data.
// assert_eq!(event_data["tx_hash"].as_str().unwrap(), tx.txid().to_string());
}
12 changes: 9 additions & 3 deletions mm2src/common/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ macro_rules! some_or_return_ok_none {
#[macro_export]
macro_rules! cross_test {
($test_name:ident, $test_code:block) => {
#[cfg(not(target_arch = "wasm32"))]
#[tokio::test(flavor = "multi_thread")]
async fn $test_name() { $test_code }
cross_test!($test_name, $test_code, not(target_arch = "wasm32"));
};

($test_name:ident, $test_code:block, $($cfgs:meta),+) => {
$(
#[cfg($cfgs)]
#[tokio::test(flavor = "multi_thread")]
async fn $test_name() { $test_code }
)+

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen_test]
Expand Down
1 change: 1 addition & 0 deletions mm2src/common/custom_futures/repeatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ mod tests {
}

#[test]
#[cfg(not(target_os = "macos"))] // https://github.com/KomodoPlatform/komodo-defi-framework/issues/1712#issuecomment-2669934159
fn test_until_success() {
const ATTEMPTS_TO_FINISH: usize = 5;
const LOWEST_TIMEOUT: Duration = Duration::from_millis(350);
Expand Down
5 changes: 5 additions & 0 deletions mm2src/crypto/src/key_derivation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ pub(crate) fn derive_keys_for_mnemonic(

/// Splits a path into its components and derives a key for each component.
fn derive_key_from_path(master_node: &[u8], path: &str) -> MmResult<[u8; 32], KeyDerivationError> {
if master_node.len() < 64 {
return MmError::err(KeyDerivationError::InvalidKeyLength);
}

let mut current_key_material = master_node.to_vec();

for segment in path.split('/').filter(|s| !s.is_empty()) {
let mut mac = HmacSha512::new_from_slice(&current_key_material[..32])
.map_err(|_| KeyDerivationError::HmacInitialization)?;
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_bin_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

[package]
name = "mm2_bin_lib"
version = "2.3.0-beta"
authors = ["James Lee", "Artem Pikulin", "Artem Grinblat", "Omar S.", "Onur Ozkan", "Alina Sharon", "Caglar Kaya", "Cipi", "Sergey Boiko", "Samuel Onoja", "Roman Sztergbaum", "Kadan Stadelmann <ca333@komodoplatform.com>", "Dimxy", "Omer Yacine"]
version = "2.4.0-beta"
authors = ["James Lee", "Artem Pikulin", "Artem Grinblat", "Omar S.", "Onur Ozkan", "Alina Sharon", "Caglar Kaya", "Cipi", "Sergey Boiko", "Samuel Onoja", "Roman Sztergbaum", "Kadan Stadelmann <ca333@komodoplatform.com>", "Dimxy", "Omer Yacine", "DeckerSU"]
edition = "2018"
default-run = "kdf"

Expand Down
Loading

0 comments on commit 6d0871a

Please sign in to comment.