Skip to content

Commit

Permalink
fixup! get rid of "lookup" word
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
  • Loading branch information
bajtos committed Mar 8, 2024
1 parent 274909e commit 0498482
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions lib/miner-lookup.js → lib/miner-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { RPC_REQUEST } from './constants.js'
* @param {string} minerId A miner actor id, e.g. `f0142637`
* @returns {Promise<string>} Miner's PeerId, e.g. `12D3KooWMsPmAA65yHAHgbxgh7CPkEctJHZMeM3rAvoW8CZKxtpG`
*/
export async function lookupMinerPeerId (minerId) {
export async function getMinerPeerId (minerId) {
try {
const res = await rpc('Filecoin.StateMinerInfo', minerId, null)
return res.PeerId
} catch (err) {
err.message = `Cannot lookup miner ${minerId}: ${err.message}`
err.message = `Cannot obtain miner info for ${minerId}: ${err.message}`
throw err
}
}
Expand Down
6 changes: 3 additions & 3 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 { lookupMinerPeerId } from './miner-lookup.js'
import { getMinerPeerId } from './miner-info.js'
import {
encodeHex
} from '../vendor/deno-deps.js'
Expand All @@ -17,7 +17,7 @@ export default class Spark {

constructor ({ fetch = globalThis.fetch } = {}) {
this.#fetch = fetch
this.lookupMinerPeerId = lookupMinerPeerId
this.getMinerPeerId = getMinerPeerId
}

async getRetrieval () {
Expand All @@ -43,7 +43,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.lookupMinerPeerId(retrieval.minerId)
const peerId = await this.getMinerPeerId(retrieval.minerId)
console.log(`Found peer id: ${peerId}`)
stats.providerId = peerId
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './test/ipni-client.test.js'
import './test/miner-lookup.test.js'
import './test/miner-info.test.js'
import './test/integration.js'
import './test/spark.js'
2 changes: 1 addition & 1 deletion test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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.lookupMinerPeerId = async (minerId) => {
spark.getMinerPeerId = async (minerId) => {
assertEquals(minerId, OUR_FAKE_MINER_ID)
return FRISBEE_PEER_ID
}
Expand Down
21 changes: 21 additions & 0 deletions test/miner-info.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from 'zinnia:test'
import { assertMatch, AssertionError } from 'zinnia:assert'
import { getMinerPeerId } from '../lib/miner-info.js'

const KNOWN_MINER_ID = 'f0142637'

test('get peer id of a known miner', async () => {
const result = await getMinerPeerId(KNOWN_MINER_ID)
assertMatch(result, /^12D3KooW/)
})

test('get peer id of a miner that does not exist', async () => {
try {
const result = await getMinerPeerId('f010')
throw new AssertionError(
`Expected "getMinerPeerId()" to fail, but it resolved with "${result}" instead.`
)
} catch (err) {
assertMatch(err.toString(), /\bf010\b.*\bactor code is not miner/)
}
})
21 changes: 0 additions & 21 deletions test/miner-lookup.test.js

This file was deleted.

0 comments on commit 0498482

Please sign in to comment.