Skip to content

Commit

Permalink
fixup! make getMinerPeerId private
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Mar 8, 2024
1 parent 0498482 commit 7378e8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 () {
Expand All @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7378e8d

Please sign in to comment.