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

feat: add cache sub commands and allow for proper transaction data logging #1173

Merged
merged 32 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e4319e0
feat: use data directory and store simulations and transaction responses
willemneal Mar 7, 2024
2efce94
feat: add data logging to all commands that use a transaction
willemneal Mar 7, 2024
e93a3a2
feat: add "--no-cache" global arg
willemneal Mar 9, 2024
cbf8d70
feat: add spec cache, speeding up `invoke`
willemneal Mar 11, 2024
6a8891c
fix: clippy and fmt
willemneal Mar 11, 2024
9cf10f3
feat: implement display for Dated Action to see formated list of actions
willemneal Mar 12, 2024
976825e
fix: docs
willemneal Mar 28, 2024
f5ca6dd
feat: rename to cache command
willemneal Mar 28, 2024
a1d8a50
fix: revert change to invoke test
willemneal Apr 8, 2024
4ca157c
fix: md
willemneal Apr 8, 2024
445a15d
feat: cache read
willemneal Apr 15, 2024
9210164
fix: clippy
willemneal Apr 16, 2024
38a290e
fix: docs
willemneal Apr 16, 2024
f417924
fix: fetch SAC contract spec
willemneal Apr 16, 2024
26ddb5a
fix: PR suggestions
willemneal Apr 23, 2024
ead02f2
fix: remove option when cleaning and fix up refactor
willemneal Apr 23, 2024
a9e311d
feat: create data_local_dir function to ensure consistent location
willemneal Apr 23, 2024
ed02780
fix: md
willemneal Apr 23, 2024
93c1a1c
Merge branch 'main' into feat/data_logging
leighmcculloch Apr 30, 2024
b5642c0
Merge branch 'main' into feat/data_logging
willemneal May 1, 2024
8b4d359
Merge remote-tracking branch 'origin/main' into feat/data_logging
willemneal May 1, 2024
c745de7
fix: add actionlog subcommand
willemneal May 1, 2024
eecf3e3
Merge branch 'main' into feat/data_logging
leighmcculloch May 2, 2024
a99b828
com -> org
leighmcculloch May 2, 2024
e4f03c1
fix clean erroring on not found
leighmcculloch May 2, 2024
a0e1104
rename info to path and add experimental doc
leighmcculloch May 2, 2024
6d5a5e3
use terms simulate and send for consistency with actions a user performs
leighmcculloch May 2, 2024
c0bf977
simply the actionlog cache output
leighmcculloch May 2, 2024
def7d29
use snake_case for json to match other json the cli outputs
leighmcculloch May 2, 2024
d15db7c
match names in output
leighmcculloch May 2, 2024
72ab2b7
Update soroban-cli-full-docs.md
leighmcculloch May 2, 2024
e996366
add room for more data stored with actions
leighmcculloch May 2, 2024
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
54 changes: 53 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ tracing-subscriber = "0.3.16"
tracing-appender = "0.2.2"
which = "4.4.0"
wasmparser = "0.90.0"
directories = "5.0.1"
ulid = { version = "1.1" }
termcolor = "1.1.3"
termcolor_output = "1.0.1"
ed25519-dalek = "2.0.0"
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ serde_json = "1.0.93"
which = { workspace = true }
tokio = "1.28.1"
walkdir = "2.4.0"
ulid.workspace = true

[features]
it = []
4 changes: 3 additions & 1 deletion cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ impl TestEnv {
.env("SOROBAN_ACCOUNT", TEST_ACCOUNT)
.env("SOROBAN_RPC_URL", &self.rpc_url)
.env("SOROBAN_NETWORK_PASSPHRASE", LOCAL_NETWORK_PASSPHRASE)
.env("XDG_CONFIG_HOME", self.temp_dir.as_os_str())
.env("XDG_CONFIG_HOME", self.temp_dir.join("config").as_os_str())
.env("XDG_DATA_HOME", self.temp_dir.join("data").as_os_str())
.current_dir(&self.temp_dir);
cmd
}
Expand Down Expand Up @@ -246,6 +247,7 @@ impl TestEnv {
verbose: false,
very_verbose: false,
list: false,
no_cache: false,
}),
Some(&config),
)
Expand Down
7 changes: 7 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::integration::util::extend_contract;

use super::util::{deploy_hello, extend, HELLO_WORLD};

