Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dowlandaiello/enhance…
Browse files Browse the repository at this point in the history
…ment-instantiate2
  • Loading branch information
dowlandaiello committed Aug 16, 2024
2 parents 0134361 + 315128e commit a933596
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,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.
12 changes: 11 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,16 @@ 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));

// 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")
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();
}
}
13 changes: 12 additions & 1 deletion src/utils/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 serde_json::Value;
Expand Down Expand Up @@ -401,6 +403,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 {
Expand Down

0 comments on commit a933596

Please sign in to comment.