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(cheatcodes): implement new cheatcode to check if a string contains another string #9085

Merged

Conversation

leovct
Copy link
Contributor

@leovct leovct commented Oct 9, 2024

Motivation

Closes #4859

Solution

Simple check if a string contains another string.

As a follow-up, we could implement other cheatcodes to check if an array contains an element?

@leovct leovct marked this pull request as ready for review October 9, 2024 21:43
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.

I just realized that we don't even have vm.contains
so this would just by assert(vm.contains())

wdyt @grandizzy

@grandizzy
Copy link
Collaborator

I just realized that we don't even have vm.contains so this would just by assert(vm.contains())

wdyt @grandizzy

yep, agree vm.contains to return bool would be better as could have further usages in test (execute conditional branches)

testdata/cheats/Vm.sol Outdated Show resolved Hide resolved
testdata/cheats/Vm.sol Outdated Show resolved Hide resolved
leovct and others added 4 commits October 10, 2024 10:14
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
@zerosnacks zerosnacks self-requested a review October 10, 2024 08:35
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

Personally don't have a strong preference for renaming assertContains -> contains as proposed by others but wouldn't mind it either. Without the assert* prefix would be more clear to users that they can use it in branches and it doesn't throw a hard error that they might expect when using assertions.

@leovct
Copy link
Contributor Author

leovct commented Oct 10, 2024

Thanks! LGTM

Personally don't have a strong preference for renaming assertContains -> contains as proposed by others but wouldn't mind it either. Without the assert* prefix would be more clear to users that they can use it in branches and it doesn't throw a hard error that they might expect when using assertions.

Sure, let me rename the method from assertContains to contains, as this makes more sense to align with the standard.

@zerosnacks zerosnacks requested a review from mattsse October 10, 2024 09:00
Co-authored-by: Matt Solomon <matt@mattsolomon.dev>
@leovct
Copy link
Contributor Author

leovct commented Oct 11, 2024

@zerosnacks PR is ready for another review :)

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.

Lgtm!

@zerosnacks zerosnacks self-requested a review October 11, 2024 18:43
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

Thanks @leovct! LGTM

@zerosnacks zerosnacks merged commit bcacf39 into foundry-rs:master Oct 11, 2024
21 checks passed
@leovct leovct deleted the feat/implement-assert-contains-cheatcode branch October 11, 2024 21:09
@johnnyshankman
Copy link

@zerosnacks @leovct @grandizzy thank you so much for getting this over the line and closing out my older PR! Cheers!

mds1 pushed a commit to foundry-rs/forge-std that referenced this pull request Nov 25, 2024
- add `delegatecall` flag to `prank` cheatcodes
(foundry-rs/foundry#8863)
- support EIP-7702 Delegations (`create/sign/attachDelegation`)
(foundry-rs/foundry#9236)
- add `contains` to check if a string contains another string
(foundry-rs/foundry#9085)
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
…ns another string (foundry-rs#9085)

* feat: implement new cheatcode to check if a string contains another string

* chore: make clippy and rustfmt happy

* chore: vm.contains should return a boolean

* Update testdata/cheats/Vm.sol

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Update crates/cheatcodes/spec/src/vm.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* chore: update `cheatcodes.json`

* chore: update var names

* chore: rename to `vm.contains`

* Update crates/cheatcodes/spec/src/vm.rs

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>

* Update crates/cheatcodes/spec/src/vm.rs

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>

* chore: address PR comments

---------

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-authored-by: Matt Solomon <matt@mattsolomon.dev>
thomas-lamb-tech pushed a commit to thomas-lamb-tech/std_forge that referenced this pull request Dec 26, 2024
- add `delegatecall` flag to `prank` cheatcodes
(foundry-rs/foundry#8863)
- support EIP-7702 Delegations (`create/sign/attachDelegation`)
(foundry-rs/foundry#9236)
- add `contains` to check if a string contains another string
(foundry-rs/foundry#9085)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add vm.assertContains with overloads (String, etc..)
7 participants