Skip to content

Commit

Permalink
merge with origin/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Sep 24, 2024
2 parents 1ebc318 + 4fc8388 commit 7bbe8b4
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 143 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ opt-level = 3
strip = true
codegen-units = 1
# lto = true
panic = "abort"
panic = 'unwind'

[profile.dev]
opt-level = 0
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

## What is the Komodo DeFi Framework?

The Komodo DeFi Framework is open-source [atomic-swap](https://komodoplatform.com/en/academy/atomic-swaps/) software for seamless, decentralised, peer to peer trading between almost every blockchain asset in existence. This software works with propagation of orderbooks and swap states through the [libp2p](https://libp2p.io/) protocol and uses [Hash Time Lock Contracts (HTLCs)](https://en.bitcoinwiki.org/wiki/Hashed_Timelock_Contracts) for ensuring that the two parties in a swap either mutually complete a trade, or funds return to thier original owner.
The Komodo DeFi Framework is open-source [atomic-swap](https://komodoplatform.com/en/academy/atomic-swaps/) software for seamless, decentralized, peer to peer trading between almost every blockchain asset in existence. This software works with propagation of orderbooks and swap states through the [libp2p](https://libp2p.io/) protocol and uses [Hash Time Lock Contracts (HTLCs)](https://en.bitcoinwiki.org/wiki/Hashed_Timelock_Contracts) for ensuring that the two parties in a swap either mutually complete a trade, or funds return to thier original owner.

There is no 3rd party intermediary, no proxy tokens, and at all times users remain in sole possession of their private keys.

Expand Down Expand Up @@ -172,7 +172,7 @@ Refer to the [Komodo Developer Docs](https://developers.komodoplatform.com/basic

## Project structure

[mm2src](mm2src) - Rust code, contains some parts ported from C `as is` (e.g. `lp_ordermatch`) to reach the most essential/error prone code. Some other modules/crates are reimplemented from scratch.
[mm2src](mm2src) - Rust code, contains some parts ported from C `as is` (e.g. `lp_ordermatch`) to reach the most essential/error-prone code. Some other modules/crates are reimplemented from scratch.


## Additional docs for developers
Expand All @@ -185,8 +185,8 @@ Refer to the [Komodo Developer Docs](https://developers.komodoplatform.com/basic

## Disclaimer

This repository contains the `work in progress` code of the brand new Komodo DeFi Framework (kdf) built mainly on Rust.
The current state can be considered as a alpha version.
This repository contains the `work in progress` code of the brand-new Komodo DeFi Framework (kdf) built mainly on Rust.
The current state can be considered as an alpha version.

**<b>WARNING: Use with test coins only or with assets which value does not exceed an amount you are willing to lose. This is alpha stage software! </b>**

Expand Down
58 changes: 40 additions & 18 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
use super::*;
use crate::eth::for_tests::{eth_coin_for_test, eth_coin_from_keypair};
use crate::{DexFee, IguanaPrivKey};
use common::{block_on, block_on_f01, now_sec};
#[cfg(not(target_arch = "wasm32"))]
use ethkey::{Generator, Random};
use crate::IguanaPrivKey;
use common::{block_on, block_on_f01};
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::{ETH_MAINNET_CHAIN_ID, ETH_MAINNET_NODE, ETH_SEPOLIA_CHAIN_ID, ETH_SEPOLIA_NODES,

cfg_native!(
use crate::eth::for_tests::{eth_coin_for_test, eth_coin_from_keypair};
use crate::DexFee;

use common::now_sec;
use ethkey::{Generator, Random};
use mm2_test_helpers::for_tests::{ETH_MAINNET_CHAIN_ID, ETH_MAINNET_NODE, ETH_SEPOLIA_CHAIN_ID, ETH_SEPOLIA_NODES,
ETH_SEPOLIA_TOKEN_CONTRACT};
use mocktopus::mocking::*;

/// The gas price for the tests
const GAS_PRICE: u64 = 50_000_000_000;
// `GAS_PRICE` increased by 3%
const GAS_PRICE_APPROXIMATION_ON_START_SWAP: u64 = 51_500_000_000;
// `GAS_PRICE` increased by 5%
const GAS_PRICE_APPROXIMATION_ON_ORDER_ISSUE: u64 = 52_500_000_000;
// `GAS_PRICE` increased by 7%
const GAS_PRICE_APPROXIMATION_ON_TRADE_PREIMAGE: u64 = 53_500_000_000;
use mocktopus::mocking::*;

/// The gas price for the tests
const GAS_PRICE: u64 = 50_000_000_000;
/// `GAS_PRICE` increased by 3%
const GAS_PRICE_APPROXIMATION_ON_START_SWAP: u64 = 51_500_000_000;
/// `GAS_PRICE` increased by 5%
const GAS_PRICE_APPROXIMATION_ON_ORDER_ISSUE: u64 = 52_500_000_000;
/// `GAS_PRICE` increased by 7%
const GAS_PRICE_APPROXIMATION_ON_TRADE_PREIMAGE: u64 = 53_500_000_000;
);

// old way to add some extra gas to the returned value from gas station (non-existent now), still used in tests
const GAS_PRICE_PERCENT: u64 = 10;

const TAKER_PAYMENT_SPEND_SEARCH_INTERVAL: f64 = 1.;

fn check_sum(addr: &str, expected: &str) {
let actual = checksum_address(addr);
assert_eq!(expected, actual);
Expand Down Expand Up @@ -154,8 +158,11 @@ fn test_wei_from_big_decimal() {
assert_eq!(expected_wei, wei);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_wait_for_payment_spend_timeout() {
const TAKER_PAYMENT_SPEND_SEARCH_INTERVAL: f64 = 1.;

EthCoin::spend_events.mock_safe(|_, _, _, _| MockResult::Return(Box::new(futures01::future::ok(vec![]))));
EthCoin::current_block.mock_safe(|_| MockResult::Return(Box::new(futures01::future::ok(900))));

Expand Down Expand Up @@ -304,6 +311,7 @@ fn test_add_ten_pct_one_gwei() {
assert_eq!(expected, actual);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn get_sender_trade_preimage() {
/// Trade fee for the ETH coin is `2 * 150_000 * gas_price` always.
Expand Down Expand Up @@ -359,6 +367,7 @@ fn get_sender_trade_preimage() {
assert_eq!(actual, expected);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn get_erc20_sender_trade_preimage() {
const APPROVE_GAS_LIMIT: u64 = 60_000;
Expand Down Expand Up @@ -461,6 +470,7 @@ fn get_erc20_sender_trade_preimage() {
);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn get_receiver_trade_preimage() {
EthCoin::get_gas_price.mock_safe(|_| MockResult::Return(Box::pin(futures::future::ok(GAS_PRICE.into()))));
Expand All @@ -479,6 +489,7 @@ fn get_receiver_trade_preimage() {
assert_eq!(actual, expected_fee);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_get_fee_to_send_taker_fee() {
const DEX_FEE_AMOUNT: u64 = 100_000;
Expand Down Expand Up @@ -529,6 +540,7 @@ fn test_get_fee_to_send_taker_fee() {
///
/// Please note this test doesn't work correctly now,
/// because as of now [`EthCoin::get_fee_to_send_taker_fee`] doesn't process the `Exception` web3 error correctly.
#[cfg(not(target_arch = "wasm32"))]
#[test]
#[ignore]
fn test_get_fee_to_send_taker_fee_insufficient_balance() {
Expand Down Expand Up @@ -558,6 +570,7 @@ fn test_get_fee_to_send_taker_fee_insufficient_balance() {
);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn validate_dex_fee_invalid_sender_eth() {
let (_ctx, coin) = eth_coin_for_test(EthCoinType::Eth, &[ETH_MAINNET_NODE], None, ETH_MAINNET_CHAIN_ID);
Expand Down Expand Up @@ -587,6 +600,7 @@ fn validate_dex_fee_invalid_sender_eth() {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn validate_dex_fee_invalid_sender_erc() {
let (_ctx, coin) = eth_coin_for_test(
Expand Down Expand Up @@ -624,6 +638,7 @@ fn validate_dex_fee_invalid_sender_erc() {
}
}

#[cfg(not(target_arch = "wasm32"))]
fn sender_compressed_pub(tx: &SignedEthTx) -> [u8; 33] {
let tx_pubkey = tx.public.unwrap();
let mut raw_pubkey = [0; 65];
Expand All @@ -633,6 +648,7 @@ fn sender_compressed_pub(tx: &SignedEthTx) -> [u8; 33] {
secp_public.serialize()
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn validate_dex_fee_eth_confirmed_before_min_block() {
let (_ctx, coin) = eth_coin_for_test(EthCoinType::Eth, &[ETH_MAINNET_NODE], None, ETH_MAINNET_CHAIN_ID);
Expand Down Expand Up @@ -664,6 +680,7 @@ fn validate_dex_fee_eth_confirmed_before_min_block() {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn validate_dex_fee_erc_confirmed_before_min_block() {
let (_ctx, coin) = eth_coin_for_test(
Expand Down Expand Up @@ -704,6 +721,7 @@ fn validate_dex_fee_erc_confirmed_before_min_block() {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_negotiate_swap_contract_addr_no_fallback() {
let (_, coin) = eth_coin_for_test(EthCoinType::Eth, &[ETH_MAINNET_NODE], None, ETH_MAINNET_CHAIN_ID);
Expand Down Expand Up @@ -731,6 +749,7 @@ fn test_negotiate_swap_contract_addr_no_fallback() {
assert_eq!(Some(slice.to_vec().into()), result);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_negotiate_swap_contract_addr_has_fallback() {
let fallback = Address::from_str("0x8500AFc0bc5214728082163326C2FF0C73f4a871").unwrap();
Expand Down Expand Up @@ -826,6 +845,7 @@ fn polygon_check_if_my_payment_sent() {
assert_eq!(expected_hash, my_payment.tx_hash_as_bytes());
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_message_hash() {
let key_pair = Random.generate().unwrap();
Expand All @@ -844,6 +864,7 @@ fn test_message_hash() {
);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_sign_verify_message() {
let key_pair = KeyPair::from_secret_slice(
Expand All @@ -868,6 +889,7 @@ fn test_sign_verify_message() {
assert!(is_valid);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_eth_extract_secret() {
let key_pair = Random.generate().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ macro_rules! try_f {
};
}

#[cfg(feature = "enable-solana")]
#[cfg(all(feature = "enable-solana", not(target_arch = "wasm32")))]
macro_rules! try_tx_fus_err {
($err: expr) => {
return Box::new(futures01::future::err(crate::TransactionErr::Plain(ERRL!(
Expand All @@ -133,7 +133,7 @@ macro_rules! try_tx_fus_err {
};
}

#[cfg(feature = "enable-solana")]
#[cfg(all(feature = "enable-solana", not(target_arch = "wasm32")))]
macro_rules! try_tx_fus_opt {
($e: expr, $err: expr) => {
match $e {
Expand Down
Loading

0 comments on commit 7bbe8b4

Please sign in to comment.