Skip to content

Commit

Permalink
fix pass time when run test adaprer
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Mar 19, 2024
1 parent 19a9956 commit 400629c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions adapters/utils/runAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions cli/testAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) }
Expand All @@ -54,15 +56,15 @@ 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)
console.info("\n")
} 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 }))
))
Expand Down

0 comments on commit 400629c

Please sign in to comment.