diff --git a/README.md b/README.md index ad8ba47..918167e 100644 --- a/README.md +++ b/README.md @@ -601,7 +601,7 @@ Everything below runs offline, with no deployed contracts, except three fork sui | Suite | Count | Command | |---|---|---| | Contracts: unit, fuzz, E2E, upgrade, deploy-script, handover and 22 invariants | 799 | `forge test` | -| Oracle | 1542 | `cd oracle && node --test` | +| Oracle | 1544 | `cd oracle && node --test` | | SDK | 392 | `cd packages/sdk && npx vitest run` | Counts are individual tests, so each of the 22 invariants counts once. The contracts were counted on 15 November 2026, the SDK on 15 November and the oracle on 15 November. Without a fork URL, 787 of the contract tests run and 12 skip. Run after `npm run build`, 383 of the SDK's 392 pass and 9 skip: the 8 integration tests, which need a live deployment, and one check that runs only in CI. Without a build, the 9 built-package tests skip too. Vitest strips types without checking them, so `npm run typecheck` in `packages/sdk` checks the tests against the SDK's types as well as the sources. [`scripts/mutation`](scripts/mutation/README.md) holds the harnesses that measure whether these tests would catch a deliberate break in the contracts or deploy scripts. diff --git a/docs/whitepaper.md b/docs/whitepaper.md index 53bf049..a5c3ee3 100644 --- a/docs/whitepaper.md +++ b/docs/whitepaper.md @@ -635,7 +635,7 @@ apply to a fresh deployment, not to the testnet. **Test coverage**, as of 15 November 2026: 799 contract tests across 36 Foundry test files including fuzz and invariant tests (the two slash drill suites fork Arc testnet themselves, and -the twelve in `SplitAuthorityFork` skip without `--fork-url`), 1542 oracle tests and 392 in the SDK (9 skip +the twelve in `SplitAuthorityFork` skip without `--fork-url`), 1544 oracle tests and 392 in the SDK (9 skip outside CI and without a live deployment; every test that runs passes). CI runs Foundry, the oracle and SDK suites, and Slither static analysis on every push, plus a documentation check that fails when the site states something the contracts do not. diff --git a/oracle/site-app.test.js b/oracle/site-app.test.js index 5ca7211..e55c3de 100644 --- a/oracle/site-app.test.js +++ b/oracle/site-app.test.js @@ -43,9 +43,10 @@ function element(id) { /** * The page, loaded. `agents` maps an address to its chain state; `hold(did)` may return a promise the - * RPC waits on before it answers a lookup of that agent, or rejects with. + * RPC waits on before it answers a lookup of that agent, or rejects with. `rpc` replaces the stub RPC's + * fetch. Every timer the page sets fires at once, and `waits` records the delay it asked for. */ -function load({ agents = {}, hold = () => null } = {}) { +function load({ agents = {}, hold = () => null, rpc = null } = {}) { const els = new Map(); const $ = (id) => { if (!els.has(id)) els.set(id, element(id)); return els.get(id); }; const byDid = new Map(Object.entries(agents).map(([addr, s]) => [didOf(addr), { addr, ...s }])); @@ -84,19 +85,27 @@ function load({ agents = {}, hold = () => null } = {}) { } return { json: async () => one(body) }; }; + const waits = []; const ctx = vm.createContext({ document: { getElementById: $, createElement: () => element(null), querySelector: () => null, querySelectorAll: () => [] }, window: { addEventListener() {}, dispatchEvent() {} }, Event: class { constructor(type) { this.type = type; } }, SigvaraDid: Did, - fetch, - setTimeout: (fn) => setImmediate(fn), + fetch: rpc ?? fetch, + setTimeout: (fn, ms) => { waits.push(ms); return setImmediate(fn); }, + clearTimeout: clearImmediate, + AbortController, console, }); vm.runInContext(SOURCE, ctx, { filename: 'app.js' }); - return { ctx, $, batches, get: (name) => vm.runInContext(name, ctx) }; + return { ctx, $, batches, waits, get: (name) => vm.runInContext(name, ctx) }; } +// A node that accepts the connection and never answers: the request ends only if the page aborts it. +const neverAnswers = (_url, init) => new Promise((_, reject) => { + init.signal?.addEventListener('abort', () => reject(new DOMException('This operation was aborted', 'AbortError'))); +}); + /** An EIP-1193 wallet. `chain` can be changed under the page, as a user switching networks does. */ function wallet({ chain = ARC, account = OPERATOR, switchError = null, addSwitches = true } = {}) { const p = { @@ -233,3 +242,16 @@ test('a Suspended agent below the minimum is not called suspended by its operato assert.match(status, /bond it back to the minimum and reactivate it/); assert.match(page.$('stakeNote').innerHTML, /then reactivate it/); }); + +test('a read the RPC never answers fails after 20 seconds with a message, rather than leaving the page waiting', async () => { + const page = load({ rpc: neverAnswers }); + await idle(); + assert.equal(page.$('feeNow').textContent, 'unavailable', 'the token reads at load are still waiting'); + assert.match(page.$('log').innerHTML, /RPC read failed: the RPC did not answer within 20 seconds/); + + page.$('agentAddr').value = B; + page.ctx.lookup(); // not awaited: a lookup with no limit never settles + await idle(); + assert.match(page.$('log').innerHTML, /lookup failed: the RPC did not answer within 20 seconds/); + assert.deepEqual(page.waits, [20000, 20000], 'one 20 s limit on each request'); +}); diff --git a/oracle/site-pages.test.js b/oracle/site-pages.test.js index ea6fdf6..9f9e3f4 100644 --- a/oracle/site-pages.test.js +++ b/oracle/site-pages.test.js @@ -85,3 +85,34 @@ test('the agents page reads the chain only for the agents it shows, 50 rows at a assert.match(html, /Rows 51 to 100 of 130\./); assert.deepEqual([...new Set(asked.slice(300))], Array.from({ length: 40 }, (_, i) => word(i + 61)), 'only the rows not read before'); }); + +test('the testnet page reports a read the RPC never answers after 20 seconds, rather than waiting for good', async () => { + const source = fs.readFileSync(path.join(__dirname, '..', 'site', 'assets', 'testnet.js'), 'utf8'); + const els = new Map(); + const $ = (id) => { + if (!els.has(id)) els.set(id, { textContent: '', value: '', href: '', setAttribute() {}, addEventListener() {} }); + return els.get(id); + }; + let ready = null; + const waits = []; + const ctx = vm.createContext({ + window: { SigvaraDid: did }, + document: { getElementById: $, querySelector: () => null, addEventListener: (type, fn) => { if (type === 'DOMContentLoaded') ready = fn; } }, + // An address in the query string starts a check when the page loads. + URLSearchParams, + location: { search: '?a=0x00000000000000000000000000000000000000a1' }, + AbortController, + // A node that accepts the connection and never answers: the request ends only if the page aborts it. + fetch: (_url, init) => new Promise((_, reject) => { + init.signal?.addEventListener('abort', () => reject(new DOMException('This operation was aborted', 'AbortError'))); + }), + // The page's timer fires at once, and the test checks the delay it asked for. + setTimeout: (fn, ms) => { waits.push(ms); return setImmediate(fn); }, + clearTimeout: clearImmediate, + }); + vm.runInContext(source, ctx); + ready(); + for (let i = 0; i < 20; i++) await new Promise(setImmediate); + assert.equal($('cardDid').textContent, 'read failed: the RPC did not answer within 20 seconds'); + assert.deepEqual(waits, [20000]); +}); diff --git a/site/app.html b/site/app.html index 5568364..a29a48d 100644 --- a/site/app.html +++ b/site/app.html @@ -140,6 +140,6 @@

Activity

- + diff --git a/site/assets/app.js b/site/assets/app.js index ca9da95..3f059c5 100644 --- a/site/assets/app.js +++ b/site/assets/app.js @@ -127,10 +127,31 @@ function decodeString(hex) { } // ---- chain io ---- +// Every RPC read goes through here. A node that accepts the connection and never answers would leave +// the page waiting with no message, so a request that has not finished in 20 s, body included, is +// aborted and fails like any other read. The epochs page uses the same limit (epochs.js). +async function rpcPost(body) { + const ctl = new AbortController(); + const t = setTimeout(() => ctl.abort(), 20000); + try { + const res = await fetch(RPC, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body), + signal: ctl.signal, + }); + return await res.json(); + } catch (e) { + if (e.name === "AbortError") throw new Error("the RPC did not answer within 20 seconds"); + throw e; + } finally { + clearTimeout(t); + } +} + async function rpcRead(to, data) { const body = { jsonrpc: "2.0", id: 1, method: "eth_call", params: [{ to, data }, "latest"] }; - const res = await fetch(RPC, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }); - const j = await res.json(); + const j = await rpcPost(body); if (j.error) throw new Error(j.error.message); return j.result; } @@ -150,12 +171,7 @@ async function rpcBatch(calls) { jsonrpc: "2.0", id: i, method: "eth_call", params: [{ to: c.to, data: c.data }, "latest"], })); - const res = await fetch(RPC, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(body), - }); - const arr = await res.json(); + const arr = await rpcPost(body); if (!Array.isArray(arr)) throw new Error(arr?.error?.message ?? "batch call failed"); const byId = new Map(arr.map(r => [r.id, r])); return calls.map((c, i) => { diff --git a/site/assets/testnet.js b/site/assets/testnet.js index 574119a..5ec6aea 100644 --- a/site/assets/testnet.js +++ b/site/assets/testnet.js @@ -52,12 +52,26 @@ params: c.params || [{ to: c.to, data: c.data }, "latest"], }; }); - var res = await fetch(RPC, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(body), - }); - var arr = await res.json(); + // A node that accepts the connection and never answers would leave the card reading the + // chain with no message, so a request that has not finished in 20 s, body included, is + // aborted and reported like any other failed read. The epochs page uses the same limit. + var ctl = new AbortController(); + var timer = setTimeout(function () { ctl.abort(); }, 20000); + var arr; + try { + var res = await fetch(RPC, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body), + signal: ctl.signal, + }); + arr = await res.json(); + } catch (e) { + if (e.name === "AbortError") throw new Error("the RPC did not answer within 20 seconds"); + throw e; + } finally { + clearTimeout(timer); + } if (!Array.isArray(arr)) throw new Error((arr && arr.error && arr.error.message) || "RPC batch failed"); var byId = {}; arr.forEach(function (r) { byId[r.id] = r; }); diff --git a/site/testnet.html b/site/testnet.html index cf27de6..dbdba8c 100644 --- a/site/testnet.html +++ b/site/testnet.html @@ -187,6 +187,6 @@

Five steps to a live agent.

- +