Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions crates/cli/src/output/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ mod tests {
failing_contract_id: None,
call_chain: None,
resource_diagnostics: None,
operation_index: None,
operation_count: None,
learn_more: "https://developers.stellar.org/docs/learn/smart-contracts/errors"
.to_string(),
}
Expand Down Expand Up @@ -596,6 +598,8 @@ mod tests {
write_bytes: 500,
},
return_value: None,
operation_index: None,
operation_count: None,
};

let output = render_context_table(&context);
Expand Down
24 changes: 6 additions & 18 deletions crates/core/src/bin/taxonomy_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,14 @@ fn main() {
process::exit(1);
}

let issues = match grat_core::taxonomy::linter::lint_dir(&dir) {
Ok(issues) => issues,
match grat_core::taxonomy::linter::lint_dir(&dir) {
Ok(()) => {
println!("✅ No issues found in {}", dir.display());
process::exit(0);
}
Err(e) => {
eprintln!("error: lint_dir failed: {e}");
eprintln!("error: lint_dir execution failed: {e}");
process::exit(1);
}
};

if issues.is_empty() {
println!("✅ No issues found in {}", dir.display());
process::exit(0);
}

for issue in &issues {
match &issue.entry_id {
Some(eid) => eprintln!("{}:{}: {}", issue.file, eid, issue.message),
None => eprintln!("{}:: {}", issue.file, issue.message),
}
}

eprintln!("❌ Found {} issue(s) in {}", issues.len(), dir.display());
process::exit(1);
}
18 changes: 11 additions & 7 deletions crates/core/src/cache/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ impl CacheStore {
let path = self.entry_path(category, key);
if path.exists() {
// Explicitly update access metadata to ensure LRU eviction works even if atime is disabled.
if let Ok(file) = std::fs::File::open(&path) {
let _ = file.set_times(std::fs::FileTimes::new().set_accessed(SystemTime::now()));
if let Ok(file) = std::fs::OpenOptions::new().write(true).open(&path) {
let now = SystemTime::now();
let _ = file.set_times(
std::fs::FileTimes::new()
.set_accessed(now)
.set_modified(now),
);
}
let data = std::fs::read(&path)
.map_err(|e| GratError::CacheError(format!("Failed to read cache entry: {e}")))?;
Expand Down Expand Up @@ -160,12 +165,11 @@ impl CacheStore {
GratError::CacheError(format!("Failed to read cache file metadata: {e}"))
})?;

let accessed = meta
.accessed()
.or_else(|_| meta.modified())
.unwrap_or(SystemTime::UNIX_EPOCH);
let accessed = meta.accessed().unwrap_or(SystemTime::UNIX_EPOCH);
let modified = meta.modified().unwrap_or(SystemTime::UNIX_EPOCH);
let last_used = std::cmp::max(accessed, modified);

files.push((accessed, entry));
files.push((last_used, entry));
}
}

