Skip to content

Commit

Permalink
return swap policy docker tests (lost in merge)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimxy committed May 17, 2024
1 parent a785274 commit 1cbf2f2
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use super::docker_tests_common::{random_secp256k1_secret, ERC1155_TEST_ABI, ERC7
use bitcrypto::{dhash160, sha256};
use coins::eth::{checksum_address, eth_addr_to_hex, eth_coin_from_conf_and_request, EthCoin, ERC20_ABI};
use coins::nft::nft_structs::{Chain, ContractType, NftInfo};
use coins::{CoinProtocol, CoinWithDerivationMethod, ConfirmPaymentInput, DerivationMethod, FoundSwapTxSpend,
MakerNftSwapOpsV2, MarketCoinOps, NftSwapInfo, ParseCoinAssocTypes, PrivKeyBuildPolicy, RefundPaymentArgs,
SearchForSwapTxSpendInput, SendNftMakerPaymentArgs, SendPaymentArgs, SpendNftMakerPaymentArgs,
SpendPaymentArgs, SwapOps, SwapTxTypeWithSecretHash, ToBytes, Transaction, ValidateNftMakerPaymentArgs};
use coins::{CoinProtocol, CoinWithDerivationMethod, ConfirmPaymentInput, DerivationMethod, Eip1559Ops,
FoundSwapTxSpend, MakerNftSwapOpsV2, MarketCoinOps, NftSwapInfo, ParseCoinAssocTypes, PrivKeyBuildPolicy,
RefundPaymentArgs, SearchForSwapTxSpendInput, SendNftMakerPaymentArgs, SendPaymentArgs,
SpendNftMakerPaymentArgs, SpendPaymentArgs, SwapOps, SwapTxFeePolicy, SwapTxTypeWithSecretHash, ToBytes,
Transaction, ValidateNftMakerPaymentArgs};
use common::{block_on, now_sec};
use crypto::Secp256k1Secret;
use ethereum_types::U256;
Expand Down Expand Up @@ -60,6 +61,7 @@ pub fn erc721_contract() -> Address { unsafe { GETH_ERC721_CONTRACT } }
pub fn erc1155_contract() -> Address { unsafe { GETH_ERC1155_CONTRACT } }

fn wait_for_confirmation(tx_hash: H256) {
thread::sleep(Duration::from_millis(2000));
loop {
match block_on(GETH_WEB3.eth().transaction_receipt(tx_hash)) {
Ok(Some(r)) => match r.block_hash {
Expand Down Expand Up @@ -392,9 +394,9 @@ pub fn fill_eth_erc20_with_private_key(priv_key: Secp256k1Secret) {
fill_erc20(my_address, U256::from(10000000000u64));
}

#[test]
fn send_and_refund_eth_maker_payment() {
fn send_and_refund_eth_maker_payment_impl(swap_txfee_policy: SwapTxFeePolicy) {
let eth_coin = eth_coin_with_random_privkey(swap_contract());
eth_coin.set_swap_transaction_fee_policy(swap_txfee_policy);

let time_lock = now_sec() - 100;
let other_pubkey = &[
Expand Down Expand Up @@ -467,10 +469,20 @@ fn send_and_refund_eth_maker_payment() {
}

#[test]
fn send_and_spend_eth_maker_payment() {
fn send_and_refund_eth_maker_payment_internal_gas_policy() {
send_and_refund_eth_maker_payment_impl(SwapTxFeePolicy::Internal);
}

#[test]
fn send_and_refund_eth_maker_payment_priority_fee() { send_and_refund_eth_maker_payment_impl(SwapTxFeePolicy::Medium); }

fn send_and_spend_eth_maker_payment_impl(swap_txfee_policy: SwapTxFeePolicy) {
let maker_eth_coin = eth_coin_with_random_privkey(swap_contract());
let taker_eth_coin = eth_coin_with_random_privkey(swap_contract());

maker_eth_coin.set_swap_transaction_fee_policy(swap_txfee_policy.clone());
taker_eth_coin.set_swap_transaction_fee_policy(swap_txfee_policy);

let time_lock = now_sec() + 1000;
let maker_pubkey = maker_eth_coin.derive_htlc_pubkey(&[]);
let taker_pubkey = taker_eth_coin.derive_htlc_pubkey(&[]);
Expand Down Expand Up @@ -542,8 +554,16 @@ fn send_and_spend_eth_maker_payment() {
}

#[test]
fn send_and_refund_erc20_maker_payment() {
fn send_and_spend_eth_maker_payment_internal_gas_policy() {
send_and_spend_eth_maker_payment_impl(SwapTxFeePolicy::Internal);
}

#[test]
fn send_and_spend_eth_maker_payment_priority_fee() { send_and_spend_eth_maker_payment_impl(SwapTxFeePolicy::Medium); }

fn send_and_refund_erc20_maker_payment_impl(swap_txfee_policy: SwapTxFeePolicy) {
let erc20_coin = erc20_coin_with_random_privkey(swap_contract());
erc20_coin.set_swap_transaction_fee_policy(swap_txfee_policy);

let time_lock = now_sec() - 100;
let other_pubkey = &[
Expand Down Expand Up @@ -617,10 +637,22 @@ fn send_and_refund_erc20_maker_payment() {
}

#[test]
fn send_and_spend_erc20_maker_payment() {
fn send_and_refund_erc20_maker_payment_internal_gas_policy() {
send_and_refund_erc20_maker_payment_impl(SwapTxFeePolicy::Internal);
}

#[test]
fn send_and_refund_erc20_maker_payment_priority_fee() {
send_and_refund_erc20_maker_payment_impl(SwapTxFeePolicy::Medium);
}

fn send_and_spend_erc20_maker_payment_impl(swap_txfee_policy: SwapTxFeePolicy) {
let maker_erc20_coin = erc20_coin_with_random_privkey(swap_contract());
let taker_erc20_coin = erc20_coin_with_random_privkey(swap_contract());

maker_erc20_coin.set_swap_transaction_fee_policy(swap_txfee_policy.clone());
taker_erc20_coin.set_swap_transaction_fee_policy(swap_txfee_policy);

let time_lock = now_sec() + 1000;
let maker_pubkey = maker_erc20_coin.derive_htlc_pubkey(&[]);
let taker_pubkey = taker_erc20_coin.derive_htlc_pubkey(&[]);
Expand Down Expand Up @@ -691,6 +723,16 @@ fn send_and_spend_erc20_maker_payment() {
assert_eq!(expected, search_tx);
}

#[test]
fn send_and_spend_erc20_maker_payment_internal_gas_policy() {
send_and_spend_erc20_maker_payment_impl(SwapTxFeePolicy::Internal);
}

#[test]
fn send_and_spend_erc20_maker_payment_priority_fee() {
send_and_spend_erc20_maker_payment_impl(SwapTxFeePolicy::Medium);
}

#[test]
fn send_and_spend_erc721_maker_payment() {
// TODO: Evaluate implementation strategy — either employing separate contracts for maker and taker
Expand Down

0 comments on commit 1cbf2f2

Please sign in to comment.