Skip to content
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

feat(forge): Solidity cheat to find and replace text in bytes and string variables #4789

Closed
PaulRBerg opened this issue Apr 21, 2023 · 2 comments
Labels
A-cheatcodes Area: cheatcodes T-feature Type: feature

Comments

@PaulRBerg
Copy link
Contributor

PaulRBerg commented Apr 21, 2023

Component

Forge

Describe the feature you would like

Suppose you have a differential test that compares the bytecodes of a contract deployed using two different methods, e.g. see deployPermit2.

Now, imagine the contract-under-test takes a storage record of its address(this) in the constructor. In this case, the two deployment methods would produce two slightly different bytecodes (only ~20 bytes would be different), so the differential test would fail.

There are various ways to fix this using vm.ffi, but it would be nice to have a native find-and-replace cheat so that users don't have to exit Solidity in this scenario.

Additional context

Late edit: it looks like I could use Solady's LibString for this.

@Tudmotu
Copy link
Contributor

Tudmotu commented Oct 5, 2023

I would also like this feature.

LibString is not sufficient for me since I need UTF support. solidity-stringutils is too low-level and too slow for my needs.

What I have in mind is this interface:

function stringReplaceAll (string memory source, string memory pattern, string memory replacement);

Where pattern will be a regex (as in Regex::new(pattern).unwrap()) and the cheatcode would invoke .replace_all(source, replacement).

@PaulRBerg @mattsse WDYT?

@zerosnacks
Copy link
Member

Marking as resolved by #6891, implementing native cheatcodes for working with strings, including replace

Feel free to re-open if there are still action items @Tudmotu / @PaulRBerg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes T-feature Type: feature
Projects
Archived in project
Development

No branches or pull requests

4 participants