Skip to content

Commit 99ba9ac

Browse files
SgtPookilidel
andauthored
* chore: update ipld-explorer-components * chore: use [email protected] * feat: use latest kubo, kubo-rpc-client, & ipfsd-ctl * test: debugging tests * fix(ci): typecheck for kubo-rpc-client * fix: update ipld-explorer-components and fix explore tests * chore: remove unused imports * chore: some minor cleanup * test: fix RPC e2e tests * chore: lint fix * chore: code cleanup and type fixes * chore: remove unused var in test * test: fix remote rpc api tests * chore: PR comments * chore: lint fix --------- Co-authored-by: Marcin Rataj <[email protected]>
1 parent 2250374 commit 99ba9ac

File tree

11 files changed

+1768
-5466
lines changed

11 files changed

+1768
-5466
lines changed

package-lock.json

Lines changed: 1663 additions & 5386 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
"ipfs-css": "^1.4.0",
6868
"ipfs-geoip": "^9.1.0",
6969
"ipfs-provider": "^2.1.0",
70-
"ipld-explorer-components": "^5.2.0",
70+
"ipld-explorer-components": "^7.0.2",
7171
"is-ipfs": "^8.0.1",
7272
"istextorbinary": "^6.0.0",
7373
"it-all": "^1.0.5",
7474
"it-first": "^1.0.6",
7575
"it-last": "^1.0.5",
7676
"it-map": "^1.0.5",
77-
"kubo-rpc-client": "^3.0.2",
77+
"kubo-rpc-client": "^4.1.1",
7878
"milliseconds": "^1.0.3",
7979
"money-clip": "^3.0.5",
8080
"multiformats": "^13.0.1",
@@ -164,10 +164,10 @@
164164
"http-proxy": "^1.18.1",
165165
"http-server": "^14.1.1",
166166
"ipfs": "0.58.3",
167-
"ipfsd-ctl": "^13.0.0",
167+
"ipfsd-ctl": "^14.1.0",
168168
"jest": "^28.1.3",
169169
"jest-environment-jsdom": "^28.1.3",
170-
"kubo": "^0.24.0",
170+
"kubo": "^0.30.0",
171171
"npm-run-all": "^4.1.5",
172172
"nyc": "^15.1.0",
173173
"os-browserify": "^0.3.0",

