Skip to content

Commit

Permalink
assume responsibility of givenDailyParticipants test helper from spar…
Browse files Browse the repository at this point in the history
…k-evaluate
  • Loading branch information
PatrickNercessian committed Sep 10, 2024
1 parent 3f31756 commit 32980fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion observer/test/observer.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert'
import { beforeEach, describe, it } from 'mocha'
import { getPgPools } from '@filecoin-station/spark-stats-db'
import { givenDailyParticipants } from 'spark-evaluate/test/helpers/queries.js'
import { givenDailyParticipants } from '../../stats/test/test-helpers.js'

import { observeTransferEvents, observeScheduledRewards } from '../lib/observer.js'

Expand Down
3 changes: 1 addition & 2 deletions stats/test/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import http from 'node:http'
import { once } from 'node:events'
import assert from 'node:assert'
import createDebug from 'debug'
import { givenDailyParticipants } from 'spark-evaluate/test/helpers/queries.js'
import { getPgPools } from '@filecoin-station/spark-stats-db'

import { assertResponseStatus, getPort } from './test-helpers.js'
import { assertResponseStatus, getPort, givenDailyParticipants } from './test-helpers.js'
import { createHandler } from '../lib/handler.js'
import { today } from '../lib/request-helpers.js'

Expand Down
18 changes: 18 additions & 0 deletions stats/test/test-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert, { AssertionError } from 'node:assert'
import { mapParticipantsToIds } from 'spark-evaluate/lib/platform-stats.js'

export const assertResponseStatus = async (res, status) => {
if (res.status !== status) {
Expand All @@ -18,3 +19,20 @@ export const getPort = (server) => {
assert(typeof address === 'object')
return address.port
}

/**
* @param {import('@filecoin-station/spark-stats-db').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())
])
}

0 comments on commit 32980fa

Please sign in to comment.