From db46964025659c4c6c2681a6b52588f5de7cddc7 Mon Sep 17 00:00:00 2001 From: Danil Shaymurzin Date: Fri, 21 Nov 2025 18:32:13 +0500 Subject: [PATCH] test(oracles): add integration tests for classic price collector --- .../collectPricesClassicOracles.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/oracles/collectPricesClassicOracles.test.ts diff --git a/tests/oracles/collectPricesClassicOracles.test.ts b/tests/oracles/collectPricesClassicOracles.test.ts new file mode 100644 index 00000000..272eefe2 --- /dev/null +++ b/tests/oracles/collectPricesClassicOracles.test.ts @@ -0,0 +1,47 @@ +import { Cell } from '@ton/core'; +import { ClassicCollector, DefaultPriceSourcesConfig, MAINNET_POOL_ASSETS_CONFIG } from '../../src'; +import { ORACLES_MAINNET } from '../../src/constants/general'; +import { PriceSourcesConfig } from '../../src/oracles/Types'; +import { FetchConfig } from '../../src/utils/utils'; + +const MIN_ORACLES = 3; +const FAST_FETCH: FetchConfig = { retries: 0, timeout: 1500 }; + +describe('ClassicCollector.#collectPricesWithValidation (integration)', () => { + test('falls back from an invalid endpoint to a working production source', async () => { + const sources: PriceSourcesConfig = { + backendEndpoints: ['invalid.evaa.space', ...DefaultPriceSourcesConfig.backendEndpoints], + icpEndpoints: DefaultPriceSourcesConfig.icpEndpoints, + }; + + const collector = new ClassicCollector({ + poolAssetsConfig: MAINNET_POOL_ASSETS_CONFIG, + minimalOracles: MIN_ORACLES, + evaaOracles: ORACLES_MAINNET, + sourcesConfig: sources, + }); + + const prices = await collector.getPrices(undefined, FAST_FETCH); + + expect(prices.dict.values().length).toBeGreaterThan(0); + expect(prices.dataCell).not.toEqual(Cell.EMPTY); + }); + + test('throws when all production sources are unavailable', async () => { + const sources: PriceSourcesConfig = { + backendEndpoints: ['invalid.evaa.space'], + icpEndpoints: ['invalid.raw.icp0.io'], + }; + + const collector = new ClassicCollector({ + poolAssetsConfig: MAINNET_POOL_ASSETS_CONFIG, + minimalOracles: MIN_ORACLES, + evaaOracles: ORACLES_MAINNET, + sourcesConfig: sources, + }); + + await expect(collector.getPrices(undefined, { retries: 0, timeout: 1000 })).rejects.toThrow( + /Failed to collect sufficient prices/, + ); + }); +});