Skip to content

Commit

Permalink
para to para integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrishoLukamba committed May 30, 2024
1 parent 75d69fa commit 04ef165
Showing 1 changed file with 76 additions and 29 deletions.
105 changes: 76 additions & 29 deletions parachain/integration-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
#![cfg(test)]

use anyhow::anyhow;
use std::{collections::HashMap, sync::Arc, time::Duration};
use std::collections::BTreeMap;
use subxt::{rpc_params, OnlineClient};
use subxt_utils::Hyperbridge;
use hex::ToHex;
use ismp::host::StateMachine;
use sc_service::TaskManager;
use sp_keyring::sr25519::Keyring;
use std::{
collections::{BTreeMap, HashMap},
ops::Div,
sync::Arc,
time::Duration,
};
use subxt::{
ext::sp_core::{sr25519::Pair, Pair as PairT},
tx::PairSigner,
rpc_params,
tx::{PairSigner, Signer},
utils::AccountId32,
OnlineClient,
};
use subxt::tx::Signer;
use subxt_signer::sr25519::{
dev::{self},
Keypair,
};
use subxt_utils::gargantua::{
api,
api::{
runtime_types,
runtime_types::{gargantua_runtime::RuntimeCall, pallet_ismp_demo::pallet::TransferParams},
use subxt_utils::{
gargantua::{
api,
api::{
runtime_types,
runtime_types::{
gargantua_runtime::RuntimeCall, pallet_ismp_demo::pallet::TransferParams,
},
},
},
Hyperbridge,
};
use tesseract::logging::setup as log_setup;
use tesseract_config::AnyConfig;
Expand Down Expand Up @@ -82,7 +90,7 @@ pub async fn initial_test_setup(
},
};

log::info!("url_a: {:?}",url_a);
log::info!("url_a: {:?}", url_a);
let (url_b, config_b) = match chain_b_config.clone() {
AnyConfig::Substrate(substrate_config) =>
(substrate_config.clone().rpc_ws, substrate_config),
Expand Down Expand Up @@ -158,14 +166,21 @@ async fn submit_transfer_function_works() -> Result<(), anyhow::Error> {
// call transfer call in pallet ismpDemo
let amount = 100000000000000000;
let transfer_call = api::tx().ismp_demo().transfer(TransferParams {
to: AccountId32(Keyring::Alice.public().0),
to: AccountId32(Keyring::Bob.public().0),
amount,
para_id: 2000,
timeout: 0,
});

let alice_key = api::storage().system().account(AccountId32(Keyring::Alice.public().0));
let initial_balance = client_a.storage().at_latest().await?.fetch(&alice_key).await?.ok_or("Failed to fetch").unwrap();
let initial_balance = client_a
.storage()
.at_latest()
.await?
.fetch(&alice_key)
.await?
.ok_or("Failed to fetch")
.unwrap();

let alice_signer =
PairSigner::<Hyperbridge, _>::new(Pair::from_string("//Alice", None).expect("kk"));
Expand All @@ -175,22 +190,47 @@ async fn submit_transfer_function_works() -> Result<(), anyhow::Error> {
.sign_and_submit_then_watch_default(&transfer_call, &alice_signer)
.await?;

tokio::time::sleep(Duration::from_secs(10)).await;

let re = result.next_item().await.unwrap(); // Still the tx is not reflected immediately and sometimes it doesnt at all
// but the invalid return is still persistent
log::info!(
" Chain A events: {:?}",
re
);
// but the invalid return is still persistent

log::info!(" Chain A events: {:?}", re);

tokio::time::sleep(Duration::from_secs(20)).await;

// TODO!
// assert events emitted

// assert statements here , it wont reach here
let rem_amount = client_a.storage().at_latest().await?.fetch(&alice_key).await?.ok_or("Failed to fetch").unwrap();
//assert_eq!(rem_amount.data.free + amount,initial_balance.data.free);
// assert statements here , it wont reach here sometimes

// asserting burnt amount
// round off to make asserting easy
let rem_amount = client_a
.storage()
.at_latest()
.await?
.fetch(&alice_key)
.await?
.ok_or("Failed to fetch")
.unwrap();

let rem_amount_rounded = f64::try_from((rem_amount.data.free + amount) as u32)
.unwrap()
.div(10f64.powi(1000))
.ceil();
let initial_balance_rounded = f64::try_from(initial_balance.data.free as u32)
.unwrap()
.div(10f64.powi(1000))
.ceil();
assert_eq!(rem_amount_rounded, initial_balance_rounded);
// check the depositing in chain b
let alice_chain_b_balance = client_b.storage().at_latest().await?.fetch(&alice_key).await?.ok_or("Failed to fetch").unwrap();
//assert_eq!(alice_chain_b_balance.data.free, initial_balance.data.free + amount);

// messaging relayer still has issues

//let alice_chain_b_balance =
// client_b.storage().at_latest().await?.fetch(&alice_key).await?.ok_or("Failed to
// fetch").unwrap(); assert_eq!(alice_chain_b_balance.data.free, initial_balance.data.free +
// amount);

Ok(())
}
Expand All @@ -199,10 +239,17 @@ async fn submit_transfer_function_works() -> Result<(), anyhow::Error> {
async fn get_request_works() -> Result<(), anyhow::Error> {
log_setup()?;
log::info!("🧊 Initializing tesseract messaging task for integration test for para to para: get request");
let (client_a,client_b) = initial_test_setup().await?;
let (client_a, client_b) = initial_test_setup().await?;

let key = api::storage().system().account(AccountId32(dev::bob().public_key().0));
let result = client_a.storage().at_latest().await?.fetch(&key).await?.ok_or("Failed to fetch").unwrap();
let result = client_a
.storage()
.at_latest()
.await?
.fetch(&key)
.await?
.ok_or("Failed to fetch")
.unwrap();
log::info!("Alice acc: {:?}", result);
Ok(())
}
Expand Down Expand Up @@ -242,8 +289,8 @@ async fn timed_out_transfer_requests_async_backed_effect() -> Result<(), anyhow:
async fn transact_post_request_works() -> Result<(), anyhow::Error> {
log_setup()?;
log::info!("🧊 Initializing tesseract messaging task for integration test for para to para: remote tx request");
let (client_a,clinent_b) = initial_test_setup().await?;
let (client_a, clinent_b) = initial_test_setup().await?;
let events = client_a.events().at_latest().await?;
log::info!("Events: {:?}",events);
log::info!("Events: {:?}", events);
Ok(())
}

0 comments on commit 04ef165

Please sign in to comment.