Skip to content

Commit

Permalink
migrate cosmos tx history test
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 Jun 6, 2024
1 parent 0096707 commit b3c603a
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 751 deletions.
60 changes: 30 additions & 30 deletions mm2src/mm2_main/tests/docker_tests/tendermint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use mm2_number::BigDecimal;
use mm2_test_helpers::for_tests::{atom_testnet_conf, disable_coin, disable_coin_err, enable_tendermint,
enable_tendermint_token, enable_tendermint_without_balance,
get_tendermint_my_tx_history, ibc_withdraw, iris_nimda_testnet_conf,
iris_ibc_nucleus_testnet_conf, nucleus_testnet_conf,
iris_testnet_conf, my_balance, send_raw_transaction, withdraw_v1, MarketMakerIt,
Mm2TestConf};
use mm2_test_helpers::structs::{Bip44Chain, HDAccountAddressId, RpcV2Response, TendermintActivationResult,
Expand Down Expand Up @@ -430,23 +431,22 @@ fn test_tendermint_token_withdraw() {
}

#[test]
#[ignore]
fn test_tendermint_tx_history() {
const TEST_SEED: &str = "Vdo8Xt8pTAetRlMq3kV0LzE393eVYbPSn5Mhtw4p";
const TX_FINISHED_LOG: &str = "Tx history fetching finished for IRIS-TEST.";
const TX_FINISHED_LOG: &str = "Tx history fetching finished for NUCLEUS-TEST.";
const TX_HISTORY_PAGE_LIMIT: usize = 50;
const IRIS_TEST_EXPECTED_TX_COUNT: u64 = 16;
const IRIS_NIMDA_EXPECTED_TX_COUNT: u64 = 10;
const NUCLEUS_EXPECTED_TX_COUNT: u64 = 7;
const IRIS_IBC_EXPECTED_TX_COUNT: u64 = 1;

let iris_test_constant_history_txs = include_str!("../../../mm2_test_helpers/dummy_files/iris_test_history.json");
let iris_test_constant_history_txs: Vec<TransactionDetails> =
serde_json::from_str(iris_test_constant_history_txs).unwrap();
let nucleus_constant_history_txs = include_str!("../../../mm2_test_helpers/dummy_files/nucleus-history.json");
let nucleus_constant_history_txs: Vec<TransactionDetails> =
serde_json::from_str(nucleus_constant_history_txs).unwrap();

let iris_nimda_constant_history_txs = include_str!("../../../mm2_test_helpers/dummy_files/iris_nimda_history.json");
let iris_nimda_constant_history_txs: Vec<TransactionDetails> =
serde_json::from_str(iris_nimda_constant_history_txs).unwrap();
let iris_ibc_constant_history_txs = include_str!("../../../mm2_test_helpers/dummy_files/iris-ibc-nucleus-history.json");
let iris_ibc_constant_history_txs: Vec<TransactionDetails> =
serde_json::from_str(iris_ibc_constant_history_txs).unwrap();

let coins = json!([iris_testnet_conf(), iris_nimda_testnet_conf()]);
let coins = json!([nucleus_testnet_conf(), iris_ibc_nucleus_testnet_conf()]);
let platform_coin = coins[0]["coin"].as_str().unwrap();
let token = coins[1]["coin"].as_str().unwrap();

Expand All @@ -457,7 +457,7 @@ fn test_tendermint_tx_history() {
&mm,
platform_coin,
&[token],
IRIS_TESTNET_RPC_URLS,
NUCLEUS_TESTNET_RPC_URLS,
true,
));

Expand All @@ -466,41 +466,41 @@ fn test_tendermint_tx_history() {
panic!("Tx history didn't finish which is not expected");
}

// testing IRIS-TEST history
let iris_tx_history_response = block_on(get_tendermint_my_tx_history(
// testing NUCLEUS-TEST history
let nucleus_history_response = block_on(get_tendermint_my_tx_history(
&mm,
platform_coin,
TX_HISTORY_PAGE_LIMIT,
1,
));
let total_txs = iris_tx_history_response["result"]["total"].as_u64().unwrap();
assert_eq!(total_txs, IRIS_TEST_EXPECTED_TX_COUNT);
let total_txs = nucleus_history_response["result"]["total"].as_u64().unwrap();
assert_eq!(total_txs, NUCLEUS_EXPECTED_TX_COUNT);

let mut iris_txs_from_request = iris_tx_history_response["result"]["transactions"].clone();
for i in 0..IRIS_TEST_EXPECTED_TX_COUNT {
iris_txs_from_request[i as usize]
let mut nucleus_txs_from_request = nucleus_history_response["result"]["transactions"].clone();
for i in 0..NUCLEUS_EXPECTED_TX_COUNT {
nucleus_txs_from_request[i as usize]
.as_object_mut()
.unwrap()
.remove("confirmations");
}
let iris_txs_from_request: Vec<TransactionDetails> = serde_json::from_value(iris_txs_from_request).unwrap();
assert_eq!(iris_test_constant_history_txs, iris_txs_from_request);
let nucleus_txs_from_request: Vec<TransactionDetails> = serde_json::from_value(nucleus_txs_from_request).unwrap();
assert_eq!(nucleus_constant_history_txs, nucleus_txs_from_request);

// testing IRIS-NIMDA history
let nimda_tx_history_response = block_on(get_tendermint_my_tx_history(&mm, token, TX_HISTORY_PAGE_LIMIT, 1));
let total_txs = nimda_tx_history_response["result"]["total"].as_u64().unwrap();
assert_eq!(total_txs, IRIS_NIMDA_EXPECTED_TX_COUNT);
// testing IRIS-IBC-NUCLEUS-TEST history
let iris_ibc_tx_history_response = block_on(get_tendermint_my_tx_history(&mm, token, TX_HISTORY_PAGE_LIMIT, 1));
let total_txs = iris_ibc_tx_history_response["result"]["total"].as_u64().unwrap();
assert_eq!(total_txs, IRIS_IBC_EXPECTED_TX_COUNT);

let mut nimda_txs_from_request = nimda_tx_history_response["result"]["transactions"].clone();
for i in 0..IRIS_NIMDA_EXPECTED_TX_COUNT {
nimda_txs_from_request[i as usize]
let mut iris_ibc_txs_from_request = iris_ibc_tx_history_response["result"]["transactions"].clone();
for i in 0..IRIS_IBC_EXPECTED_TX_COUNT {
iris_ibc_txs_from_request[i as usize]
.as_object_mut()
.unwrap()
.remove("confirmations");
}
let nimda_txs_from_request: Vec<TransactionDetails> = serde_json::from_value(nimda_txs_from_request).unwrap();
let iris_ibc_txs_from_request: Vec<TransactionDetails> = serde_json::from_value(iris_ibc_txs_from_request).unwrap();

assert_eq!(iris_nimda_constant_history_txs, nimda_txs_from_request);
assert_eq!(iris_ibc_constant_history_txs, iris_ibc_txs_from_request);

block_on(mm.stop()).unwrap();
}
Expand Down
18 changes: 9 additions & 9 deletions mm2src/mm2_main/tests/docker_tests_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ use docker_tests::qrc20_tests::{qtum_docker_node, QtumDockerOps, QTUM_REGTEST_DO
pub fn docker_tests_runner(tests: &[&TestDescAndFn]) {
// pretty_env_logger::try_init();
let docker = Cli::default();
let mut containers = vec![];
// let mut containers = vec![];
// skip Docker containers initialization if we are intended to run test_mm_start only
if std::env::var("_MM2_TEST_CONF").is_err() {
pull_docker_image(NUCLEUS_IMAGE);
pull_docker_image(ATOM_IMAGE);
// pull_docker_image(NUCLEUS_IMAGE);
// pull_docker_image(ATOM_IMAGE);

remove_docker_containers(NUCLEUS_IMAGE);
remove_docker_containers(ATOM_IMAGE);
// remove_docker_containers(NUCLEUS_IMAGE);
// remove_docker_containers(ATOM_IMAGE);

let nucleus_node = nucleus_node(&docker, 26657);
let atom_node = atom_node(&docker, 26658);
// let nucleus_node = nucleus_node(&docker, 26657);
// let atom_node = atom_node(&docker, 26658);

containers.push(nucleus_node);
containers.push(atom_node);
// containers.push(nucleus_node);
// containers.push(atom_node);
}
// detect if docker is installed
// skip the tests that use docker if not installed
Expand Down
30 changes: 30 additions & 0 deletions mm2src/mm2_test_helpers/dummy_files/iris-ibc-nucleus-history.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"tx_hex": "0a2a6e7563317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c37376e303738122a6e756331366e6c653735746572323674613278303671726d6e7066307833786637346e337276763677391a4f0a446962632f46374632384646334330393032344130323235454442424442323037453538373244324234454632464238373446453437423035454639433941374432313143120734303030303030",
"tx_hash": "9EB45C82244FEF0A1D84AF59780389A265B29D18EAC7B7FA0DEE8F5E3B9522E7",
"from": [
"nuc1z609g9z8ef4jlkcfgg36c2ljgcmna50l77n078"
],
"to": [
"nuc16nle75ter26ta2x06qrmnpf0x3xf74n3rvv6w9"
],
"total_amount": "4",
"spent_by_me": "4",
"received_by_me": "0",
"my_balance_change": "-4",
"block_height": 178,
"timestamp": 1717499824,
"fee_details": {
"type": "Tendermint",
"coin": "NUCLEUS-TEST",
"amount": "0.025689",
"gas_limit": 125000
},
"coin": "IRIS-IBC-NUCLEUS-TEST",
"internal_id": "3935464134384431413046454634343232384335344245390000000000000000",
"transaction_type": {
"TokenTransfer": "da5368780890dadaff39ad08ae29eaf6ae408fc4f8ece2f1336975ec2e70095f"
},
"memo": ""
}
]
Loading

0 comments on commit b3c603a

Please sign in to comment.