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

Add support for logs file detection in test_context. #16

Merged
merged 1 commit into from
Aug 17, 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
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ pub const DEFAULT_AUCTION_LABEL: &str = "auction";

pub const TX_HASH_QUERY_RETRIES: u16 = 5;
pub const TX_HASH_QUERY_PAUSE_SEC: u64 = 2;

/// Contains information about ibc paths, time started
/// Used for cache invalidation purposes
pub const LOGS_FILE_PATH: &str = "configs/logs.json";
45 changes: 45 additions & 0 deletions src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@ use super::super::{
use derive_builder::Builder;
use serde::Deserialize;

/// Struct representing the contents of config/logs.json
#[derive(Deserialize)]
pub struct Logs {
pub start_time: u64,
pub chains: Vec<LogsChainEntry>,
pub ibc_channels: Vec<LogsChannelEntry>,
}

/// Represents a chain entry in the logs file
#[derive(Deserialize)]
pub struct LogsChainEntry {
pub chain_id: String,
pub chain_name: String,
pub rpc_address: String,
pub grpc_address: String,
pub p2p_address: String,
pub ibc_paths: Vec<String>,
}

/// Represents an IBC channel entry in the logs file
#[derive(Deserialize)]
pub struct LogsChannelEntry {
pub chain_id: String,
pub channel: LogsChannel,
}

/// Represents the channel info in a channel entry
#[derive(Deserialize)]
pub struct LogsChannel {
pub state: String,
pub ordering: String,
pub counterparty: LogsCounterparty,
pub connection_hops: Vec<String>,
pub version: String,
pub port_id: String,
pub channel_id: String,
}

/// Represents counterparty info in a channel entry
#[derive(Deserialize)]
pub struct LogsCounterparty {
pub port_id: String,
pub channel_id: String,
}

#[derive(Deserialize, Default, Builder, Debug)]
#[builder(setter(into, prefix = "with"))]
pub struct ChainsVec {
Expand Down
17 changes: 14 additions & 3 deletions src/utils/test_context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use super::super::{
error::Error,
types::{config::ConfigChain, contract::DeployedContractInfo, ibc::Channel as QueryChannel},
LOCAL_IC_API_URL, NEUTRON_CHAIN_NAME, TRANSFER_PORT,
types::{
config::{ConfigChain, Logs},
contract::DeployedContractInfo,
ibc::Channel as QueryChannel,
},
LOCAL_IC_API_URL, LOGS_FILE_PATH, NEUTRON_CHAIN_NAME, TRANSFER_PORT,
};

use localic_std::{
Expand All @@ -11,7 +15,7 @@ use localic_std::{
transactions::ChainRequestBuilder,
};
use serde_json::Value;
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, fs::OpenOptions, path::PathBuf};

/// A configurable builder that can be used to create a TestContext.
pub struct TestContextBuilder {
Expand Down Expand Up @@ -313,6 +317,9 @@ impl TestContextBuilder {
);
}

let log_f = OpenOptions::new().read(true).open(LOGS_FILE_PATH).unwrap();
let log_file: Logs = serde_json::from_reader(&log_f).unwrap();

Ok(TestContext {
chains,
transfer_channel_ids,
Expand All @@ -326,6 +333,7 @@ impl TestContextBuilder {
astroport_token_registry: None,
astroport_factory: None,
unwrap_logs: *unwrap_raw_logs,
log_file,
})
}
}
Expand Down Expand Up @@ -353,6 +361,9 @@ pub struct TestContext {

/// Whether or not logs should be expected and guarded for each tx
pub unwrap_logs: bool,

/// chains/logs.json
pub log_file: Logs,
}

pub struct LocalChain {
Expand Down
Loading