Skip to content

Commit

Permalink
add integration test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Jan 16, 2025
1 parent 6e5e145 commit cf2f8c7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
48 changes: 47 additions & 1 deletion mm2src/mm2_main/tests/docker_tests/tendermint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mm2_test_helpers::for_tests::{atom_testnet_conf, disable_coin, disable_coin_
my_balance, nucleus_testnet_conf, orderbook, orderbook_v2, send_raw_transaction,
set_price, tendermint_validators, withdraw_v1, MarketMakerIt, Mm2TestConf};
use mm2_test_helpers::structs::{Bip44Chain, HDAccountAddressId, OrderbookAddress, OrderbookV2Response, RpcV2Response,
TendermintActivationResult, TransactionDetails};
TendermintActivationResult, TransactionDetails, TransactionType};
use serde_json::json;
use std::collections::HashSet;
use std::iter::FromIterator;
Expand Down Expand Up @@ -677,6 +677,52 @@ fn test_tendermint_validators_rpc() {
assert_eq!(validators_raw_response["result"]["validators"][0]["jailed"], false);
}

#[test]
fn test_tendermint_add_delegate() {
const MY_ADDRESS: &str = "nuc150evuj4j7k9kgu38e453jdv9m3u0ft2n4fgzfr";
const VALIDATOR_ADDRESS: &str = "nucvaloper15d4sf4z6y0vk9dnum8yzkvr9c3wq4q897vefpu";

let coins = json!([nucleus_testnet_conf()]);
let coin_ticker = coins[0]["coin"].as_str().unwrap();

let conf = Mm2TestConf::seednode(TENDERMINT_TEST_SEED, &coins);
let mm = MarketMakerIt::start(conf.conf, conf.rpc_password, None).unwrap();

let activation_res = block_on(enable_tendermint(
&mm,
coin_ticker,
&[],
NUCLEUS_TESTNET_RPC_URLS,
false,
));

log!(
"Activation with assets {}",
serde_json::to_string(&activation_res).unwrap()
);

let delegation_amount = "0.6150";
let tx_details = block_on(withdraw_v1(
&mm,
coin_ticker,
VALIDATOR_ADDRESS,
delegation_amount,
None,
));

let expected_total: BigDecimal = delegation_amount.parse().unwrap();
assert_eq!(tx_details.total_amount, expected_total);
assert_eq!(tx_details.spent_by_me, expected_total);
assert_eq!(tx_details.my_balance_change, expected_total * BigDecimal::from(-1));
assert_eq!(tx_details.received_by_me, BigDecimal::default());
assert_eq!(tx_details.to, vec![VALIDATOR_ADDRESS.to_owned()]);
assert_eq!(tx_details.from, vec![MY_ADDRESS.to_owned()]);
assert_eq!(tx_details.transaction_type, TransactionType::StakingDelegation);

let send_raw_tx = block_on(send_raw_transaction(&mm, coin_ticker, &tx_details.tx_hex));
log!("Send raw tx {}", serde_json::to_string(&send_raw_tx).unwrap());
}

mod swap {
use super::*;

Expand Down
28 changes: 28 additions & 0 deletions mm2src/mm2_test_helpers/src/for_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3118,6 +3118,34 @@ pub async fn tendermint_validators(
json::from_str(&response.1).unwrap()
}

pub async fn tendermint_add_delegate(
mm: &MarketMakerIt,
coin: &str,
validator_address: &str,
amount: BigDecimal,
) -> Json {
let rpc_endpoint = "add_delegate";
let request = json!({
"userpass": mm.userpass,
"method": rpc_endpoint,
"mmrpc": "2.0",
"params": {
"coin": coin,
"staking_details": {
"type": "Cosmos",
"validator_address": validator_address,
"amount": amount,
}
}
});
log!("{rpc_endpoint} request {}", json::to_string(&request).unwrap());

let response = mm.rpc(&request).await.unwrap();
assert_eq!(response.0, StatusCode::OK, "{rpc_endpoint} failed: {}", response.1);
log!("{rpc_endpoint} response {}", response.1);
json::from_str(&response.1).unwrap()
}

pub async fn init_utxo_electrum(
mm: &MarketMakerIt,
coin: &str,
Expand Down

0 comments on commit cf2f8c7

Please sign in to comment.