Skip to content

feat(tests): zcoin unit test to validate dex fee#2460

Merged
shamardy merged 16 commits intodevfrom
zcoin-dex-fee-unit-test
Jun 16, 2025
Merged

feat(tests): zcoin unit test to validate dex fee#2460
shamardy merged 16 commits intodevfrom
zcoin-dex-fee-unit-test

Conversation

@dimxy
Copy link
Copy Markdown
Collaborator

@dimxy dimxy commented May 20, 2025

Adds a framework for creating a zcoin unit tests to call and test Zcoin {} validation functions.
Also fixes a bug with address check in the validate_dex_fee_output fn (and adds a unit test for it). Was fixed in another PR before this, this one adds the unit test for it.

PS: also removed 'multicore' feature from zcash_proofs for the wasm platform (as this caused errors in a wasm test)

use crate::{DexFee, DexFeeBurnDestination};
use mm2_number::MmNumber;

dd
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

mistake

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed the file

Copy link
Copy Markdown
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! It adds quite a lot of code just to test a very specific thing—maybe this zcoin unit testing framework can be used for other cases in the future, though. One concern: since the test code depends on ZCoin’s internal structure and initialization, we’ll have to change and maintain it whenever those internals change, which could make these tests fragile and harder to keep up-to-date. But I do get that the extra setup is necessary. Just out of curiosity, why didn't you cover this case in dockerized tests instead?

Comment on lines +786 to +787
#[cfg(all(test, not(target_arch = "wasm32")))]
UnitTests,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can't we do the tests for wasm as well using cross_test

Copy link
Copy Markdown
Collaborator Author

@dimxy dimxy May 27, 2025

Choose a reason for hiding this comment

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

I tried to make it a cross_test and was getting a failure on wasm with an error in zcash_proofs/bellman::multicore mod:

Error { kind: Unsupported, message: "operation not supported on this platform" }

