Skip to content

Commit

Permalink
Parser+Processor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 committed Apr 15, 2024
1 parent 8f904b6 commit 55cc599
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 25 deletions.
93 changes: 78 additions & 15 deletions tools/compiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tools/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
regress = "0.9.1"
reqwest = { version = "0.12.3", features = ["json"] }
tempdir = "0.3.7"
thiserror = "1.0.58"
tokio = { version = "1.37.0", features = ["full"] }
tracing-subscriber = "0.3"
tracing = "0.1"
tracing-subscriber = "0.3.18"
tracing = "0.1.40"
8 changes: 4 additions & 4 deletions tools/compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ pub struct IbcConnection {
}

pub const LOCAL_REGISTRY_DIR: &str = "../../registry";
const LOCAL_INPUT_DIR: &str = "../../input";
pub const LOCAL_INPUT_DIR: &str = "../../input";

/// Retrieves a list of `ChainConfig` objects representing the configuration for various chains.
/// This function assumes a specific directory structure and configs inside:
///
/// input/
/// ├── penumbra-testnet-deimos-6.json
/// └── mars-1.json
pub fn get_chain_configs() -> AppResult<Vec<ChainConfig>> {
pub fn get_chain_configs(registry_dir: &str, input_dir: &str) -> AppResult<Vec<ChainConfig>> {
// Clear registry output dir
let registry_dir = Path::new(LOCAL_REGISTRY_DIR);
let registry_dir = Path::new(registry_dir);
if registry_dir.exists() {
fs::remove_dir_all(registry_dir)?;
}
fs::create_dir_all(registry_dir)?;

let chain_configs = fs::read_dir(LOCAL_INPUT_DIR)?;
let chain_configs = fs::read_dir(input_dir)?;
Ok(chain_configs
.into_iter()
.map(|input| -> AppResult<ChainConfig> {
Expand Down
10 changes: 6 additions & 4 deletions tools/compiler/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use tokio::task;

use crate::error::AppResult;
use crate::github::assetlist_schema::AssetTypeAsset;
use crate::parser::{get_chain_configs, ChainConfig, IbcConnection, Rpc, LOCAL_REGISTRY_DIR};
use crate::parser::{
get_chain_configs, ChainConfig, IbcConnection, Rpc, LOCAL_INPUT_DIR, LOCAL_REGISTRY_DIR,
};
use crate::querier::query_github_assets;

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -44,7 +46,7 @@ pub async fn generate_registry() -> AppResult<()> {
let mut tasks = Vec::new();

// Get local configs from /input directory
let chain_configs = get_chain_configs()?;
let chain_configs = get_chain_configs(LOCAL_REGISTRY_DIR, LOCAL_INPUT_DIR)?;
chain_configs.into_iter().for_each(|c| {
// Async fetch metadata for ibc assets from cosmos registry
let task = task::spawn(async move { process_chain_config(c).await });
Expand All @@ -65,7 +67,7 @@ pub async fn generate_registry() -> AppResult<()> {

/// Given `ibc_data` describing a channel and `source_asset` on the source chain,
/// compute the metadata for the asset when it is transported along the channel onto a Penumbra chain.
fn transport_metadata_along_channel(
pub fn transport_metadata_along_channel(
ibc_data: &IbcConnection,
source_asset: Metadata,
) -> AppResult<Metadata> {
Expand Down Expand Up @@ -94,7 +96,7 @@ fn transport_metadata_along_channel(
Ok(Metadata::try_from(pb_metadata)?)
}

fn base64_id(m: &Metadata) -> AppResult<String> {
pub fn base64_id(m: &Metadata) -> AppResult<String> {
let id_json = serde_json::to_value(m.id())?;
let base64_str = id_json
.get("inner")
Expand Down
Loading

0 comments on commit 55cc599

Please sign in to comment.