Skip to content

Commit

Permalink
e2e helper in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Dec 21, 2024
1 parent 779905d commit decd69f
Show file tree
Hide file tree
Showing 8 changed files with 1,111 additions and 221 deletions.
1,193 changes: 974 additions & 219 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[workspace]
members = ["packages/relayer"]
members = ["packages/relayer", "e2e"]
exclude = ["node_modules/*", "packages/relayer/src/abis"]
resolver = "2"
26 changes: 26 additions & 0 deletions e2e/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "email-tx-builder-e2e-receiver"
version = "1.0.0"
edition = "2021"

[dependencies]
anyhow = "1.0.89"
axum = "0.7.7"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
bigdecimal = "0.3.1"
tokio = { version = "1.40.0", features = ["full"] }
tower-http = { version = "0.6.1", features = ["cors"] }
relayer-utils = { git = "https://github.com/zkemail/relayer-utils.git", branch = "main" }
slog = { version = "2.7.0", features = [
"max_level_trace",
"release_max_level_warn",
] }
uuid = { version = "1.10.0", features = ["serde", "v4"] }
chrono = { version = "0.4.38", features = ["serde"] }
reqwest = { version = "0.12.8", features = ["json"] }
handlebars = "6.1.0"
lazy_static = "1.5.0"
relayer-imap = { version = "0.1.0", git = "https://github.com/zkemail/relayer-imap.git", branch = "feat/config_file" }
relayer-smtp = { version = "0.1.0", git = "https://github.com/zkemail/relayer-smtp.git", branch = "feat/serde" }
regex = "1.10.6"
79 changes: 79 additions & 0 deletions e2e/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use anyhow::Error;
use relayer_imap::RelayerIMAPConfig;
use relayer_smtp::RelayerSMTPConfig;
use serde::Deserialize;
use serde_json;
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::Read;

// #[derive(Deserialize, Debug, Clone)]
// #[serde(rename_all = "camelCase")]
// pub struct ReceiverConfigs {
// pub configs: Vec<ReceiverConfig>,
// pub json_logger: bool,
// // pub logs_path: String,
// }

// unsafe impl Send for ReceiverConfigs {}
// unsafe impl Sync for ReceiverConfigs {}

// impl ReceiverConfigs {
// pub fn from_file(file_path: &str) -> Result<Self, Error> {
// // Open the configuration file
// let mut file = File::open(file_path)
// .map_err(|e| anyhow::anyhow!("Failed to open config file: {}", e))?;

// // Read the file's content into a string
// let mut data = String::new();
// file.read_to_string(&mut data)
// .map_err(|e| anyhow::anyhow!("Failed to read config file: {}", e))?;

// // Deserialize the JSON content into a Config struct
// let config: Self = serde_json::from_str(&data)
// .map_err(|e| anyhow::anyhow!("Failed to parse config file: {}", e))?;

// // Setting Logger ENV
// if config.json_logger {
// env::set_var("JSON_LOGGER", "true");
// }
// Ok(config)
// }
// }

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ReceiverConfig {
pub id: String,
pub imap: RelayerIMAPConfig,
pub smtp: RelayerSMTPConfig,
pub json_logger: bool,
// pub logs_path: String,
}

unsafe impl Send for ReceiverConfig {}
unsafe impl Sync for ReceiverConfig {}

impl ReceiverConfig {
pub fn from_file(file_path: &str) -> Result<Self, Error> {
// Open the configuration file
let mut file = File::open(file_path)
.map_err(|e| anyhow::anyhow!("Failed to open config file: {}", e))?;

// Read the file's content into a string
let mut data = String::new();
file.read_to_string(&mut data)
.map_err(|e| anyhow::anyhow!("Failed to read config file: {}", e))?;

// Deserialize the JSON content into a Config struct
let config: Self = serde_json::from_str(&data)
.map_err(|e| anyhow::anyhow!("Failed to parse config file: {}", e))?;

// Setting Logger ENV
if config.json_logger {
env::set_var("JSON_LOGGER", "true");
}
Ok(config)
}
}
30 changes: 30 additions & 0 deletions e2e/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use anyhow::{Error, Result};
use relayer_imap;
use relayer_smtp;
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::task;
pub mod config;
use config::*;
use std::env;
use std::path::Path;
use std::process::Command;

#[tokio::main]
async fn main() -> Result<(), Error> {
let args: Vec<String> = env::args().collect();
match args.get(1).map(|s| s.as_str()) {
Some("--run-smtp") => {
let config = ReceiverConfig::from_file(&args[2])?;
relayer_smtp::run(config.smtp).await?;
}
Some("--run-imap") => {
let config = ReceiverConfig::from_file(&args[2])?;
relayer_imap::run(config.imap).await?;
}
_ => {
panic!("Invalid arguments");
}
}
Ok(())
}
Empty file added e2e/src/replyer.rs
Empty file.
Empty file added e2e/src/utils.rs
Empty file.
2 changes: 1 addition & 1 deletion packages/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ chrono = { version = "0.4.38", features = ["serde"] }
ethers = "2.0.14"
reqwest = { version = "0.12.8", features = ["json"] }
handlebars = "6.1.0"
regex = "1.11.0"
regex = "1.10.6"
ic-agent = { version = "0.37.1", features = ["pem", "reqwest"] }
ic-utils = "0.37.0"
candid = "0.10.10"
Expand Down

0 comments on commit decd69f

Please sign in to comment.