Skip to content

Commit

Permalink
maker swap v2 docker tests (on sepolia)
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Sep 8, 2024
1 parent 3815d08 commit 7498eec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
4 changes: 2 additions & 2 deletions mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,8 @@ pub fn init_geth_node() {
SEPOLIA_ETOMIC_MAKER_NFT_SWAP_V2 = EthAddress::from_str("0x9eb88cd58605d8fb9b14652d6152727f7e95fb4d").unwrap();
SEPOLIA_ERC20_CONTRACT = EthAddress::from_str("0xF7b5F8E8555EF7A743f24D3E974E23A3C6cB6638").unwrap();
SEPOLIA_TAKER_SWAP_V2 = EthAddress::from_str("0x7Cc9F2c1c3B797D09B9d1CCd7FDcD2539a4b3874").unwrap();
// TODO update this
SEPOLIA_MAKER_SWAP_V2 = EthAddress::from_str("0x7Cc9F2c1c3B797D09B9d1CCd7FDcD2539a4b3874").unwrap();
// deploy tx https://sepolia.etherscan.io/tx/0x6f743d79ecb806f5899a6a801083e33eba9e6f10726af0873af9f39883db7f11
SEPOLIA_MAKER_SWAP_V2 = EthAddress::from_str("0xf9000589c66Df3573645B59c10aa87594Edc318F").unwrap();

let alice_passphrase = get_passphrase!(".env.client", "ALICE_PASSPHRASE").unwrap();
let alice_keypair = key_pair_from_seed(&alice_passphrase).unwrap();
Expand Down
59 changes: 43 additions & 16 deletions mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use coins::{lp_coinfind, CoinProtocol, CoinWithDerivationMethod, CoinsContext, C
NftSwapInfo, ParseCoinAssocTypes, ParseNftAssocTypes, PrivKeyBuildPolicy, RefundFundingSecretArgs,
RefundMakerPaymentSecretArgs, RefundMakerPaymentTimelockArgs, RefundNftMakerPaymentArgs,
RefundPaymentArgs, RefundTakerPaymentArgs, SearchForSwapTxSpendInput, SendMakerPaymentArgs,
SendNftMakerPaymentArgs, SendPaymentArgs, SendTakerFundingArgs, SpendNftMakerPaymentArgs,
SpendPaymentArgs, SwapOps, SwapTxFeePolicy, SwapTxTypeWithSecretHash, TakerCoinSwapOpsV2, ToBytes,
Transaction, TxPreimageWithSig, ValidateMakerPaymentArgs, ValidateNftMakerPaymentArgs,
ValidateTakerFundingArgs};
SendNftMakerPaymentArgs, SendPaymentArgs, SendTakerFundingArgs, SpendMakerPaymentArgs,
SpendNftMakerPaymentArgs, SpendPaymentArgs, SwapOps, SwapTxFeePolicy, SwapTxTypeWithSecretHash,
TakerCoinSwapOpsV2, ToBytes, Transaction, TxPreimageWithSig, ValidateMakerPaymentArgs,
ValidateNftMakerPaymentArgs, ValidateTakerFundingArgs};
use common::{block_on, now_sec};
use crypto::Secp256k1Secret;
use ethereum_types::U256;
Expand Down Expand Up @@ -2097,9 +2097,9 @@ fn send_and_refund_taker_funding_exceed_pre_approve_timelock_erc20() {
wait_for_confirmations(&taker_coin, &funding_tx_refund, 150);
}

#[ignore]
#[test]
fn send_maker_payment_and_refund_timelock_eth() {
thread::sleep(Duration::from_secs(150));
let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ETH, &eth_sepolia_conf(), false);
let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ETH, &eth_sepolia_conf(), false);

Expand Down Expand Up @@ -2149,9 +2149,9 @@ fn send_maker_payment_and_refund_timelock_eth() {
wait_for_confirmations(&maker_coin, &payment_tx_refund, 100);
}

#[ignore]
#[test]
fn send_maker_payment_and_refund_timelock_erc20() {
thread::sleep(Duration::from_secs(120));
let erc20_conf = &sepolia_erc20_dev_conf(&sepolia_erc20_contract_checksum());
let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ERC20, erc20_conf, true);
let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ERC20, erc20_conf, true);
Expand Down Expand Up @@ -2202,9 +2202,9 @@ fn send_maker_payment_and_refund_timelock_erc20() {
wait_for_confirmations(&maker_coin, &payment_tx_refund, 100);
}

#[ignore]
#[test]
fn send_maker_payment_and_refund_secret_eth() {
thread::sleep(Duration::from_secs(90));
let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ETH, &eth_sepolia_conf(), false);
let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ETH, &eth_sepolia_conf(), false);

Expand Down Expand Up @@ -2251,9 +2251,9 @@ fn send_maker_payment_and_refund_secret_eth() {
wait_for_confirmations(&maker_coin, &payment_tx_refund, 100);
}

