feat(tests): zcoin unit test to validate dex fee#2460
Conversation
…o avoid creating ZOMBIE.conf)
| use crate::{DexFee, DexFeeBurnDestination}; | ||
| use mm2_number::MmNumber; | ||
|
|
||
| dd |
shamardy
left a comment
There was a problem hiding this comment.
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?
mm2src/coins/z_coin.rs
Outdated
| #[cfg(all(test, not(target_arch = "wasm32")))] | ||
| UnitTests, |
There was a problem hiding this comment.
Can't we do the tests for wasm as well using cross_test
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
weird, even tho mocktopus supports WASM
There was a problem hiding this comment.
@dimxy please could you be more specific on the issue you had using mocktopus in wasm?
|
@dimxy please always check that CI passes before making a PR ready for review. |
To add a test for this case I needed to mock dex and burn addresses. This is convenient to do in unit tests. |
Okay (I guess it was a temp runner failure when I last updated this PR) |
mm2src/coins/z_coin.rs
Outdated
| 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), | ||
| ); |
There was a problem hiding this comment.
| 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); |
|
@borngraced can you please check if your notes have been resolved and approve if so |
|
|
@dimxy |
* 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
* 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
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)