-
Notifications
You must be signed in to change notification settings - Fork 866
EVM Watcher Divergence Tests #4931
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
Open
djb15
wants to merge
13
commits into
wormhole-foundation:main
Choose a base branch
from
bemic:evm-regression-test-data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1953b1d
wip hash test
bemic 27b0b08
add test cases, script and test
bemic 6dcc146
add receipts, docs and update tests
bemic 30282a6
Pull RunWithScissors into functions and helper function for creating …
djb15 38d6c72
Split postMessage into more logical constituent parts
djb15 2fd5b5a
Add testdata and the test for parity checking
djb15 13d388d
add messageSent and error message to test receipts
bemic 298cf9a
update receipts with messageSent and error fied
bemic 4793759
Test real receipts and also error cases
djb15 1bed34f
node: update test date receipts and parity test
bemic dab418c
node: finalize EVM receipt hash tests
bemic 003ae4f
Fix lints + spellcheck
djb15 ff73554
Update README
djb15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,6 +191,7 @@ reobservation | |
| Reobservation | ||
| reobservations | ||
| Reobservations | ||
| reobserve | ||
| reobserved | ||
| repoint | ||
| RLUSD | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # EVM watcher tests | ||
|
|
||
| This package has two complementary groups of tests: unit and integration tests | ||
| covering the watcher's behavior, and hash regression tests that pin the exact | ||
| digests the watcher produces for checked-in transaction receipts. | ||
|
|
||
| ## Unit and integration tests | ||
|
|
||
| | File | What it covers | | ||
| | ---- | -------------- | | ||
| | `watcher_test.go` | Message processing: `postMessage` dispatch, immediate publication, pending-message queueing, `processNewBlock` finality handling, `verifyAndPublish`, consistency-level handling, and block-time retry logic. | | ||
| | `reobserve_test.go` | Reobservation request handling: invalid chain IDs, receipt errors, failed transaction status, skipped logs, deterministic ordering, large receipts, and transfer-verifier integration. | | ||
| | `by_transaction_test.go` | Core bridge log validation (`isValidCoreBridgeMessagePublicationLog`): wrong contract, wrong topic, removed logs, malformed topics. | | ||
| | `custom_consistency_level_test.go` | Custom consistency level (CCL) config parsing and effective-consistency-level handling. | | ||
| | `chain_config_test.go` | Per-chain configuration: finality support, EVM chain IDs, mainnet contract addresses. | | ||
| | `blocks_by_timestamp_test.go` | The block-by-timestamp cache used for CCQ. | | ||
| | `ccq_test.go`, `ccq_backfill_test.go` | Cross-chain query (CCQ) request handling and backfill. | | ||
| | `tron_integration_test.go` | Live integration against the Tron Nile testnet (requires network access). | | ||
| | `watcher_test_helpers_test.go` | Shared mock connector and test helpers. | | ||
|
|
||
| ## Hash regression tests | ||
|
|
||
| These fixtures protect the message hash used to match live observations with | ||
| re-observations. The expected hashes are checked in and are constructed without | ||
| calling `MessagePublication.CreateDigest()`, so an accidental change to watcher | ||
| message construction is caught by the tests. | ||
|
|
||
| ### Source of truth | ||
|
|
||
| `TestObservationReobservationParity` in | ||
| `observation_reobservation_parity_test.go` loads the canonical receipt vectors | ||
| and sends each receipt through both watcher paths: | ||
|
|
||
| - live observation: `runMessageProcessor` / `postMessage` | ||
| - re-observation: `runReobservationHandler` / | ||
| `handleReobservationRequest` | ||
|
|
||
| For every receipt, the test requires both paths to emit exactly the same | ||
| digests - compared without regard to order, but with every duplicate counted - | ||
| and requires those digests to match the checked-in `expectedMessages[].hash` | ||
| values. It also asserts that `CreateDigest()` and `VAAHash()` remain | ||
| equivalent. | ||
|
|
||
| The digest is the double Keccak-256 hash of the serialized VAA body fields: | ||
|
|
||
| 1. timestamp as a big-endian `uint32` | ||
| 2. nonce as a big-endian `uint32` | ||
| 3. Wormhole chain ID as a big-endian `uint16` | ||
| 4. 32-byte emitter address | ||
| 5. sequence as a big-endian `uint64` | ||
| 6. consistency level as a `uint8` | ||
| 7. payload bytes | ||
|
|
||
| Receipt metadata such as transaction hash, block hash, block number, | ||
| transaction index, log index, gas fields, bloom, and `IsReobservation` must not | ||
| change the digest. `TestGeneratedReceiptGoldenVectorMetadataIndependence` | ||
| checks this explicitly. | ||
|
|
||
| ### Receipt fixtures | ||
|
|
||
| The tests load only these canonical files: | ||
|
|
||
| - `testdata/generated_receipts.json`: 210 deterministic synthetic receipt | ||
| vectors containing 211 expected messages. | ||
| - `testdata/real_receipts.json`: 200 Ethereum mainnet receipt vectors containing | ||
| 202 expected messages. Two receipts contain two Wormhole Core events. | ||
|
|
||
| Each vector has this shape: | ||
|
|
||
| ```json | ||
| { | ||
| "name": "real-000-tx-2461b4bce349", | ||
| "comment": "real: Ethereum Wormhole Core ...", | ||
| "wormholeChainId": 2, | ||
| "blockTime": 1749806543, | ||
| "receipt": {}, | ||
| "expectedMessages": [ | ||
| { | ||
| "logIndex": 645, | ||
| "hash": "cfdc8c25256503257c9d66a22b43e00a1ce42445592e5e8653c684e219cae1b5" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| `hash` is the observation-matching digest, encoded as 32 lowercase hexadecimal | ||
| bytes without a `0x` prefix. `logIndex` makes message selection explicit for | ||
| receipts containing unrelated logs or multiple Wormhole events. | ||
|
|
||
| ### Data provenance and hash construction | ||
|
|
||
| The synthetic vectors were built from explicit event fields, ABI-encoded into | ||
| `LogMessagePublished` receipt logs, and paired with independently calculated | ||
| hashes. The real vectors were derived from full Ethereum receipts. Historical | ||
| block timestamps were matched to the corresponding Wormholescan VAAs by | ||
| transaction hash, emitter, and sequence because timestamp is part of the signed | ||
| body. | ||
|
|
||
| For both data sets, each expected hash was calculated by serializing the VAA | ||
| body fields in protocol order and applying Keccak-256 twice. This calculation | ||
| did not call `MessagePublication.CreateDigest()`, `VAAHash()`, or another watcher | ||
| hash helper. All 200 previously recorded historical hashes matched this | ||
| independent calculation. The full receipts also revealed two additional valid | ||
| Wormhole Core events, which is why 200 real receipts contain 202 expected | ||
| messages. | ||
|
|
||
| The fixtures are therefore checked from two independent directions: the stored | ||
| hashes come from direct protocol serialization, while the tests decode the | ||
| receipt logs through the production ABI and construct `MessagePublication` | ||
| objects through the watcher paths. A mistake in watcher field mapping, | ||
| serialization, or event selection causes the produced digest to differ from the | ||
| checked-in value. | ||
|
|
||
| The generated corpus covers: | ||
|
|
||
| - empty, binary, all-zero, 1-, 31-, 32-, 33-, and 4096-byte payloads | ||
| - leading-zero emitter addresses | ||
| - timestamps with non-round and high-bit values | ||
| - chain ID `4004` | ||
| - sequence boundaries including `0`, `uint64` max, and `2^53 + 1` | ||
| - maximum `uint32` nonce | ||
| - immediate, safe, finalized, custom, and historical consistency levels | ||
| - unrelated logs, wrong-contract logs, and multiple Wormhole events in one | ||
| receipt | ||
|
|
||
| `TestGeneratedReceiptGoldenVectorsCoverage` pins these properties so fixture | ||
| changes cannot silently weaken the corpus. | ||
|
|
||
| ### Tests to run | ||
|
|
||
| From `node`: | ||
|
|
||
| ```sh | ||
| go test ./pkg/watchers/evm -run TestObservationReobservationParity -count=1 | ||
| go test ./pkg/watchers/evm -run 'TestGeneratedReceiptGolden|TestConsistencyLevelMatches' -count=1 | ||
| go test ./pkg/watchers/evm -count=1 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.