Expand Down
9 changes: 5 additions & 4 deletions crates/core/src/decode/argument_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ mod tests {
use super::*;
use crate::spec::decoder::{ContractStructDef, ContractStructField};
use serde_json::json;
use stellar_xdr::curr::{
Hash, ScAddress, ScMapEntry, ScString, ScSymbol, ScVal,
};
use stellar_xdr::curr::{Hash, ScAddress, ScMapEntry, ScString, ScSymbol, ScVal};

fn sym(s: &str) -> ScVal {
ScVal::Symbol(ScSymbol(s.try_into().unwrap()))
Expand Down Expand Up @@ -271,7 +269,10 @@ mod tests {
let decoder = ArgumentDecoder::new();
let func = ContractFunction {
name: "transfer".to_string(),
params: vec![("to".to_string(), "Address".to_string()), ("amount".to_string(), "U128".to_string())],
params: vec![
("to".to_string(), "Address".to_string()),
("amount".to_string(), "U128".to_string()),
],
return_type: "Void".to_string(),
doc: None,
return_type_def: Some(ScSpecTypeDef::Void),
Expand Down
7 changes: 4 additions & 3 deletions crates/core/src/decode/chain_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ impl ChainAnalyzer {
chain.trace = chain.render_trace();
chain
}

}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -488,7 +487,7 @@ impl DeepestErrorFinder {
// Evaluate every failure event, not just the first
// ----------------------------------------------------------------
if is_failure(event, &topics, &v0.data) {
let depth = stack.len();
let depth = stack.len().saturating_sub(1);

let is_new_deepest = match &deepest {
None => true,
Expand All @@ -500,7 +499,9 @@ impl DeepestErrorFinder {

if is_new_deepest {
let (contract_address, function_name) = match stack.last() {
Some(frame) => (frame.contract_address.clone(), frame.function_name.clone()),
Some(frame) => {
(frame.contract_address.clone(), frame.function_name.clone())
}
None => {
let address = event
.event
Expand Down
21 changes: 6 additions & 15 deletions crates/core/src/decode/function_call_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ mod tests {
let decoder = FunctionCallDecoder::new();
let func = ContractFunction {
name: "add".to_string(),
params: vec![("a".to_string(), "U32".to_string()), ("b".to_string(), "U32".to_string())],
params: vec![
("a".to_string(), "U32".to_string()),
("b".to_string(), "U32".to_string()),
],
return_type: "U32".to_string(),
doc: None,
return_type_def: Some(ScSpecTypeDef::U32),
Expand All @@ -102,13 +105,7 @@ mod tests {
let raw_args = vec![ScVal::U32(10), ScVal::U32(20)];
let return_val = ScVal::U32(30);

let decoded = decoder.decode(
"add",
&raw_args,
Some(&func),
Some(&return_val),
None,
);
let decoded = decoder.decode("add", &raw_args, Some(&func), Some(&return_val), None);

assert_eq!(decoded.function_name, "add");
assert_eq!(decoded.arguments.len(), 2);
Expand All @@ -125,13 +122,7 @@ mod tests {
let decoder = FunctionCallDecoder::new();
let raw_args = vec![ScVal::U32(5)];

let decoded = decoder.decode(
"test_func",
&raw_args,
None,
None,
None,
);
let decoded = decoder.decode("test_func", &raw_args, None, None, None);

assert_eq!(decoded.function_name, "test_func");
assert_eq!(decoded.arguments.len(), 1);
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub mod host_error;
pub mod mappings;
pub mod multi_op_decoder;
pub mod report;
pub mod return_decoder;
pub mod resource_analyzer;
pub mod return_decoder;
pub mod scval_to_json;
pub mod walker;

Expand All @@ -26,13 +26,13 @@ pub use auth::{
AuthorizationType,
};
pub use auth_address_nonce::AddressWithNonce;
pub use function_call_decoder::{DecodedArgument, DecodedFunctionCall, FunctionCallDecoder};
pub use return_decoder::ReturnValueDecoder;
pub use chain_analyzer::{analyze_call_chain, CallChain, ChainAnalyzer, ChainFrame, FrameRole};
pub use function_call_decoder::{DecodedArgument, DecodedFunctionCall, FunctionCallDecoder};
pub use multi_op_decoder::{decode_transaction_with_op_filter, MultiOpDecoder};
pub use resource_analyzer::{
MetricDiagnostic, MetricKind, ResourceDiagnostics, ResourceUsageAnalyzer, TransactionResultMeta,
};
pub use multi_op_decoder::{decode_transaction_with_op_filter, MultiOpDecoder};
pub use return_decoder::ReturnValueDecoder;
pub use scval_to_json::scval_to_json;
pub use walker::{
walk_diagnostic_events, DiagnosticEventKind, DiagnosticEventWalker, StructuredDiagnosticEvent,
Expand Down
Loading