Skip to content

Commit

Permalink
Merge pull request #8 from timewave-computer/dowlandaiello/enhancemen…
Browse files Browse the repository at this point in the history
…t-relayer

Add Start & Stop Relayer
  • Loading branch information
dowlandaiello authored Aug 15, 2024
2 parents 6272c78 + 8bbe015 commit 3b84b83
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 8 additions & 1 deletion examples/neutron_osmosis.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -18,6 +18,13 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_transfer_channels("osmosis", "neutron")
.build()?;

// Kill and restart the relayer
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")
Expand Down
32 changes: 31 additions & 1 deletion src/utils/setup/ibc.rs
Original file line number Diff line number Diff line change
@@ -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},
};

Expand Down Expand Up @@ -134,4 +136,32 @@ impl TestContext {

Ok(())
}

pub fn start_relayer(&mut self) {
// 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(&chain.rb.api)
.json(&serde_json::json!({ "chain_id": NEUTRON_CHAIN_ID, "action": "start-relayer"}))
.send()
.unwrap();
}

pub fn stop_relayer(&mut self) {
// 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(&chain.rb.api)
.json(&serde_json::json!({ "chain_id": NEUTRON_CHAIN_ID, "action": "stop-relayer"}))
.send()
.unwrap();
}
}

0 comments on commit 3b84b83

Please sign in to comment.