Skip to content

Commit

Permalink
Merge branch 'franciszekjob/2706-validate-fee-args-greater-than-zero'…
Browse files Browse the repository at this point in the history
… of https://github.com/foundry-rs/starknet-foundry into franciszekjob/2707-show-info-about-converted-max-fee-with-v3-txs
  • Loading branch information
franciszekjob committed Jan 14, 2025
2 parents 7f1fbbc + 4d7229f commit 756b5c7
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 64 deletions.
32 changes: 19 additions & 13 deletions .github/ISSUE_TEMPLATE/work_item.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
name: Work item
description: Submit an actionable task
body:
- type: dropdown
id: tool-name
- type: textarea
id: current-state
attributes:
label: Which components does the task require to be changed? (think hard pls)
multiple: true
options:
- snforge
- sncast
- cairo-profiler
- other (describe below)
label: Current State
description: Describe the current state and outline the problem
placeholder: Currently, the `print_a` cheatcode prints `"a"` to stdout. This is problematic because user might want it to be printed on their actual printer.
validations:
required: true

- type: textarea
id: description
- type: input
id: objective
attributes:
label: Description
description: Describe the issue here.
label: Objective
description: Briefly describe the correct state
placeholder: The `print_a` cheatcode should magically detect if user wants to print to stdout or a printer.
validations:
required: true

- type: textarea
id: additional-context
attributes:
label: Additional Context
description: Provide additional context on the desired state.
placeholder: If we can detect any printers in local network it might indicate that user wants to print to it.
validations:
required: false
14 changes: 1 addition & 13 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions crates/conversions/src/serde/deserialize/deserialize_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ macro_rules! impl_deserialize_for_felt_type {
}
};
}

