Skip to content

Commit

Permalink
Merge branch 'master' into kkawula/update-installation-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kkawula authored Jan 15, 2025
2 parents b9a0e22 + 6af1722 commit 7c981e2
Show file tree
Hide file tree
Showing 50 changed files with 774 additions and 216 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.* text eol=lf
*.png -text
*.jpg -text
*.gif -text
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
4 changes: 4 additions & 0 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:

jobs:
get-scarb-versions:
if: "! github.event.repository.fork"
name: Get Scarb versions
outputs:
versions: ${{ steps.get_versions.outputs.versions }}
Expand All @@ -30,6 +31,7 @@ jobs:
echo "versions=[${scarb_versions[@]}]" >> "$GITHUB_OUTPUT"
test-forge-unit-and-integration:
if: "! github.event.repository.fork"
runs-on: ubuntu-latest
needs: get-scarb-versions
strategy:
Expand All @@ -50,6 +52,7 @@ jobs:
- run: cargo test --release -p forge integration

test-forge-e2e:
if: "! github.event.repository.fork"
runs-on: ubuntu-latest
needs: get-scarb-versions
strategy:
Expand Down Expand Up @@ -89,6 +92,7 @@ jobs:
- run: cargo test --release -p forge e2e

test-cast:
if: "! github.event.repository.fork"
runs-on: ubuntu-latest
needs: get-scarb-versions
strategy:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.36.0] - 2025-01-15

### Forge

#### Changed
Expand All @@ -17,8 +19,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Added

- When using `--max-fee` with transactions v3, calculated max gas and max gas unit price are automatically validated to ensure they are greater than 0 after conversion
- interactive interface that allows setting created or imported account as the default

#### Changed

- Values passed to the `--max-fee`, `--max-gas`, and `--max-gas-unit-price` flags must be greater than 0

#### Deprecated

- `--version` flag

## [0.35.1] - 2024-12-16

### Forge
Expand Down
24 changes: 6 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ members = [
]

[workspace.package]
version = "0.35.1"
version = "0.36.0"
edition = "2021"
repository = "https://github.com/foundry-rs/starknet-foundry"
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions crates/conversions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub mod contract_address;
pub mod entrypoint_selector;
pub mod eth_address;
pub mod felt;
pub mod non_zero_felt;
pub mod non_zero_u128;
pub mod non_zero_u64;
pub mod nonce;
pub mod padded_felt;
pub mod primitive;
Expand Down
23 changes: 23 additions & 0 deletions crates/conversions/src/non_zero_felt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::FromConv;
use starknet_types_core::felt::{Felt, NonZeroFelt};
use std::num::{NonZeroU128, NonZeroU64};

impl FromConv<NonZeroU64> for NonZeroFelt {
fn from_(value: NonZeroU64) -> Self {
NonZeroFelt::try_from(Felt::from(value.get())).unwrap_or_else(|_| {
unreachable!(
"NonZeroU64 is always greater than 0, so it should be convertible to NonZeroFelt"
)
})
}
}

impl FromConv<NonZeroU128> for NonZeroFelt {
fn from_(value: NonZeroU128) -> Self {
NonZeroFelt::try_from(Felt::from(value.get())).unwrap_or_else(|_| {
unreachable!(
"NonZeroU128 is always greater than 0, so it should be convertible to NonZeroFelt"
)
})
}
}
14 changes: 14 additions & 0 deletions crates/conversions/src/non_zero_u128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::TryFromConv;
use starknet_types_core::felt::{Felt, NonZeroFelt};
use std::num::{NonZero, NonZeroU128};

impl TryFromConv<NonZeroFelt> for NonZeroU128 {
type Error = String;
fn try_from_(value: NonZeroFelt) -> Result<Self, Self::Error> {
let value: u128 = Felt::from(value)
.try_into()
.map_err(|_| "felt was too large to fit in u128")?;
Ok(NonZero::new(value)
.unwrap_or_else(|| unreachable!("non zero felt is always greater than 0")))
}
}
14 changes: 14 additions & 0 deletions crates/conversions/src/non_zero_u64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::TryFromConv;
use starknet_types_core::felt::{Felt, NonZeroFelt};
use std::num::{NonZero, NonZeroU64};

