Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cw-orch tests #496

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cw-orch-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ uid = "0.1.7"
# Deserialize network config
toml = "0.8"
http = "1.1.0"
libc-print = "0.1.23"

[dev-dependencies]
cw-orch-daemon = { path = "." }
Expand Down
4 changes: 2 additions & 2 deletions cw-orch-daemon/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ static LOGS_DISABLED: Once = Once::new();
pub fn print_if_log_disabled() -> Result<(), DaemonError> {
LOGS_DISABLED.call_once(|| {
// Here we check for logging capabilities.
if !log::log_enabled!(log::Level::Info) && DaemonEnvVars::logs_message(){
if !log::log_enabled!(log::Level::Info) && DaemonEnvVars::logs_message() {
println!(
"Warning: It seems like you haven't enabled logs. In order to do so, you have to :
"Warning: It seems like you haven't enabled logs. In order to do so, you have to :
- use `env_logger::init()` at the start of your script.
- Set the env variable `RUST_LOG=info` for standard logs. See https://docs.rs/env_logger/latest/env_logger/"
)
Expand Down
4 changes: 2 additions & 2 deletions cw-orch-daemon/src/senders/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
}

// If there is not enough asset balance, we need to warn the user
println!(
log::info!(

Check warning on line 350 in cw-orch-daemon/src/senders/cosmos.rs

View check run for this annotation

Codecov / codecov/patch

cw-orch-daemon/src/senders/cosmos.rs#L350

Added line #L350 was not covered by tests
"Not enough funds on chain {} at address {} to deploy the contract.
Needed: {}{} but only have: {}.
Press 'y' when the wallet balance has been increased to resume deployment",
Expand All @@ -371,7 +371,7 @@
})
}
} else {
println!("No Manual Interactions, defaulting to 'no'");
log::info!("No Manual Interactions, defaulting to 'no'");

Check warning on line 374 in cw-orch-daemon/src/senders/cosmos.rs

View check run for this annotation

Codecov / codecov/patch

cw-orch-daemon/src/senders/cosmos.rs#L374

Added line #L374 was not covered by tests
return Err(DaemonError::NotEnoughBalance {
expected: fee.clone(),
current: balance,
Expand Down
1 change: 0 additions & 1 deletion cw-orch-daemon/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ pub trait DeployedChains<Chain: CwEnv>: cw_orch_core::contract::Deploy<Chain> {
/// ...
/// },
/// "uni-6": {

/// }
/// }
/// ...
Expand Down
1 change: 1 addition & 0 deletions cw-orch-daemon/tests/authz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod tests {
#[test]
#[serial_test::serial]
fn authz() -> anyhow::Result<()> {
super::common::enable_logger();
use cw_orch_networks::networks;

let daemon = Daemon::builder(networks::LOCAL_JUNO)
Expand Down
45 changes: 25 additions & 20 deletions cw-orch-daemon/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub use node::*;

#[cfg(feature = "node-tests")]
mod node {
use libc_print::libc_println;
use std::{env, fs, path::Path, thread::sleep, time::Duration};

use ctor::{ctor, dtor};
Expand All @@ -21,30 +22,29 @@ mod node {
const LOCAL_MNEMONIC: &str = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose";

pub mod state_file {
use super::{fs, Path};

use super::*;
pub fn exists(file: &str) -> bool {
if Path::new(file).exists() {
log::info!("File found: {}", file);
libc_println!("File found: {}", file);
true
} else {
log::info!("File not found: {}", file);
libc_println!("File not found: {}", file);
false
}
}

pub fn remove(file: &str) {
if self::exists(file) {
log::info!("Removing state file: {}", file);
libc_println!("Removing state file: {}", file);
let _ = fs::remove_file(file);
}
}
}

pub mod container {
use crate::common::STAKE_TOKEN;

use super::cmd;
use super::*;
use crate::common::STAKE_TOKEN;

pub fn find(name: &String) -> bool {
let read = cmd!("docker", "container", "ls", "--all")
Expand All @@ -56,7 +56,7 @@ mod node {

match read {
Ok(val) => {
log::info!("Container found: {}", name);
libc_println!("Container found: {}", name);
val == *name
}
Err(_) => false,
Expand Down Expand Up @@ -98,7 +98,7 @@ mod node {
return true;
}

log::info!("Stopping container: {}", name);
libc_println!("Stopping container: {}", name);

let res = cmd!("docker", "container", "stop", name)
.read()
Expand All @@ -113,7 +113,7 @@ mod node {
return true;
}

log::info!("Removing container: {}", name);
libc_println!("Removing container: {}", name);

let res = cmd!("docker", "container", "rm", name).read().ok().unwrap();

Expand All @@ -128,7 +128,7 @@ mod node {
}

pub fn docker_container_start() {
log::info!("Running docker_container_start");
libc_println!("Running docker_container_start");

// Set environment variables
// this does not seems to be working in this case
Expand All @@ -150,13 +150,13 @@ mod node {
env::set_var("LOCAL_MNEMONIC", LOCAL_MNEMONIC);
}

log::info!("Using RUST_LOG: {}", env::var("RUST_LOG").unwrap());
log::info!("Using CONTAINER_NAME: {}", container);
log::info!(
libc_println!("Using RUST_LOG: {}", env::var("RUST_LOG").unwrap());
libc_println!("Using CONTAINER_NAME: {}", &container);
libc_println!(
"Using STATE_FILE: {}",
DaemonEnvVars::state_file().display()
);
log::info!(
libc_println!(
"Using LOCAL_MNEMONIC: {:?}",
DaemonEnvVars::local_mnemonic()
);
Expand All @@ -168,7 +168,7 @@ mod node {
}

pub fn docker_container_stop() {
log::info!("Running docker_container_stop");
libc_println!("Running docker_container_stop");
container::ensure_removal(&env::var("CONTAINER_NAME").unwrap());
let temp_dir = env::temp_dir();
let expected_state_file = temp_dir.join("cw_orch_test_local.json");
Expand All @@ -179,14 +179,19 @@ mod node {

#[ctor]
fn common_start() {
env_logger::Builder::new()
.filter_level(log::LevelFilter::Debug)
.init();
docker_container_start()
docker_container_start();
libc_println!("Finish start");
}

#[dtor]
fn common_stop() {
docker_container_stop()
}

#[cfg(test)]
pub fn enable_logger() {
let _ = env_logger::Builder::new()
.filter_level(log::LevelFilter::Debug)
.try_init();
}
}
2 changes: 2 additions & 0 deletions cw-orch-daemon/tests/daemon_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod tests {
#[test]
#[serial_test::serial]
fn helper_traits() {
super::common::enable_logger();
use cw_orch_networks::networks;

let mut daemon = Daemon::builder(networks::LOCAL_JUNO)
Expand Down Expand Up @@ -87,6 +88,7 @@ mod tests {
#[test]
#[serial_test::serial]
fn cw_orch_interface_traits() {
super::common::enable_logger();
use cw_orch_networks::networks;

let daemon = Daemon::builder(networks::LOCAL_JUNO)
Expand Down
1 change: 1 addition & 0 deletions cw-orch-daemon/tests/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod tests {
#[serial_test::serial]
fn mnemonic_index() -> anyhow::Result<()> {
use cw_orch_networks::networks;
super::common::enable_logger();

let daemon = Daemon::builder(networks::LOCAL_JUNO)
.is_test(true)
Expand Down
1 change: 1 addition & 0 deletions cw-orch-daemon/tests/instantiate2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod test {
#[test]
#[serial_test::serial]
fn instantiate2() -> anyhow::Result<()> {
super::common::enable_logger();
let app = Daemon::builder(networks::LOCAL_JUNO)
.is_test(true)
.build()
Expand Down
1 change: 0 additions & 1 deletion cw-orch-interchain/examples/doc_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use cw_orch::prelude::*;
use cw_orch_interchain::{
ChannelCreationValidator, ChannelCreator, DaemonInterchain, InterchainEnv, Starship,
};
/// Others

fn create_daemon_env() -> cw_orch::anyhow::Result<DaemonInterchain> {
// ANCHOR: DAEMON_INTERCHAIN_CREATION
Expand Down
2 changes: 2 additions & 0 deletions cw-orch/examples/async_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use cw_orch_daemon::DaemonAsync;
use cw_orch_mock::Mock;

/// In order to use this script, you need to set the following env variables
///
/// RUST_LOG (recommended value `info`) to see the app logs
///
/// TEST_MNEMONIC to be able to sign and broadcast a transaction on UNI testnet
#[tokio::main]
pub async fn main() -> anyhow::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions cw-orch/examples/complex_testnet_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// pub const SUBDENOM: &str = "complex-test";

/// In order to use this script, you need to set the following env variables
///
/// RUST_LOG (recommended value `info`) to see the app logs
/// TEST_MNEMONIC to be able to sign and broadcast a transaction on UNI testnet
pub fn main() {
Expand Down
1 change: 1 addition & 0 deletions cw-orch/examples/testnet_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use cw_orch::{
};

/// In order to use this script, you need to set the following env variables
///
/// RUST_LOG (recommended value `info`) to see the app logs
/// TEST_MNEMONIC to be able to sign and broadcast a transaction on UNI testnet
pub fn main() {
Expand Down
3 changes: 1 addition & 2 deletions cw-orch/src/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn parse_storage(storage: &[(Vec<u8>, Vec<u8>)]) -> Vec<(String, String)> {
/// The name you input to the function should be different from all other snapshots in your repository
/// Find more details on how snapshot testing works on the official quick-start guide: https://insta.rs/docs/quickstart/
/// This function will panic if the snapshot is different from the reference snapshot

#[macro_export]
macro_rules! take_storage_snapshot {
($chain: ident, $name: literal) => {
Expand All @@ -49,7 +48,7 @@ macro_rules! take_storage_snapshot {
}

#[cfg(test)]
pub mod tests {
mod tests {
use crate::mock::cw_multi_test::ContractWrapper;
use cosmwasm_std::Empty;
use cw_orch::prelude::{CwOrchInstantiate, CwOrchUpload, Mock};
Expand Down
1 change: 0 additions & 1 deletion packages/cw-orch-networks/src/networks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub use xion::XION_TESTNET_1;
/// ```
/// ---
/// supported chains are defined by the `SUPPORT_NETWORKS` variable

pub fn parse_network(net_id: &str) -> Result<ChainInfo, String> {
SUPPORTED_NETWORKS
.iter()
Expand Down
1 change: 1 addition & 0 deletions packages/interchain/interchain-core/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! This defines types and traits associated with IBC channels.
//!
//! Those structures are mostly used internally for dealing with channel creation and analysis
//! But they can also be used in a user application if they need specific channel description

Expand Down
22 changes: 11 additions & 11 deletions packages/interchain/interchain-core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use crate::{
/// In this example the struct contains all transaction results for channel creation
/// Those transactions are usually sent by a validator
/// [More info about channel creation here](https://github.com/cosmos/ibc/blob/main/spec/core/ics-004-channel-and-packet-semantics/README.md)

pub struct ChannelCreation<R> {
/// First step, channel creation open-initialization (src_chain)
pub init: R,
Expand Down Expand Up @@ -57,6 +56,7 @@ impl<R> ChannelCreation<R> {
pub type ChainId<'a> = &'a str;

/// This trait allows to extend `cw_orch::prelude::CwEnv` with interchain capabilities
///
/// The center of those capabilities is the ability to follow the execution of outgoing IBC packets
/// This enables users to script chain execution even throughout IBC executions which are more asynchronous than usual transactions.
/// With the following simple syntax, users are even able to await and analyze the execution of all packets submitted in a single transactions
Expand All @@ -73,9 +73,9 @@ pub type ChainId<'a> = &'a str;
/// use cw_orch::mock::cw_multi_test::Executor;
/// use cw_orch_interchain::prelude::*;
/// use ibc_relayer_types::core::ics24_host::identifier::PortId;

///
/// let interchain = MockInterchainEnv::new(vec![("juno-1", "sender"), ("stargaze-1", "sender")]);

///
/// let channel = interchain.create_channel(
/// "juno-1",
/// "stargaze-1",
Expand All @@ -86,11 +86,11 @@ pub type ChainId<'a> = &'a str;
/// ).unwrap();
/// let juno = interchain.get_chain("juno-1").unwrap();
/// let stargaze = interchain.get_chain("stargaze-1").unwrap();

///
/// let channel = channel
/// .interchain_channel
/// .get_ordered_ports_from("juno-1").unwrap();

///
/// juno.add_balance(&juno.sender_addr(), vec![coin(100_000, "ujuno")]).unwrap();
/// let tx_resp = juno.app.borrow_mut().execute(
/// juno.sender_addr(),
Expand All @@ -105,7 +105,7 @@ pub type ChainId<'a> = &'a str;
/// memo: None,
/// }),
/// ).unwrap();

///
/// // This makes sure that the packets arrive successfully and present a success ack
/// let result = interchain.await_and_check_packets("juno-1", tx_resp).unwrap();
/// ```
Expand Down Expand Up @@ -379,9 +379,9 @@ pub trait InterchainEnv<Chain: IbcQueryHandler> {
/// use cw_orch::mock::cw_multi_test::Executor;
/// use cw_orch_interchain::prelude::*;
/// use ibc_relayer_types::core::ics24_host::identifier::PortId;

///
/// let interchain = MockInterchainEnv::new(vec![("juno-1", "sender"), ("stargaze-1", "sender")]);

///
/// let channel = interchain.create_channel(
/// "juno-1",
/// "stargaze-1",
Expand All @@ -392,11 +392,11 @@ pub trait InterchainEnv<Chain: IbcQueryHandler> {
/// ).unwrap();
/// let juno = interchain.get_chain("juno-1").unwrap();
/// let stargaze = interchain.get_chain("stargaze-1").unwrap();

///
/// let channel = channel
/// .interchain_channel
/// .get_ordered_ports_from("juno-1").unwrap();

///
/// juno.add_balance(&juno.sender_addr(), vec![coin(100_000, "ujuno")]).unwrap();
/// let tx_resp = juno.app.borrow_mut().execute(
/// juno.sender_addr(),
Expand All @@ -411,7 +411,7 @@ pub trait InterchainEnv<Chain: IbcQueryHandler> {
/// memo: None,
/// }),
/// ).unwrap();

///
/// // This makes sure that the packets arrive successfully and present a success ack
/// let result = interchain.await_and_check_packets("juno-1", tx_resp).unwrap();
/// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ impl InterchainLog {
/// Initiates an interchain log setup
/// This will log the different chain interactions and updates on separate files for each chain.
/// This is useful for tracking operations happenning on IBC chains

pub fn new() -> Self {
Self::default()
}
Expand Down
1 change: 0 additions & 1 deletion packages/interchain/interchain-mock/src/interchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub type MockBase<A> = cw_orch_mock::MockBase<A, MockState>;

/// Interchain environment for cw_multi_test Mock environment
/// This leverages Abstract's fork of cw_multi_test enabling IBC interactions

pub struct MockInterchainEnvBase<A: Api> {
/// Mock chains registered within the structure
pub mocks: HashMap<String, MockBase<A>>,
Expand Down
Loading
Loading