From 400629c83ad1b847f9a21ca7b34f561d0679f06d Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Tue, 19 Mar 2024 14:37:24 +0000 Subject: [PATCH] fix pass time when run test adaprer --- adapters/utils/runAdapter.ts | 4 ++-- cli/testAdapter.ts | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/adapters/utils/runAdapter.ts b/adapters/utils/runAdapter.ts index dc7092c8e4..66074a4547 100644 --- a/adapters/utils/runAdapter.ts +++ b/adapters/utils/runAdapter.ts @@ -63,7 +63,7 @@ export default async function runAdapter(volumeAdapter: BaseAdapter, cleanCurren const createBalances: () => Balances = () => { return new Balances({ timestamp: closeToCurrentTime ? undefined : timestamp, chain }) } - const toTimestamp = timestamp + const toTimestamp = timestamp - 1 const fromTimestamp = toTimestamp - ONE_DAY_IN_SECONDS const fromChainBlocks = {} const getFromBlock = async () => await getBlock(fromTimestamp, chain, fromChainBlocks) @@ -88,7 +88,7 @@ export default async function runAdapter(volumeAdapter: BaseAdapter, cleanCurren const api = new ChainApi({ chain, timestamp: withinTwoHours ? undefined : timestamp, block: toBlock }) const startOfDay = getUniqStartOfTodayTimestamp(new Date(toTimestamp * 1000)) const startTimestamp = fromTimestamp - const endTimestamp = toTimestamp + const endTimestamp = toTimestamp + 1 const getStartBlock = getFromBlock const getEndBlock = getToBlock const toApi = api diff --git a/cli/testAdapter.ts b/cli/testAdapter.ts index d2ffd22cbc..3a4384fdf2 100644 --- a/cli/testAdapter.ts +++ b/cli/testAdapter.ts @@ -25,18 +25,20 @@ function getTimestamp30MinutesAgo() { const adapterType: AdapterType = process.argv[2] as AdapterType const passedFile = path.resolve(process.cwd(), `./${adapterType}/${process.argv[3]}`); (async () => { - const cleanDayTimestamp = process.argv[4] ? getUniqStartOfTodayTimestamp(new Date(+process.argv[4] * 1000 + 60 * 60 * 24 * 1000)) : getUniqStartOfTodayTimestamp(new Date()) - let endCleanDayTimestamp = cleanDayTimestamp - 1 + const cleanDayTimestamp = process.argv[4] ? Number(process.argv[4]) : getUniqStartOfTodayTimestamp(new Date()) + let endCleanDayTimestamp = cleanDayTimestamp; console.info(`🦙 Running ${process.argv[3].toUpperCase()} adapter 🦙`) console.info(`_______________________________________`) // Import module to test let module: Adapter = (await import(passedFile)).default const adapterVersion = module.version - let timestamp = endCleanDayTimestamp + let endTimestamp = endCleanDayTimestamp if (adapterVersion === 2) { - timestamp = (process.argv[4] ? Number(process.argv[4]) : getTimestamp30MinutesAgo()) // 1 day; + endTimestamp = (process.argv[4] ? Number(process.argv[4]) : getTimestamp30MinutesAgo()) // 1 day; } - console.info(`${upperCaseFirst(adapterType)} for ${formatTimestampAsDate(String(getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))))}`) + + const runAt = adapterVersion === 2 ? endTimestamp : endTimestamp - 1; + console.info(`${upperCaseFirst(adapterType)} for ${formatTimestampAsDate(String(getUniqStartOfTodayTimestamp(new Date((runAt * 1000)))))}`) console.info(`_______________________________________\n`) // Get closest block to clean day. Only for EVM compatible ones. @@ -45,7 +47,7 @@ const passedFile = path.resolve(process.cwd(), `./${adapterType}/${process.argv[ const chainBlocks: ChainBlocks = {}; await Promise.all(allChains.map(async (chain) => { try { - const latestBlock = await getBlock(timestamp, chain, chainBlocks).catch((e: any) => console.error(`${e.message}; ${timestamp}, ${chain}`)) + const latestBlock = await getBlock(endTimestamp, chain, chainBlocks).catch((e: any) => console.error(`${e.message}; ${endTimestamp}, ${chain}`)) if (latestBlock) chainBlocks[chain] = latestBlock } catch (e) { console.log(e) } @@ -54,7 +56,7 @@ const passedFile = path.resolve(process.cwd(), `./${adapterType}/${process.argv[ if ("adapter" in module) { const adapter = module.adapter // Get adapter - const volumes = await runAdapter(adapter, timestamp, chainBlocks, undefined, undefined, { + const volumes = await runAdapter(adapter, endTimestamp, chainBlocks, undefined, undefined, { adapterVersion, }) printVolumes(volumes, adapter) @@ -62,7 +64,7 @@ const passedFile = path.resolve(process.cwd(), `./${adapterType}/${process.argv[ } else if ("breakdown" in module) { const breakdownAdapter = module.breakdown const allVolumes = await Promise.all(Object.entries(breakdownAdapter).map(([version, adapter]) => - runAdapter(adapter, timestamp, chainBlocks, undefined, undefined, { + runAdapter(adapter, endTimestamp, chainBlocks, undefined, undefined, { adapterVersion, }).then(res => ({ version, res })) ))