Skip to content

Commit

Permalink
add docker test
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 16, 2025
1 parent 6e5e145 commit 1dd2b73
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
39 changes: 37 additions & 2 deletions mm2src/mm2_main/tests/docker_tests/tendermint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ 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, tendermint_validators, withdraw_v1, MarketMakerIt, Mm2TestConf};
set_price, tendermint_add_delegation, 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 +678,40 @@ fn test_tendermint_validators_rpc() {
assert_eq!(validators_raw_response["result"]["validators"][0]["jailed"], false);
}

#[test]
fn test_tendermint_add_delegation() {
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 tx_details = block_on(tendermint_add_delegation(&mm, coin_ticker, VALIDATOR_ADDRESS, "0.5"));

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
30 changes: 30 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,36 @@ pub async fn tendermint_validators(
json::from_str(&response.1).unwrap()
}

pub async fn tendermint_add_delegation(
mm: &MarketMakerIt,
coin: &str,
validator_address: &str,
amount: &str,
) -> TransactionDetails {
let rpc_endpoint = "add_delegation";
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);

let json: Json = json::from_str(&response.1).unwrap();
json::from_value(json["result"].clone()).unwrap()
}

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

0 comments on commit 1dd2b73

Please sign in to comment.