This commit is contained in:
2026-10-29 11:45:51 -04:00
parent b3a1179703
commit b427fa4217
35 changed files with 469 additions and 158 deletions
+8 -1
View File
@@ -2,8 +2,9 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import { StateClient } from '../shared/rpc-client.ts';
import { NETWORK, type TestnetBlock } from '../shared/testnet.ts';
import { expectedChainIdentity } from '../shared/chain-identity.ts';
const genesis='0'.repeat(64),chainId='f'.repeat(64);
const { genesis, chainId } = await expectedChainIdentity();
const block=(height:number,previousHash:string):TestnetBlock=>({ network:NETWORK,chainId,height,
hash:height.toString(16).padStart(64,'0'),previousHash,transactions:[] }) as unknown as TestnetBlock;
test('default browser-style fetch receives the global receiver, not StateClient',async()=>{
@@ -18,6 +19,12 @@ test('default browser-style fetch receives the global receiver, not StateClient'
try{const state=await new StateClient().load();assert.equal(state.tip,genesis);assert.equal(calls,2);}
finally{globalThis.fetch=original;}
});
test('browser rejects a node with the same network label but a different chain identity', async () => {
const client = new StateClient((async () => Response.json({ network: NETWORK, chainId: 'f'.repeat(64),
genesis: '0'.repeat(64), tip: '0'.repeat(64), height: 0, revision: 0,
cumulativeWork: '0', pendingTransfers: [], peers: 0, algorithm: 'RandomX', maturity: 2 })) as typeof fetch);
await assert.rejects(client.load(), /Incompatible node summary/);
});
function fixture(count:number){
const blocks:TestnetBlock[]=[];for(let i=0;i<count;i++)blocks.push(block(i+1,blocks.at(-1)?.hash??genesis));
const calls:string[]=[];