diff --git a/lib/spark.js b/lib/spark.js index add0e33..06ae27f 100644 --- a/lib/spark.js +++ b/lib/spark.js @@ -3,7 +3,7 @@ import { ActivityState } from './activity-state.js' import { SPARK_VERSION, MAX_CAR_SIZE, APPROX_ROUND_LENGTH_IN_MS } from './constants.js' import { queryTheIndex } from './ipni-client.js' -import { getMinerPeerId } from './miner-info.js' +import { getMinerPeerId as defaultGetMinerPeerId } from './miner-info.js' import { encodeHex } from '../vendor/deno-deps.js' @@ -12,12 +12,16 @@ const sleep = dt => new Promise(resolve => setTimeout(resolve, dt)) export default class Spark { #fetch + #getMinerPeerId #activity = new ActivityState() #maxTasksPerNode = 360 - constructor ({ fetch = globalThis.fetch } = {}) { + constructor ({ + fetch = globalThis.fetch, + getMinerPeerId = defaultGetMinerPeerId + } = {}) { this.#fetch = fetch - this.getMinerPeerId = getMinerPeerId + this.#getMinerPeerId = getMinerPeerId } async getRetrieval () { @@ -43,7 +47,7 @@ export default class Spark { async executeRetrievalCheck (retrieval, stats) { console.log(`Calling Filecoin JSON-RPC to get PeerId of miner ${retrieval.minerId}`) try { - const peerId = await this.getMinerPeerId(retrieval.minerId) + const peerId = await this.#getMinerPeerId(retrieval.minerId) console.log(`Found peer id: ${peerId}`) stats.providerId = peerId } catch (err) { diff --git a/test/integration.js b/test/integration.js index b282207..4873a57 100644 --- a/test/integration.js +++ b/test/integration.js @@ -18,12 +18,13 @@ test('integration', async () => { }) test('retrieval check for our CID', async () => { - const spark = new Spark() - spark.getRetrieval = async () => ({ cid: KNOWN_CID, minerId: OUR_FAKE_MINER_ID }) - spark.getMinerPeerId = async (minerId) => { + const getMinerPeerId = async (minerId) => { assertEquals(minerId, OUR_FAKE_MINER_ID) return FRISBEE_PEER_ID } + const spark = new Spark({ getMinerPeerId }) + spark.getRetrieval = async () => ({ cid: KNOWN_CID, minerId: OUR_FAKE_MINER_ID }) + const measurementId = await spark.nextRetrieval() const res = await fetch(`https://api.filspark.com/measurements/${measurementId}`) assert(res.ok)