RPC
This commit is contained in:
@@ -6,6 +6,18 @@ import { NETWORK, type TestnetBlock } from '../shared/testnet.ts';
|
||||
const genesis='0'.repeat(64),chainId='f'.repeat(64);
|
||||
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()=>{
|
||||
const original=globalThis.fetch;
|
||||
let calls=0;
|
||||
globalThis.fetch=async function(this:unknown,input:RequestInfo|URL,init?:RequestInit){
|
||||
assert.equal(this,globalThis,'native browser fetch would throw Illegal invocation for another receiver');
|
||||
assert.equal(input,'/api/summary');assert.equal(init?.redirect,'error');calls++;
|
||||
return Response.json({network:NETWORK,chainId,genesis,tip:genesis,height:0,revision:0,
|
||||
cumulativeWork:'0',pendingTransfers:[],peers:0,algorithm:'RandomX',maturity:2});
|
||||
};
|
||||
try{const state=await new StateClient().load();assert.equal(state.tip,genesis);assert.equal(calls,2);}
|
||||
finally{globalThis.fetch=original;}
|
||||
});
|
||||
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[]=[];
|
||||
|
||||
Reference in New Issue
Block a user