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(chisel): Introduces a Solidity REPL #3465

Merged
merged 125 commits into from
Dec 8, 2022

Conversation

refcell
Copy link
Contributor

@refcell refcell commented Oct 8, 2022

Current PR Status: RFC

This pr introduces a Solidity REPL called chisel.

chisel is a foundry-native solidity REPL that is largely based off of soli with the goal of being "feature complete" (insofaras soli presents feature completion).

Motivation

Closes issue #230

Solution

Creates a new chisel crate

@mattsse
Copy link
Member

mattsse commented Oct 8, 2022

this is pretty cool.

fyi: I started hacking on this here #240 perhaps some parts are still useful

@refcell
Copy link
Contributor Author

refcell commented Oct 8, 2022

this is pretty cool.

fyi: I started hacking on this here #240 perhaps some parts are still useful

Awesome!! Please shoot over any comments and let us know if there's a better way of architecting!

@@ -464,18 +465,17 @@ fn write_json(
path: impl AsRef<Path>,
json_path_or_none: Option<&str>,
) -> Result<Bytes, Bytes> {
let json: Value = serde_json::from_str(object).unwrap_or(Value::String(object.to_owned()));
let json: Value =
serde_json::from_str(object).unwrap_or_else(|_| Value::String(object.to_owned()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have a map here?

Copy link
Contributor

Choose a reason for hiding this comment

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

This change is a byproduct of cleaning up some clippy warnings:
Screenshot from 2022-11-26 13-45-55

Copy link
Contributor

Choose a reason for hiding this comment

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

hm, curious about why clippy would prefer a map. @mattsse, any idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

According to the big book o' clippy lints, it probably has something to do with allocating heap memory for the object str slice via to_owned, but not 100% sure. It likely is an unnecessary change given that it's not very expensive.

});

// Print intro header
println!("Welcome to Chisel! Type `{}` to show available commands.", Paint::green("!help"));
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to go below the subcommand match
Screenshot from 2022-11-26 13-57-14

Copy link
Contributor

Choose a reason for hiding this comment

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

resolved

@gakonst
Copy link
Member

gakonst commented Nov 26, 2022

Should we ship a lib called forge-addressbook or something whcih contains pre-specified addresses and interfaces for popular contracts by network? Would be nice to close the feedback loop on ethers-addressbook as well : https://github.com/gakonst/ethers-rs/blob/master/ethers-addressbook/src/contracts/contracts.json.

That way we could instantly make dai for example available on the repl w/o any user config.

@clabby
Copy link
Contributor

clabby commented Nov 27, 2022

Should we ship a lib called forge-addressbook or something whcih contains pre-specified addresses and interfaces for popular contracts by network? Would be nice to close the feedback loop on ethers-addressbook as well : https://github.com/gakonst/ethers-rs/blob/master/ethers-addressbook/src/contracts/contracts.json.

That way we could instantly make dai for example available on the repl w/o any user config.

This would be a pretty nice addition! Could also make a cheatcode for accessing the address book, i.e. vm.rolodex("dai"), as well as an optional foundry.toml configuration section for expanding it per-project.

@devtooligan
Copy link

Should we ship a lib called forge-addressbook or something whcih contains pre-specified addresses and interfaces for popular contracts by network?

yes please. this would save me time lost searching plus the context switching many times per month

@mds1
Copy link
Collaborator

mds1 commented Nov 28, 2022

Resurfacing the relevant address book discussion started in gakonst/ethers-rs#769 (comment), since trueblocks has a large mainnet DB that could be a good starting point

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.

okay, finally went through this.

Overall, I think this looks pretty good already.

Have a bunch of nits/suggestions.

Once addressed, I'll take another look at it.

.gitmodules Outdated
Comment on lines 1 to 3
[submodule "testdata/lib/forge-std"]
path = testdata/lib/forge-std
url = https://github.com/foundry-rs/forge-std
Copy link
Member

Choose a reason for hiding this comment

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

this has since been removed

does chisel require forge-std in tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

Chisel includes Vm.sol in the binary for use within the compilation source, so the inclusion of cheatcodes would have to be reworked if we decide to remove it. The idea here was to not have to fetch the source from GitHub so that chisel can be used in an offline setting.

See: https://github.com/whitenois3/foundry/blob/feat/repl/chisel/src/session_source.rs#L20

Copy link
Member

Choose a reason for hiding this comment

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

having the submodule there caused the tests to fail iirc.

can we replace this with the Cheats.sol file in testdata instead? perhaps rename to Vm?

The reason why we don't have forge-std as a module here is that we'd otherwise have a cyclical dependency forge <-> forge-std

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good- adjusted the session source to use Cheats.sol. We could rename it for continuity, but shouldn't be necessary. Kept the variable name as vm, so no ux changes apart from changing the import.

chisel/src/cli.rs Outdated Show resolved Hide resolved
chisel/src/cli.rs Outdated Show resolved Hide resolved
chisel/src/dispatcher.rs Outdated Show resolved Hide resolved
chisel/src/dispatcher.rs Outdated Show resolved Hide resolved
chisel/src/executor.rs Outdated Show resolved Hide resolved
chisel/src/executor.rs Outdated Show resolved Hide resolved
chisel/src/executor.rs Show resolved Hide resolved
chisel/src/runner.rs Outdated Show resolved Hide resolved
chisel/src/session.rs Outdated Show resolved Hide resolved
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.

@clabby okay play around with this a bit and had a closer look. I have a pretty good understanding now, so should be able to debug any discovered bugs I think.

last blocker is the q regarding the submodule vs. existing Cheats.sol

good to merge otherwise.

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.

lgtm

@mattsse
Copy link
Member

mattsse commented Dec 6, 2022

needs cargo +nightly fmt

@clabby
Copy link
Contributor

clabby commented Dec 6, 2022

needs cargo +nightly fmt

Whoops, sorry about that- done 👍

@mattsse
Copy link
Member

mattsse commented Dec 8, 2022

great,

should we merge now or wait until we have this in the book?
This will ship via foundryup as an additional tool, so having an overview in the book as a reference would be ideal.

@gakonst
Copy link
Member

gakonst commented Dec 8, 2022

I think let's ship ASAP and @Vex can fast-follow-up on the book before tweeting out the full thing?

@gakonst gakonst merged commit 43ca957 into foundry-rs:master Dec 8, 2022
@mattsse mattsse mentioned this pull request Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-chisel Command: chisel T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants