Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3069f61
test: use Multicall from "forge-std"
PaulRBerg Jan 19, 2023
dd3b0b6
build: separate normal from deterministic deployment scripts
PaulRBerg Jan 19, 2023
e3fd376
build: use Forge Std's CREATE2 factory
PaulRBerg Jan 19, 2023
144446c
docs: improve wording in NatSpec comments
PaulRBerg Jan 19, 2023
c2f19aa
build: add gas snapshot
PaulRBerg Jan 19, 2023
e1971d1
build: add gas report and snapshot commands in "package.json"
PaulRBerg Jan 19, 2023
bc252d4
docs: fix contract names in NatSpec comments
PaulRBerg Jan 19, 2023
4d8ae25
refactor: rename "LockupCreateAmounts" to "CreateLockupAmounts"
PaulRBerg Jan 19, 2023
308393d
test: test cancel and withdraw in integration tests
PaulRBerg Jan 20, 2023
f96f2fc
refactor: reference event name in code comments
PaulRBerg Jan 20, 2023
dc33fcb
build: gas snapshot for optimized profile
PaulRBerg Jan 20, 2023
c06185f
test: run tests against deploy scripts
PaulRBerg Jan 20, 2023
ccb7dbd
test: reference event name in all comments
PaulRBerg Jan 20, 2023
80156b1
test: pass "err" string to all assertions
PaulRBerg Jan 20, 2023
24b82b1
chore: commit ".vscode" in version control
PaulRBerg Jan 21, 2023
86b7416
build: regenerate gas snapshot
PaulRBerg Jan 21, 2023
1541752
test: add "_Unit" suffix to all unit test contracts
PaulRBerg Jan 21, 2023
cb5f800
chore: delete stale "ci" Foundry profile
PaulRBerg Jan 21, 2023
4af75ca
test: separate tests in "unit" and "fuzz"
PaulRBerg Jan 22, 2023
b985d26
build: regenerate gas snapshot
PaulRBerg Jan 22, 2023
046eaab
test: rename "integration" to "e2e" tests
PaulRBerg Jan 22, 2023
3c1f312
ci: split "build-and-test" job
PaulRBerg Jan 22, 2023
85e6356
build: ugprade "forge-std" and "prb-math"
PaulRBerg Jan 22, 2023
0f45b48
test: add header separators for shared functions
PaulRBerg Jan 24, 2023
c8d8d0a
test: test all values initialized in constructors
PaulRBerg Jan 24, 2023
77b770f
chore: delete unusable "gas:report:optimized" script
PaulRBerg Jan 24, 2023
1173668
test: nest "test/helpers" under "test/shared"
PaulRBerg Jan 23, 2023
19d22c8
test: move "test/shared/flash-loan" under "test/shared/mockups"
PaulRBerg Jan 24, 2023
f5745f1
ci: re-add weekly fuzz seed
PaulRBerg Jan 24, 2023
3df796c
ci: selective fuzz runs
PaulRBerg Jan 24, 2023
76be144
chore: use "override" specifier in linear
andreivladbrg Jan 27, 2023
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
219 changes: 219 additions & 0 deletions .gas-snapshot

Large diffs are not rendered by default.

105 changes: 90 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ concurrency:
cancel-in-progress: true

env:
INFURA_API_KEY: "${{ secrets.INFURA_API_KEY }}"
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}

on:
pull_request:
Expand Down Expand Up @@ -36,10 +38,10 @@ jobs:

- name: "Add lint summary"
run: |
echo "## Lint results" >> $GITHUB_STEP_SUMMARY
echo "## Lint result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY

test:
build:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
Expand All @@ -53,18 +55,9 @@ jobs:
- name: "Show the Foundry config"
run: "forge config"

- name: "Generate fuzz seed that changes weekly to avoid burning through RPC allowance"
run: >
echo "FOUNDRY_FUZZ_SEED=$(
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800))
)" >> $GITHUB_ENV

- name: "Produce an optimized build with --via-ir"
run: "FOUNDRY_PROFILE=optimized forge build"

- name: "Run the unit and the integration tests against the optimized build"
run: "FOUNDRY_PROFILE=test-optimized forge test"

- name: "Store contract ABIs as artifacts in GitHub Actions"
uses: "actions/upload-artifact@v3"
with:
Expand All @@ -88,12 +81,94 @@ jobs:
optimized-out/SablierV2LockupLinear.sol/SablierV2LockupLinear.json
optimized-out/SablierV2LockupPro.sol/SablierV2LockupPro.json

- name: "Add build summary"
run: |
echo "## Build result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY

test-unit:
needs: ["lint", "build"]
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Produce an optimized build with --via-ir"
run: "FOUNDRY_PROFILE=optimized forge build"

- name: "Run the unit tests against the optimized build"
run: "FOUNDRY_PROFILE=test-optimized forge test --match-path \"test/unit/**/*.sol\""

- name: "Add test summary"
run: |
echo "## Test results" >> $GITHUB_STEP_SUMMARY
echo "## Unit tests result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY

test-fuzz:
env:
FOUNDRY_FUZZ_RUNS: "20000"
needs: ["lint", "build"]
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Produce an optimized build with --via-ir"
run: "FOUNDRY_PROFILE=optimized forge build"

- name: "Run the fuzz tests against the optimized build"
run: "FOUNDRY_PROFILE=test-optimized forge test --match-path \"test/fuzz/**/*.sol\""

- name: "Add test summary"
run: |
echo "## Fuzz tests result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY


