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(cheats): ffi #416

Closed
wants to merge 2 commits into from
Closed

feat(cheats): ffi #416

wants to merge 2 commits into from

Conversation

ZeroEkkusu
Copy link
Collaborator

Motivation

When I started using Foundry, I didn't find ffi intuitive. I thought I could give it a command, but, I was supposed to initialize an array first, assign values, etc.

This cheat makes it work the way I thought it did. I'll let you decide if it's worth adding.

Solution

Before

string[] memory inputs = new string[](3);

inputs[0] = "echo";
inputs[1] = "-n";
inputs[2] = "hello world";

bytes memory res = vm.ffi(inputs);

After

bytes memory res = ffi("echo -n", raw("hello world"));

Note: raw passes the text as-is.



Before

string[] memory inputs = new string[](4);

inputs[0] = "yarn";
inputs[1] = "ts-node";
inputs[2] = "path/to/script.ts";
inputs[3] = vm.toString(
    abi.encode(
        user,
        data
    )
);

bytes memory res = vm.ffi(inputs);

After

bytes memory res = ffi(
    "yarn ts-node path/to/script.ts",
    vm.toString(abi.encode(user, data))
);

Note: ffi accepts up to five arguments. Both examples used two.

@ZeroEkkusu ZeroEkkusu requested a review from mds1 July 19, 2023 17:45
@mds1
Copy link
Collaborator

mds1 commented Jul 19, 2023

This is pretty neat and definitely nicer UX, but in the spirit of foundry-rs/foundry#3782 and gradually migrating towards that I'd rather implement this natively in forge and minimize addition of new StdCheats

@ZeroEkkusu
Copy link
Collaborator Author

Alright!

@ZeroEkkusu ZeroEkkusu closed this Jul 19, 2023
@DaniPopes DaniPopes deleted the feat/ffi branch October 24, 2024 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants