From 68b0e7405c8a584077285d2334538d111d4dbd52 Mon Sep 17 00:00:00 2001 From: Luca Joss <43531661+ljoss17@users.noreply.github.com> Date: Tue, 13 Aug 2024 12:10:48 +0200 Subject: [PATCH] Remove MBT related parts (#4141) --- .github/workflows/integration.yaml | 39 --- Cargo.lock | 1 - Cargo.toml | 1 - tools/integration-test/Cargo.toml | 4 - tools/integration-test/src/lib.rs | 4 - tools/integration-test/src/mbt/README.md | 7 - tools/integration-test/src/mbt/handlers.rs | 291 ---------------- tools/integration-test/src/mbt/itf.rs | 132 -------- tools/integration-test/src/mbt/mod.rs | 8 - tools/integration-test/src/mbt/state.rs | 85 ----- tools/integration-test/src/mbt/transfer.rs | 373 --------------------- tools/integration-test/src/mbt/utils.rs | 132 -------- 12 files changed, 1077 deletions(-) delete mode 100644 tools/integration-test/src/mbt/README.md delete mode 100644 tools/integration-test/src/mbt/handlers.rs delete mode 100644 tools/integration-test/src/mbt/itf.rs delete mode 100644 tools/integration-test/src/mbt/mod.rs delete mode 100644 tools/integration-test/src/mbt/state.rs delete mode 100644 tools/integration-test/src/mbt/transfer.rs delete mode 100644 tools/integration-test/src/mbt/utils.rs diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 899ac76fd4..8475a2e18b 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -294,42 +294,3 @@ jobs: nix shell .#python ${{ matrix.chain.package }} -c \ cargo nextest run -p ibc-integration-test --no-fail-fast --failure-output final --test-threads=2 \ --features celestia - - model-based-test: - runs-on: ubuntu-20.04 - timeout-minutes: 60 - strategy: - matrix: - gaiad: - - gaia6 - steps: - - uses: actions/checkout@v4 - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@main - with: - extra-conf: | - substituters = https://cache.nixos.org - trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= - - name: Install Cachix - uses: cachix/cachix-action@v15 - with: - name: cosmos-nix - - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable - - uses: actions-rs/cargo@v1 - with: - command: test - args: -p ibc-integration-test --features mbt --no-fail-fast --no-run - # Disable running MBT tests until flakiness is addressed - # - env: - # RUST_LOG: debug - # RUST_BACKTRACE: 1 - # NO_COLOR_LOG: 1 - # run: | - # nix shell \ - # .#${{ matrix.gaiad }} \ - # .#apalache \ - # -c cargo \ - # test -p ibc-integration-test --features mbt --no-fail-fast -- \ - # --failure-output final --test-threads=2 --test-threads=1 mbt diff --git a/Cargo.lock b/Cargo.lock index 99874a3d39..d1d527a186 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1537,7 +1537,6 @@ dependencies = [ "prost", "serde", "serde_json", - "tempfile", "tendermint", "tendermint-rpc", "time", diff --git a/Cargo.toml b/Cargo.toml index 4e2109b73e..537e56f982 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,7 +102,6 @@ signal-hook = "0.3.17" signature = "2.1.0" strum = "0.25" subtle-encoding = "0.5.1" -tempfile = "3.10.1" test-log = "0.2.14" thiserror = "1.0.63" time = "0.3" diff --git a/tools/integration-test/Cargo.toml b/tools/integration-test/Cargo.toml index f23398217a..180f33f2e5 100644 --- a/tools/integration-test/Cargo.toml +++ b/tools/integration-test/Cargo.toml @@ -36,7 +36,6 @@ ordered = [] ica = [] ics29-fee = [] experimental = [] -mbt = [] forward-packet = [] ics31 = [] clean-workers = [] @@ -54,6 +53,3 @@ benchmark = [] [[bin]] name = "test_setup_with_binary_channel" doc = true - -[dev-dependencies] -tempfile = { workspace = true } diff --git a/tools/integration-test/src/lib.rs b/tools/integration-test/src/lib.rs index f4b83a25c4..75d580024e 100644 --- a/tools/integration-test/src/lib.rs +++ b/tools/integration-test/src/lib.rs @@ -1,7 +1,3 @@ #[allow(clippy::too_many_arguments)] #[cfg(test)] pub mod tests; - -#[cfg(any(all(test, feature = "mbt"), doc))] -#[macro_use] -pub mod mbt; diff --git a/tools/integration-test/src/mbt/README.md b/tools/integration-test/src/mbt/README.md deleted file mode 100644 index f2c0311b28..0000000000 --- a/tools/integration-test/src/mbt/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# MBT for Hermes Integration Test - -Make sure [`apalache-mc`](https://github.com/informalsystems/apalache) is installed and setup properly. Check `apalache-mc version`. - -```bash -cargo test -p ibc-integration-test --features mbt mbt::transfer -``` diff --git a/tools/integration-test/src/mbt/handlers.rs b/tools/integration-test/src/mbt/handlers.rs deleted file mode 100644 index 53421f20c8..0000000000 --- a/tools/integration-test/src/mbt/handlers.rs +++ /dev/null @@ -1,291 +0,0 @@ -use ibc_relayer::util::task::TaskHandle; -use ibc_relayer::worker::client::spawn_refresh_client; - -use ibc_test_framework::bootstrap::binary::chain::bootstrap_foreign_client_pair; -use ibc_test_framework::bootstrap::binary::connection::bootstrap_connection; -use ibc_test_framework::prelude::*; -use ibc_test_framework::relayer::channel::{assert_eventually_channel_established, init_channel}; -use ibc_test_framework::relayer::connection::{ - assert_eventually_connection_established, init_connection, -}; -use ibc_test_framework::types::binary::client::ClientIdPair; -use ibc_test_framework::types::tagged::mono::Tagged; - -use super::state::Packet; - -use super::utils::{get_denom, get_wallet, wait_for_client}; - -pub fn setup_chains( - chains: &ConnectedChains, -) -> Result<(), Error> { - { - let _refresh_task_a = spawn_refresh_client(chains.foreign_clients.client_b_to_a.clone()) - .ok_or_else(|| eyre!("expect refresh task spawned"))?; - - let _refresh_task_b = spawn_refresh_client(chains.foreign_clients.client_a_to_b.clone()) - .ok_or_else(|| eyre!("expect refresh task spawned"))?; - - bootstrap_connection(&chains.foreign_clients, Default::default())?; - }; - - wait_for_client(); - - Ok(()) -} - -pub fn local_transfer_handler( - node: Tagged, - source: u128, - target: u128, - denom: u128, - amount: u128, - fees: &TaggedTokenRef, -) -> Result<(), Error> { - let wallets = node.wallets(); - - let source_wallet = get_wallet(&wallets, source); - let target_wallet = get_wallet(&wallets, target); - let denom = get_denom(&node, denom); - - node.chain_driver().local_transfer_token( - &source_wallet, - &target_wallet.address(), - &denom.with_amount(amount).as_ref(), - fees, - )?; - - Ok(()) -} - -pub fn create_channel( - chain_handle_a: &ChainA, - chain_handle_b: &ChainB, - channel: &mut Option>, - refresh_task_a: &mut Option, - refresh_task_b: &mut Option, -) -> Result<(), Error> { - let port_a = tagged_transfer_port(); - let port_b = tagged_transfer_port(); - - let clients2 = - bootstrap_foreign_client_pair(chain_handle_a, chain_handle_b, Default::default())?; - - *refresh_task_a = Some( - spawn_refresh_client(clients2.client_b_to_a.clone()) - .ok_or_else(|| eyre!("expect refresh task spawned"))?, - ); - - *refresh_task_b = Some( - spawn_refresh_client(clients2.client_a_to_b.clone()) - .ok_or_else(|| eyre!("expect refresh task spawned"))?, - ); - - let (connection_id_b, new_connection_b) = init_connection( - chain_handle_a, - chain_handle_b, - &clients2.client_b_to_a.tagged_client_id(), - &clients2.client_a_to_b.tagged_client_id(), - )?; - - let connection_id_a = assert_eventually_connection_established( - chain_handle_b, - chain_handle_a, - &connection_id_b.as_ref(), - )?; - - let (channel_id_b_2, channel_b_2) = init_channel( - chain_handle_a, - chain_handle_b, - &clients2.client_b_to_a.tagged_client_id(), - &clients2.client_a_to_b.tagged_client_id(), - &connection_id_a.as_ref(), - &connection_id_b.as_ref(), - &port_a.as_ref(), - &port_b.as_ref(), - )?; - - let channel_id_a_2 = assert_eventually_channel_established( - chain_handle_b, - chain_handle_a, - &channel_id_b_2.as_ref(), - &port_b.as_ref(), - )?; - - let client_ids = ClientIdPair::new( - clients2.client_b_to_a.tagged_client_id().cloned(), - clients2.client_a_to_b.tagged_client_id().cloned(), - ); - - let new_connected_connection = ConnectedConnection::new( - client_ids, - new_connection_b.flipped(), - connection_id_a, - connection_id_b, - ); - - let connected_channel = ConnectedChannel { - connection: new_connected_connection, - channel: channel_b_2.flipped(), - channel_id_a: channel_id_a_2, - channel_id_b: channel_id_b_2, - port_a, - port_b, - }; - - *channel = Some(connected_channel); - - info!("Channel is created"); - - Ok(()) -} - -pub fn expire_channel( - channel: &mut Option>, - refresh_task_a: &mut Option, - refresh_task_b: &mut Option, -) -> Result<(), Error> { - // dropping the client handler to expire the clients - super::utils::drop(refresh_task_a.take()); - super::utils::drop(refresh_task_b.take()); - - wait_for_client(); - - super::utils::drop(channel.take()); - - info!("Channel expired"); - - Ok(()) -} - -pub fn ibc_transfer_send_packet( - node_source: Tagged, - node_target: Tagged, - channels: &ConnectedChannel, - packet: &Packet, -) -> Result<(), Error> { - let wallets_source = node_source.wallets(); - let wallets_target = node_target.wallets(); - - let wallet_source = get_wallet(&wallets_source, packet.from); - let wallet_target = get_wallet(&wallets_target, packet.to); - let denom_source = get_denom(&node_source, packet.denom); - let amount_source_to_target = packet.amount; - - let (port_source, channel_id_source) = ( - DualTagged::new(channels.port_a.value()), - DualTagged::new(channels.channel_id_a.value()), - ); - - let balance_source = node_source - .chain_driver() - .query_balance(&wallet_source.address(), &denom_source)?; - - info!( - "Sending IBC transfer from chain {} to chain {} with amount of {} {}", - node_source.chain_id(), - node_target.chain_id(), - amount_source_to_target, - denom_source, - ); - - node_source.chain_driver().ibc_transfer_token( - &port_source, - &channel_id_source, - &wallet_source, - &wallet_target.address(), - &denom_source.with_amount(amount_source_to_target).as_ref(), - )?; - - node_source.chain_driver().assert_eventual_wallet_amount( - &wallet_source.address(), - &(balance_source - amount_source_to_target).as_ref(), - )?; - - Ok(()) -} - -pub fn ibc_transfer_receive_packet( - node_source: Tagged, - node_target: Tagged, - channels: &ConnectedChannel, - packet: &Packet, -) -> Result<(), Error> { - let wallets_target = node_target.wallets(); - - let wallet_target = get_wallet(&wallets_target, packet.to); - let denom_source = get_denom(&node_source, packet.denom); - let amount_source_to_target = packet.amount; - - let (port_target, channel_id_target) = ( - DualTagged::new(channels.port_b.value()), - DualTagged::new(channels.channel_id_b.value()), - ); - - let denom_target = derive_ibc_denom(&port_target, &channel_id_target, &denom_source)?; - - info!( - "Waiting for user on chain {} to receive IBC transferred amount of {} {} (chain {}/{})", - node_target.chain_id(), - amount_source_to_target, - denom_target, - node_source.chain_id(), - denom_source - ); - - node_target.chain_driver().assert_eventual_wallet_amount( - &wallet_target.address(), - &denom_target.with_amount(amount_source_to_target).as_ref(), - )?; - - Ok(()) -} - -pub fn ibc_transfer_acknowledge_packet( - node_source: Tagged, - node_target: Tagged, - _channels: &Option>, - packet: &Packet, -) -> Result<(), Error> { - let denom_source = get_denom(&node_source, packet.denom); - let amount_source_to_target = packet.amount; - - info!( - "Waiting for user on chain {} to confirm IBC transferred amount of {} {}", - node_source.chain_id(), - amount_source_to_target, - denom_source - ); - - info!( - "Successfully performed IBC transfer from chain {} to chain {}", - node_source.chain_id(), - node_target.chain_id(), - ); - - Ok(()) -} - -pub fn ibc_transfer_expire_packet( - node_source: Tagged, - node_target: Tagged, - _channels: &Option>, - packet: &Packet, -) -> Result<(), Error> { - let denom_source = get_denom(&node_source, packet.denom); - let amount_source_to_target = packet.amount; - - info!( - "Waiting for user on chain {} to get refund of previously IBC transferred amount of {} {}", - node_source.chain_id(), - amount_source_to_target, - denom_source - ); - - info!( - "Successfully performed IBC packet expiry intended from chain {} to chain {}", - node_source.chain_id(), - node_target.chain_id(), - ); - - Ok(()) -} diff --git a/tools/integration-test/src/mbt/itf.rs b/tools/integration-test/src/mbt/itf.rs deleted file mode 100644 index 44bb354ed9..0000000000 --- a/tools/integration-test/src/mbt/itf.rs +++ /dev/null @@ -1,132 +0,0 @@ -use serde::{Deserialize, Deserializer, Serialize}; - -#[derive(Debug, Serialize, Deserialize)] -pub struct Meta { - pub format: String, - #[serde(rename = "format-description")] - pub format_description: String, - pub description: String, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct InformalTrace { - #[serde(rename = "#meta")] - pub meta: Meta, - pub vars: Vec, - pub states: Vec, -} - -#[derive(Debug, Serialize)] -pub struct Map(pub Vec<(K, V)>); - -impl<'de, K, V> Deserialize<'de> for Map -where - K: Deserialize<'de>, - V: Deserialize<'de>, -{ - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - #[derive(Debug, Deserialize)] - struct Meta { - #[serde(rename = "#map")] - map: Vec<(K, V)>, - } - let s: Meta<_, _> = Deserialize::deserialize(deserializer)?; - Ok(Self(s.map)) - } -} - -#[derive(Debug, Serialize)] -pub struct Set(pub Vec); - -impl<'de, E> Deserialize<'de> for Set -where - E: Deserialize<'de>, -{ - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - #[derive(Debug, Deserialize)] - pub struct Meta { - #[serde(rename = "#set")] - set: Vec, - } - let s: Meta<_> = Deserialize::deserialize(deserializer)?; - Ok(Self(s.set)) - } -} - -mod test { - use super::{Map, Set}; - - #[test] - fn test_empty_set() { - let itf = r##"{ "#set": [] }"##; - let s: Set = serde_json::from_str(itf).unwrap(); - assert!(s.0.is_empty()); - } - - #[test] - fn test_set() { - let itf = r##"{ "#set": [1,2,3] }"##; - let s: Set = serde_json::from_str(itf).unwrap(); - assert_eq!(s.0, vec![1, 2, 3]); - } - - #[test] - fn test_empty_map() { - let itf = r##"{ "#map": [ ] }"##; - let m: Map = serde_json::from_str(itf).unwrap(); - assert!(m.0.is_empty()); - } - - #[test] - #[should_panic] - fn test_singleton_map() { - let itf = r##"{ "#map": [1, 11] }"##; - let m: Map = serde_json::from_str(itf).unwrap(); - assert_eq!(m.0, vec![(1, 11)]); - } - - #[test] - fn test_normal_map() { - let itf = r##"{ "#map": [[1, 11], [2, 22]] }"##; - let m: Map = serde_json::from_str(itf).unwrap(); - assert_eq!(m.0, vec![(1, 11), (2, 22)]); - } - - #[test] - #[cfg(feature = "manual")] - fn parse_itf() { - use super::super::itf::InformalTrace; - use super::super::state::State; - - let itf_path = concat!( - env!("CARGO_MANIFEST_DIR"), - "/spec/example/counterexample.itf.json" - ); - - let itf_json = std::fs::read_to_string(itf_path).expect("itf file does not exist"); - - let t: InformalTrace = - serde_json::from_str(&itf_json).expect("deserialization error"); - - for state in t.states { - println!( - "action: {}", - serde_json::to_string_pretty(&state.action).unwrap() - ); - println!( - "outcome: {}", - serde_json::to_string_pretty(&state.outcome).unwrap() - ); - println!( - "chains: {}", - serde_json::to_string_pretty(&state.chains).unwrap() - ); - } - } -} diff --git a/tools/integration-test/src/mbt/mod.rs b/tools/integration-test/src/mbt/mod.rs deleted file mode 100644 index 173f132abb..0000000000 --- a/tools/integration-test/src/mbt/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub mod utils; - -pub mod itf; -pub mod state; - -pub mod handlers; - -pub mod transfer; diff --git a/tools/integration-test/src/mbt/state.rs b/tools/integration-test/src/mbt/state.rs deleted file mode 100644 index b9ddf34e9e..0000000000 --- a/tools/integration-test/src/mbt/state.rs +++ /dev/null @@ -1,85 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::itf::{Map, Set}; - -pub type ChainId = u128; -pub type DenomId = ChainId; -pub type AccountId = u128; -pub type PacketId = u128; -pub type Balance = u128; - -#[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Packet { - pub id: PacketId, - pub from: AccountId, - pub source_chain_id: ChainId, - pub to: AccountId, - pub target_chain_id: ChainId, - pub denom: DenomId, - pub amount: Balance, -} - -#[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct LocalPackets { - pub list: Map, - pub pending: Set, - pub expired: Set, - pub success: Set, -} - -#[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Chain { - pub id: ChainId, - pub bank: Map>, - pub supply: Map, - pub local_packets: LocalPackets, - pub remote_packets: Map>, - pub escrow: Map>, - pub next_packet_id: PacketId, -} - -#[derive(Debug, Serialize, Deserialize)] -#[serde(tag = "name")] -pub enum Action { - Null, - #[serde(rename_all = "camelCase")] - LocalTransfer { - chain_id: ChainId, - source: AccountId, - target: AccountId, - denom: DenomId, - amount: Balance, - }, - RestoreRelay, - InterruptRelay, - IBCTransferSendPacket { - packet: Packet, - }, - IBCTransferReceivePacket { - packet: Packet, - }, - IBCTransferAcknowledgePacket { - packet: Packet, - }, - IBCTransferTimeoutPacket { - packet: Packet, - }, -} - -#[derive(Debug, Serialize, Deserialize)] -#[serde(tag = "name")] -pub enum Outcome { - Success, - Error, -} - -#[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct State { - pub chains: Map, - pub action: Action, - pub outcome: Outcome, -} diff --git a/tools/integration-test/src/mbt/transfer.rs b/tools/integration-test/src/mbt/transfer.rs deleted file mode 100644 index e10b595112..0000000000 --- a/tools/integration-test/src/mbt/transfer.rs +++ /dev/null @@ -1,373 +0,0 @@ -use std::io::Write; -use std::panic::{RefUnwindSafe, UnwindSafe}; - -use ibc_relayer::config::{ - ChainConfig, Channels as ConfigChannels, Clients as ConfigClients, - Connections as ConfigConnections, ModeConfig, Packets as ConfigPackets, -}; - -use ibc_test_framework::prelude::*; -use ibc_test_framework::types::tagged::mono::Tagged; - -use super::state::{Action, State}; - -use super::itf::InformalTrace; -use super::utils::{get_chain, CLIENT_EXPIRY}; - -const TEST_NAMES: &[&str] = &[ - "LocalTransferInv", - "IBCTransferAcknowledgePacketInv", - "IBCTransferTimeoutPacketInv", -]; -const NUM_TRACES: Option<&str> = option_env!("MBT_TRACES"); -const APALACHE: Option<&str> = option_env!("APALACHE"); - -const ITF_TRACE_DIRECTORY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/data/mbt"); - -fn generate_mbt_traces( - apalache_path: &str, - test_name: &str, - num_traces: usize, -) -> Result, Error> { - let temp_dir = tempfile::TempDir::new()?; - let run_dir = temp_dir.path().join("run"); - let tla_path = concat!(env!("CARGO_MANIFEST_DIR"), "/spec/MC_Transfer.tla"); - let mut cmd = std::process::Command::new(apalache_path); - cmd.arg("check") - .arg("--init=Init") - .arg("--next=Next") - .arg(&format!("--inv={test_name}")) - .arg(&format!("--max-error={num_traces}")) - .arg(&format!( - "--run-dir={}", - run_dir.to_str().expect("no panic") - )) - .arg(&format!( - "--out-dir={}", - temp_dir.path().to_str().expect("no panic") - )) - .arg(tla_path); - let _ = cmd.status().expect("failed to execute process"); - - std::fs::read_dir(run_dir)? - .flatten() - .map(|entry| entry.path()) - .filter(|file_path| file_path.is_file()) - .flat_map(|file_path| { - file_path - .file_name() - .and_then(|file_name| file_name.to_str()) - .and_then(|file_name| { - (file_name != "counterexample.itf.json" - && file_name.starts_with("counterexample") - && file_name.ends_with(".itf.json")) - .then(|| { - let name = format!("{test_name}_{file_name}"); - Ok(( - name, - std::fs::read_to_string(file_path.to_str().expect("should not panic")) - .expect("error while reading counterexample.itf.json"), - )) - }) - }) - }) - .collect() -} - -fn execute_mbt(f: F) -> Result<(), Error> -where - F: FnOnce(Vec) -> Result<(), Error> + UnwindSafe + RefUnwindSafe + Copy, -{ - let apalache = APALACHE.unwrap_or("apalache-mc"); - let num_traces = NUM_TRACES - .unwrap_or("2") - .parse() - .expect("an number for number of traces per test"); - - let success_traces = &format!("{ITF_TRACE_DIRECTORY}/success"); - let failure_traces = &format!("{ITF_TRACE_DIRECTORY}/failure"); - - std::fs::create_dir_all(success_traces)?; - std::fs::create_dir_all(failure_traces)?; - - for test_name in TEST_NAMES { - for (itf_name, itf_json) in generate_mbt_traces(apalache, test_name, num_traces)? { - let itf: InformalTrace = - serde_json::from_str(&itf_json).expect("deserialization error"); - - let result = std::panic::catch_unwind(|| f(itf.states).expect("to fail")); - - let unique_itf_trace_path = if result.is_ok() { - format!("{success_traces}/{itf_name}") - } else { - format!("{failure_traces}/{itf_name}") - }; - - let mut file = std::fs::File::create(unique_itf_trace_path)?; - file.write_all(itf_json.as_bytes())?; - - if let Err(err) = result { - std::panic::resume_unwind(err); - } - } - } - Ok(()) -} - -#[test] -fn test_ibc_transfer() -> Result<(), Error> { - execute_mbt(|trace| run_binary_channel_test(&IbcTransferMBT(trace))) -} - -/** - Test that IBC token transfer can still work with a single - chain that is connected to itself. -*/ -#[test] -#[cfg(feature = "manual")] -fn test_self_connected_ibc_transfer() -> Result<(), Error> { - use ibc_test_framework::framework::binary::chain::run_self_connected_binary_chain_test; - use ibc_test_framework::framework::binary::channel::RunBinaryChannelTest; - - execute_mbt(|trace| { - run_self_connected_binary_chain_test(&RunBinaryConnectionTest::new( - &RunBinaryChannelTest::new(&IbcTransferMBT(trace)), - )) - }) -} - -pub struct IbcTransferMBT(Vec); - -impl TestOverrides for IbcTransferMBT { - fn modify_relayer_config(&self, config: &mut Config) { - config.mode = ModeConfig { - clients: ConfigClients { - enabled: true, - refresh: true, - misbehaviour: true, - }, - connections: ConfigConnections { enabled: true }, - channels: ConfigChannels { enabled: true }, - packets: ConfigPackets { - enabled: true, - clear_interval: 10, - clear_on_start: true, - tx_confirmation: true, - ..Default::default() - }, - }; - - for chain_config in config.chains.iter_mut() { - match chain_config { - ChainConfig::CosmosSdk(chain_config) => { - chain_config.trusting_period = Some(CLIENT_EXPIRY); - } - } - } - } - - fn should_spawn_supervisor(&self) -> bool { - false - } -} - -impl BinaryChannelTest for IbcTransferMBT { - fn run( - &self, - config: &TestConfig, - relayer: RelayerDriver, - chains: ConnectedChains, - channels: ConnectedChannel, - ) -> Result<(), Error> { - let fee_denom_a: MonoTagged = - MonoTagged::new(Denom::base(config.native_token(0))); - // relayer is spawned - let mut supervisor = Some(relayer.spawn_supervisor()?); - - for state in &self.0 { - match &state.action { - Action::Null => { - info!("[Init] Done"); - } - Action::LocalTransfer { - chain_id, - source, - target, - denom, - amount, - } => { - info!("[LocalTransfer] Init"); - let node: Tagged = get_chain(&chains, *chain_id); - super::handlers::local_transfer_handler( - node, - *source, - *target, - *denom, - *amount, - &fee_denom_a.with_amount(381000000u64).as_ref(), - )?; - info!("[LocalTransfer] Done"); - } - Action::RestoreRelay => { - if supervisor.is_none() { - supervisor = Some(relayer.spawn_supervisor()?); - } - - info!("[RestoreRelay] Done"); - } - Action::InterruptRelay => { - supervisor.take().expect("one").shutdown(); - - info!("[InterruptRelay] Done"); - } - Action::IBCTransferSendPacket { packet } => { - info!("[IBCTransferSendPacket] {:?}", packet); - - match (packet.source_chain_id, packet.target_chain_id) { - (1, 2) => { - assert!( - super::utils::get_committed_packets_at_src( - &chains.handle_a, - &channels - )? - .is_empty(), - "no packets present" - ); - - super::handlers::ibc_transfer_send_packet( - chains.node_a.as_ref(), - chains.node_b.as_ref(), - &channels, - packet, - )?; - - assert_eq!( - super::utils::get_committed_packets_at_src( - &chains.handle_a, - &channels, - )? - .len(), - 1, - "one packet is sent" - ); - } - (2, 1) => { - assert!( - super::utils::get_committed_packets_at_src( - &chains.handle_b, - &channels.clone().flip() - )? - .is_empty(), - "no packets present" - ); - - super::handlers::ibc_transfer_send_packet( - chains.node_b.as_ref(), - chains.node_a.as_ref(), - &channels.clone().flip(), - packet, - )?; - - assert_eq!( - super::utils::get_committed_packets_at_src( - &chains.handle_b, - &channels.clone().flip() - )? - .len(), - 1, - "one packet is present" - ); - } - _ => unreachable!(), - } - - info!("[IBCTransferSendPacket] Done"); - } - Action::IBCTransferReceivePacket { packet } => { - info!("[IBCTransferReceivePacket] {:?}", packet); - match (packet.source_chain_id, packet.target_chain_id) { - (1, 2) => { - super::handlers::ibc_transfer_receive_packet( - chains.node_a.as_ref(), - chains.node_b.as_ref(), - &channels, - packet, - )?; - assert_eq!( - super::utils::get_acknowledged_packets_at_dst( - &chains.handle_b, - &channels.clone().flip() - )? - .len(), - 1, - "one packet is received and sent acknowledgement" - ); - } - (2, 1) => { - super::handlers::ibc_transfer_receive_packet( - chains.node_b.as_ref(), - chains.node_a.as_ref(), - &channels.clone().flip(), - packet, - )?; - assert_eq!( - super::utils::get_acknowledged_packets_at_dst( - &chains.handle_a, - &channels - )? - .len(), - 1, - "one packet is received and sent acknowledgement" - ); - } - _ => unreachable!(), - } - - info!("[IBCTransferReceivePacket] Done"); - } - Action::IBCTransferAcknowledgePacket { packet } => { - info!("[IBCTransferAcknowledgePacket] {:?}", packet); - super::utils::wait_for_client(); - match (packet.source_chain_id, packet.target_chain_id) { - (1, 2) => { - assert!( - super::utils::get_committed_packets_at_src( - &chains.handle_a, - &channels - )? - .is_empty(), - "commitment is completed" - ); - } - (2, 1) => { - assert!( - super::utils::get_committed_packets_at_src( - &chains.handle_b, - &channels.clone().flip() - )? - .is_empty(), - "commitment is completed" - ); - } - _ => unreachable!(), - } - - info!("[IBCTransferAcknowledgePacket] Done"); - } - Action::IBCTransferTimeoutPacket { packet } => { - info!("[IBCTransferTimeoutPacket] {:?}", packet); - - match (packet.source_chain_id, packet.target_chain_id) { - (1, 2) => {} - (2, 1) => {} - _ => unreachable!(), - } - - info!("[IBCTransferTimeoutPacket] Done") - } - } - } - - Ok(()) - } -} diff --git a/tools/integration-test/src/mbt/utils.rs b/tools/integration-test/src/mbt/utils.rs deleted file mode 100644 index 308dc45ab3..0000000000 --- a/tools/integration-test/src/mbt/utils.rs +++ /dev/null @@ -1,132 +0,0 @@ -use ibc_relayer::chain::requests::{ - Paginate, QueryPacketAcknowledgementsRequest, QueryPacketCommitmentsRequest, - QueryUnreceivedAcksRequest, QueryUnreceivedPacketsRequest, -}; -use ibc_relayer_types::core::ics04_channel::packet::Sequence; -use ibc_test_framework::prelude::*; -use ibc_test_framework::types::tagged::mono::Tagged; - -use super::{ - itf::InformalTrace, - state::{DenomId, State}, -}; - -pub const CLIENT_EXPIRY: Duration = Duration::from_secs(15); - -pub fn get_chain( - chains: &ConnectedChains, - chain_id: u128, -) -> Tagged -where - ChainA: ChainHandle, - ChainB: ChainHandle, - ChainX: ChainHandle, -{ - Tagged::new(match chain_id { - 1 => chains.node_a.value(), - 2 => chains.node_b.value(), - _ => unreachable!(), - }) -} - -pub fn get_wallet<'a, ChainX>( - wallets: &'a Tagged, - user: u128, -) -> Tagged { - match user { - 1 => wallets.user1(), - 2 => wallets.user2(), - _ => unreachable!(), - } -} - -pub fn get_denom<'a, ChainX>( - chain: &'a Tagged, - denom: DenomId, -) -> Tagged { - match denom { - 1 => chain.denom(), - 2 => chain.denom(), - _ => unreachable!(), - } -} - -pub fn wait_for_client() { - let sleep_time = CLIENT_EXPIRY + Duration::from_secs(5); - - info!( - "Sleeping for {} seconds to wait for IBC client to expire", - sleep_time.as_secs() - ); - - sleep(sleep_time); -} - -pub fn parse_itf_from_json(itf_path: &str) -> Vec { - let itf_json = std::fs::read_to_string(itf_path).expect("itf file does not exist. did you run `apalache check --inv=Invariant --run-dir=run main.tla` first?"); - - let trace: InformalTrace = - serde_json::from_str(&itf_json).expect("deserialization error"); - - trace.states -} - -pub fn get_unreceived_packets_at_dst( - chain: &ChainA, - channel: &ConnectedChannel, -) -> Result, Error> { - let port_id_a = channel.port_a.value(); - let channel_id_a = channel.channel_id_a.value(); - let request = QueryUnreceivedPacketsRequest { - port_id: port_id_a.clone(), - channel_id: channel_id_a.clone(), - packet_commitment_sequences: Vec::new(), - }; - Ok(chain.query_unreceived_packets(request)?) -} - -pub fn get_committed_packets_at_src( - chain: &ChainA, - channel: &ConnectedChannel, -) -> Result, Error> { - let port_id_a = channel.port_a.value(); - let channel_id_a = channel.channel_id_a.value(); - let request = QueryPacketCommitmentsRequest { - port_id: port_id_a.clone(), - channel_id: channel_id_a.clone(), - pagination: Paginate::All, - }; - let (sequences, _) = chain.query_packet_commitments(request)?; - Ok(sequences) -} - -pub fn get_unacknowledged_packets_at_src( - chain: &ChainA, - channel: &ConnectedChannel, -) -> Result, Error> { - let port_id_a = channel.port_a.value(); - let channel_id_a = channel.channel_id_a.value(); - let request = QueryUnreceivedAcksRequest { - port_id: port_id_a.clone(), - channel_id: channel_id_a.clone(), - packet_ack_sequences: Vec::new(), - }; - Ok(chain.query_unreceived_acknowledgements(request)?) -} - -pub fn get_acknowledged_packets_at_dst( - chain: &ChainA, - channel: &ConnectedChannel, -) -> Result, Error> { - let port_id_a = channel.port_a.value(); - let channel_id_a = channel.channel_id_a.value(); - let request = QueryPacketAcknowledgementsRequest { - port_id: port_id_a.clone(), - channel_id: channel_id_a.clone(), - pagination: Paginate::All, - packet_commitment_sequences: Vec::new(), - }; - Ok(chain.query_packet_acknowledgements(request)?.0) -} - -pub fn drop(_: X) {}