From b547c5c299003a1212095fa29e952931f73dc7d8 Mon Sep 17 00:00:00 2001 From: Dowland Aiello Date: Wed, 14 Aug 2024 20:38:34 +0000 Subject: [PATCH 1/4] ibc: Add functions for killing and starting relayer. --- examples/neutron_osmosis.rs | 4 ++++ src/utils/setup/ibc.rs | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/examples/neutron_osmosis.rs b/examples/neutron_osmosis.rs index 5170c69..45d6c8e 100644 --- a/examples/neutron_osmosis.rs +++ b/examples/neutron_osmosis.rs @@ -18,6 +18,10 @@ fn main() -> Result<(), Box> { .with_transfer_channels("osmosis", "neutron") .build()?; + // Kill and restart the relayer + ctx.stop_relayer(); + ctx.start_relayer(); + ctx.build_tx_create_tokenfactory_token() .with_chain_name("neutron") .with_subdenom("bruhtoken") diff --git a/src/utils/setup/ibc.rs b/src/utils/setup/ibc.rs index 590778e..5f20312 100644 --- a/src/utils/setup/ibc.rs +++ b/src/utils/setup/ibc.rs @@ -1,5 +1,7 @@ use super::super::{ - super::{error::Error, DEFAULT_KEY, DEFAULT_TRANSFER_PORT, NEUTRON_CHAIN_NAME}, + super::{ + error::Error, DEFAULT_KEY, DEFAULT_TRANSFER_PORT, NEUTRON_CHAIN_ID, NEUTRON_CHAIN_NAME, + }, test_context::{LocalChain, TestContext}, }; @@ -134,4 +136,24 @@ impl TestContext { Ok(()) } + + pub fn start_relayer(&mut self) { + let neutron = self.get_chain(NEUTRON_CHAIN_NAME); + + reqwest::blocking::Client::default() + .post(&neutron.rb.api) + .json(&serde_json::json!({ "chain_id": NEUTRON_CHAIN_ID, "action": "start-relayer"})) + .send() + .unwrap(); + } + + pub fn stop_relayer(&mut self) { + let neutron = self.get_chain(NEUTRON_CHAIN_NAME); + + reqwest::blocking::Client::default() + .post(&neutron.rb.api) + .json(&serde_json::json!({ "chain_id": NEUTRON_CHAIN_ID, "action": "stop-relayer"})) + .send() + .unwrap(); + } } From 8bbe0153563a1428c636bc2c561e633ab69846eb Mon Sep 17 00:00:00 2001 From: Dowland Aiello Date: Thu, 15 Aug 2024 14:27:57 +0000 Subject: [PATCH 2/4] ibc: For start/stop relayer, use whichever chain is available. Instead of assumming Neutron exists. --- examples/neutron_osmosis.rs | 5 ++++- src/utils/setup/ibc.rs | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/neutron_osmosis.rs b/examples/neutron_osmosis.rs index 45d6c8e..8b8ac6a 100644 --- a/examples/neutron_osmosis.rs +++ b/examples/neutron_osmosis.rs @@ -1,5 +1,5 @@ use localic_utils::{ConfigChainBuilder, TestContextBuilder}; -use std::error::Error; +use std::{error::Error, thread, time::Duration}; const ACC_0_ADDR: &str = "osmo1hj5fveer5cjtn4wd6wstzugjfdxzl0xpwhpz63"; const NEUTRON_ACC_0_ADDR: &str = "neutron1hj5fveer5cjtn4wd6wstzugjfdxzl0xpznmsky"; @@ -22,6 +22,9 @@ fn main() -> Result<(), Box> { ctx.stop_relayer(); ctx.start_relayer(); + // Wait for the relayer to start up + thread::sleep(Duration::from_secs(10)); + ctx.build_tx_create_tokenfactory_token() .with_chain_name("neutron") .with_subdenom("bruhtoken") diff --git a/src/utils/setup/ibc.rs b/src/utils/setup/ibc.rs index 5f20312..a8e9905 100644 --- a/src/utils/setup/ibc.rs +++ b/src/utils/setup/ibc.rs @@ -138,20 +138,28 @@ impl TestContext { } pub fn start_relayer(&mut self) { - let neutron = self.get_chain(NEUTRON_CHAIN_NAME); + // Any random chain will allow us to kill the relayer, + // so select any chain we can get the API URL from + let chain = self.chains.values().next().unwrap(); + // See above. chain_id does not matter, since there is + // one relayer running reqwest::blocking::Client::default() - .post(&neutron.rb.api) + .post(&chain.rb.api) .json(&serde_json::json!({ "chain_id": NEUTRON_CHAIN_ID, "action": "start-relayer"})) .send() .unwrap(); } pub fn stop_relayer(&mut self) { - let neutron = self.get_chain(NEUTRON_CHAIN_NAME); + // Any random chain will allow us to kill the relayer, + // so select any chain we can get the API URL from + let chain = self.chains.values().next().unwrap(); + // See above. chain_id does not matter, since there is + // one relayer running reqwest::blocking::Client::default() - .post(&neutron.rb.api) + .post(&chain.rb.api) .json(&serde_json::json!({ "chain_id": NEUTRON_CHAIN_ID, "action": "stop-relayer"})) .send() .unwrap(); From b27b40466daee8902bc49f81c4b304f4ee764c76 Mon Sep 17 00:00:00 2001 From: Udit Vira Date: Thu, 15 Aug 2024 11:30:41 -0400 Subject: [PATCH 3/4] Fix broken link in README.md The link to the examples directory was missing the repository name in the URL. This PR fixes the link. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dc20130..ee063f8 100644 --- a/README.md +++ b/README.md @@ -216,4 +216,4 @@ Note that most `tx_*` helper functions expose a `.with_key(key: &str)` builder f ### Complete Example -Examples of using almost every helper function provided by this repository are available in the [examples](https://github.com/timewave-computer/tree/main/examples) directory. +Examples of using almost every helper function provided by this repository are available in the [examples](https://github.com/timewave-computer/localic-utils/tree/main/examples) directory. From 315128eb4c1267490acea6e9ee4c3600e1561d0e Mon Sep 17 00:00:00 2001 From: Keyne Date: Thu, 15 Aug 2024 17:04:27 +0100 Subject: [PATCH 4/4] Add wait_for_blocks function (#10) * add wait_for_blocks function * remove useless line * undo --- examples/neutron_osmosis.rs | 3 +++ src/utils/test_context.rs | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/neutron_osmosis.rs b/examples/neutron_osmosis.rs index 8b8ac6a..3c633a6 100644 --- a/examples/neutron_osmosis.rs +++ b/examples/neutron_osmosis.rs @@ -25,6 +25,9 @@ fn main() -> Result<(), Box> { // Wait for the relayer to start up thread::sleep(Duration::from_secs(10)); + // Wait for some blocks + ctx.get_chain("neutron").wait_for_blocks(20); + ctx.build_tx_create_tokenfactory_token() .with_chain_name("neutron") .with_subdenom("bruhtoken") diff --git a/src/utils/test_context.rs b/src/utils/test_context.rs index bdbae81..b4d37ce 100644 --- a/src/utils/test_context.rs +++ b/src/utils/test_context.rs @@ -5,7 +5,9 @@ use super::super::{ }; use localic_std::{ - modules::cosmwasm::CosmWasm, relayer::Channel, relayer::Relayer, + modules::cosmwasm::CosmWasm, + node::Chain, + relayer::{Channel, Relayer}, transactions::ChainRequestBuilder, }; use std::{collections::HashMap, path::PathBuf}; @@ -400,6 +402,15 @@ impl LocalChain { let id = abs_path.file_stem().unwrap().to_str().unwrap(); self.contract_codes.insert(id.to_string(), code); } + + pub fn wait_for_blocks(&self, blocks: u64) { + let chain = Chain::new(&self.rb); + let current_height = chain.get_height(); + + while chain.get_height() < current_height + blocks { + std::thread::sleep(std::time::Duration::from_millis(500)); + } + } } impl TestContext {