I managed to fix this error to by disabling the multicore feature in zcash_proofs for wasm dependencies (like it had been before the workspace dependencies PR #2449. See zcash_proofs in the main branch Cargo.toml ).
@borngraced you may want to disable multicore for zcash_proofs for wasm, as we now have zcash_proofs only with multicore in workspace deps.

PS However the wasm test still would not work as looks like mocktopus is not working there
(I even tried to make mocktopus as a release dependency but still no luck)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

weird, even tho mocktopus supports WASM

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@dimxy please could you be more specific on the issue you had using mocktopus in wasm?

@shamardy
Copy link
Copy Markdown
Collaborator

@dimxy please always check that CI passes before making a PR ready for review.

@dimxy
Copy link
Copy Markdown
Collaborator Author

dimxy commented May 27, 2025

Just out of curiosity, why didn't you cover this case in dockerized tests instead?

To add a test for this case I needed to mock dex and burn addresses. This is convenient to do in unit tests.
Since we have unit tests for other coins I thought it's a moment to add a similar framework for zcoin as well. Ofc the idea was to use it not only for this case but for others as well (like we do this for utxo for e.g.).

@dimxy
Copy link
Copy Markdown
Collaborator Author

dimxy commented May 27, 2025

@dimxy please always check that CI passes before making a PR ready for review.

Okay (I guess it was a temp runner failure when I last updated this PR)

dimxy added 7 commits May 27, 2025 21:13
* dev:
  fix(evm-api): find enabled erc20 token using platform ticker (#2445)
  chore(docs): add DeepWiki badge to README (#2463)
  chore(core): organize deps using workspace.dependencies (#2449)
  feat(db-arch): more dbdir to address_dir replacements (#2398)
Copy link
Copy Markdown

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

last notes from my side

Comment on lines +2200 to +2210
add_test_spend(
coin,
&mut tx_builder,
dex_params.1
+ if let Some(ref burn_params) = burn_params {
burn_params.1
} else {
0
}
+ u64::from(DEFAULT_FEE),
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
add_test_spend(
coin,
&mut tx_builder,
dex_params.1
+ if let Some(ref burn_params) = burn_params {
burn_params.1
} else {
0
}
+ u64::from(DEFAULT_FEE),
);
let amount = dex_params.1 + burn_params.map(|(_, v)| v).unwrap_or_default() + u64::from(DEFAULT_FEE);
add_test_spend(coin, &mut tx_builder, amount);

onur-ozkan
onur-ozkan previously approved these changes May 28, 2025
Copy link
Copy Markdown

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

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

LGTM other than one note:

@shamardy
Copy link
Copy Markdown
Collaborator

shamardy commented May 28, 2025

@borngraced can you please check if your notes have been resolved and approve if so

@borngraced
Copy link
Copy Markdown

@borngraced can you please check if your notes have been resolved and approve if so

#2460 (comment)

borngraced
borngraced previously approved these changes May 28, 2025
@shamardy
Copy link
Copy Markdown
Collaborator

@dimxy test_validate_zcoin_dex_fee is currently failing in CI

@dimxy
Copy link
Copy Markdown
Collaborator Author

dimxy commented May 31, 2025

@dimxy test_validate_zcoin_dex_fee is currently failing in CI

Oh, so we did not download zcash params in the CI host OS. I have added code for this (for tests) ae28620

@shamardy shamardy changed the title feat(tests): zcoin unit test to validate dex fee, fix address check bug feat(tests): zcoin unit test to validate dex fee Jun 16, 2025
@shamardy shamardy merged commit dc39db7 into dev Jun 16, 2025
26 checks passed
@shamardy shamardy deleted the zcoin-dex-fee-unit-test branch June 16, 2025 05:57
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request Jun 27, 2025
* dev: (30 commits)
  chore(core): replace hash_raw_entry with stable entry() API (GLEECBTC#2473)
  chore(core): adapt `MmError` and usages for compatibility with new rustc versions (GLEECBTC#2443)
  feat(wallet): add `delete_wallet` RPC (GLEECBTC#2497)
  chore(release): add changelog entries for v2.5.0-beta (GLEECBTC#2494)
  chore(release): bump kdf version to 2.5.0-beta (GLEECBTC#2492)
  feat(tests): zcoin unit test to validate dex fee (GLEECBTC#2460)
  fix(zcoin): correctly track unconfirmed z-coin notes (GLEECBTC#2331)
  improvement(orders): remove BTC specific volume from min_trading_vol logic (GLEECBTC#2483)
  feat(ibc-routing-part-2): supporting entire Cosmos network for swaps (GLEECBTC#2476)
  fix(startup): don't initialize WalletConnect during startup (GLEECBTC#2485)
  fix(dns): better ip resolution (GLEECBTC#2487)
  improvement(event-streaming): strong type streamer IDs (GLEECBTC#2441)
  bump timed-map to `1.4.1` (GLEECBTC#2481)
  improvement(RPC): unified interface for legacy and current RPC interfaces (GLEECBTC#2450)
  improvement(tendermint): `tendermint_tx_internal_id` helper (GLEECBTC#2438)
  feat(walletconnect): add WalletConnect v2 support for EVM and Cosmos (GLEECBTC#2223)
  feat(ibc-routing-part-1): supporting entire Cosmos network for swaps (GLEECBTC#2459)
  fix(test): fix HD Wallet message signing tests (GLEECBTC#2474)
  improvement(builds): enable static CRT linking for MSVC builds (GLEECBTC#2464)
  feat(wallet): implement HD multi-address support for message signing (GLEECBTC#2432)
  ...

# Conflicts:
#	mm2src/coins/qrc20.rs
#	mm2src/mm2_main/src/lp_swap/maker_swap.rs
dimxy pushed a commit that referenced this pull request Jun 27, 2025
* dev:
  chore(core): replace hash_raw_entry with stable entry() API (#2473)
  chore(core): adapt `MmError` and usages for compatibility with new rustc versions (#2443)
  feat(wallet): add `delete_wallet` RPC (#2497)
  chore(release): add changelog entries for v2.5.0-beta (#2494)
  chore(release): bump kdf version to 2.5.0-beta (#2492)
  feat(tests): zcoin unit test to validate dex fee (#2460)

# Conflicts:
#	mm2src/coins/qrc20.rs
#	mm2src/mm2_main/src/lp_swap/maker_swap.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug: swap improvement: tests priority: medium Moderately important tasks that should be completed but are not urgent. status: pending review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants