-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, one suggestion
crates/cast/src/cmd/call.rs
Outdated
|
||
/// Override the time field of a block | ||
/// | ||
/// Format: block:time | ||
#[arg(long = "override-time", value_name = "BLOCK:TIME")] | ||
pub time_overrides: Option<Vec<String>>, |
There was a problem hiding this comment.
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
crates/cast/src/cmd/call.rs
Outdated
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)) | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this 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
crates/cast/src/cmd/call.rs
Outdated
// 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(); |
There was a problem hiding this comment.
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
@Soubhik-10 while we're at it, let's also add a block.number override value? |
Sure 🫡 |
crates/cast/src/cmd/call.rs
Outdated
.with_number(U256::from(self.block_number.unwrap())) | ||
.with_time(self.block_time.unwrap()); |
There was a problem hiding this comment.
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)
crates/cast/src/lib.rs
Outdated
@@ -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()); |
There was a problem hiding this comment.
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
crates/cast/src/lib.rs
Outdated
) -> 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); |
There was a problem hiding this comment.
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
@klkvr I believe we changed the rlp in txenvelope derive, so do we need to update some tests here? |
closes #6062