impl TryFromConv<NonZeroFelt> for NonZeroU64 {
type Error = String;
fn try_from_(value: NonZeroFelt) -> Result<Self, Self::Error> {
let value: u64 = Felt::from(value)
.try_into()
.map_err(|_| "felt was too large to fit in u64")?;
Ok(NonZero::new(value)
.unwrap_or_else(|| unreachable!("non zero felt is always greater than 0")))
}
}
38 changes: 26 additions & 12 deletions crates/conversions/src/serde/deserialize/deserialize_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{byte_array::ByteArray, IntoConv};
use num_traits::cast::ToPrimitive;
use starknet::providers::Url;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, Nonce};
use starknet_types_core::felt::Felt;
use std::num::NonZeroU32;
use starknet_types_core::felt::{Felt, NonZeroFelt};
use std::num::NonZero;

impl CairoDeserialize for Url {
fn deserialize(reader: &mut BufferReader<'_>) -> BufferReadResult<Self> {
Expand All @@ -13,12 +13,6 @@ impl CairoDeserialize for Url {
}
}

impl CairoDeserialize for NonZeroU32 {
fn deserialize(reader: &mut BufferReader<'_>) -> BufferReadResult<Self> {
NonZeroU32::new(reader.read()?).ok_or(BufferReadError::ParseFailed)
}
}

impl CairoDeserialize for Felt {
fn deserialize(reader: &mut BufferReader<'_>) -> BufferReadResult<Self> {
reader.read_felt()
Expand Down Expand Up @@ -71,6 +65,24 @@ impl CairoDeserialize for bool {
}
}

impl CairoDeserialize for NonZeroFelt {
fn deserialize(reader: &mut BufferReader<'_>) -> BufferReadResult<Self> {
let felt = reader.read::<Felt>()?;
NonZeroFelt::try_from(felt).map_err(|_| BufferReadError::ParseFailed)
}
}

macro_rules! impl_deserialize_for_nonzero_num_type {
($type:ty) => {
impl CairoDeserialize for NonZero<$type> {
fn deserialize(reader: &mut BufferReader<'_>) -> BufferReadResult<Self> {
let val = <$type>::deserialize(reader)?;
NonZero::new(val).ok_or(BufferReadError::ParseFailed)
}
}
};
}

macro_rules! impl_deserialize_for_felt_type {
($type:ty) => {
impl CairoDeserialize for $type {
Expand All @@ -80,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 All @@ -99,6 +109,10 @@ impl_deserialize_for_felt_type!(ContractAddress);
impl_deserialize_for_felt_type!(Nonce);
impl_deserialize_for_felt_type!(EntryPointSelector);

impl_deserialize_for_nonzero_num_type!(u32);
impl_deserialize_for_nonzero_num_type!(u64);
impl_deserialize_for_nonzero_num_type!(u128);

impl_deserialize_for_num_type!(u8);
impl_deserialize_for_num_type!(u16);
impl_deserialize_for_num_type!(u32);
Expand Down
3 changes: 3 additions & 0 deletions crates/conversions/tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ mod contract_address;
mod entrypoint_selector;
mod felt;
mod field_elements;
mod non_zero_felt;
mod non_zero_u128;
mod non_zero_u64;
mod nonce;
mod padded_felt;
mod string;
21 changes: 21 additions & 0 deletions crates/conversions/tests/e2e/non_zero_felt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[cfg(test)]
mod tests_non_zero_felt {
use std::num::{NonZeroU128, NonZeroU64};

use conversions::FromConv;
use starknet_types_core::felt::{Felt, NonZeroFelt};

#[test]
fn test_happy_case() {
let non_zero_felt = NonZeroFelt::try_from(Felt::from(1_u8)).unwrap();

assert_eq!(
non_zero_felt,
NonZeroFelt::from_(NonZeroU64::new(1).unwrap())
);
assert_eq!(
non_zero_felt,
NonZeroFelt::from_(NonZeroU128::new(1).unwrap())
);
}
}
Loading

0 comments on commit 7c981e2

Please sign in to comment.