Skip to content

feat(cast): Add file option for calldata input #10397

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

Conversation

Ayushdubey86
Copy link
Contributor

This issue should close #10013 .

Hello @yash-atreya @zerosnacks @grandizzy please review it once free!

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

left couple of comments, please add tests for the new arg. thank you

@Ayushdubey86
Copy link
Contributor Author

Have pushed test case @grandizzy , please do check them out once free!

let final_args = if let Some(file_path) = file {
let contents = fs::read_to_string(file_path)?;
let contents = contents.trim();
vec![contents.to_string()]
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct as it treats the entire file as a single argument. It should split the string into arguments using .lines().collect(). This should also be done above in AbiEncode since it's a similar command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool , done

@Ayushdubey86
Copy link
Contributor Author

Have made those changes , do check them out @DaniPopes

Comment on lines +200 to +209
let contents = fs::read_to_string(file_path)?;
contents
.lines()
.map(str::trim)
.filter(|line| !line.is_empty())
.map(String::from)
.collect()
} else {
args
};
Copy link
Member

Choose a reason for hiding this comment

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

this looks alright to me,
having 1 line per arg seems okay

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

thank you, lgtm

@grandizzy grandizzy enabled auto-merge (squash) May 2, 2025 10:31
@grandizzy grandizzy added T-feature Type: feature C-cast Command: cast labels May 2, 2025
@grandizzy grandizzy changed the title feat: Add file option for calldata input feat(cast): Add file option for calldata input May 2, 2025
@grandizzy grandizzy merged commit 33cb8d2 into foundry-rs:master May 2, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry May 2, 2025
@DaniPopes
Copy link
Member

This should also be added to abi encode above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast T-feature Type: feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

feat(cast): enable cast calldata (or any such commands) to take --file as input argument.
4 participants