diff --git a/db/index.js b/db/index.js index eff41df..645d879 100644 --- a/db/index.js +++ b/db/index.js @@ -1,5 +1,4 @@ import { migrateWithPgClient as migrateEvaluateDB } from 'spark-evaluate/lib/migrate.js' -import { mapParticipantsToIds } from 'spark-evaluate/lib/platform-stats.js' import pg from 'pg' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' @@ -110,20 +109,3 @@ export const migrateStatsDB = async (client) => { console.log('Migrated `spark-stats` DB schema to version', await postgrator.getDatabaseVersion()) } - -/** - * @param {import('./typings.js').Queryable} pgPool - * @param {string} day - * @param {string[]} participantAddresses - */ -export const givenDailyParticipants = async (pgPool, day, participantAddresses) => { - const ids = await mapParticipantsToIds(pgPool, new Set(participantAddresses)) - await pgPool.query(` - INSERT INTO daily_participants (day, participant_id) - SELECT $1 as day, UNNEST($2::INT[]) AS participant_id - ON CONFLICT DO NOTHING - `, [ - day, - Array.from(ids.values()) - ]) -} diff --git a/db/test-helpers.js b/db/test-helpers.js new file mode 100644 index 0000000..7560be0 --- /dev/null +++ b/db/test-helpers.js @@ -0,0 +1,18 @@ +import { mapParticipantsToIds } from 'spark-evaluate/lib/platform-stats.js' + +/** + * @param {import('./typings.js').Queryable} pgPool + * @param {string} day + * @param {string[]} participantAddresses + */ +export const givenDailyParticipants = async (pgPool, day, participantAddresses) => { + const ids = await mapParticipantsToIds(pgPool, new Set(participantAddresses)) + await pgPool.query(` + INSERT INTO daily_participants (day, participant_id) + SELECT $1 as day, UNNEST($2::INT[]) AS participant_id + ON CONFLICT DO NOTHING + `, [ + day, + Array.from(ids.values()) + ]) +} diff --git a/observer/test/observer.test.js b/observer/test/observer.test.js index 06ceca3..18ab9c2 100644 --- a/observer/test/observer.test.js +++ b/observer/test/observer.test.js @@ -1,6 +1,7 @@ import assert from 'node:assert' import { beforeEach, describe, it } from 'mocha' -import { getPgPools, givenDailyParticipants } from '@filecoin-station/spark-stats-db' +import { getPgPools } from '@filecoin-station/spark-stats-db' +import { givenDailyParticipants } from '@filecoin-station/spark-stats-db/test-helpers.js' import { observeTransferEvents, observeScheduledRewards } from '../lib/observer.js' diff --git a/stats/test/handler.test.js b/stats/test/handler.test.js index f4bfd9f..34505f2 100644 --- a/stats/test/handler.test.js +++ b/stats/test/handler.test.js @@ -2,7 +2,8 @@ import http from 'node:http' import { once } from 'node:events' import assert from 'node:assert' import createDebug from 'debug' -import { getPgPools, givenDailyParticipants } from '@filecoin-station/spark-stats-db' +import { getPgPools } from '@filecoin-station/spark-stats-db' +import { givenDailyParticipants } from '@filecoin-station/spark-stats-db/test-helpers.js' import { assertResponseStatus, getPort } from './test-helpers.js' import { createHandler } from '../lib/handler.js'