Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
fast
Browse files Browse the repository at this point in the history
  • Loading branch information
renan061 committed Jun 21, 2023
1 parent 9c9c885 commit a47a1dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
7 changes: 5 additions & 2 deletions offchain/test-fixtures/src/docker_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ pub fn rm(id: &str) {
docker_run(&["rm", "-v", id]);
}

pub fn run(image: &str) -> String {
let id = docker_run(&["run", "-d", "-v", "awsout:/app", image]);
pub fn run(image: &str, args: &[&str]) -> String {
let mut cmd = vec!["run", "-d"];
cmd.extend(args);
cmd.push(image);
let id = docker_run(&cmd);
let id = std::str::from_utf8(&id).unwrap().trim();
id.to_string()
}
Expand Down
47 changes: 30 additions & 17 deletions offchain/test-fixtures/src/local_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ use crate::docker_cli;

const TAG: &str = "cartesi/localstack";
const DOCKERFILE: &str = "../test-fixtures/docker/local_stack.Dockerfile";
const FROM_CONTAINER: &str = "/app/key_id.txt";

pub struct LocalStackFixture {
container_id: String,
dir: tempfile::TempDir,
}

impl Drop for LocalStackFixture {
fn drop(&mut self) {
//docker_cli::stop(&self.container_id);
//docker_cli::rm(&self.container_id);
docker_cli::stop(&self.container_id);
docker_cli::rm(&self.container_id);
}
}

Expand All @@ -43,43 +43,56 @@ impl LocalStackFixture {
docker_cli::build(DOCKERFILE, TAG, &[]);
tracing::debug!("finished building the docker image");

let container_id = docker_cli::run("cartesi/localstack");
let container_id = docker_cli::run(
"cartesi/localstack",
&[
"-p",
"4566:4566",
"-p",
"4510-4559:4510-4559",
"-v",
"awsout:/app",
],
);
tracing::debug!("running container {}", container_id);

let dir = tempfile::tempdir().expect("failed to create temp dir");

Self { container_id, dir }
Self { container_id }
}

pub fn endpoint(&self) -> String {
"todo".to_string()
"http://0.0.0.0:4566".to_string()
}

pub fn create_key(&self) -> String {
tracing::debug!("creating key");
let aws_cmd = "awslocal kms create-key \
let aws_cmd = format!(
"awslocal kms create-key \
--key-spec ECC_SECG_P256K1 \
--key-usage SIGN_VERIFY \
> /app/key_id.txt 2>&1";
let docker_cmd = ["sh", "-c", aws_cmd];
> {} 2>&1",
FROM_CONTAINER
);
let docker_cmd = ["sh", "-c", &aws_cmd];
println!("create-key cmd: {:?}", docker_cmd);
docker_cli::exec(&self.container_id, &docker_cmd);
tracing::trace!("created key");

// TODO: user docker_cli::cp
let from_container =
format!("{}:{}", self.container_id, FROM_CONTAINER);
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
let to_host = temp_dir.path().join("key_id.txt");
let to_host = to_host.to_str().unwrap();
docker_cli::cp(&from_container, to_host);

/*
let json_string =
std::fs::read_to_string(path).expect("failed to read volume");
let json_string = std::fs::read_to_string(to_host)
.expect("failed to read volume data");
tracing::trace!("JSON STRING: {:?}", json_string);

let key_id = json::parse(&json_string).unwrap()["KeyMetadata"]["KeyId"]
.to_string();
tracing::trace!("created key {}", key_id);

key_id
*/
"todo".into()
}

/*
Expand Down

0 comments on commit a47a1dc

Please sign in to comment.