Skip to content

Commit

Permalink
ci: add CI job to check whether anvil state is up to date (#237)
Browse files Browse the repository at this point in the history
Fixes #234 

### What Changed?
This PR introduces the following changes
* Adds a CI job to check if the anvil dump state is up to date.
* Fixes the anvil's initial timestamp, otherwise the dump state will be
different each time (since the timestamps are included in the state).
* Updates the anvil dump state.

The CI job works by generating a new anvil state and comparing it
against the existing one using the `diff` command.
If the new anvil state is different it means the existing one is
outdated and therefore the CI will fail.
**Note:** before performing the comparison between the existing and the
new state, both files are sorted since the JSON format does preserve
item order.

### Reviewer Checklist

- [ ] New features are tested and documented
- [ ] PR has one of the `changelog-X` labels (if applies)
- [ ] Code deprecates any old functionality before removing it
  • Loading branch information
ricomateo authored Jan 20, 2025
1 parent 7fdacd0 commit d4ef497
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,37 @@ jobs:
with:
name: coverage-summary
path: coverage.zip

check_anvil_dump:
strategy:
fail-fast: true

name: Check anvil dump state is up to date
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./crates/contracts/anvil
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable

- name: Backup existing anvil dump state
run: |
cd contracts_deployed_anvil_state.json
cp state.json previous_state.json
- name: Generate new anvil dump state
run: ./deploy-contracts-save-anvil-state.sh

- name: Check whether the anvil dump state has changed
run: |
cd contracts_deployed_anvil_state.json
jq --sort-keys . previous_state.json > previous_state.json
jq --sort-keys . state.json > state.json
diff previous_state.json state.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion crates/contracts/anvil/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ start_anvil_docker() {
docker run --rm -d --name anvil -p 8545:8545 $LOAD_STATE_VOLUME_DOCKER_ARG $DUMP_STATE_VOLUME_DOCKER_ARG \
--entrypoint anvil \
$FOUNDRY_IMAGE \
$LOAD_STATE_ANVIL_ARG $DUMP_STATE_ANVIL_ARG --host 0.0.0.0
$LOAD_STATE_ANVIL_ARG $DUMP_STATE_ANVIL_ARG --host 0.0.0.0 \
--timestamp 0
sleep 2
}

0 comments on commit d4ef497

Please sign in to comment.