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 49854d7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 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
48 changes: 38 additions & 10 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 @@ -2314,6 +2314,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,16 +2338,29 @@ 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_args,
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]
Expand All @@ -2363,6 +2377,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 +2401,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_args,
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 49854d7

Please sign in to comment.