|
| 1 | +import assert from "assert"; |
| 2 | +import http, { Server, ServerResponse } from "http"; |
| 3 | +import StreamingWeb3HttpProvider from "../lib/"; |
| 4 | + |
| 5 | +describe("test", () => { |
| 6 | + const PORT = 9451; |
| 7 | + let server: Server; |
| 8 | + const SIZE = (1000000000 / 2) | 0; |
| 9 | + beforeEach(() => { |
| 10 | + server = http.createServer(); |
| 11 | + server |
| 12 | + .on("request", (request, response: ServerResponse) => { |
| 13 | + let body: Buffer[] = []; |
| 14 | + request |
| 15 | + .on("data", (chunk: Buffer) => { |
| 16 | + body.push(chunk); |
| 17 | + }) |
| 18 | + .on("end", () => { |
| 19 | + response.writeHead(200, "OK", { |
| 20 | + "content-type": "application/json" |
| 21 | + }); |
| 22 | + const prefix = '{"id":1,"result":{"structLogs":["'; |
| 23 | + const postfix = '"]}}'; |
| 24 | + response.write(prefix); |
| 25 | + // .5 gigs of utf-8 0s |
| 26 | + const lots = Buffer.allocUnsafe(SIZE).fill(48); |
| 27 | + response.write(lots); |
| 28 | + response.write('","'); |
| 29 | + response.write(lots); |
| 30 | + response.write('","'); |
| 31 | + response.write(lots); |
| 32 | + response.write('","'); |
| 33 | + response.write(lots); |
| 34 | + response.write(postfix); |
| 35 | + response.end(); |
| 36 | + }); |
| 37 | + }) |
| 38 | + .listen(PORT); |
| 39 | + }); |
| 40 | + afterEach(async () => { |
| 41 | + server && server.close(); |
| 42 | + }); |
| 43 | + (it("handle giant traces", async () => { |
| 44 | + const provider = new StreamingWeb3HttpProvider(`http://localhost:${PORT}`); |
| 45 | + const result = await new Promise<any>((resolve, reject) => { |
| 46 | + provider.send( |
| 47 | + { |
| 48 | + id: 1, |
| 49 | + jsonrpc: "2.0", |
| 50 | + method: "debug_traceTransaction", |
| 51 | + params: ["0x1234"] |
| 52 | + }, |
| 53 | + (err, result) => { |
| 54 | + if (err) return void reject(err); |
| 55 | + resolve(result); |
| 56 | + } |
| 57 | + ); |
| 58 | + }); |
| 59 | + assert.strictEqual(result.structLogs.length, 4); |
| 60 | + result.structLogs.forEach((log: Buffer) => { |
| 61 | + assert.strictEqual(log.length, SIZE); |
| 62 | + }); |
| 63 | + assert(true); |
| 64 | + }) as any).timeout(0); |
| 65 | +}); |
0 commit comments