From fa5f6eaa189451a53ffb4b0e273cf95b801a71db Mon Sep 17 00:00:00 2001 From: Eugene Aseev Date: Thu, 26 Nov 2026 00:28:37 +0800 Subject: [PATCH] Skip malformed Chainstats catalog names --- src/helpers/getData.test.js | 24 ++++++++++++++++++++++++ src/helpers/pricingCatalog.mjs | 6 ++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/helpers/getData.test.js b/src/helpers/getData.test.js index 1cef1c5..7785934 100644 --- a/src/helpers/getData.test.js +++ b/src/helpers/getData.test.js @@ -104,6 +104,30 @@ describe('processData', () => { ]); }); + it.each([ + ['non-string network name', { network: { name: 42 } }], + ['non-string client name', { client: { name: { id: 'bor' } } }], + ['blank network name', { network: { name: ' ' } }], + ['blank client name', { client: { name: ' ' } }], + ])('skips entries with a %s', async (_, invalidName) => { + axios.get.mockResolvedValue({ + data: { + blockchains: { + invalid: catalogEntry(invalidName), + valid: catalogEntry(), + }, + }, + }); + + await expect(processData()).resolves.toEqual([ + { + protocol: 'polygon-pos', + network: 'polygon-pos-mainnet', + full: [{ node_data: { client: 'bor', size_required: 850 } }], + }, + ]); + }); + it('rejects a catalog with no usable storage sizes', async () => { axios.get.mockResolvedValue({ data: { blockchains: { missingSize: catalogEntry({ total_storage_gb: 0 }) } }, diff --git a/src/helpers/pricingCatalog.mjs b/src/helpers/pricingCatalog.mjs index da6eb95..a5204f2 100644 --- a/src/helpers/pricingCatalog.mjs +++ b/src/helpers/pricingCatalog.mjs @@ -43,8 +43,10 @@ const parsePricingCatalog = (data) => { size <= 0 || typeof protocolName !== 'string' || !protocolName.trim() || - !network || - !client + typeof network !== 'string' || + !network.trim() || + typeof client !== 'string' || + !client.trim() ) { continue; }