#[allow(clippy::too_many_lines)]
#[tokio::test]
async fn invoke() {
let sandbox = &TestEnv::new();
Expand Down Expand Up @@ -63,6 +64,12 @@ async fn invoke() {
};
let id = &deploy_hello(sandbox).await;
extend_contract(sandbox, id).await;
let uid = sandbox
.new_assert_cmd("cache")
.arg("ls")
.assert()
.stdout_as_str();
ulid::Ulid::from_string(&uid).expect("invalid ulid");
// Note that all functions tested here have no state
invoke_hello_world(sandbox, id);

Expand Down
2 changes: 2 additions & 0 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] }
cargo_metadata = "0.15.4"
pathdiff = "0.2.1"
dotenvy = "0.15.7"
directories = { workspace = true }
ulid = { workspace = true, features = ["serde"] }
strum = "0.17.1"
strum_macros = "0.17.1"
gix = { version = "0.58.0", default-features = false, features = [
Expand Down
27 changes: 27 additions & 0 deletions cmd/soroban-cli/src/commands/cache/clean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::fs;

use super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Io(#[from] std::io::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let binding = data::project_dir()?;
let dir = binding.data_dir();
fs::remove_dir_all(dir)?;
Ok(())
}
}
21 changes: 21 additions & 0 deletions cmd/soroban-cli/src/commands/cache/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
println!("{:?}", data::data_local_dir()?);
leighmcculloch marked this conversation as resolved.
Show resolved Hide resolved
Ok(())
}
}
44 changes: 44 additions & 0 deletions cmd/soroban-cli/src/commands/cache/ls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use clap::command;

use super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {
#[command(flatten)]
pub config_locator: locator::Args,

#[arg(long, short = 'l')]
pub long: bool,
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let res = if self.long { self.ls_l() } else { self.ls() }?.join("\n");
println!("{res}");
Ok(())
}

pub fn ls(&self) -> Result<Vec<String>, Error> {
Ok(data::list_ulids()?
.iter()
.map(ToString::to_string)
.collect())
}

pub fn ls_l(&self) -> Result<Vec<String>, Error> {
Ok(data::list_actions()?
.iter()
.map(ToString::to_string)
.collect())
}
}
42 changes: 42 additions & 0 deletions cmd/soroban-cli/src/commands/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use clap::Parser;

pub mod clean;
pub mod info;
pub mod ls;
pub mod read;

#[derive(Debug, Parser)]
pub enum Cmd {
/// List cached actions (transactions, simulations)
Ls(ls::Cmd),
/// Show location of cache
Info(info::Cmd),
/// Delete all cached actions
Clean(clean::Cmd),
/// Read cached action
Read(read::Cmd),
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Info(#[from] info::Error),
#[error(transparent)]
Ls(#[from] ls::Error),
#[error(transparent)]
Clean(#[from] clean::Error),
#[error(transparent)]
Read(#[from] read::Error),
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
match self {
Cmd::Ls(cmd) => cmd.run()?,
Cmd::Info(cmd) => cmd.run()?,
Cmd::Clean(cmd) => cmd.run()?,
Cmd::Read(cmd) => cmd.run()?,
};
Ok(())
}
}
73 changes: 73 additions & 0 deletions cmd/soroban-cli/src/commands/cache/read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use std::{
fs,
path::{Path, PathBuf},
};

use clap::ValueEnum;
use ulid::Ulid;

use super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Ulid(#[from] ulid::DecodeError),
#[error("failed to find cache entry {0}")]
NotFound(String),
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {
/// ULID of the cache entry
leighmcculloch marked this conversation as resolved.
Show resolved Hide resolved
#[arg(long)]
pub id: String,
#[arg(long)]
pub output: Option<OutputType>,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, ValueEnum, Default)]
pub enum OutputType {
// Status,
#[default]
Envelope,
// ResultMeta,
// Result,
}
leighmcculloch marked this conversation as resolved.
Show resolved Hide resolved

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let file = self.file()?;
tracing::debug!("reading file {}", file.display());
let (action, _) = data::read(&self.ulid()?)?;
let output = if self.output.is_some() {
match action {
data::Action::Transaction(sim) => sim.envelope_xdr.expect("missing envelope"),
data::Action::Simulation(_) => todo!("Only read transactions"),
}
} else {
serde_json::to_string_pretty(&action)?
};
println!("{output}");
Ok(())
}

pub fn file(&self) -> Result<PathBuf, Error> {
Ok(data::actions_dir()?.join(&self.id).with_extension("json"))
}

pub fn read_file(&self, file: &Path) -> Result<String, Error> {
fs::read_to_string(file).map_err(|_| Error::NotFound(self.id.clone()))
}

pub fn ulid(&self) -> Result<Ulid, Error> {
Ok(Ulid::from_string(&self.id)?)
}
}
Loading
Loading