Skip to content

feat: added block.time and block.number override in cast #10727

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

Merged
merged 18 commits into from
Jun 18, 2025

Conversation

Soubhik-10
Copy link
Contributor

closes #6062

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, one suggestion

Comment on lines 151 to 156

/// Override the time field of a block
///
/// Format: block:time
#[arg(long = "override-time", value_name = "BLOCK:TIME")]
pub time_overrides: Option<Vec<String>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can name this just block.time because block overrides arent't that complex, this can be a simple u64

Comment on lines 440 to 445
fn time_value_override(input: &str) -> Result<(&str, &str), eyre::Report> {
let (block_str, time_str) = input.split_once(':').ok_or_else(|| {
eyre::eyre!("Invalid override `{input}`. Expected format: <block>:<time>")
})?;
Ok((block_str, time_str))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this we can change to a single u64 arg on the cli

@Soubhik-10 Soubhik-10 requested a review from mattsse June 9, 2025 11:05
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

only thing is missing is another alloy release that unlocks a single call here

Comment on lines 381 to 386
// Early return if no override set - <https://github.com/foundry-rs/foundry/issues/10705>
if self.block_time.as_ref().is_none() {
return Ok(None);
}

let block_overrides = BlockOverrides::default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works, we'll need to check this for any additional overrides field we will introduce

@mattsse
Copy link
Member

mattsse commented Jun 10, 2025

@Soubhik-10 while we're at it, let's also add a block.number override value?

@Soubhik-10
Copy link
Contributor Author

@Soubhik-10 while we're at it, let's also add a block.number override value?

Sure 🫡

@Soubhik-10 Soubhik-10 changed the title added time override feat: added block.time and block.number override in cast Jun 11, 2025
Comment on lines 391 to 392
.with_number(U256::from(self.block_number.unwrap()))
.with_time(self.block_time.unwrap());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I think this would currently be problematic because the is_none check only returns Ok(None) if all are none but this unwraps all.

we could do

let overrides = BlockOverrides {...}
if overrides.is_empty() return Ok(None)

@@ -149,6 +150,7 @@ impl<P: Provider<AnyNetwork>> Cast<P> {
func: Option<&Function>,
block: Option<BlockId>,
state_override: Option<StateOverride>,
_block_override: Option<BlockOverrides>,
) -> Result<String> {
let mut call = self.provider.call(req.clone()).block(block.unwrap_or_default());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should now be a setter for BlockOverrides as Option

mattsse
mattsse previously approved these changes Jun 17, 2025
) -> Result<String> {
let mut call = self.provider.call(req.clone()).block(block.unwrap_or_default());
if let Some(state_override) = state_override {
call = call.overrides(state_override)
}
call = call.with_block_overrides_opt(block_override);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this to L155

@mattsse
Copy link
Member

mattsse commented Jun 17, 2025

@klkvr I believe we changed the rlp in txenvelope derive, so do we need to update some tests here?

@mattsse mattsse marked this pull request as ready for review June 17, 2025 18:11
@klkvr klkvr enabled auto-merge (squash) June 17, 2025 18:19
@klkvr klkvr merged commit 6ceff66 into foundry-rs:master Jun 18, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

feat(cast) Add --timestamp flag to cast call --block to override the timestamp of the block
4 participants