src/bundles/identity.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ describe.skip('identity.js', function () {
2929
let ipfs
3030
let ipfsd
3131
beforeAll(async () => {
32-
// const kuboRpcModule = await import('kubo-rpc-client')
33-
// console.log('kuboRpcModule: ', kuboRpcModule)
34-
const kuboRpcModule = await import('kubo-rpc-client')
35-
const { createController } = await import('ipfsd-ctl')
32+
const { create } = await import('kubo-rpc-client')
33+
const { createNode } = await import('ipfsd-ctl')
3634
const ipfsBin = (await import('kubo')).default.path()
3735
console.log('ipfsBin: ', ipfsBin)
3836
/**
@@ -41,16 +39,16 @@ describe.skip('identity.js', function () {
4139
*/
4240
const KUBO_PORT = process.env.KUBO_PORT_2033_TEST
4341
if (KUBO_PORT == null) {
44-
ipfsd = await createController({
45-
type: 'go',
46-
ipfsBin,
47-
kuboRpcModule,
42+
ipfsd = await createNode({
43+
type: 'kubo',
44+
bin: ipfsBin,
45+
rpc: create,
4846
test: true,
4947
disposable: true
5048
})
5149
ipfs = ipfsd.api
5250
} else {
53-
ipfs = kuboRpcModule(`http://localhost:${KUBO_PORT}`)
51+
ipfs = create(`http://127.0.0.1:${KUBO_PORT}`)
5452
}
5553
})
5654

src/bundles/ipfs-provider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ const actions = {
368368
const result = await getIpfs({
369369
/**
370370
*
371-
* @param {import('kubo-rpc-client').IPFSHTTPClient} ipfs
371+
* @param {import('kubo-rpc-client').KuboRPCClient} ipfs
372372
* @returns {Promise<boolean>}
373373
*/
374374
connectionTest: async (ipfs) => {

test/e2e/explore.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const __dirname = dirname(__filename)
1919
* @param {any} value
2020
* @param {import('multiformats/block').BlockEncoder<Code, any>} codec
2121
* @param {import('multiformats/hashes/interface').MultihashHasher<Code>} hasher
22-
* @returns {CID | null}
22+
* @param {import('multiformats/cid').Version} version
23+
* @returns {Promise<CID | null>}
2324
*/
2425
const createCID = async (value, codec, hasher, version = 1) => {
2526
try {
@@ -60,9 +61,9 @@ async function testExploredCid ({ cid, type, humanReadableCID, page, fillOutForm
6061
/**
6162
* Loads saved block fixtures from fixtures/explore/blocks and adds them locally to the ipfs node
6263
* @param {object} param0
63-
* @param {import('kubo-rpc-client').IPFSHTTPClient} param0.ipfs
64+
* @param {import('kubo-rpc-client').KuboRPCClient} param0.ipfs
6465
* @param {string|string[]} param0.blockCid
65-
* @param {object} param0.blockPutArgs
66+
* @param {object} [param0.blockPutArgs]
6667
*/
6768
async function loadBlockFixtures ({ ipfs, blockCid, blockPutArgs = { format: 'v0' } }) {
6869
try {
@@ -119,19 +120,20 @@ test.describe('Explore screen', () => {
119120
})
120121

121122
test('should open dag-pb', async ({ page }) => {
123+
test.setTimeout(60000)
122124
const cidData = new Uint8Array(Buffer.from('hello world'))
123125
const dagPbAsDagJson = {
124126
Data: cidData,
125127
Links: []
126128
}
127-
const cid = await createCID(dagPbAsDagJson, dagPb, sha256, 0)
129+
const cid = await createCID(dagPbAsDagJson, dagPb, sha256, 0) // QmU1Sq1B7RPQD2XcQNLB58qJUyJffVJqihcxmmN1STPMxf
128130

129131
// add bytes to backend node so that explore page can load the content
130132
const cidInstance = await ipfs.dag.put(dagPbAsDagJson, {
131133
storeCodec: 'dag-pb',
132134
hashAlg: 'sha2-256'
133135
})
134-
const dagPbCid = cidInstance.toString()
136+
const dagPbCid = cidInstance.toString() // bafybeicuhktpnonfgpel7acwqcim34slne5kul43k5fdg6cnqrrp3rkxtq
135137

136138
await testExploredCid({
137139
page,
@@ -174,7 +176,7 @@ test.describe('Explore screen', () => {
174176
})
175177

176178
test('should open dag-pb unixFS XKCD Archives', async ({ page }) => {
177-
test.setTimeout(60000)
179+
test.setTimeout(120000)
178180
await loadBlockFixtures({
179181
ipfs,
180182
blockCid: [
@@ -212,7 +214,7 @@ test.describe('Explore screen', () => {
212214
})
213215

214216
test('should explore Project Apollo Archive', async ({ page }) => {
215-
test.setTimeout(90000)
217+
test.setTimeout(240000)
216218
await loadBlockFixtures({
217219
ipfs,
218220
blockCid: [

test/e2e/fixtures/generateFixtures.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ save_fixture() {
88
shift
99
local fixture_path="$1/$fixture_cid"
1010
echo -e "\$fixture_path: $fixture_path \n"
11-
ipfs block get $fixture_cid > $fixture_path
11+
npx kubo block get $fixture_cid > $fixture_path
1212
}
1313

1414
# Example call:

test/e2e/ipns.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from './setup/coverage.js'
2-
import { createController } from 'ipfsd-ctl'
3-
import { path as getGoIpfsPath } from 'kubo'
4-
import * as kuboRpcModule from 'kubo-rpc-client'
2+
import { createNode } from 'ipfsd-ctl'
3+
import { path as kuboPath } from 'kubo'
4+
import { create } from 'kubo-rpc-client'
55

66
// TODO: Fix parallelism of these tests
77
test.describe.configure({ mode: 'serial' })
@@ -12,10 +12,10 @@ test.describe('IPNS publishing', () => {
1212

1313
test.beforeAll(async () => {
1414
// spawn a second ephemeral local node as a peer for ipns publishing
15-
ipfsd = await createController({
16-
type: 'go',
17-
ipfsBin: getGoIpfsPath(),
18-
kuboRpcModule,
15+
ipfsd = await createNode({
16+
type: 'kubo',
17+
bin: process.env.IPFS_GO_EXEC || kuboPath(),
18+
rpc: create,
1919
test: true,
2020
disposable: true
2121
})
@@ -26,7 +26,7 @@ test.describe('IPNS publishing', () => {
2626
test.describe('Settings screen', () => {
2727
let ipfs
2828
test.beforeEach(async ({ page }) => {
29-
ipfs = kuboRpcModule.create(process.env.IPFS_RPC_ADDR)
29+
ipfs = create(process.env.IPFS_RPC_ADDR)
3030
await page.goto('/#/settings')
3131
})
3232
test('should list IPNS keys', async ({ page }) => {
@@ -76,7 +76,7 @@ test.describe('IPNS publishing', () => {
7676
let ipfs
7777
test.beforeEach(async ({ page }) => {
7878
keyName = 'pet-name-e2e-ipns-test-' + new Date().getTime() + Math.random().toString(16).slice(2)
79-
ipfs = kuboRpcModule.create(process.env.IPFS_RPC_ADDR)
79+
ipfs = create(process.env.IPFS_RPC_ADDR)
8080
await ipfs.key.gen(keyName)
8181
await page.goto('/#/files')
8282
await page.reload()

test/e2e/peers.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from './setup/coverage.js'
2-
import { createController } from 'ipfsd-ctl'
3-
import * as kuboRpcModule from 'kubo-rpc-client'
4-
import { path as getGoIpfsPath } from 'kubo'
2+
import { createNode } from 'ipfsd-ctl'
3+
import { create } from 'kubo-rpc-client'
4+
import { path as kuboPath } from 'kubo'
55

66
const addConnection = 'text=Add connection'
77

@@ -10,18 +10,18 @@ test.describe('Peers screen', () => {
1010
let peeraddr
1111
test.beforeAll(async () => {
1212
// spawn an ephemeral local node for manual swarm connect test
13-
ipfsd = await createController({
14-
type: 'go',
15-
ipfsBin: getGoIpfsPath(),
16-
kuboRpcModule,
13+
ipfsd = await createNode({
14+
type: 'kubo',
15+
bin: process.env.IPFS_GO_EXEC || kuboPath(),
16+
rpc: create,
1717
test: true,
1818
disposable: true
1919
})
2020
const { addresses } = await ipfsd.api.id()
2121
peeraddr = addresses.find((ma) => ma.toString().startsWith('/ip4/127.0.0.1')).toString()
2222

2323
// connect ipfs-backend used by webui to this new peer to have something in the peer table
24-
const webuiIpfs = kuboRpcModule.create(process.env.IPFS_RPC_ADDR)
24+
const webuiIpfs = create(process.env.IPFS_RPC_ADDR)
2525
await webuiIpfs.swarm.connect(peeraddr)
2626
})
2727

test/e2e/remote-rpc-api.test.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
// @ts-check
12
import { test, expect } from './setup/coverage.js'
2-
import { createController } from 'ipfsd-ctl'
3-
import getPort from 'get-port'
3+
import { createNode } from 'ipfsd-ctl'
4+
import getPort from 'aegir/get-port'
45
import { createServer } from 'http'
56
import httpProxy from 'http-proxy'
67
import basicAuth from 'basic-auth'
78
import { multiaddrToUri as toUri } from '@multiformats/multiaddr-to-uri'
8-
import { path as getGoIpfsPath } from 'kubo'
9-
import * as kuboRpcModule from 'kubo-rpc-client'
9+
import { path as kuboPath } from 'kubo'
10+
import { create } from 'kubo-rpc-client'
1011
const { createProxyServer } = httpProxy
1112

13+
// we need these tests to run in serial otherwise we try to start up two nodes on the same port
14+
test.describe.configure({ mode: 'serial' })
15+
1216
test.describe('Remote RPC API tests', () => {
1317
// Basic Auth Proxy Setup
1418
// -----------------------------------
@@ -24,16 +28,32 @@ test.describe('Remote RPC API tests', () => {
2428
let password
2529
let proxyPort
2630

27-
let rpcMaddr
31+
let rpcPort
32+
let rpcAddr
2833
let rpcUrl
2934
let rpcId
3035

3136
test.beforeAll(async () => {
32-
// spawn an ephemeral local node to ensure we connect to a different, remote node
33-
ipfsd = await createController({
34-
type: 'go',
35-
ipfsBin: getGoIpfsPath(),
36-
kuboRpcModule,
37+
rpcPort = await getPort(55055, '0.0.0.0')
38+
rpcAddr = `/ip4/127.0.0.1/tcp/${rpcPort}`
39+
// spawn an ephemeral local node to ensure we connect to a different, remote node
40+
ipfsd = await createNode({
41+
type: 'kubo',
42+
bin: kuboPath(),
43+
rpc: create,
44+
init: {
45+
config: {
46+
Addresses: {
47+
API: rpcAddr
48+
},
49+
Gateway: {
50+
NoFetch: true
51+
},
52+
Routing: {
53+
Type: 'none'
54+
}
55+
}
56+
},
3757
test: true,
3858
disposable: true
3959
})
@@ -46,8 +66,7 @@ test.describe('Remote RPC API tests', () => {
4666
password = 'pass'
4767

4868
const proxy = createProxyServer()
49-
rpcMaddr = ipfsd.apiAddr.toString()
50-
const remoteApiUrl = toUri(rpcMaddr, { assumeHttp: true })
69+
const remoteApiUrl = toUri(rpcAddr, { assumeHttp: true })
5170
rpcUrl = new URL(remoteApiUrl).toString() // normalization for browsers
5271
proxy.on('proxyReq', (proxyReq, req, res, options) => {
5372
// swap Origin before passing to the real API
@@ -57,21 +76,19 @@ test.describe('Remote RPC API tests', () => {
5776
proxyReq.setHeader('Host', new URL(remoteApiUrl).host)
5877
})
5978

60-
proxy.on('error', function (err, req, res) {
79+
proxy.on('error', function (err, req, /** @type {import('http').ServerResponse} */ res) {
6180
res.writeHead(500, { 'Content-Type': 'text/plain' })
6281
res.end(`proxyd error: ${JSON.stringify(err)}`)
6382
})
6483

6584
proxyd = createServer((req, res) => {
66-
// console.log(`${req.method}\t\t${req.url}`)
67-
68-
res.oldWriteHead = res.writeHead
85+
const oldWriteHead = res.writeHead.bind(res)
6986
res.writeHead = function (statusCode, headers) {
7087
// hardcoded liberal CORS for easier testing
7188
res.setHeader('Access-Control-Allow-Origin', '*')
7289
// usual suspects + 'authorization' header
7390
res.setHeader('Access-Control-Allow-Headers', 'X-Stream-Output, X-Chunked-Output, X-Content-Length, authorization')
74-
res.oldWriteHead(statusCode)
91+
return oldWriteHead(statusCode)
7592
}
7693

7794
const auth = basicAuth(req)
@@ -139,8 +156,7 @@ test.describe('Remote RPC API tests', () => {
139156
endpoint = uri.port || endpoint
140157
}
141158
} catch (_) {}
142-
// await page.waitForFunction(`localStorage.getItem('ipfsApi') && localStorage.getItem('ipfsApi').includes('${endpoint}')`)
143-
await page.waitForFunction(endpoint => window.localStorage.getItem('ipfsApi') && window.localStorage.getItem('ipfsApi').includes(endpoint), endpoint)
159+
await page.waitForFunction(endpoint => window.localStorage.getItem('ipfsApi')?.includes(endpoint), endpoint)
144160
return
145161
}
146162
await page.waitForFunction(() => window.localStorage.getItem('ipfsApi') === null)
@@ -203,19 +219,19 @@ test.describe('Remote RPC API tests', () => {
203219

204220
test.describe('RPC @ multiaddr', () => {
205221
test('should be possible to set via Settings page', async ({ page }) => {
206-
await switchIpfsApiEndpointViaSettings(rpcMaddr, page)
222+
await switchIpfsApiEndpointViaSettings(rpcAddr, page)
207223
await expectPeerIdOnStatusPage(rpcId, page)
208224
})
209225

210226
test('should show full multiaddr on Status page', async ({ page }) => {
211-
await switchIpfsApiEndpointViaSettings(rpcMaddr, page)
212-
await expectHttpApiAddressOnStatusPage(rpcMaddr, page)
227+
await switchIpfsApiEndpointViaSettings(rpcAddr, page)
228+
await expectHttpApiAddressOnStatusPage(rpcAddr, page)
213229
await expectPeerIdOnStatusPage(rpcId, page)
214230
})
215231

216232
test('should show full multiaddr on Settings page', async ({ page }) => {
217-
await switchIpfsApiEndpointViaSettings(rpcMaddr, page)
218-
await expectHttpApiAddressOnSettingsPage(rpcMaddr, page)
233+
await switchIpfsApiEndpointViaSettings(rpcAddr, page)
234+
await expectHttpApiAddressOnSettingsPage(rpcAddr, page)
219235
})
220236
})
221237

test/e2e/setup/global-setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const globalSetup = async config => {
5050
const rpcEndpoint = `${apiOpts.protocol}://${apiOpts.host}:${apiOpts.port}`
5151

5252
await page.context().addInitScript(({ kuboGateway, rpcEndpoint }) => {
53-
localStorage.setItem('kuboGateway', JSON.stringify(kuboGateway))
53+
localStorage.setItem('kuboGateway', JSON.stringify({ ...kuboGateway, trustlessBlockBrokerConfig: { init: { allowInsecure: true, allowLocal: true } } }))
5454
localStorage.setItem('ipfsApi', JSON.stringify(rpcEndpoint))
5555
localStorage.setItem('explore.ipld.gatewayEnabled', 'false') // disable gateway network requests when testing e2e
5656
}, { rpcEndpoint, kuboGateway })

0 commit comments

Comments
 (0)