Skip to content
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
f3625e5
make mockable optional
Apr 27, 2024
d3f843d
add support for utxo coin burn account to dex fee
Apr 29, 2024
bc5c005
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Apr 29, 2024
7894f7d
remove left over dup dex_fee_rate()
Apr 29, 2024
2984c67
fix coins crate mocktopus dependency for mm2_main crate tests
Apr 29, 2024
128c4b4
fix dex fee changed due to new burn output in couple of lp_swap tests
Apr 29, 2024
23f2a08
fix swap v2 test non-kmd burn output
May 1, 2024
2c810b0
fix fmt
May 6, 2024
af45b71
remove comment
May 6, 2024
0e2869e
Merge branch 'dev' into burn-dex-fee-for-non-kmd
May 14, 2024
0f34d2e
Merge branch 'dev' into burn-dex-fee-for-non-kmd
May 22, 2024
d53dc37
fix zombie chain scan block num
Jun 14, 2024
81263e0
add burn output for privacy coin,
Jun 14, 2024
7719b80
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Jun 16, 2024
9331e40
use custom log! instead debug! (as env_logger disabled) in qrc20 dock…
Jun 17, 2024
b343275
fix to make should_burn_dex_fee explicitly in each coin (to fix qrc20…
Jun 17, 2024
587b1ae
restore original test log message
Jun 17, 2024
58d84cf
add test for std dex fee for zcoin
Jun 17, 2024
1243935
remove unused cache dir var in z_coin init block
Jun 17, 2024
bc00ee8
fix clippy
Jun 18, 2024
4d59545
fix burn addr in ZOutput
Jun 19, 2024
dc9e710
refactor dex fee code;
Jun 19, 2024
7a2399c
refactor dex fee code to eliminate extra if-else
Jun 19, 2024
4625554
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Jul 3, 2024
b84b3a9
fix comments (by review notes)
Jul 3, 2024
35b04a2
refactor var names on review notes
Aug 7, 2024
8b1033e
refactor fee_amount var names to dex_fee (as those are structs)
Aug 7, 2024
1a48a04
add test for qtum dex fee with burn output validation
Aug 7, 2024
06e36b5
remove todo for qrc20 with burn test (as we decided not to add evm bu…
Aug 7, 2024
1e79216
fix fn should_burn_dex_fee uninmlemented for solana
Aug 8, 2024
9fd47a4
fix restore cach_db_path (deleted by mistake)
Aug 9, 2024
217a313
fix review notes: delete unused fn, add cfg for test code
Aug 9, 2024
f35be00
fix review: add test from todo
Aug 9, 2024
26552c3
add NegotiationDataMsg V4 with version field, add swap features activ…
Aug 11, 2024
c02253a
add non-kmd burn activation with negotiation msg V4
Aug 11, 2024
fd5b4fe
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Aug 12, 2024
22b5c42
added NegotiationDataMsgVersion, removed NegotiationDataV4 (bcz V2 is…
Aug 12, 2024
9951626
fix activation ver
Aug 12, 2024
d72a313
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Aug 12, 2024
a63c3e0
fix after merge
Aug 12, 2024
983d8ef
remove relaxed dex fee validation (in favour versioned check)
Aug 13, 2024
849b190
add mocktopus to mm2_main
Aug 13, 2024
8e2fdaf
fix version in recreate swap
Aug 13, 2024
b844318
fix node version determination: try versioned then old negotiation me…
Aug 13, 2024
ddb4863
add test feature to emulate old non-versioned negotiation msgs (also …
Aug 14, 2024
9a34268
fix fmt
Aug 14, 2024
f8b543b
fix swap tx spend size
Aug 15, 2024
44a2586
move version activation swap_feature mod to coins (to allow using it …
Aug 17, 2024
e6fe67f
add delay between broadcasts of new and old messages
Aug 17, 2024
b20e679
fix old (non-versioned) taker and maker emulation (for tests)
Aug 17, 2024
e930f58
fix swap proto version: use new topic for versioned negotiation (Swap…
Aug 19, 2024
80d34f6
fix comment
Aug 19, 2024
5cc210e
add DexFee::NoFee option support for utxo if taker is dex pubkey (dex…
Aug 24, 2024
69cbfa4
add tests for swap v1 mycoin to mycoin with dex pubkey as Alice (to t…
Aug 24, 2024
248536a
fix tests to validate fee and recreate swaps
Aug 25, 2024
b0fabcf
fix DexFee::NoFee taker payment spending outputs for swaps V2
Aug 26, 2024
f6cc684
fix tests for no dex fee for swaps v1, add tests for no dex fee for s…
Aug 26, 2024
7053e2e
fix TODO for delay in broadcast msgs
Aug 26, 2024
1def60d
fixes for review notes
Aug 26, 2024
74d8ea3
fixes for review notes
Aug 26, 2024
bc560b8
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Sep 13, 2024
c4b494a
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Oct 4, 2024
347093d
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Oct 21, 2024
f95b91e
add dex fee burning for tendermint coins
Oct 31, 2024
e19b738
fix should_burn_dex_fee to true and burn_pubkey for validate dex fee …
Oct 31, 2024
446b3db
add mockable support for TendermintCoin (note: some TendermintCoin co…
Nov 1, 2024
8aa7a06
refactor validate_taker_fee_test with mocked txns
Nov 1, 2024
53a553f
add test to validate taker fee tx with burn for tendermint
Nov 1, 2024
2f47bdc
add test to calc DexFee with burn for nucleus ticker
Nov 1, 2024
a61d4a0
Refactor dex fee code:
Nov 2, 2024
63ecd0b
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Nov 2, 2024
29ad460
fix await in zhtlc tests
Nov 2, 2024
2ea8b9f
add TODO zhtlc feature
Nov 2, 2024
ab4f2a5
fix fmt
Nov 2, 2024
8711131
add comments how to run zcoin native tests
Nov 4, 2024
bf65293
add print into tests with hint how to sync wallet db
Nov 4, 2024
5f0d3d6
add debug logging for updating zcoin wallet db
Nov 4, 2024
b3eccf8
add scan interval in zcoin tests to prevent 'Can't assign requested a…
Nov 5, 2024
d5b9bbd
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Nov 5, 2024
b92d065
fix review notes
Nov 7, 2024
601519d
fix build err
Nov 7, 2024
05feb72
add swap feature deactivation by version
Nov 7, 2024
ce1a5e0
improve comments for protocol version
Nov 7, 2024
dcfdbbd
fix burn_pubkey as taker in DexFee::NoFee;
Nov 8, 2024
dfb9673
fix fmt
Nov 8, 2024
2559e0e
fix tests with burn key as taker
Nov 8, 2024
70a8bd0
add real burn addr pubkey
shamardy Jan 15, 2025
0a36a09
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Jan 16, 2025
51b58d7
fix: remove compatibility with old swap nodes (no need this anymore)
Jan 17, 2025
1e24dcf
fix test to reject too old nodes
Jan 17, 2025
ea4d046
temp disable burn dex fee for zcoin
Jan 17, 2025
f321ac0
fix tendermint test burn tx
Jan 17, 2025
afb417e
del temp tx hex logging
Jan 17, 2025
9a801c2
remove old comment
Jan 20, 2025
ab96ba8
remove unused code to broadcast multiple msgs
Jan 20, 2025
bbe2b5b
fix after merge (remove solana src)
Jan 21, 2025
897aa4d
refactor (laruh): rename version fields
Jan 21, 2025
e4e8de0
remove negotiation msg version (to be impl in a different way)
Jan 27, 2025
0b37b10
remove unused features
Jan 27, 2025
de4394f
refactor test mock def, removed unused mockable
Jan 27, 2025
af3762b
cargo fmt
Jan 27, 2025
de079ba
add test helper (mariocynicys)
Jan 27, 2025
a505386
review (borngraced): dex fee errors improved, make value underflow ch…
Feb 3, 2025
019209f
review (mariocynicys): refactor dex fee dust handling
Feb 3, 2025
d7e18d4
review (borngraced): use as_ref for tendermint address
Feb 4, 2025
30a13fa
review (mariocynicys): add dex_address, burn_address fn for utxo
Feb 4, 2025
4b1b867
add flavor multithread to zcoin tests
Feb 4, 2025
1dcb774
update zcoin txns for real dex and burn address
Feb 4, 2025
114cfe9
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Feb 4, 2025
78033be
clear version leftovers in test files
Feb 5, 2025
89e23ae
remove unused const
Feb 5, 2025
40ef614
remove unused error
Feb 5, 2025
2fcda6c
removed unused AddressDerivationPath
Feb 6, 2025
0cab109
eliminated dex_fee_from_taker_coin
Feb 6, 2025
2ef2bb6
delete oneinch leftover file
Feb 6, 2025
07986cb
review (mariocynicys): move TestCoin to for-tests feature, use for-te…
Feb 6, 2025
56f13b2
review (mariocynicys): add taker_pubkey_bytes fn to CommonSwapOpsV2 f…
Feb 6, 2025
8513c3f
add doc to DEX_FEE_ADDR_PUBKEY
Feb 6, 2025
05488f9
add more sepolia nodes for tests
Feb 6, 2025
703e887
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Feb 6, 2025
2873ac3
review (laruh): fix taker swap v2 check balance (add dexfee), refacto…
Feb 11, 2025
0198dba
fix after refactor: revert dex_fee for dust check
Feb 11, 2025
8c8c335
review (mariocynicys): refactor TEST_BURN_ADDR_RAW_PUBKEY as lazy_static
Feb 11, 2025
d86ee02
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Feb 11, 2025
0f9ed06
review: add const to should_burn_dex_fee
Feb 11, 2025
7c335aa
disable burning non kmd dex fee (use standard dex fee) until swap com…
Feb 26, 2025
acc3b7e
fix should_burn_dex_fee for sia coin
Mar 5, 2025
12b7bb1
refactor (laruh) dexfee and burn outputs creation
Mar 5, 2025
473930c
refactor dexfee (shamardy mariocynicys): move dexfee for dust check i…
Mar 5, 2025
8f9065a
refactor dexfee (shamardy): add new DexFee::new_with_taker_pubkey to …
Mar 5, 2025
356eaad
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Mar 5, 2025
5a09169
refactor: eliminate else in dexfee calc
Mar 7, 2025
6200833
fix actual z burn address
Mar 17, 2025
3cddd92
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Mar 17, 2025
74202d3
fix after merge
Mar 17, 2025
87a1e49
rename dex fee fn for maker
Mar 20, 2025
7ace910
Merge branch 'dev' into burn-dex-fee-for-non-kmd
Mar 20, 2025
1ed4af7
fix after merge: fix mockable parse error
Mar 20, 2025
d953e6c
Merge branch 'dev' into burn-dex-fee-for-non-kmd
shamardy Mar 24, 2025
101b69f
fix mac-dylib-x86-64 dev build issue
shamardy Mar 24, 2025
d886fd8
add x86_64-apple-darwin target
shamardy Mar 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enable-sia = [
]
default = []
run-docker-tests = []
for-tests = []
for-tests = ["dep:mocktopus"]

[lib]
path = "lp_coins.rs"
Expand Down Expand Up @@ -72,7 +72,7 @@ mm2_number = { path = "../mm2_number"}
mm2_p2p = { path = "../mm2_p2p", default-features = false }
mm2_rpc = { path = "../mm2_rpc" }
mm2_state_machine = { path = "../mm2_state_machine" }
mocktopus = "0.8.0"
mocktopus = { version = "0.8.0", optional = true }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could add it as a for-test feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way like it is now is convenient as we may use mocktopus both from tests inside the crate and from other crates, without extra features, and at the same time avoiding building it into releases

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from tests inside the crate -> dev-deps section
from tests from outside/integration -> for-test flag to activate it, this has the downside though as u said will enable all and every extra test features we have, but it's a for-test build anyway so i wouldn't worry much about that and instead prioritize having less complex cfgs around the code base.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from tests from outside/integration -> for-test flag to activate it

I think, in this case mocktopus would be built into release what is not recommended for performance reasons.
The optional flag is a way to avoid this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im going over my old comments before reviewing so excuse me if things changed and aren't relevant anymore, you can resolve them then.

I think, in this case mocktopus would be built into release what is not recommended for performance reasons.

No it wouldn't make it to release. It will only get included when for-test is enabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As can see, feature 'for-tests' is used to activate certain test code in certain packages.
We may or may not need mocktopus with this test code.
Also, with this approach, if we decide to use mocktopus in other dependency packages we would need to define an extra 'for-tests' feature there, instead simply using features=["mocktopus"]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may or may not need mocktopus with this test code.

if we don't need it, then it's a bloat. but who cares, that's a for-test build of mm2 no body will use it.

Also, with this approach, if we decide to use mocktopus in other dependency packages we would need to define an extra 'for-tests' feature

no, we can simply use features=["for-tests"] just like (instead of) feautres=["mocktopus"].

my problem is that having so many features gets things complicated. and these features aren't even real features that get baked into release, they are only test used features.
why have a feature x to bake this functionality into mm2 and another feature y to bake another functionality and so on. and only activate features x when we are running from this testing crate, and only activate y when we are doing that.
we can instead have a build-mm2-with-all-test-features/for-test feature to enable all the functionalities we need for testing from wherever.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we can simply use features=["for-tests"] just like (instead of) feautres=["mocktopus"].

To use mocktopus in some subpackage with 'for-tests' you would need to define 'for-tests' in each such subpackage (if it was not defined yet there), although dep:mocktopus is natively defined, w/o extra config and ready-to use.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im lost in the convo, but this is what i mean, might be clearer in code: d5d2bbd

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is what I meant too:
For e.g. there is a new trading_api package where mocktopus is activated from mm2_main:
https://github.com/KomodoPlatform/komodo-defi-framework/blob/ff0eefcdccfa9b48161052ed95d8185220ba2cbd/mm2src/mm2_main/Cargo.toml#L132
Doing it this way it's no need to define an extra [for-tests] feature in trading_api

num-traits = "0.2"
parking_lot = { version = "0.12.0", features = ["nightly"] }
primitives = { path = "../mm2_bitcoin/primitives" }
Expand Down Expand Up @@ -162,6 +162,7 @@ winapi = "0.3"

[dev-dependencies]
mm2_test_helpers = { path = "../mm2_test_helpers" }
mocktopus = { version = "0.8.0" }
mm2_p2p = { path = "../mm2_p2p", features = ["application"] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
Expand Down
26 changes: 12 additions & 14 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ use instant::Instant;
use mm2_core::mm_ctx::{MmArc, MmWeak};
use mm2_number::bigdecimal_custom::CheckedDivision;
use mm2_number::{BigDecimal, BigUint, MmNumber};
#[cfg(test)] use mocktopus::macros::*;
use rand::seq::SliceRandom;
use rlp::{DecoderError, Encodable, RlpStream};
use rpc::v1::types::Bytes as BytesJson;
Expand Down Expand Up @@ -1284,14 +1283,8 @@ impl Deref for EthCoin {

#[async_trait]
impl SwapOps for EthCoin {
async fn send_taker_fee(
&self,
fee_addr: &[u8],
dex_fee: DexFee,
_uuid: &[u8],
_expire_at: u64,
) -> TransactionResult {
let address = try_tx_s!(addr_from_raw_pubkey(fee_addr));
async fn send_taker_fee(&self, dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionResult {
let address = try_tx_s!(addr_from_raw_pubkey(self.dex_pubkey()));
self.send_to_address(
address,
try_tx_s!(wei_from_big_decimal(&dex_fee.fee_amount().into(), self.decimals)),
Expand Down Expand Up @@ -1358,7 +1351,6 @@ impl SwapOps for EthCoin {
validate_fee_impl(self.clone(), EthValidateFeeArgs {
fee_tx_hash: &tx.tx_hash(),
expected_sender: validate_fee_args.expected_sender,
fee_addr: validate_fee_args.fee_addr,
amount: &validate_fee_args.dex_fee.fee_amount().into(),
min_block_number: validate_fee_args.min_block_number,
uuid: validate_fee_args.uuid,
Expand Down Expand Up @@ -1697,7 +1689,6 @@ impl WatcherOps for EthCoin {
validate_fee_impl(self.clone(), EthValidateFeeArgs {
fee_tx_hash: &H256::from_slice(validate_fee_args.taker_fee_hash.as_slice()),
expected_sender: &validate_fee_args.sender_pubkey,
fee_addr: &validate_fee_args.fee_addr,
amount: &BigDecimal::from(0),
min_block_number: validate_fee_args.min_block_number,
uuid: &[],
Expand Down Expand Up @@ -2307,7 +2298,6 @@ impl WatcherOps for EthCoin {

#[async_trait]
#[cfg_attr(test, mockable)]
#[async_trait]
impl MarketCoinOps for EthCoin {
fn ticker(&self) -> &str { &self.ticker[..] }

Expand Down Expand Up @@ -2672,6 +2662,9 @@ impl MarketCoinOps for EthCoin {
MmNumber::from(1) / MmNumber::from(10u64.pow(pow))
}

#[inline]
fn should_burn_dex_fee(&self) -> bool { false }

fn is_trezor(&self) -> bool { self.priv_key_policy.is_trezor() }
}

Expand Down Expand Up @@ -5981,8 +5974,7 @@ fn validate_fee_impl(coin: EthCoin, validate_fee_args: EthValidateFeeArgs<'_>) -
let sender_addr = try_f!(
addr_from_raw_pubkey(validate_fee_args.expected_sender).map_to_mm(ValidatePaymentError::InvalidParameter)
);
let fee_addr =
try_f!(addr_from_raw_pubkey(validate_fee_args.fee_addr).map_to_mm(ValidatePaymentError::InvalidParameter));
let fee_addr = try_f!(addr_from_raw_pubkey(coin.dex_pubkey()).map_to_mm(ValidatePaymentError::InvalidParameter));
let amount = validate_fee_args.amount.clone();
let min_block_number = validate_fee_args.min_block_number;

Expand Down Expand Up @@ -7344,6 +7336,12 @@ impl CommonSwapOpsV2 for EthCoin {
fn derive_htlc_pubkey_v2_bytes(&self, swap_unique_data: &[u8]) -> Vec<u8> {
self.derive_htlc_pubkey_v2(swap_unique_data).to_bytes()
}

#[inline(always)]
fn taker_pubkey_bytes(&self) -> Option<Vec<u8>> {
let dummy_unique_data = []; // not used for non-private coins
Some(self.derive_htlc_pubkey_v2(&dummy_unique_data).to_bytes())
}
}

#[cfg(all(feature = "for-tests", not(target_arch = "wasm32")))]
Expand Down
4 changes: 0 additions & 4 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ fn validate_dex_fee_invalid_sender_eth() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &DEX_FEE_ADDR_RAW_PUBKEY,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 0,
uuid: &[],
Expand Down Expand Up @@ -616,7 +615,6 @@ fn validate_dex_fee_invalid_sender_erc() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &DEX_FEE_ADDR_RAW_PUBKEY,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 0,
uuid: &[],
Expand Down Expand Up @@ -656,7 +654,6 @@ fn validate_dex_fee_eth_confirmed_before_min_block() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &compressed_public,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 11784793,
uuid: &[],
Expand Down Expand Up @@ -695,7 +692,6 @@ fn validate_dex_fee_erc_confirmed_before_min_block() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &compressed_public,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 11823975,
uuid: &[],
Expand Down
10 changes: 3 additions & 7 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,7 @@ impl LightningCoin {
#[async_trait]
impl SwapOps for LightningCoin {
// Todo: This uses dummy data for now for the sake of swap P.O.C., this should be implemented probably after agreeing on how fees will work for lightning
async fn send_taker_fee(
&self,
_fee_addr: &[u8],
_dex_fee: DexFee,
_uuid: &[u8],
_expire_at: u64,
) -> TransactionResult {
async fn send_taker_fee(&self, _dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionResult {
Ok(TransactionEnum::LightningPayment(PaymentHash([1; 32])))
}

Expand Down Expand Up @@ -1251,6 +1245,8 @@ impl MarketCoinOps for LightningCoin {
// Todo: doesn't take routing fees into account too, There is no way to know the route to the other side of the swap when placing the order, need to find a workaround for this
fn min_trading_vol(&self) -> MmNumber { self.min_tx_amount().into() }

fn should_burn_dex_fee(&self) -> bool { false }

fn is_trezor(&self) -> bool { self.platform.coin.is_trezor() }
}

Expand Down
Loading
Loading