|
| 1 | +import { createAntAosLoader } from './utils.mjs'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | +import { |
| 4 | + AO_LOADER_HANDLER_ENV, |
| 5 | + DEFAULT_HANDLE_OPTIONS, |
| 6 | +} from '../tools/constants.mjs'; |
| 7 | + |
| 8 | +describe('JSON limits', async () => { |
| 9 | + const { handle: originalHandle, memory: startMemory } = |
| 10 | + await createAntAosLoader(); |
| 11 | + |
| 12 | + async function handle(options = {}, mem = startMemory) { |
| 13 | + return originalHandle( |
| 14 | + mem, |
| 15 | + { |
| 16 | + ...DEFAULT_HANDLE_OPTIONS, |
| 17 | + ...options, |
| 18 | + }, |
| 19 | + AO_LOADER_HANDLER_ENV, |
| 20 | + ); |
| 21 | + } |
| 22 | + |
| 23 | + it('should not be able to parse a large json', async () => { |
| 24 | + const records = {}; |
| 25 | + const controllers = []; |
| 26 | + const balances = {}; |
| 27 | + for (let i = 0; i < 15_000; i++) { |
| 28 | + records[`${i}-name`] = { |
| 29 | + transactionId: ''.padEnd(43, '1'), |
| 30 | + ttlSeconds: 900, |
| 31 | + }; |
| 32 | + const controller = ''.padEnd(43, i.toString()); |
| 33 | + controllers.push(controller); |
| 34 | + balances[controller] = 1; |
| 35 | + } |
| 36 | + const data = JSON.stringify({ |
| 37 | + records, |
| 38 | + controllers, |
| 39 | + balances, |
| 40 | + }); |
| 41 | + console.log('parsing data size: ' + data.length); |
| 42 | + const result = await handle({ |
| 43 | + Data: data, |
| 44 | + Tags: [{ name: 'Content-Type', value: 'application/json' }], |
| 45 | + }); |
| 46 | + |
| 47 | + console.dir(result, { depth: null }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments