Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feat/solidity-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	book/src/SUMMARY.md
  • Loading branch information
agostbiro committed Jun 20, 2024
2 parents e9228c7 + 62cb5f0 commit 736a018
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 31 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/edr-npm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
DEBUG: napi:*
APP_NAME: edr
MACOSX_DEPLOYMENT_TARGET: "10.13"
NUMBER_OF_TARGETS: 7
permissions:
contents: write
id-token: write
Expand Down Expand Up @@ -87,6 +88,12 @@ jobs:
working-directory: ./crates/edr_napi
steps:
- uses: actions/checkout@v4
- name: Check number of targets
shell: bash
run: |
echo "Number of build jobs: ${{ strategy.job-total }}"
echo "Expected number of build jobs: $NUMBER_OF_TARGETS"
test ${{ strategy.job-total }} -eq "$NUMBER_OF_TARGETS"
- uses: pnpm/action-setup@v2
with:
version: 9
Expand Down Expand Up @@ -154,6 +161,8 @@ jobs:
settings:
- host: macos-12
target: x86_64-apple-darwin
- host: macos-14
target: aarch64-apple-darwin
- host: windows-2022
target: x86_64-pc-windows-msvc
node:
Expand Down Expand Up @@ -303,9 +312,15 @@ jobs:
pnpm testNoBuild
ls -la
test-linux-aarch64-musl-binding:
name: Test bindings on aarch64-unknown-linux-musl - node@lts
name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
node:
- "18"
- "20"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -333,7 +348,7 @@ jobs:
- name: Setup and run tests
uses: addnab/docker-run-action@v3
with:
image: node:lts-alpine
image: node:${{ matrix.node }}-alpine
options: "--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build/crates/edr_napi -e CI=1"
run: |
wget -qO- 'https://unpkg.com/@pnpm/self-installer' | node
Expand Down Expand Up @@ -395,6 +410,15 @@ jobs:
uses: actions/download-artifact@v3
with:
path: ./crates/edr_napi/artifacts
- name: Check number of artifacts
shell: bash
run: |
tree artifacts
# get number of artifacts with unique names
NUMBER_OF_ARTIFACTS=$(ls -1q artifacts/*/*.node | xargs -n 1 basename | sort | uniq | wc -l)
echo "Number of unique artifacts: $NUMBER_OF_ARTIFACTS"
echo "Expected number of unique artifacts: $NUMBER_OF_TARGETS"
test "$NUMBER_OF_ARTIFACTS" -eq "$NUMBER_OF_TARGETS"
- name: Install sponge
run: |
sudo apt-get update
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy mdBook site to Pages

on:
push:
branches: ["main"]
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

defaults:
run:
working-directory: book/

jobs:
build:
runs-on: ubuntu-latest
env:
MDBOOK_VERSION: 0.4.36
steps:
- uses: actions/checkout@v4
- name: Setup mdBook
uses: peaceiris/actions-mdbook@ee69d230fe19748b7abf22df32acaa93833fad08 # v2.0.0
with:
mdbook-version: '0.4.37'
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Build with mdBook
run: mdbook build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./book

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
27 changes: 27 additions & 0 deletions book/src/02_development/05_pnpm_link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Using pnpm link

When working on something that needs changes in both EDR and Hardhat (or just something that needs EDR to be locally installed), using [`pnpm link`](https://pnpm.io/cli/link) is the recommended approach.

To use the local version of EDR in Hardhat, you need to go to the `hardhat-core` directory and link your local `edr_napi` package:

```bash
cd ~/repos/hardhat/packages/hardhat-core
pnpm install
pnpm link ~/repos/edr/crates/edr_napi
pnpm build
```

You can then use the same process to link Hardhat in some Hardhat-based project[^1]:

```bash
cd ~/repos/some-hardhat-project
pnpm install
pnpm link ~/repos/hardhat/packages/hardhat-core

# this task will now use the local versions of Hardhat and EDR
pnpm hardhat test
```

---

[^1]: This assumes that the Hardhat-based project uses pnpm, which is not always the case. But, if needed, migrating a project from npm/yarn to pnpm is normally straightforward.
File renamed without changes.
3 changes: 2 additions & 1 deletion book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
- [Verdaccio](02_development/02_verdaccio.md)
- [Local release](02_development/03_local_release.md)
- [Update N-API targets](02_development/04_update_napi_targets.md)
- [Solidity test cheatcodes](02_development/05_cheatcodes.md)
- [Using pnpm link](02_development/05_pnpm_link.md)
- [Solidity test cheatcodes](02_development/06_cheatcodes)

- [Release](./03_release.md)

Expand Down
4 changes: 2 additions & 2 deletions crates/foundry/cheatcodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This, combined with the use of an internal [`Cheatcode`](../macros/impl/src/chea

Cheatcodes are manually implemented through the `Cheatcode` trait, which is called in the `Cheatcodes` inspector implementation.

See the [cheatcodes dev documentation](../../../book/src/02_development/05_cheatcodes.md#adding-a-new-cheatcode) for more details.
See the [cheatcodes dev documentation](../../../book/src/02_development/06_cheatcodes#adding-a-new-cheatcode) for more details.

### JSON interface

Expand All @@ -33,7 +33,7 @@ If you are making use of the JSON interface, please don't hesitate to open a PR

### Adding a new cheatcode

Please see the [cheatcodes dev documentation](../../../book/src/02_development/05_cheatcodes.md#adding-a-new-cheatcode) on how to add new cheatcodes.
Please see the [cheatcodes dev documentation](../../../book/src/02_development/06_cheatcodes#adding-a-new-cheatcode) on how to add new cheatcodes.

[`sol!`]: https://docs.rs/alloy-sol-macro/latest/alloy_sol_macro/macro.sol.html
[`spec/src/vm.rs`]: ./spec/src/vm.rs
44 changes: 18 additions & 26 deletions hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,26 @@ function defineTest(
? testDefinition.description
: path.relative(__dirname, dirPath);

// test definitions can optionally further restrict the solc version range,
// if that's the case we skip the test if the current solc version doesn't
// match the range in the test definition
const solcVersionDoesntMatch: boolean =
testDefinition.solc !== undefined &&
!semver.satisfies(compilerOptions.solidityVersion, testDefinition.solc);

dirPath.includes("oog-chaining");
const skipViaIR =
testDefinition.skipViaIR === true &&
compilerOptions.optimizer?.viaIR === true;

const func = async function (this: Mocha.Context) {
this.timeout(TEST_TIMEOUT_MILLIS);

await runTest(dirPath, testDefinition, sources, compilerOptions);
};

if (
testDefinition.skip === true ||
(testDefinition.skipViaIR === true &&
compilerOptions.optimizer?.viaIR === true) ||
solcVersionDoesntMatch
) {
if (testDefinition.skip === true || skipViaIR || solcVersionDoesntMatch) {
it.skip(desc, func);
} else if (testDefinition.only !== undefined && testDefinition.only) {
} else if (testDefinition.only === true) {
// eslint-disable-next-line mocha/no-exclusive-tests
it.only(desc, func);
} else {
Expand Down Expand Up @@ -193,22 +193,6 @@ function defineDirTests(dirPath: string, compilerOptions: SolidityCompiler) {
describe(description, function () {
defineTest(dirPath, testDefinition, sources, compilerOptions);
});

if (process.env.HARDHAT_NETWORK_TESTS_WITH_OPTIMIZATIONS !== undefined) {
const runsNumbers = [1, 200, 10000];

for (const runs of runsNumbers) {
describe(`With optimizations (${runs} run)`, function () {
defineTest(dirPath, testDefinition, sources, {
...compilerOptions,
optimizer: {
viaIR: false,
runs,
},
});
});
}
}
}

for (const dir of dirs) {
Expand Down Expand Up @@ -687,7 +671,11 @@ async function runDeploymentTransactionTest(
gas: tx.gas !== undefined ? BigInt(tx.gas) : undefined,
});

return trace as CreateMessageTrace;
if (!("deployedContract" in trace)) {
assert.fail("Expected trace to be a deployment trace");
}

return trace;
}

async function runCallTransactionTest(
Expand Down Expand Up @@ -722,7 +710,11 @@ async function runCallTransactionTest(
gas: tx.gas !== undefined ? BigInt(tx.gas) : undefined,
});

return trace as CallMessageTrace;
if (!("calldata" in trace) || "precompile" in trace) {
assert.fail("Expected trace to be a call trace");
}

return trace;
}

const onlyLatestSolcVersions =
Expand Down

0 comments on commit 736a018

Please sign in to comment.