Skip to content

Commit dfaff20

Browse files
committed
test(e2e): the full stack against a real chain, and four indexer bugs it found
Deploys the real contracts to anvil, registers a quote asset through every §420 gate, launches a market, buys twice and sells, then runs the real indexer and asserts the projection equals what the chain actually did. Contracts come from the artifacts Foundry already built, so this indexes the same bytecode the test suite ran against. It found four bugs on its first run, none of which any existing test could see, because every one of them lives between the contracts and the reducer. Blocks: only the first block of each range was recorded, while rows referencing every block in the range were inserted. With a 500-block batch that is 499 blocks of foreign key violations, the tick fails, the cursor never advances, and indexing stops at the first range with an event outside its own first block. Timestamps: every log in a range was stamped with the range's first block time. That puts trades in the wrong candle and, far worse, in the wrong TWAB epoch — Stockback integrates balances over time, so a shifted timestamp is a shifted entitlement. Quote decimals: hardcoded to eighteen. xStocks are not eighteen-decimal assets, so every price and notional in the projection was scaled by 10^12. Now read from the registry, which is where §699 says it comes from. Same-range launches: getLogs filters by address, and a market's address is only known after its launch log is read — so everything a market emitted in the range it launched in was never fetched. On mainnet that is the first several minutes of every market's life. Two smaller faults surfaced while fixing those: the in-memory market map was mutated inside the transaction, so a rollback left it claiming a market the database did not have and every subsequent tick failed forever; and a token's genesis transfers precede TokenLaunched in the same transaction, so the market's opening balance was dropped and the first buy drove it negative.
1 parent 77fb742 commit dfaff20

8 files changed

Lines changed: 672 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ jobs:
157157
DATABASE_URL: postgres://sent:sent@localhost:5432/sent
158158
run: node --experimental-strip-types tests/integration/live.ts
159159

160+
# The largest seam in the system: real contracts, real chain, real indexer.
161+
# Foundry supplies anvil; the artifacts come from the contracts job's own
162+
# compiler, so this indexes the same bytecode the test suite ran against.
163+
- uses: foundry-rs/foundry-toolchain@v1
164+
- name: Build contracts
165+
run: forge build --root contracts
166+
- name: Full stack against anvil
167+
env:
168+
DATABASE_URL: postgres://sent:sent@localhost:5432/sent
169+
RPC_URL: http://127.0.0.1:8545
170+
run: |
171+
anvil --silent &
172+
for i in $(seq 1 30); do
173+
if cast block-number --rpc-url http://127.0.0.1:8545 >/dev/null 2>&1; then break; fi
174+
sleep 1
175+
done
176+
node --experimental-strip-types tests/e2e/stack.ts
177+
160178
contracts:
161179
name: Foundry
162180
runs-on: ubuntu-latest

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"sim:format": "node --experimental-strip-types apps/web/sim/format.ts",
4040
"sim:chart": "node --experimental-strip-types apps/web/sim/chart.ts",
4141
"sim:approve": "node --experimental-strip-types packages/sdk/sim/approve.ts",
42-
"sim:tx": "node --experimental-strip-types apps/web/sim/tx.ts"
42+
"sim:tx": "node --experimental-strip-types apps/web/sim/tx.ts",
43+
"e2e": "node --experimental-strip-types tests/e2e/stack.ts"
4344
},
4445
"devDependencies": {
4546
"@types/node": "^26.4.1",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/indexer/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"private": true,
55
"type": "module",
66
"description": "Reorg-safe HyperEVM event ingestion. Produces the projection per Masterplan 138.",
7+
"exports": {
8+
".": "./src/ingest.ts"
9+
},
710
"dependencies": {
811
"viem": "^2.56.3",
912
"@sent/database": "workspace:*",

0 commit comments

Comments
 (0)