Skip to content

Commit 0030d2d

Browse files
add library
1 parent d741d0a commit 0030d2d

File tree

6 files changed

+18
-196
lines changed

6 files changed

+18
-196
lines changed

lib/miner-info.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const smartContractClient = new ethers.Contract(
2323
* @returns {Promise<string>} The peer ID of the miner.
2424
*/
2525
export async function getMinerPeerId (minerId, { maxAttempts = 5 } = {}) {
26-
const { peerId } = await getIndexProviderPeerId(minerId, smartContractClient, {
26+
const { peerId, source } = await getIndexProviderPeerId(minerId, smartContractClient, {
2727
rpcUrl: RPC_URL,
2828
rpcAuth: RPC_AUTH,
2929
maxAttempts
3030
})
31+
console.log(`Peer ID fetched from ${source}.`)
3132
return peerId
32-
}
33+
}

lib/spark.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ActivityState } from './activity-state.js'
44
import { SPARK_VERSION, MAX_CAR_SIZE, APPROX_ROUND_LENGTH_IN_MS } from './constants.js'
55
import { queryTheIndex } from './ipni-client.js'
66
import { assertOkResponse } from './http-assertions.js'
7-
import { getIndexProviderPeerId as defaultGetIndexProvider } from './miner-info.js'
7+
import { getMinerPeerId as defaultGetIndexProvider } from './miner-info.js'
88
import { multiaddrToHttpUrl } from './multiaddr.js'
99
import { Tasker } from './tasker.js'
1010

manual-check.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55

66
import Spark, { getRetrievalUrl } from './lib/spark.js'
7-
import { getIndexProviderPeerId as defaultGetIndexProvider } from './lib/miner-info.js'
7+
import { getMinerPeerId as defaultGetIndexProvider } from './lib/miner-info.js'
88

99
// The task to check, replace with your own values
1010
const task = {

test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ import './test/miner-info.test.js'
44
import './test/multiaddr.test.js'
55

66
import './test/integration.js'
7-
import './test/spark.js'
8-
import './test/smart-contract-client.test.js'
7+
import './test/spark.js'

test/miner-info.test.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import { test } from 'zinnia:test'
2-
import { assertMatch, AssertionError } from 'zinnia:assert'
3-
import { getIndexProviderPeerId } from '../lib/miner-info.js'
2+
import { assertMatch, AssertionError, assert, assertEquals } from 'zinnia:assert'
3+
import { getMinerPeerId } from '../lib/miner-info.js'
44

55
const KNOWN_MINER_ID = 'f0142637'
66

77
test('get peer id of a known miner', async () => {
8-
const result = await getIndexProviderPeerId(KNOWN_MINER_ID)
8+
const result = await getMinerPeerId(KNOWN_MINER_ID)
99
assertMatch(result, /^12D3KooW/)
1010
})
1111

1212
test('get peer id of a miner that does not exist', async () => {
1313
try {
14-
const result = await getIndexProviderPeerId('f010', { maxAttempts: 1 })
14+
const result = await getMinerPeerId('f010', { maxAttempts: 1 })
1515
throw new AssertionError(
16-
`Expected "getIndexProviderPeerId()" to fail, but it resolved with "${result}" instead.`
16+
`Expected "getMinerPeerId()" to fail, but it resolved with "${result}" instead.`
1717
)
1818
} catch (err) {
1919
assertMatch(err.toString(), /Error fetching index provider PeerID for miner f010/)
2020
}
2121
})
22+
23+
test('getMinerPeerId returns correct peer id for miner f03303347', async () => {
24+
const peerId = await getMinerPeerId('f03303347')
25+
26+
assert(typeof peerId === 'string', 'Expected peerId to be a string')
27+
assertEquals(peerId, '12D3KooWJ91c6xQshrNe7QAXPFAaeRrHWq2UrgXGPf8UmMZMwyZ5')
28+
})

test/smart-contract-client.test.js

-185
This file was deleted.

0 commit comments

Comments
 (0)