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: README improvements, yarn -> npm #64

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,79 @@
# juice-contracts-v3

Protocol overview, architecture, and API documentation: https://info.juicebox.money/dev/
## Develop
This repository contains the core Juicebox contracts. To learn more about the Juicebox protocol, visit the [docs](https://docs.juicebox.money/dev/). If you have question, join the [JuiceboxDAO Discord](https://discord.gg/juicebox).

### Unit Tests
## Dependencies

To run the unit tests suite (in Javascript), you'll need to run `yarn install` first then manually run Hardhat in order to enable ESM support:
`juice-contracts-v3` uses the Foundry smart contract development toolchain. To install Foundry, open your terminal and run the following command:

```bash
node --require esm ./node_modules/.bin/hardhat test --network hardhat
curl -L https://foundry.paradigm.xyz | bash
```

Alternatively, you can run a local Hardhat node in another terminal using
Once you have Foundry installed, run `foundryup` to update to the latest versions of `forge`, `cast`, `anvil`, and `chisel`. More detailed instructions can be found in the [Foundry Book](https://book.getfoundry.sh/getting-started/installation).

```bash
yarn chain --network hardhat
```
`juice-contracts-v3` also has NPM dependencies. To use them, install [node.js](https://nodejs.org/).

then run the following:
To install both `forge` and `npm` dependencies, run:

```bash
yarn test
forge install && npm install
```

It might happens that Hardhat cannot resolve custom error (test failing on "Expecter nameOfTheError() but reverted
without a reason string"), just restart yarn chain.

### System Tests

End-to-end tests have been written in Solidity, using Foundry.

To get set up:

1. Install [Foundry](https://github.com/gakonst/foundry).
If you encounter issues with nested `forge` dependencies, try running:

```bash
curl -L https://foundry.paradigm.xyz | sh
git submodule update --init --recursive
```

2. Install external lib(s)
## Unit Tests

The `juice-contracts-v3` unit test suite is written in JavaScript with [Hardhat](https://hardhat.org/). To run the unit tests, install the JavaScript dependencies with `npm install`. Then manually run Hardhat to enable ESM support:

```bash
git submodule update --init --recursive
node --require esm ./node_modules/.bin/hardhat test --network hardhat
```

3. Run tests:
Alternatively, you can run a local Hardhat node in another terminal using:

```bash
forge test
npm run chain -- --network hardhat
```

4. Update Foundry periodically:
then run the tests with:

```bash
foundryup
npm run test
```

Resources:
If Hardhat fails to resolve a custom error (i.e. tests fail on "Expecter nameOfTheError() but revert without a reason string"), restart `npm run chain`.

- [The Forge-Book](https://onbjerg.github.io/foundry-book/forge)

### Coverage

To check current unit tests coverage:
To check current unit test coverage, run:

```bash
node --require esm ./node_modules/.bin/hardhat coverage --network hardhat
```

A few notes:

- Unit tests can be found in the `test` directory.
- Hardhat doesn't support [esm](https://nodejs.org/api/esm.html) yet, hence running manually with node.
- We are currently using a forked version of [solidity-coverage](https://www.npmjs.com/package/solidity-coverage) that includes optimizer settings. Ideally we will move to the maintained version after this is fixed on their end.
- Juicebox V3 codebase being quite large, Solidity Coverage might run out of memory if you modify/add parts to it. Please check [Solidity-coverage FAQ](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md) in order to address the issue.

## Deploy
## System Tests

End-to-end tests have been written in Solidity, using Foundry. Once you have installed `forge` dependencies with `forge install`, you can run the tests with:

Juicebox uses the [Hardhat Deploy](https://github.com/wighawag/hardhat-deploy) plugin to deploy contracts to a given network. But before using it, you must create a `./mnemonic.txt` file containing the mnemonic phrase of the wallet used to deploy. You can generate a new mnemonic using [this tool](https://github.com/itinance/mnemonics). Generate a mnemonic at your own risk.
```bash
forge test
```

System tests can be found in the `forge_tests` directory.

## Deployment

Juicebox uses the [Hardhat Deploy](https://github.com/wighawag/hardhat-deploy) plugin to deploy contracts to a given network. To use it, you must create a `./mnemonic.txt` file containing the mnemonic phrase of the wallet used to deploy. You can generate a new mnemonic using [this tool](https://github.com/itinance/mnemonics). Generate a mnemonic at your own risk.

Then, to execute the `./deploy/deploy.js` script, run the following:

Expand All @@ -90,10 +87,14 @@ Contract artifacts will be outputted to `./deployments/$network/**` and should b

## Verification

To verify the contracts on [Etherscan](https://etherscan.io), make sure you have an `ETHERSCAN_API_KEY` set in your `./.env` file. Then run the following:
To verify the contracts on [Etherscan](https://etherscan.io), make sure you have an `ETHERSCAN_API_KEY` set in your `./.env` file. Then run:

```bash
npx hardhat --network $network etherscan-verify
```

This will verify all of the deployed contracts in `./deployments`.

## Editor

We recommend using [VSCode](https://code.visualstudio.com/) with Juan Blanco's [solidity](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity) extension. To display code coverage in VSCode, install [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) (Ryan Luker). In VSCode, press `F1` and run "Coverage Gutters: Display Coverage". Coverage will be displayed as colored markdown lines in the left gutter, after the line numbers.
Loading
Loading