From 2559e0e1fbdf435cf501f4c7a833692608b4035e Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 8 Nov 2024 21:47:27 +0500 Subject: [PATCH] fix tests with burn key as taker --- mm2src/coins/lp_coins.rs | 12 +++++------ mm2src/coins/utxo/utxo_common.rs | 20 +++++++++---------- mm2src/mm2_main/src/lp_swap/maker_swap.rs | 6 +++--- mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs | 10 +++++----- mm2src/mm2_main/src/lp_swap/taker_swap.rs | 6 +++--- mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs | 10 +++++----- .../tests/docker_tests/docker_tests_common.rs | 6 +++--- .../tests/docker_tests/docker_tests_inner.rs | 8 ++++---- .../tests/docker_tests/swap_proto_v2_tests.rs | 14 ++++++------- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 2e88818bfa..08431fa03e 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -92,7 +92,7 @@ use utxo_signer::with_key_pair::UtxoSignWithKeyPairError; use zcash_primitives::transaction::Transaction as ZTransaction; #[cfg(feature = "for-tests")] -pub static mut TEST_DEX_FEE_ADDR_RAW_PUBKEY: Option> = None; +pub static mut TEST_BURN_ADDR_RAW_PUBKEY: Option> = None; cfg_native! { use crate::lightning::LightningCoin; @@ -1203,19 +1203,19 @@ pub trait SwapOps { fn maker_locktime_multiplier(&self) -> f64 { 2.0 } - fn dex_pubkey(&self) -> &[u8] { + fn dex_pubkey(&self) -> &[u8] { &DEX_FEE_ADDR_RAW_PUBKEY } + + fn burn_pubkey(&self) -> &[u8] { #[cfg(feature = "for-tests")] { unsafe { - if let Some(ref test_pk) = TEST_DEX_FEE_ADDR_RAW_PUBKEY { + if let Some(ref test_pk) = TEST_BURN_ADDR_RAW_PUBKEY { return test_pk.as_slice(); } } } - &DEX_FEE_ADDR_RAW_PUBKEY + &DEX_BURN_ADDR_RAW_PUBKEY } - - fn burn_pubkey(&self) -> &[u8] { &DEX_BURN_ADDR_RAW_PUBKEY } } /// Operations on maker coin from taker swap side diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index 89e41ff820..1b686a88ed 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -1285,20 +1285,20 @@ async fn gen_taker_payment_spend_preimage( { match *args.dex_fee { DexFee::NoFee => { - if args.taker_pub.to_vec().as_slice() != coin.dex_pubkey() { - panic!("taker pubkey must be equal to dex pubkey for DexFee::NoFee"); + if args.taker_pub.to_vec().as_slice() != coin.burn_pubkey() { + panic!("taker pubkey must be equal to burn pubkey for DexFee::NoFee"); } assert_eq!(outputs.len(), 1); // only the maker output }, DexFee::Standard(..) => { - if args.taker_pub.to_vec().as_slice() == coin.dex_pubkey() { - panic!("taker pubkey must NOT be equal to dex pubkey for DexFee::Standard"); + if args.taker_pub.to_vec().as_slice() == coin.burn_pubkey() { + panic!("taker pubkey must NOT be equal to burn pubkey for DexFee::Standard"); } assert_eq!(outputs.len(), 1); // only the dex fee output (maker output will be added later) }, DexFee::WithBurn { .. } => { - if args.taker_pub.to_vec().as_slice() == coin.dex_pubkey() { - panic!("taker pubkey must NOT be equal to dex pubkey for DexFee::WithBurn"); + if args.taker_pub.to_vec().as_slice() == coin.burn_pubkey() { + panic!("taker pubkey must NOT be equal to burn pubkey for DexFee::WithBurn"); } assert_eq!(outputs.len(), 3); // dex fee, burn and maker outputs }, @@ -1504,14 +1504,14 @@ where panic!("should not send dex fee for DexFee::NoFee"); }, DexFee::Standard(..) => { - if taker_pub.as_slice() == coin.dex_pubkey() { - panic!("taker pubkey must NOT be equal to dex pubkey for DexFee::Standard"); + if taker_pub.as_slice() == coin.burn_pubkey() { + panic!("taker pubkey must NOT be equal to burn pubkey for DexFee::Standard"); } assert_eq!(outputs.len(), 1); }, DexFee::WithBurn { .. } => { - if taker_pub.as_slice() == coin.dex_pubkey() { - panic!("taker pubkey must NOT be equal to dex pubkey for DexFee::WithBurn"); + if taker_pub.as_slice() == coin.burn_pubkey() { + panic!("taker pubkey must NOT be equal to burn pubkey for DexFee::WithBurn"); } assert_eq!(outputs.len(), 2); }, diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap.rs b/mm2src/mm2_main/src/lp_swap/maker_swap.rs index 6faa542821..8610373d46 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap.rs @@ -21,7 +21,7 @@ use coins::lp_price::fetch_swap_coins_price; use coins::swap_features::LegacySwapFeature; use coins::SWAP_PROTOCOL_VERSION; #[cfg(feature = "run-docker-tests")] -use coins::TEST_DEX_FEE_ADDR_RAW_PUBKEY; +use coins::TEST_BURN_ADDR_RAW_PUBKEY; use coins::{dex_fee_from_taker_coin, CanRefundHtlc, CheckIfMyPaymentSentArgs, ConfirmPaymentInput, DexFee, FeeApproxStage, FoundSwapTxSpend, MmCoin, MmCoinEnum, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs, SpendPaymentArgs, @@ -488,9 +488,9 @@ impl MakerSwap { async fn start(&self) -> Result<(Option, Vec), String> { #[cfg(feature = "run-docker-tests")] - if let Ok(env_pubkey) = std::env::var("TEST_DEX_FEE_ADDR_RAW_PUBKEY") { + if let Ok(env_pubkey) = std::env::var("TEST_BURN_ADDR_RAW_PUBKEY") { unsafe { - TEST_DEX_FEE_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); + TEST_BURN_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); } } diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 3579e46d87..2751a32f80 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -10,7 +10,7 @@ use crate::lp_swap::{swap_v2_pb::*, NO_REFUND_FEE}; use async_trait::async_trait; use bitcrypto::{dhash160, sha256}; #[cfg(feature = "run-docker-tests")] -use coins::TEST_DEX_FEE_ADDR_RAW_PUBKEY; +use coins::TEST_BURN_ADDR_RAW_PUBKEY; use coins::{dex_fee_from_taker_coin, CanRefundHtlc, ConfirmPaymentInput, DexFee, FeeApproxStage, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, MakerCoinSwapOpsV2, MmCoin, ParseCoinAssocTypes, RefundMakerPaymentSecretArgs, RefundMakerPaymentTimelockArgs, SearchForFundingSpendErr, @@ -470,9 +470,9 @@ impl Result<(RestoredMachine, Box>), Self::RecreateError> { #[cfg(feature = "run-docker-tests")] - if let Ok(env_pubkey) = std::env::var("TEST_DEX_FEE_ADDR_RAW_PUBKEY") { + if let Ok(env_pubkey) = std::env::var("TEST_BURN_ADDR_RAW_PUBKEY") { unsafe { - TEST_DEX_FEE_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); + TEST_BURN_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); } } @@ -808,9 +808,9 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { #[cfg(feature = "run-docker-tests")] - if let Ok(env_pubkey) = std::env::var("TEST_DEX_FEE_ADDR_RAW_PUBKEY") { + if let Ok(env_pubkey) = std::env::var("TEST_BURN_ADDR_RAW_PUBKEY") { unsafe { - TEST_DEX_FEE_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); + TEST_BURN_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); } } diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap.rs b/mm2src/mm2_main/src/lp_swap/taker_swap.rs index 26de407439..45eae4b02d 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap.rs @@ -21,7 +21,7 @@ use coins::lp_price::fetch_swap_coins_price; use coins::swap_features::LegacySwapFeature; use coins::SWAP_PROTOCOL_VERSION; #[cfg(feature = "run-docker-tests")] -use coins::TEST_DEX_FEE_ADDR_RAW_PUBKEY; +use coins::TEST_BURN_ADDR_RAW_PUBKEY; use coins::{dex_fee_from_taker_coin, lp_coinfind, CanRefundHtlc, CheckIfMyPaymentSentArgs, ConfirmPaymentInput, DexFee, FeeApproxStage, FoundSwapTxSpend, MmCoin, MmCoinEnum, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, RefundPaymentArgs, SearchForSwapTxSpendInput, SendPaymentArgs, SpendPaymentArgs, @@ -1039,9 +1039,9 @@ impl TakerSwap { async fn start(&self) -> Result<(Option, Vec), String> { #[cfg(feature = "run-docker-tests")] - if let Ok(env_pubkey) = std::env::var("TEST_DEX_FEE_ADDR_RAW_PUBKEY") { + if let Ok(env_pubkey) = std::env::var("TEST_BURN_ADDR_RAW_PUBKEY") { unsafe { - TEST_DEX_FEE_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); + TEST_BURN_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); } } diff --git a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs index 574c3da564..112eb00b73 100644 --- a/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs @@ -9,7 +9,7 @@ use crate::lp_swap::{swap_v2_pb::*, NO_REFUND_FEE}; use async_trait::async_trait; use bitcrypto::{dhash160, sha256}; #[cfg(feature = "run-docker-tests")] -use coins::TEST_DEX_FEE_ADDR_RAW_PUBKEY; +use coins::TEST_BURN_ADDR_RAW_PUBKEY; use coins::{dex_fee_from_taker_coin, CanRefundHtlc, ConfirmPaymentInput, DexFee, FeeApproxStage, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, MakerCoinSwapOpsV2, MmCoin, ParseCoinAssocTypes, RefundFundingSecretArgs, RefundTakerPaymentArgs, SendTakerFundingArgs, SpendMakerPaymentArgs, @@ -499,9 +499,9 @@ impl Result<(RestoredMachine, Box>), Self::RecreateError> { #[cfg(feature = "run-docker-tests")] - if let Ok(env_pubkey) = std::env::var("TEST_DEX_FEE_ADDR_RAW_PUBKEY") { + if let Ok(env_pubkey) = std::env::var("TEST_BURN_ADDR_RAW_PUBKEY") { unsafe { - TEST_DEX_FEE_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); + TEST_BURN_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); } } @@ -922,9 +922,9 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { #[cfg(feature = "run-docker-tests")] - if let Ok(env_pubkey) = std::env::var("TEST_DEX_FEE_ADDR_RAW_PUBKEY") { + if let Ok(env_pubkey) = std::env::var("TEST_BURN_ADDR_RAW_PUBKEY") { unsafe { - TEST_DEX_FEE_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); + TEST_BURN_ADDR_RAW_PUBKEY = Some(hex::decode(env_pubkey).expect("valid hex")); } } diff --git a/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs b/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs index 892f87b239..b3b711faa3 100644 --- a/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs +++ b/mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs @@ -104,7 +104,7 @@ pub static SEPOLIA_RPC_URL: &str = "https://ethereum-sepolia-rpc.publicnode.com" // use thread local to affect only the current running test thread_local! { /// Set test dex pubkey as Taker (to check DexFee::NoFee) - pub static SET_DEX_PUBKEY_TO_ALICE: Cell = Cell::new(false); + pub static SET_BURN_PUBKEY_TO_ALICE: Cell = Cell::new(false); pub static USE_NON_VERSIONED_MAKER: Cell = Cell::new(false); pub static USE_NON_VERSIONED_TAKER: Cell = Cell::new(false); } @@ -878,8 +878,8 @@ pub fn trade_base_rel((base, rel): (&str, &str)) { ); let mut envs = vec![]; - if SET_DEX_PUBKEY_TO_ALICE.get() { - envs.push(("TEST_DEX_FEE_ADDR_RAW_PUBKEY", alice_pubkey_str.as_str())); + if SET_BURN_PUBKEY_TO_ALICE.get() { + envs.push(("TEST_BURN_ADDR_RAW_PUBKEY", alice_pubkey_str.as_str())); } if USE_NON_VERSIONED_MAKER.get() { envs.push(("USE_NON_VERSIONED_MAKER", "true")); diff --git a/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs b/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs index 5f194f321d..69ce1afb48 100644 --- a/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs +++ b/mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs @@ -1,5 +1,5 @@ use crate::docker_tests::docker_tests_common::{generate_utxo_coin_with_privkey, trade_base_rel, GETH_RPC_URL, MM_CTX, - SET_DEX_PUBKEY_TO_ALICE}; + SET_BURN_PUBKEY_TO_ALICE}; use crate::docker_tests::eth_docker_tests::{erc20_coin_with_random_privkey, erc20_contract_checksum, fill_eth_erc20_with_private_key, swap_contract}; use crate::{fill_address, generate_utxo_coin_with_random_privkey, random_secp256k1_secret, rmd160_from_priv, @@ -3891,10 +3891,10 @@ fn test_trade_base_rel_eth_erc20_coins() { trade_base_rel(("ETH", "ERC20DEV")); #[test] fn test_trade_base_rel_mycoin_mycoin1_coins() { trade_base_rel(("MYCOIN", "MYCOIN1")); } -// run swap with dex pubkey set to alice +// run swap with burn pubkey set to alice (no dex fee) #[test] -fn test_trade_base_rel_mycoin_mycoin1_coins_dex_as_alice() { - SET_DEX_PUBKEY_TO_ALICE.set(true); +fn test_trade_base_rel_mycoin_mycoin1_coins_burnkey_as_alice() { + SET_BURN_PUBKEY_TO_ALICE.set(true); trade_base_rel(("MYCOIN", "MYCOIN1")); } diff --git a/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs b/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs index a899c7dfd2..4c028b28b6 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_proto_v2_tests.rs @@ -1,4 +1,4 @@ -use crate::{generate_utxo_coin_with_random_privkey, MYCOIN, MYCOIN1, SET_DEX_PUBKEY_TO_ALICE}; +use crate::{generate_utxo_coin_with_random_privkey, MYCOIN, MYCOIN1, SET_BURN_PUBKEY_TO_ALICE}; use bitcrypto::dhash160; use coins::utxo::UtxoCommonOps; use coins::{ConfirmPaymentInput, DexFee, FundingTxSpend, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, @@ -623,10 +623,10 @@ fn send_and_refund_maker_payment_taker_secret() { #[test] fn test_v2_swap_utxo_utxo() { test_v2_swap_utxo_utxo_impl(); } -// test a swap when taker is dex pubkey (no dex fee should be paid) +// test a swap when taker is burn pubkey (no dex fee should be paid) #[test] -fn test_v2_swap_utxo_utxo_dex_as_alice() { - SET_DEX_PUBKEY_TO_ALICE.set(true); +fn test_v2_swap_utxo_utxo_burnkey_as_alice() { + SET_BURN_PUBKEY_TO_ALICE.set(true); test_v2_swap_utxo_utxo_impl(); } @@ -642,8 +642,8 @@ fn test_v2_swap_utxo_utxo_impl() { .to_vec(), ); let mut envs = vec![]; - if SET_DEX_PUBKEY_TO_ALICE.get() { - envs.push(("TEST_DEX_FEE_ADDR_RAW_PUBKEY", alice_pubkey_str.as_str())); + if SET_BURN_PUBKEY_TO_ALICE.get() { + envs.push(("TEST_BURN_ADDR_RAW_PUBKEY", alice_pubkey_str.as_str())); } let bob_conf = Mm2TestConf::seednode_trade_v2(&format!("0x{}", hex::encode(bob_priv_key)), &coins); @@ -715,7 +715,7 @@ fn test_v2_swap_utxo_utxo_impl() { let locked_alice = block_on(get_locked_amount(&mm_alice, MYCOIN1)); assert_eq!(locked_alice.coin, MYCOIN1); - let expected: MmNumberMultiRepr = if SET_DEX_PUBKEY_TO_ALICE.get() { + let expected: MmNumberMultiRepr = if SET_BURN_PUBKEY_TO_ALICE.get() { MmNumber::from("777.00001").into() // no dex fee if dex pubkey is alice } else { MmNumber::from("778.00001").into()