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

fix(cheatcodes): Make serializeString always serialize values into a string, add serializeJson cheatcode #4602

Closed

Conversation

mattsse
Copy link
Member

@mattsse mattsse commented Mar 19, 2023

Motivation

Closes #4601
don't rely on from_str when using serializeString

this fails a test test_serializeNotSimpleJson that uses a serialized string a serializes it again.

not sure what to make of this. wdyt @odyslam ?

I think serialize string was rather serialize object, so unsure if this change breaks some assumptions.

Solution

@mattsse mattsse added T-bug Type: bug A-cheatcodes Area: cheatcodes labels Mar 19, 2023
@mattsse mattsse force-pushed the matt/serialize-string-always-as-string branch from 9495814 to 3bde428 Compare March 19, 2023 22:07
Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

gm, adding this for convo and alignment (as i'm working on parseJson stuff i can take over on this)

I think the assumption being broken here is that serializeString has two uses:

  • If the value passed in is a valid object, then it will be serialized as an object.
  • If the value passed in is a string, then it will be serialized as a string.

The note on the book supports this assumption: https://book.getfoundry.sh/cheatcodes/serialize-json?highlight=serializestring#example

IMHO, this is a huge footgun actually. I believe serializeString should explicitly, always serialize objects to string, and have some other cheatcode like serializeJson that always expects serializable objects for composability. wdyt @mds1 ?

@mds1
Copy link
Collaborator

mds1 commented Jul 18, 2023

IMHO, this is a huge footgun actually. I believe serializeString should explicitly, always serialize objects to string, and have some other cheatcode like serializeJson that always expects serializable objects for composability.

This seems like a good solution to me, would be curious to confirm with @sakulstra also

@Evalir Evalir changed the title fix: always serialize string value as string fix(cheatcodes): Make serializeString always serialize values into a string, add serializeJson cheatcode Jul 18, 2023
@Evalir Evalir self-requested a review July 18, 2023 19:39
@Evalir
Copy link
Member

Evalir commented Jul 18, 2023

@mds1 & @mattsse updated this PR with the new scope:

  • serializeString will now always serialize values as a string. It CANNOT be used to serialize json values, as they will be parsed as a string. This might be a breaking change for some I understand.
  • A new cheatcode, serializeJson, now performs the other function serializeString had, which is, it takes a valid JSON string and serializes it to a json object. It will revert if it fails to do so.

@mds1
Copy link
Collaborator

mds1 commented Jul 18, 2023

sgtm!

This might be a breaking change for some I understand.

Yea, given this we probably should merge this into the v1 branch and hold off on releasing it, since it might break user scripts

Copy link
Member Author

@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.

agree, lgtm

@sakulstra
Copy link
Contributor

lgtm, agree with the gist of the discussion here.


Regarding v1 or main i don't have a strong opinion.
It wouldn't have been the first breaking change on foundry <1, but it's also not so urgent to change the behavior 🤷
Imo both paths are fine.

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

cool! i'd say let's keep this for v1, as it's a breaking change

@Evalir Evalir changed the base branch from master to evalir/v1 July 19, 2023 02:57
@Evalir Evalir changed the base branch from evalir/v1 to master July 19, 2023 02:58
@Evalir Evalir changed the base branch from master to evalir/v1 August 1, 2023 15:53
@Evalir Evalir changed the base branch from evalir/v1 to master August 1, 2023 15:53
@Evalir Evalir changed the base branch from master to v1 September 21, 2023 15:12
@DaniPopes
Copy link
Member

Closing as superseded by #5755 (from what I can tell).
Anyway the diff is not that big and would have to be re-implemented entirely due to #6131.

@DaniPopes DaniPopes closed this Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes T-bug Type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vm.serializeString might produce numbers
5 participants