Skip to content

Commit

Permalink
chore: use [email protected] (#2257)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
SgtPooki and lidel authored Sep 13, 2024
1 parent 2250374 commit 99ba9ac
Show file tree
Hide file tree
Showing 11 changed files with 1,768 additions and 5,466 deletions.
7,049 changes: 1,663 additions & 5,386 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
"ipfs-css": "^1.4.0",
"ipfs-geoip": "^9.1.0",
"ipfs-provider": "^2.1.0",
"ipld-explorer-components": "^5.2.0",
"ipld-explorer-components": "^7.0.2",
"is-ipfs": "^8.0.1",
"istextorbinary": "^6.0.0",
"it-all": "^1.0.5",
"it-first": "^1.0.6",
"it-last": "^1.0.5",
"it-map": "^1.0.5",
"kubo-rpc-client": "^3.0.2",
"kubo-rpc-client": "^4.1.1",
"milliseconds": "^1.0.3",
"money-clip": "^3.0.5",
"multiformats": "^13.0.1",
Expand Down Expand Up @@ -164,10 +164,10 @@
"http-proxy": "^1.18.1",
"http-server": "^14.1.1",
"ipfs": "0.58.3",
"ipfsd-ctl": "^13.0.0",
"ipfsd-ctl": "^14.1.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"kubo": "^0.24.0",
"kubo": "^0.30.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"os-browserify": "^0.3.0",
Expand Down
16 changes: 7 additions & 9 deletions src/bundles/identity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ describe.skip('identity.js', function () {
let ipfs
let ipfsd
beforeAll(async () => {
// const kuboRpcModule = await import('kubo-rpc-client')
// console.log('kuboRpcModule: ', kuboRpcModule)
const kuboRpcModule = await import('kubo-rpc-client')
const { createController } = await import('ipfsd-ctl')
const { create } = await import('kubo-rpc-client')
const { createNode } = await import('ipfsd-ctl')
const ipfsBin = (await import('kubo')).default.path()
console.log('ipfsBin: ', ipfsBin)
/**
Expand All @@ -41,16 +39,16 @@ describe.skip('identity.js', function () {
*/
const KUBO_PORT = process.env.KUBO_PORT_2033_TEST
if (KUBO_PORT == null) {
ipfsd = await createController({
type: 'go',
ipfsBin,
kuboRpcModule,
ipfsd = await createNode({
type: 'kubo',
bin: ipfsBin,
rpc: create,
test: true,
disposable: true
})
ipfs = ipfsd.api
} else {
ipfs = kuboRpcModule(`http://localhost:${KUBO_PORT}`)
ipfs = create(`http://127.0.0.1:${KUBO_PORT}`)
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/bundles/ipfs-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ const actions = {
const result = await getIpfs({
/**
*
* @param {import('kubo-rpc-client').IPFSHTTPClient} ipfs
* @param {import('kubo-rpc-client').KuboRPCClient} ipfs
* @returns {Promise<boolean>}
*/
connectionTest: async (ipfs) => {
Expand Down
16 changes: 9 additions & 7 deletions test/e2e/explore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const __dirname = dirname(__filename)
* @param {any} value
* @param {import('multiformats/block').BlockEncoder<Code, any>} codec
* @param {import('multiformats/hashes/interface').MultihashHasher<Code>} hasher
* @returns {CID | null}
* @param {import('multiformats/cid').Version} version
* @returns {Promise<CID | null>}
*/
const createCID = async (value, codec, hasher, version = 1) => {
try {
Expand Down Expand Up @@ -60,9 +61,9 @@ async function testExploredCid ({ cid, type, humanReadableCID, page, fillOutForm
/**
* Loads saved block fixtures from fixtures/explore/blocks and adds them locally to the ipfs node
* @param {object} param0
* @param {import('kubo-rpc-client').IPFSHTTPClient} param0.ipfs
* @param {import('kubo-rpc-client').KuboRPCClient} param0.ipfs
* @param {string|string[]} param0.blockCid
* @param {object} param0.blockPutArgs
* @param {object} [param0.blockPutArgs]
*/
async function loadBlockFixtures ({ ipfs, blockCid, blockPutArgs = { format: 'v0' } }) {
try {
Expand Down Expand Up @@ -119,19 +120,20 @@ test.describe('Explore screen', () => {
})

test('should open dag-pb', async ({ page }) => {
test.setTimeout(60000)
const cidData = new Uint8Array(Buffer.from('hello world'))
const dagPbAsDagJson = {
Data: cidData,
Links: []
}
const cid = await createCID(dagPbAsDagJson, dagPb, sha256, 0)
const cid = await createCID(dagPbAsDagJson, dagPb, sha256, 0) // QmU1Sq1B7RPQD2XcQNLB58qJUyJffVJqihcxmmN1STPMxf

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

await testExploredCid({
page,
Expand Down Expand Up @@ -174,7 +176,7 @@ test.describe('Explore screen', () => {
})

test('should open dag-pb unixFS XKCD Archives', async ({ page }) => {
test.setTimeout(60000)
test.setTimeout(120000)
await loadBlockFixtures({
ipfs,
blockCid: [
Expand Down Expand Up @@ -212,7 +214,7 @@ test.describe('Explore screen', () => {
})

test('should explore Project Apollo Archive', async ({ page }) => {
test.setTimeout(90000)
test.setTimeout(240000)
await loadBlockFixtures({
ipfs,
blockCid: [
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixtures/generateFixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ save_fixture() {
shift
local fixture_path="$1/$fixture_cid"
echo -e "\$fixture_path: $fixture_path \n"
ipfs block get $fixture_cid > $fixture_path
npx kubo block get $fixture_cid > $fixture_path
}

# Example call:
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/ipns.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from './setup/coverage.js'
import { createController } from 'ipfsd-ctl'
import { path as getGoIpfsPath } from 'kubo'
import * as kuboRpcModule from 'kubo-rpc-client'
import { createNode } from 'ipfsd-ctl'
import { path as kuboPath } from 'kubo'
import { create } from 'kubo-rpc-client'

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

test.beforeAll(async () => {
// spawn a second ephemeral local node as a peer for ipns publishing
ipfsd = await createController({
type: 'go',
ipfsBin: getGoIpfsPath(),
kuboRpcModule,
ipfsd = await createNode({
type: 'kubo',
bin: process.env.IPFS_GO_EXEC || kuboPath(),
rpc: create,
test: true,
disposable: true
})
Expand All @@ -26,7 +26,7 @@ test.describe('IPNS publishing', () => {
test.describe('Settings screen', () => {
let ipfs
test.beforeEach(async ({ page }) => {
ipfs = kuboRpcModule.create(process.env.IPFS_RPC_ADDR)
ipfs = create(process.env.IPFS_RPC_ADDR)
await page.goto('/#/settings')
})
test('should list IPNS keys', async ({ page }) => {
Expand Down Expand Up @@ -76,7 +76,7 @@ test.describe('IPNS publishing', () => {
let ipfs
test.beforeEach(async ({ page }) => {
keyName = 'pet-name-e2e-ipns-test-' + new Date().getTime() + Math.random().toString(16).slice(2)
ipfs = kuboRpcModule.create(process.env.IPFS_RPC_ADDR)
ipfs = create(process.env.IPFS_RPC_ADDR)
await ipfs.key.gen(keyName)
await page.goto('/#/files')
await page.reload()
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/peers.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from './setup/coverage.js'
import { createController } from 'ipfsd-ctl'
import * as kuboRpcModule from 'kubo-rpc-client'
import { path as getGoIpfsPath } from 'kubo'
import { createNode } from 'ipfsd-ctl'
import { create } from 'kubo-rpc-client'
import { path as kuboPath } from 'kubo'

const addConnection = 'text=Add connection'

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

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

Expand Down
64 changes: 40 additions & 24 deletions test/e2e/remote-rpc-api.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// @ts-check
import { test, expect } from './setup/coverage.js'
import { createController } from 'ipfsd-ctl'
import getPort from 'get-port'
import { createNode } from 'ipfsd-ctl'
import getPort from 'aegir/get-port'
import { createServer } from 'http'
import httpProxy from 'http-proxy'
import basicAuth from 'basic-auth'
import { multiaddrToUri as toUri } from '@multiformats/multiaddr-to-uri'
import { path as getGoIpfsPath } from 'kubo'
import * as kuboRpcModule from 'kubo-rpc-client'
import { path as kuboPath } from 'kubo'
import { create } from 'kubo-rpc-client'
const { createProxyServer } = httpProxy

// we need these tests to run in serial otherwise we try to start up two nodes on the same port
test.describe.configure({ mode: 'serial' })

test.describe('Remote RPC API tests', () => {
// Basic Auth Proxy Setup
// -----------------------------------
Expand All @@ -24,16 +28,32 @@ test.describe('Remote RPC API tests', () => {
let password
let proxyPort

let rpcMaddr
let rpcPort
let rpcAddr
let rpcUrl
let rpcId

test.beforeAll(async () => {
// spawn an ephemeral local node to ensure we connect to a different, remote node
ipfsd = await createController({
type: 'go',
ipfsBin: getGoIpfsPath(),
kuboRpcModule,
rpcPort = await getPort(55055, '0.0.0.0')
rpcAddr = `/ip4/127.0.0.1/tcp/${rpcPort}`
// spawn an ephemeral local node to ensure we connect to a different, remote node
ipfsd = await createNode({
type: 'kubo',
bin: kuboPath(),
rpc: create,
init: {
config: {
Addresses: {
API: rpcAddr
},
Gateway: {
NoFetch: true
},
Routing: {
Type: 'none'
}
}
},
test: true,
disposable: true
})
Expand All @@ -46,8 +66,7 @@ test.describe('Remote RPC API tests', () => {
password = 'pass'

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

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

proxyd = createServer((req, res) => {
// console.log(`${req.method}\t\t${req.url}`)

res.oldWriteHead = res.writeHead
const oldWriteHead = res.writeHead.bind(res)
res.writeHead = function (statusCode, headers) {
// hardcoded liberal CORS for easier testing
res.setHeader('Access-Control-Allow-Origin', '*')
// usual suspects + 'authorization' header
res.setHeader('Access-Control-Allow-Headers', 'X-Stream-Output, X-Chunked-Output, X-Content-Length, authorization')
res.oldWriteHead(statusCode)
return oldWriteHead(statusCode)
}

const auth = basicAuth(req)
Expand Down Expand Up @@ -139,8 +156,7 @@ test.describe('Remote RPC API tests', () => {
endpoint = uri.port || endpoint
}
} catch (_) {}
// await page.waitForFunction(`localStorage.getItem('ipfsApi') && localStorage.getItem('ipfsApi').includes('${endpoint}')`)
await page.waitForFunction(endpoint => window.localStorage.getItem('ipfsApi') && window.localStorage.getItem('ipfsApi').includes(endpoint), endpoint)
await page.waitForFunction(endpoint => window.localStorage.getItem('ipfsApi')?.includes(endpoint), endpoint)
return
}
await page.waitForFunction(() => window.localStorage.getItem('ipfsApi') === null)
Expand Down Expand Up @@ -203,19 +219,19 @@ test.describe('Remote RPC API tests', () => {

test.describe('RPC @ multiaddr', () => {
test('should be possible to set via Settings page', async ({ page }) => {
await switchIpfsApiEndpointViaSettings(rpcMaddr, page)
await switchIpfsApiEndpointViaSettings(rpcAddr, page)
await expectPeerIdOnStatusPage(rpcId, page)
})

test('should show full multiaddr on Status page', async ({ page }) => {
await switchIpfsApiEndpointViaSettings(rpcMaddr, page)
await expectHttpApiAddressOnStatusPage(rpcMaddr, page)
await switchIpfsApiEndpointViaSettings(rpcAddr, page)
await expectHttpApiAddressOnStatusPage(rpcAddr, page)
await expectPeerIdOnStatusPage(rpcId, page)
})

test('should show full multiaddr on Settings page', async ({ page }) => {
await switchIpfsApiEndpointViaSettings(rpcMaddr, page)
await expectHttpApiAddressOnSettingsPage(rpcMaddr, page)
await switchIpfsApiEndpointViaSettings(rpcAddr, page)
await expectHttpApiAddressOnSettingsPage(rpcAddr, page)
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/setup/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const globalSetup = async config => {
const rpcEndpoint = `${apiOpts.protocol}://${apiOpts.host}:${apiOpts.port}`

await page.context().addInitScript(({ kuboGateway, rpcEndpoint }) => {
localStorage.setItem('kuboGateway', JSON.stringify(kuboGateway))
localStorage.setItem('kuboGateway', JSON.stringify({ ...kuboGateway, trustlessBlockBrokerConfig: { init: { allowInsecure: true, allowLocal: true } } }))
localStorage.setItem('ipfsApi', JSON.stringify(rpcEndpoint))
localStorage.setItem('explore.ipld.gatewayEnabled', 'false') // disable gateway network requests when testing e2e
}, { rpcEndpoint, kuboGateway })
Expand Down
Loading

0 comments on commit 99ba9ac

Please sign in to comment.