macro_rules! impl_deserialize_for_num_type {
($type:ty) => {
impl CairoDeserialize for $type {
fn deserialize(reader: &mut BufferReader<'_>) -> BufferReadResult<Self> {
let felt = Felt::deserialize(reader)?;

felt.to_bigint()
.try_into()
.map_err(|_| BufferReadError::ParseFailed)
felt.try_into().map_err(|_| BufferReadError::ParseFailed)
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/conversions/tests/e2e/non_zero_u128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod tests_non_zero_u128 {

#[test]
fn test_felt_too_large() {
let large_felt = Felt::from_dec_str("340282366920938463463374607431768211456").unwrap(); // 2^128
let large_felt = Felt::TWO.pow(128_u8);
let non_zero_felt = NonZeroFelt::try_from(large_felt).unwrap();

let result = NonZeroU128::try_from_(non_zero_felt);
Expand Down
2 changes: 1 addition & 1 deletion crates/conversions/tests/e2e/non_zero_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod tests_non_zero_u64 {

#[test]
fn test_felt_too_large() {
let large_felt = Felt::from_dec_str("18446744073709551616").unwrap(); // 2^64
let large_felt = Felt::TWO.pow(64_u8);
let non_zero_felt = NonZeroFelt::try_from(large_felt).unwrap();

let result = NonZeroU64::try_from_(non_zero_felt);
Expand Down
1 change: 0 additions & 1 deletion crates/forge-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ conversions = { path = "../conversions" }
scarb-api = { path = "../scarb-api" }
shared = { path = "../shared" }
universal-sierra-compiler-api = { path = "../universal-sierra-compiler-api" }
fs4.workspace = true
which.workspace = true
sanitize-filename.workspace = true
3 changes: 3 additions & 0 deletions crates/forge-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use futures::StreamExt;
use package_tests::with_config_resolved::TestCaseWithResolvedConfig;
use profiler_api::run_profiler;
use shared::print::print_as_warning;
use shared::spinner::Spinner;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -68,6 +69,7 @@ pub fn maybe_save_trace_and_profile(
let name = sanitize_filename::sanitize(name.replace("::", "_"));
let trace_path = save_trace_data(&name, trace_data)?;
if execution_data_to_save.profile {
let _spinner = Spinner::create_with_message("Running cairo-profiler");
run_profiler(&name, &trace_path, &execution_data_to_save.additional_args)?;
}
return Ok(Some(trace_path));
Expand All @@ -84,6 +86,7 @@ pub fn maybe_generate_coverage(
if saved_trace_data_paths.is_empty() {
print_as_warning(&anyhow!("No trace data to generate coverage from"));
} else {
let _spinner = Spinner::create_with_message("Running cairo-coverage");
run_coverage(
saved_trace_data_paths,
&execution_data_to_save.additional_args,
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Read the docs:
Join the community:
- Follow core developers on X: https://twitter.com/swmansionxyz
- Get support via Telegram: https://t.me/starknet_foundry_support
- Or discord: https://discord.gg/KZWaFtPZJf
- Or discord: https://discord.gg/starknet-community
- Or join our general chat (Telegram): https://t.me/starknet_foundry
Report bugs: https://github.com/foundry-rs/starknet-foundry/issues/new/choose\
Expand Down
1 change: 1 addition & 0 deletions crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ starknet.workspace = true
url.workspace = true
regex.workspace = true
snapbox.workspace = true
indicatif.workspace = true
1 change: 1 addition & 0 deletions crates/shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod command;
pub mod consts;
pub mod print;
pub mod rpc;
pub mod spinner;
pub mod test_utils;
pub mod utils;

Expand Down
25 changes: 25 additions & 0 deletions crates/shared/src/spinner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use indicatif::{ProgressBar, ProgressStyle};
use std::borrow::Cow;
use std::time::Duration;

/// Styled spinner that uses [`ProgressBar`].
/// Automatically finishes and clears itself when dropped.
pub struct Spinner(ProgressBar);
impl Spinner {
/// Create [`Spinner`] with a message.
pub fn create_with_message(message: impl Into<Cow<'static, str>>) -> Self {
let spinner = ProgressBar::new_spinner();
let style = ProgressStyle::with_template("\n{spinner} {msg}\n")
.expect("template is static str and should be valid");
spinner.set_style(style);
spinner.enable_steady_tick(Duration::from_millis(100));
spinner.set_message(message);
Self(spinner)
}
}

impl Drop for Spinner {
fn drop(&mut self) {
self.0.finish_and_clear();
}
}
1 change: 1 addition & 0 deletions crates/sncast/src/helpers/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl FeeArgs {
.l1_gas_price()
.price_in_fri,
)?;
// TODO(#2852)
let max_gas = NonZeroFelt::try_from(Felt::from(max_fee)
.floor_div(&max_gas_unit_price)).context("Calculated max-gas from provided --max-fee and the current network gas price is 0. Please increase --max-fee to obtain a positive gas amount")?;
print_max_fee_conversion_info(max_fee, max_gas, max_gas_unit_price);
Expand Down
2 changes: 1 addition & 1 deletion crates/sncast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Read the docs:
Join the community:
- Follow core developers on X: https://twitter.com/swmansionxyz
- Get support via Telegram: https://t.me/starknet_foundry_support
- Or discord: https://discord.gg/KZWaFtPZJf
- Or discord: https://discord.gg/starknet-community
- Or join our general chat (Telegram): https://t.me/starknet_foundry
Report bugs: https://github.com/foundry-rs/starknet-foundry/issues/new/choose\
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ fn test_calculated_max_gas_equal_to_zero_when_max_fee_passed() {
let snapbox = runner(&args);
let output = snapbox.assert().success();

// TODO(#2852)
assert_stderr_contains(
output,
indoc! {r"
Expand Down
2 changes: 0 additions & 2 deletions crates/snforge-scarb-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ cairo-lang-macro.workspace = true
cairo-lang-parser.workspace = true
cairo-lang-utils.workspace = true
cairo-lang-syntax.workspace = true
cairo-lang-diagnostics.workspace = true
cairo-lang-filesystem.workspace = true
url.workspace = true
indoc.workspace = true
smol_str.workspace = true
Expand Down
36 changes: 18 additions & 18 deletions crates/universal-sierra-compiler-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::io::Write;
use std::str::from_utf8;
use tempfile::Builder;

use crate::spinner::spawn_spinner_message;
use crate::spinner::spawn_usc_spinner;
pub use command::*;
use shared::command::CommandExt;

Expand Down Expand Up @@ -72,25 +72,25 @@ pub fn compile_sierra_at_path<T: UniversalSierraCompilerOutput>(
sierra_file_path: &Utf8Path,
sierra_type: &SierraType,
) -> Result<T> {
let spinner = spawn_spinner_message(sierra_file_path)?;

let mut usc_command = UniversalSierraCompilerCommand::new();
let usc_output = usc_command
.inherit_stderr()
.args(vec![
&("compile-".to_string() + &sierra_type.to_string()),
"--sierra-path",
sierra_file_path.as_str(),
])
.command()
.output_checked()
.context(
"Error while compiling Sierra. \
let usc_output = {
let _spinner = spawn_usc_spinner(sierra_file_path)?;

let mut usc_command = UniversalSierraCompilerCommand::new();
usc_command
.inherit_stderr()
.args(vec![
&("compile-".to_string() + &sierra_type.to_string()),
"--sierra-path",
sierra_file_path.as_str(),
])
.command()
.output_checked()
.context(
"Error while compiling Sierra. \
Make sure you have the latest universal-sierra-compiler binary installed. \
Contact us if it doesn't help",
)?;

spinner.finish_and_clear();
)?
};

Ok(T::convert(from_utf8(&usc_output.stdout)?.to_string()))
}
Expand Down
11 changes: 3 additions & 8 deletions crates/universal-sierra-compiler-api/src/spinner.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use anyhow::Result;
use camino::Utf8Path;
use indicatif::{ProgressBar, ProgressStyle};
use shared::spinner::Spinner;
use std::env;
use std::time::Duration;

pub fn spawn_spinner_message(sierra_file_path: &Utf8Path) -> Result<ProgressBar> {
let spinner = ProgressBar::new_spinner();
spinner.set_style(ProgressStyle::with_template("\n{spinner} {msg}\n")?);
spinner.enable_steady_tick(Duration::from_millis(100));

pub fn spawn_usc_spinner(sierra_file_path: &Utf8Path) -> Result<Spinner> {
// Skip printing path when compiling unsaved sierra
// which occurs during test execution for some cheatcodes e.g. `replace_bytecode`
let message = if is_temp_file(sierra_file_path)? {
Expand All @@ -19,7 +14,7 @@ pub fn spawn_spinner_message(sierra_file_path: &Utf8Path) -> Result<ProgressBar>
sierra_file_path.canonicalize_utf8()?
)
};
spinner.set_message(message);
let spinner = Spinner::create_with_message(message);

Ok(spinner)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/snfoundryup
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Read the docs:
Join the community:
- Follow core developers on X: https://twitter.com/swmansionxyz
- Get support via Telegram: https://t.me/starknet_foundry_support
- Or discord: https://discord.gg/KZWaFtPZJf
- Or discord: https://discord.gg/starknet-community
- Or join our general chat (Telegram): https://t.me/starknet_foundry
Report bugs: https://github.com/foundry-rs/starknet-foundry/issues/new/choose
Expand Down

0 comments on commit 756b5c7

Please sign in to comment.