Skip to content

Commit

Permalink
add coverage for tendermint_validators RPC
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Jan 2, 2025
1 parent 838bee4 commit 9d0e6c8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 18 deletions.
34 changes: 33 additions & 1 deletion mm2src/mm2_main/tests/docker_tests/tendermint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mm2_test_helpers::for_tests::{atom_testnet_conf, disable_coin, disable_coin_
enable_tendermint_token, enable_tendermint_without_balance,
get_tendermint_my_tx_history, ibc_withdraw, iris_ibc_nucleus_testnet_conf,
my_balance, nucleus_testnet_conf, orderbook, orderbook_v2, send_raw_transaction,
set_price, withdraw_v1, MarketMakerIt, Mm2TestConf};
set_price, tendermint_validators, withdraw_v1, MarketMakerIt, Mm2TestConf};
use mm2_test_helpers::structs::{Bip44Chain, HDAccountAddressId, OrderbookAddress, OrderbookV2Response, RpcV2Response,
TendermintActivationResult, TransactionDetails};
use serde_json::json;
Expand Down Expand Up @@ -651,6 +651,38 @@ fn test_passive_coin_and_force_disable() {
block_on(disable_coin_err(&mm, token, false));
}

#[test]
fn test_tendermint_validators_rpc() {
let coins = json!([nucleus_testnet_conf()]);
let platform_coin = 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,
platform_coin,
&[],
NUCLEUS_TESTNET_RPC_URLS,
false,
));
assert!(&activation_res.get("result").unwrap().get("address").is_some());

let validators_res = block_on(tendermint_validators(&mm, platform_coin, "All", 10, 1));

println!("\n\n{}", validators_res);

let validators_res = block_on(tendermint_validators(&mm, platform_coin, "Bonded", 10, 1));

println!("\n\n{}", validators_res);

let validators_res = block_on(tendermint_validators(&mm, platform_coin, "Unbonded", 10, 1));

println!("\n\n{}", validators_res);

assert!(false);
}

mod swap {
use super::*;

Expand Down
57 changes: 40 additions & 17 deletions mm2src/mm2_test_helpers/src/for_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3091,6 +3091,33 @@ pub async fn enable_tendermint_token(mm: &MarketMakerIt, coin: &str) -> Json {
json::from_str(&request.1).unwrap()
}

pub async fn tendermint_validators(
mm: &MarketMakerIt,
coin: &str,
filter_by_status: &str,
limit: usize,
page_number: usize,
) -> Json {
let rpc_endpoint = "tendermint_validators";
let request = json!({
"userpass": mm.userpass,
"method": rpc_endpoint,
"mmrpc": "2.0",
"params": {
"ticker": coin,
"filter_by_status": filter_by_status,
"limit": limit,
"page_number": page_number
}
});
log!("{rpc_endpoint} request {}", json::to_string(&request).unwrap());

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

pub async fn init_utxo_electrum(
mm: &MarketMakerIt,
coin: &str,
Expand Down Expand Up @@ -3271,18 +3298,19 @@ async fn init_erc20_token(
protocol: Option<Json>,
path_to_address: Option<HDAccountAddressId>,
) -> Result<(StatusCode, Json), Json> {
let (status, response, _) = mm.rpc(&json!({
"userpass": mm.userpass,
"method": "task::enable_erc20::init",
"mmrpc": "2.0",
"params": {
"ticker": ticker,
"protocol": protocol,
"activation_params": {
"path_to_address": path_to_address.unwrap_or_default(),
let (status, response, _) = mm
.rpc(&json!({
"userpass": mm.userpass,
"method": "task::enable_erc20::init",
"mmrpc": "2.0",
"params": {
"ticker": ticker,
"protocol": protocol,
"activation_params": {
"path_to_address": path_to_address.unwrap_or_default(),
}
}
}
}))
}))
.await
.unwrap();

Expand Down Expand Up @@ -3352,12 +3380,7 @@ pub async fn get_token_info(mm: &MarketMakerIt, protocol: Json) -> TokenInfoResp
}))
.await
.unwrap();
assert_eq!(
response.0,
StatusCode::OK,
"'get_token_info' failed: {}",
response.1
);
assert_eq!(response.0, StatusCode::OK, "'get_token_info' failed: {}", response.1);
let response_json: Json = json::from_str(&response.1).unwrap();
json::from_value(response_json["result"].clone()).unwrap()
}
Expand Down

0 comments on commit 9d0e6c8

Please sign in to comment.