#[ignore]
#[test]
fn send_maker_payment_and_refund_secret_erc20() {
thread::sleep(Duration::from_secs(60));
let erc20_conf = &sepolia_erc20_dev_conf(&sepolia_erc20_contract_checksum());
let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ERC20, erc20_conf, true);
let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ERC20, erc20_conf, true);
Expand Down Expand Up @@ -2301,7 +2301,6 @@ fn send_maker_payment_and_refund_secret_erc20() {
wait_for_confirmations(&maker_coin, &payment_tx_refund, 100);
}

#[ignore]
#[test]
fn send_and_spend_maker_payment_eth() {
let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ETH, &eth_sepolia_conf(), false);
Expand All @@ -2314,6 +2313,7 @@ fn send_and_spend_maker_payment_eth() {
let payment_time_lock = now_sec() + 1000;

let maker_address = block_on(maker_coin.my_addr());
let taker_address = block_on(taker_coin.my_addr());
let maker_pub = &maker_coin.derive_htlc_pubkey_v2(&[]);
let taker_pub = &taker_coin.derive_htlc_pubkey_v2(&[]);

Expand All @@ -2337,21 +2337,34 @@ fn send_and_spend_maker_payment_eth() {
time_lock: payment_time_lock,
taker_secret_hash: &taker_secret_hash,
maker_secret_hash: &maker_secret_hash,
amount: trading_amount,
amount: trading_amount.clone(),
maker_pub,
swap_unique_data: &[],
};
block_on(taker_coin.validate_maker_payment_v2(validation_args)).unwrap();
log!("Taker validated maker ETH payment");

// TODO spend_maker_payment_v2
let spend_args = SpendMakerPaymentArgs {
maker_payment_tx: &payment_tx,
time_lock: payment_time_lock,
taker_secret_hash: &taker_secret_hash,
maker_secret_hash: &maker_secret_hash,
maker_secret: &maker_secret,
maker_pub,
swap_unique_data: &[],
amount: trading_amount,
};
wait_pending_transactions(Address::from_slice(taker_address.as_bytes()));
let spend_tx = block_on(taker_coin.spend_maker_payment_v2(spend_args)).unwrap();
log!("Taker spent maker ETH payment, tx hash: {:02x}", spend_tx.tx_hash());
wait_for_confirmations(&taker_coin, &spend_tx, 100);

// TODO wait_for_maker_payment_spend
block_on(maker_coin.wait_for_maker_payment_spend(&spend_tx, 0u64, payment_time_lock)).unwrap();
}

#[ignore]
#[test]
fn send_and_spend_maker_payment_erc20() {
thread::sleep(Duration::from_secs(30));
let erc20_conf = &sepolia_erc20_dev_conf(&sepolia_erc20_contract_checksum());
let taker_coin = get_or_create_sepolia_coin(&MM_CTX1, SEPOLIA_TAKER_PRIV, ERC20, erc20_conf, true);
let maker_coin = get_or_create_sepolia_coin(&MM_CTX, SEPOLIA_MAKER_PRIV, ERC20, erc20_conf, true);
Expand All @@ -2363,6 +2376,7 @@ fn send_and_spend_maker_payment_erc20() {
let payment_time_lock = now_sec() + 1000;

let maker_address = block_on(maker_coin.my_addr());
let taker_address = block_on(taker_coin.my_addr());
let maker_pub = &maker_coin.derive_htlc_pubkey_v2(&[]);
let taker_pub = &taker_coin.derive_htlc_pubkey_v2(&[]);

Expand All @@ -2386,14 +2400,27 @@ fn send_and_spend_maker_payment_erc20() {
time_lock: payment_time_lock,
taker_secret_hash: &taker_secret_hash,
maker_secret_hash: &maker_secret_hash,
amount: trading_amount,
amount: trading_amount.clone(),
maker_pub,
swap_unique_data: &[],
};
block_on(taker_coin.validate_maker_payment_v2(validation_args)).unwrap();
log!("Taker validated maker ERC20 payment");

// TODO spend_maker_payment_v2
let spend_args = SpendMakerPaymentArgs {
maker_payment_tx: &payment_tx,
time_lock: payment_time_lock,
taker_secret_hash: &taker_secret_hash,
maker_secret_hash: &maker_secret_hash,
maker_secret: &maker_secret,
maker_pub,
swap_unique_data: &[],
amount: trading_amount,
};
wait_pending_transactions(Address::from_slice(taker_address.as_bytes()));
let spend_tx = block_on(taker_coin.spend_maker_payment_v2(spend_args)).unwrap();
log!("Taker spent maker ERC20 payment, tx hash: {:02x}", spend_tx.tx_hash());
wait_for_confirmations(&taker_coin, &spend_tx, 100);

// TODO wait_for_maker_payment_spend
block_on(maker_coin.wait_for_maker_payment_spend(&spend_tx, 0u64, payment_time_lock)).unwrap();
}

0 comments on commit 7498eec

Please sign in to comment.