Skip to content

Commit

Permalink
fix: got it working about half the time
Browse files Browse the repository at this point in the history
  • Loading branch information
Willem Wyndham authored and willemneal committed Jan 24, 2024
1 parent 008abc8 commit 332bb35
Showing 1 changed file with 58 additions and 18 deletions.
76 changes: 58 additions & 18 deletions cmd/crates/soroban-test/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
use std::collections::HashMap;

use testcontainers::{core::WaitFor, Image};

const NAME: &str = "redis";
const TAG: &str = "5.0";
const NAME: &str = "stellar/quickstart";
// const TAG: &str = "testing";
const TAG: &str =
"soroban-dev@sha256:0ad51035cf7caba2fd99c7c1fad0945df6932be7d5c893e1520ccdef7d6a6ffe";

#[derive(Debug, Default)]
pub struct Soroban;
pub struct Soroban(HashMap<String, String>, HashMap<String, String>);

impl Soroban {
pub fn new() -> Self {
let mut map = HashMap::new();
map.insert("ENABLE_SOROBAN_RPC".to_string(), "true".to_string());
map.insert(
"ENABLE_SOROBAN_DIAGNOSTIC_EVENTS".to_string(),
"true".to_string(),
);
map.insert("ENABLE_LOGS".to_string(), "true".to_string());
map.insert("NETWORK".to_string(), "local".to_string());
map.insert("POSTGRES_PASSWORD".to_string(), "p".to_string());
#[allow(unused_mut)]
let mut volumes = HashMap::new();
// volumes.insert("/home/willem/c/s/soroban-tools/opt/stellar".to_string(), "/opt/stellar".to_string());
Soroban(map, volumes)
}
}

impl Image for Soroban {
type Args = ();
Expand All @@ -17,31 +39,49 @@ impl Image for Soroban {
TAG.to_owned()
}

fn expose_ports(&self) -> Vec<u16> {
vec![8000, 11626]
}

fn ready_conditions(&self) -> Vec<WaitFor> {
vec![WaitFor::message_on_stdout("Ready to accept connections")]
// vec![WaitFor::seconds(30)]

vec![WaitFor::message_on_stdout("friendbot: started")]
}

fn env_vars(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
Box::new(self.0.iter())
}

fn volumes(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
Box::new(self.1.iter())
}
}

#[cfg(test)]
mod tests {
use redis::Commands;
use std::thread::sleep;
use std::time::Duration;

use soroban_cli::rpc::Client;
use super::Soroban;
use testcontainers::clients;

use testcontainers_modules::redis::Redis;
// use testcontainers_modules::redis::Redis;

#[test]
fn redis_fetch_an_integer() {
#[tokio::test]
async fn testcontainers_work() {
let _ = pretty_env_logger::try_init();
let docker = clients::Cli::default();
let node = docker.run(Redis);
let host_port = node.get_host_port_ipv4(6379);
let url = format!("redis://127.0.0.1:{host_port}");

let client = redis::Client::open(url.as_ref()).unwrap();
let mut con = client.get_connection().unwrap();

con.set::<_, _, ()>("my_key", 42).unwrap();
let result: i64 = con.get("my_key").unwrap();
assert_eq!(42, result);
let node = docker.run(Soroban::new());
let host_port = node.get_host_port_ipv4(8000);
let url: String = format!("http://[::1]:{host_port}/soroban/rpc");
println!("{url}");
// sleep(Duration::from_secs(2000));
let client = Client::new(&url).unwrap();
for _ in 0..20 {
sleep(Duration::from_secs(1));
println!("{:#?}", client.get_network().await);
}
}
}

0 comments on commit 332bb35

Please sign in to comment.