test-e2e:
env:
FOUNDRY_FUZZ_RUNS: "2000"
needs: ["lint", "build"]
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Produce an optimized build with --via-ir"
run: "FOUNDRY_PROFILE=optimized forge build"

- name: "Generate fuzz seed that changes weekly to avoid burning through RPC allowance"
run: >
echo "FOUNDRY_FUZZ_SEED=$(
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800))
)" >> $GITHUB_ENV

- name: "Run the end-to-end tests against the optimized build"
run: "FOUNDRY_PROFILE=test-optimized forge test --match-path \"test/e2e/**/*.sol\""

- name: "Add test summary"
run: |
echo "## End-to-end tests result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY


coverage:
needs: ["lint", "build"]
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
Expand All @@ -115,5 +190,5 @@ jobs:

- name: "Add coverage summary"
run: |
echo "## Coverage results" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
echo "## Coverage result" >> $GITHUB_STEP_SUMMARY
echo "✅ Uploaded to Codecov" >> $GITHUB_STEP_SUMMARY
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- name: "Deploy the SablierV2LockupLinear contract"
run: >-
forge script script/DeployLinear.s.sol
forge script script/DeployLockupLinear.s.sol
--broadcast
--rpc-url ${{ github.event.inputs.chain }}
--sig "run(address,address,uint256)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ jobs:
- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Deploy the SablierV2Pro contract"
- name: "Deploy the SablierV2LockupPro contract"
run: >-
forge script script/DeployPro.s.sol
forge script script/DeployLockupPro.s.sol
--broadcast
--rpc-url "${{ github.event.inputs.chain }}"
--sig "run(address,address,uint256,uint256)"
Expand Down
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"[solidity]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"solidity.formatter": "prettier",
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": "lib"
}
87 changes: 64 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ Note: write access to the repository is required to deploy using the GitHub UI.

## Via IR

We deploy our contracts with the [`--via-ir`](https://docs.soliditylang.org/en/v0.8.17/ir-breaking-changes.html) flag
enabled.
The contracts have been deployed to mainnet with the
[`--via-ir`](https://docs.soliditylang.org/en/v0.8.17/ir-breaking-changes.html) flag enabled.

This means that the contracts are compiled with a lot of powerful optimizations, but the cost is very slow compile
times. Nonetheless, we have to run our tests against this optimized version of the contracts, since this is what end
Via IR means that the contracts are compiled with a lot of powerful optimizations, but the cost is very slow compile
times. Nonetheless, we want to run our tests against this optimized version of the contracts, since this is what end
users will ultimately interact with.

To get the best of both worlds, we have come up with a set-up where on our local machines we build and test the
Expand All @@ -174,53 +174,62 @@ without IR enabled).

## Tests

Tests are organized in two categories:
Tests are organized in three categories:

1. Unit - simple tests that check the behavior of a single function on a local development EMV.
2. Integration - complex tests that run against a fork of Ethereum Mainnet to check that Sablier V2 works with deployed
ERC-20 assets.
2. Fuzz - similar to the unit tests, but with randomized inputs.
3. End-to-end - complex tests that run against a fork of Ethereum Mainnet, which ensure that the protocol works with
deployed ERC-20 assets.

You can run all tests by using this command:

```sh
forge test
yarn test
```

By default, only unit tests run. To run all tests, including integration tests, you can use this command:
By default, the contracts are compiled using the default compiler settings, which do not contain optimizations. To run
the tests against the optimized version of the contracts, you can use this command:

```sh
yarn test:optimized
```

Alternatively, you could change the value of the `test` configuration option in the [`foundry.toml`](./foundry.toml)
file to `test/integration`.

To filter tests by name, you can use the `--match-test` flag. Here's an example for the `createWithRange` function
tests:
To filter tests by name, you can use the `--match-test` flag (shorthand `--mt`). Here's an example for how to run the
tests only for the `createWithRange` function:

```sh
forge test --match-test testCreateWithRange
yarn test --match-test test_CreateWithRange
```

You can also filter the tests by test contract name with the `--match-contract` flag. Here's an example for the
`createWithRange` function test contracts:
You can also filter the tests by test contract name with the `--match-contract` flag (shorthand `--mc`). Here's an
example for the test contract that contains all the tests for the `createWithRange` function:

```sh
forge test --match-contract CreateWithRange
yarn test --match-contract CreateWithRange
```

## Commands

Here's a list of the most frequently needed commands.
Here's a list of the most frequently needed commands, which are run either with Forge or with Yarn.

### Build

Build the contracts:
Build the contracts using the default profile:

```sh
$ forge build
```

### Build Optimized

Build the contracts using the optimized profile:

```sh
$ yarn build:optimized
```

This will compile the contracts with the `--via-ir` flag enabled.

### Clean

Delete the build artifacts and cache directories:
Expand All @@ -245,12 +254,36 @@ Format the contracts with Prettier:
$ yarn prettier
```

### Gas Usage
### Gas Report

Get a gas report:

```sh
$ forge test --gas-report
$ yarn gas:report
```

### Gas Report Optimized

Get a gas report for the optimized version of the contracts:

```sh
$ yarn gas:report:optimized
```

### Gas Snapshot

Take a gas snapshot:

```sh
$ yarn gas:snapshot
```

### Gas Snapshot Optimized

Take a gas snapshot for the optimized version of the contracts:

```sh
$ yarn gas:snapshot:optimized
```

### Lint
Expand All @@ -266,7 +299,15 @@ $ yarn lint
Run the tests:

```sh
$ forge test
$ yarn test
```

### Test Optimized

Run the tests against the optimized version of the contracts:

```sh
$ yarn test:optimized
```

### Other
Expand Down
Loading