Skip to content

Commit

Permalink
Avoid clippy warnings on zcash native tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rozhkovdmitrii committed Apr 24, 2023
1 parent 1624045 commit 1b0cd3a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fmt-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: cargo fmt -- --check

- name: x86-64 code lint
run: cargo clippy --all-targets --all-features --profile ci -- --D warnings
run: cargo clippy --all-targets --all-features -- --D warnings

wasm-lint:
timeout-minutes: 45
Expand Down
10 changes: 1 addition & 9 deletions mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,7 @@ impl ZCoin {
pub fn consensus_params_ref(&self) -> &ZcoinConsensusParams { &self.z_fields.consensus_params }

pub async fn is_sapling_state_synced(&self) -> bool {
matches!(
self.z_fields
.sync_state_connector
.lock()
.await
.current_sync_status()
.await,
Ok(SyncStatus::Finished { block_number: _ })
)
matches!(self.sync_status().await, Ok(SyncStatus::Finished { block_number: _ }))
}

#[inline]
Expand Down
138 changes: 61 additions & 77 deletions mm2src/coins/z_coin/z_coin_native_tests.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
use crate::{CoinProtocol, IguanaPrivKey};
use bitcrypto::dhash160;
use common::block_on;
use common::now_ms;
use common::{block_on, now_ms};
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::zombie_conf;
use std::path::PathBuf;
use std::time::Duration;
use zcash_client_backend::encoding::decode_extended_spending_key;

use super::*;
use crate::z_coin::{z_htlc::z_send_dex_fee, ZcoinActivationParams};
use super::{z_coin_from_conf_and_params_with_z_key, z_mainnet_constants, Future, PrivKeyBuildPolicy,
RefundPaymentArgs, SendPaymentArgs, SpendPaymentArgs, SwapOps, ValidateFeeArgs, ValidatePaymentError,
ZTransaction};
use crate::z_coin::{z_htlc::z_send_dex_fee, ZcoinActivationParams, ZcoinRpcMode};
use crate::CoinProtocol;

#[test]
fn zombie_coin_send_and_refund_maker_payment() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey(IguanaPrivKey::default());
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();

let mut conf = zombie_conf();
let params = default_zcoin_activation_params();
let pk_data = [1; 32];
let db_dir = PathBuf::from("./for_tests");

let params = ZcoinActivationParams {
mode: ZcoinRpcMode::Native,
required_confirmations: None,
requires_notarization: None,
zcash_params_path: None,
scan_blocks_per_iteration: 0,
scan_interval_ms: 0,
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();
let protocol_info = match serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() {
CoinProtocol::ZHTLC(protocol_info) => protocol_info,
other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol),
};

let mut conf = zombie_conf();
let CoinProtocol::ZHTLC(protocol_info) = serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() else { todo!() };

let coin = block_on(z_coin_from_conf_and_params_with_z_key(
&ctx,
"ZOMBIE",
&conf,
&params,
priv_key.clone(),
PrivKeyBuildPolicy::IguanaPrivKey(pk_data.into()),
db_dir,
z_key,
protocol_info,
Expand All @@ -60,15 +55,14 @@ fn zombie_coin_send_and_refund_maker_payment() {
};
let tx = coin.send_maker_payment(args).wait().unwrap();
println!("swap tx {}", hex::encode(tx.tx_hash().0));
let PrivKeyBuildPolicy::IguanaPrivKey(private_key_data) = priv_key else { todo!() };

let refund_args = RefundPaymentArgs {
payment_tx: &tx.tx_hex(),
time_lock,
other_pubkey: taker_pub,
secret_hash: &secret_hash,
swap_contract_address: &None,
swap_unique_data: private_key_data.as_slice(),
swap_unique_data: pk_data.as_slice(),
watcher_reward: false,
};
let refund_tx = coin.send_maker_refunds_payment(refund_args).wait().unwrap();
Expand All @@ -78,27 +72,22 @@ fn zombie_coin_send_and_refund_maker_payment() {
#[test]
fn zombie_coin_send_and_spend_maker_payment() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();

let db_dir = PathBuf::from("./for_tests");

let mut conf = zombie_conf();
let CoinProtocol::ZHTLC(protocol_info) = serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() else { todo!() };
let params = ZcoinActivationParams {
mode: ZcoinRpcMode::Native,
required_confirmations: None,
requires_notarization: None,
zcash_params_path: None,
scan_blocks_per_iteration: 0,
scan_interval_ms: 0,
let params = default_zcoin_activation_params();
let pk_data = [1; 32];
let db_dir = PathBuf::from("./for_tests");
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();
let protocol_info = match serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() {
CoinProtocol::ZHTLC(protocol_info) => protocol_info,
other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol),
};
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey(IguanaPrivKey::default());

let coin = block_on(z_coin_from_conf_and_params_with_z_key(
&ctx,
"ZOMBIE",
&conf,
&params,
priv_key.clone(),
PrivKeyBuildPolicy::IguanaPrivKey(pk_data.into()),
db_dir,
z_key,
protocol_info,
Expand Down Expand Up @@ -128,16 +117,14 @@ fn zombie_coin_send_and_spend_maker_payment() {

let maker_pub = taker_pub;

let PrivKeyBuildPolicy::IguanaPrivKey(private_key_data) = priv_key else { todo!() };

let spends_payment_args = SpendPaymentArgs {
other_payment_tx: &tx.tx_hex(),
time_lock: lock_time,
other_pubkey: maker_pub,
secret: &secret,
secret_hash: &[],
swap_contract_address: &None,
swap_unique_data: private_key_data.as_slice(),
swap_unique_data: pk_data.as_slice(),
watcher_reward: false,
};
let spend_tx = coin
Expand All @@ -150,21 +137,16 @@ fn zombie_coin_send_and_spend_maker_payment() {
#[test]
fn zombie_coin_send_dex_fee() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();

let db_dir = PathBuf::from("./for_tests");

let mut conf = zombie_conf();
let CoinProtocol::ZHTLC(protocol_info) = serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() else { todo!() };
let params = ZcoinActivationParams {
mode: ZcoinRpcMode::Native,
required_confirmations: None,
requires_notarization: None,
zcash_params_path: None,
scan_blocks_per_iteration: 0,
scan_interval_ms: 0,
let params = default_zcoin_activation_params();
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey([1; 32].into());
let db_dir = PathBuf::from("./for_tests");
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();
let protocol_info = match serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() {
CoinProtocol::ZHTLC(protocol_info) => protocol_info,
other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol),
};
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey(IguanaPrivKey::default());

let coin = block_on(z_coin_from_conf_and_params_with_z_key(
&ctx,
"ZOMBIE",
Expand All @@ -184,20 +166,16 @@ fn zombie_coin_send_dex_fee() {
#[test]
fn prepare_zombie_sapling_cache() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();

let db_dir = PathBuf::from("./for_tests");
let mut conf = zombie_conf();
let CoinProtocol::ZHTLC(protocol_info) = serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() else { todo!() };
let params = ZcoinActivationParams {
mode: ZcoinRpcMode::Native,
required_confirmations: None,
requires_notarization: None,
zcash_params_path: None,
scan_blocks_per_iteration: 0,
scan_interval_ms: 0,
let params = default_zcoin_activation_params();
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey([1; 32].into());
let db_dir = PathBuf::from("./for_tests");
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();
let protocol_info = match serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() {
CoinProtocol::ZHTLC(protocol_info) => protocol_info,
other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol),
};
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey(IguanaPrivKey::default());

let coin = block_on(z_coin_from_conf_and_params_with_z_key(
&ctx,
"ZOMBIE",
Expand All @@ -218,21 +196,16 @@ fn prepare_zombie_sapling_cache() {
#[test]
fn zombie_coin_validate_dex_fee() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();

let db_dir = PathBuf::from("./for_tests");

let mut conf = zombie_conf();
let CoinProtocol::ZHTLC(protocol_info) = serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() else { todo!() };
let params = ZcoinActivationParams {
mode: ZcoinRpcMode::Native,
required_confirmations: None,
requires_notarization: None,
zcash_params_path: None,
scan_blocks_per_iteration: 0,
scan_interval_ms: 0,
let params = default_zcoin_activation_params();
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey([1; 32].into());
let db_dir = PathBuf::from("./for_tests");
let z_key = decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, "secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe").unwrap().unwrap();
let protocol_info = match serde_json::from_value::<CoinProtocol>(conf["protocol"].take()).unwrap() {
CoinProtocol::ZHTLC(protocol_info) => protocol_info,
other_protocol => panic!("Failed to get protocol from config: {:?}", other_protocol),
};
let priv_key = PrivKeyBuildPolicy::IguanaPrivKey(IguanaPrivKey::default());

let coin = block_on(z_coin_from_conf_and_params_with_z_key(
&ctx,
"ZOMBIE",
Expand Down Expand Up @@ -307,3 +280,14 @@ fn zombie_coin_validate_dex_fee() {
};
coin.validate_fee(validate_fee_args).wait().unwrap();
}

fn default_zcoin_activation_params() -> ZcoinActivationParams {
ZcoinActivationParams {
mode: ZcoinRpcMode::Native,
required_confirmations: None,
requires_notarization: None,
zcash_params_path: None,
scan_blocks_per_iteration: 0,
scan_interval_ms: 0,
}
}
2 changes: 1 addition & 1 deletion mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn test_search_for_swap_tx_spend_native_was_refunded_maker() {

let search_input = SearchForSwapTxSpendInput {
time_lock,
other_pub: coin.my_public_key().unwrap().as_ref(),
other_pub: coin.my_public_key().unwrap(),
secret_hash: &[0; 20],
tx: &tx.tx_hex(),
search_from_block: 0,
Expand Down
3 changes: 2 additions & 1 deletion mm2src/mm2_main/tests/docker_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ mod swaps_file_lock_tests;

// dummy test helping IDE to recognize this as test module
#[test]
fn dummy() {}
#[allow(clippy::assertions_on_constants)]
fn dummy() { assert!(true) }
10 changes: 5 additions & 5 deletions mm2src/mm2_main/tests/mm2_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ mod zhtlc_native_reexport {
#[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))]
use zhtlc_native_reexport::*;

// dummy test helping IDE to recognize this as test module
#[test]
#[allow(clippy::assertions_on_constants)]
fn dummy() { assert!(true) }

#[cfg(all(feature = "zhtlc-native-tests", not(target_arch = "wasm32")))]
async fn enable_z_coin(mm: &MarketMakerIt, coin: &str) -> CoinActivationResult {
let init = init_z_coin_native(mm, coin).await;
Expand All @@ -46,3 +41,8 @@ async fn enable_z_coin(mm: &MarketMakerIt, coin: &str) -> CoinActivationResult {
}
}
}

// dummy test helping IDE to recognize this as test module
#[test]
#[allow(clippy::assertions_on_constants)]
fn dummy() { assert!(true) }

0 comments on commit 1b0cd3a

Please sign in to comment.