From c2545520418567a2a57fb09616a1b9b76cd63872 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 20 Oct 2022 20:22:07 +0200 Subject: [PATCH] chore: update deps, allow tests to run offline --- packages/interface-ipfs-core/package.json | 2 +- .../src/miscellaneous/dns.js | 30 ++++- .../src/miscellaneous/resolve.js | 16 ++- .../interface-ipfs-core/src/name/resolve.js | 126 +++++++++++++++--- packages/ipfs-core/package.json | 2 +- packages/ipfs-http-client/package.json | 2 +- packages/ipfs/package.json | 1 + 7 files changed, 150 insertions(+), 29 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index bef82a5caa..350bdc6acd 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -80,7 +80,7 @@ "aegir": "^37.0.11", "blockstore-core": "^2.0.1", "copyfiles": "^2.4.1", - "dag-jose": "^3.0.0", + "dag-jose": "^3.0.1", "delay": "^5.0.0", "did-jwt": "^6.2.0", "err-code": "^3.0.1", diff --git a/packages/interface-ipfs-core/src/miscellaneous/dns.js b/packages/interface-ipfs-core/src/miscellaneous/dns.js index 36270e5e1d..3ca5b7d54f 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/dns.js +++ b/packages/interface-ipfs-core/src/miscellaneous/dns.js @@ -29,8 +29,10 @@ export function testDns (factory, options) { after(() => factory.clean()) it('should non-recursively resolve ipfs.io', async function () { + const domain = 'ipfs.io' + try { - const res = await ipfs.dns('ipfs.io', { recursive: false }) + const res = await ipfs.dns(domain, { recursive: false }) // matches pattern /ipns/ expect(res).to.match(/\/ipns\/.+$/) @@ -40,13 +42,21 @@ export function testDns (factory, options) { return this.skip() } + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + throw err } }) it('should recursively resolve ipfs.io', async function () { + const domain = 'ipfs.io' + try { - const res = await ipfs.dns('ipfs.io', { recursive: true }) + const res = await ipfs.dns(domain, { recursive: true }) // matches pattern /ipfs/ expect(res).to.match(/\/ipfs\/.+$/) @@ -56,13 +66,21 @@ export function testDns (factory, options) { return this.skip() } + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + throw err } }) it('should resolve subdomain docs.ipfs.io', async function () { + const domain = 'docs.ipfs.io' + try { - const res = await ipfs.dns('docs.ipfs.io') + const res = await ipfs.dns(domain) // matches pattern /ipfs/ expect(res).to.match(/\/ipfs\/.+$/) @@ -72,6 +90,12 @@ export function testDns (factory, options) { return this.skip() } + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + throw err } }) diff --git a/packages/interface-ipfs-core/src/miscellaneous/resolve.js b/packages/interface-ipfs-core/src/miscellaneous/resolve.js index 8ca3fd0eba..49e004c4fa 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/resolve.js +++ b/packages/interface-ipfs-core/src/miscellaneous/resolve.js @@ -96,9 +96,21 @@ export function testResolve (factory, options) { it('should resolve an IPNS DNS link', async function () { // @ts-expect-error this is mocha this.retries(3) - const resolved = await ipfs.resolve('/ipns/ipfs.io') + const domain = 'ipfs.io' - expect(isIpfs.ipfsPath(resolved)).to.be.true() + try { + const resolved = await ipfs.resolve(`/ipns/${domain}`) + + expect(isIpfs.ipfsPath(resolved)).to.be.true() + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) it('should resolve IPNS link recursively by default', async function () { diff --git a/packages/interface-ipfs-core/src/name/resolve.js b/packages/interface-ipfs-core/src/name/resolve.js index f1fa281733..69deee2ff9 100644 --- a/packages/interface-ipfs-core/src/name/resolve.js +++ b/packages/interface-ipfs-core/src/name/resolve.js @@ -160,34 +160,106 @@ export function testResolve (factory, options) { after(() => factory.clean()) - it('should resolve /ipns/ipfs.io', async () => { - expect(await last(ipfs.name.resolve('/ipns/ipfs.io'))) - .to.match(/\/ipfs\/.+$/) + it('should resolve /ipns/ipfs.io', async function () { + const domain = 'ipfs.io' + + try { + expect(await last(ipfs.name.resolve(`/ipns/${domain}`))) + .to.match(/\/ipfs\/.+$/) + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) - it('should resolve /ipns/ipfs.io recursive === false', async () => { - expect(await last(ipfs.name.resolve('/ipns/ipfs.io', { recursive: false }))) - .to.match(/\/ipns\/.+$/) + it('should resolve /ipns/ipfs.io recursive === false', async function () { + const domain = 'ipfs.io' + + try { + expect(await last(ipfs.name.resolve(`/ipns/${domain}`, { recursive: false }))) + .to.match(/\/ipns\/.+$/) + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) - it('should resolve /ipns/ipfs.io recursive === true', async () => { - expect(await last(ipfs.name.resolve('/ipns/ipfs.io', { recursive: true }))) - .to.match(/\/ipfs\/.+$/) + it('should resolve /ipns/ipfs.io recursive === true', async function () { + const domain = 'ipfs.io' + + try { + expect(await last(ipfs.name.resolve(`/ipns/${domain}`, { recursive: true }))) + .to.match(/\/ipfs\/.+$/) + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) - it('should resolve /ipns/ipfs.io with remainder', async () => { - expect(await last(ipfs.name.resolve('/ipns/ipfs.io/images/ipfs-logo.svg'))) - .to.match(/\/ipfs\/.+\/images\/ipfs-logo.svg$/) + it('should resolve /ipns/ipfs.io with remainder', async function () { + const domain = 'ipfs.io' + + try { + expect(await last(ipfs.name.resolve(`/ipns/${domain}/images/ipfs-logo.svg`))) + .to.match(/\/ipfs\/.+\/images\/ipfs-logo.svg$/) + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) - it('should resolve /ipns/ipfs.io with remainder recursive === false', async () => { - expect(await last(ipfs.name.resolve('/ipns/ipfs.io/images/ipfs-logo.svg', { recursive: false }))) - .to.match(/\/ipns\/.+\/images\/ipfs-logo.svg$/) + it('should resolve /ipns/ipfs.io with remainder recursive === false', async function () { + const domain = 'ipfs.io' + + try { + expect(await last(ipfs.name.resolve(`/ipns/${domain}/images/ipfs-logo.svg`, { recursive: false }))) + .to.match(/\/ipns\/.+\/images\/ipfs-logo.svg$/) + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) - it('should resolve /ipns/ipfs.io with remainder recursive === true', async () => { - expect(await last(ipfs.name.resolve('/ipns/ipfs.io/images/ipfs-logo.svg', { recursive: true }))) - .to.match(/\/ipfs\/.+\/images\/ipfs-logo.svg$/) + it('should resolve /ipns/ipfs.io with remainder recursive === true', async function () { + const domain = 'ipfs.io' + + try { + expect(await last(ipfs.name.resolve(`/ipns/${domain}/images/ipfs-logo.svg`, { recursive: true }))) + .to.match(/\/ipfs\/.+\/images\/ipfs-logo.svg$/) + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) it('should fail to resolve /ipns/ipfs.a', async () => { @@ -198,9 +270,21 @@ export function testResolve (factory, options) { } }) - it('should resolve ipns path with hamt-shard recursive === true', async () => { - expect(await last(ipfs.name.resolve('/ipns/tr.wikipedia-on-ipfs.org/wiki/Anasayfa.html', { recursive: true }))) - .to.match(/\/ipfs\/.+$/) + it('should resolve ipns path with hamt-shard recursive === true', async function () { + const domain = 'tr.wikipedia-on-ipfs.org' + + try { + expect(await last(ipfs.name.resolve(`/ipns/${domain}/wiki/Anasayfa.html`, { recursive: true }))) + .to.match(/\/ipfs\/.+$/) + } catch (/** @type {any} */ err) { + // happens when running tests offline + if (err.message.includes(`ECONNREFUSED ${domain}`)) { + // @ts-expect-error this is mocha + return this.skip() + } + + throw err + } }) }) } diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 9ae3ec1f86..4f9ffcd02d 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -102,7 +102,7 @@ "any-signal": "^3.0.0", "array-shuffle": "^3.0.0", "blockstore-core": "^2.0.1", - "dag-jose": "^3.0.0", + "dag-jose": "^3.0.1", "datastore-core": "^8.0.1", "datastore-pubsub": "^6.0.0", "dlv": "^1.1.3", diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index 014a8b25c4..4f3ce60095 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -74,7 +74,7 @@ "@libp2p/peer-id": "^1.1.10", "@multiformats/multiaddr": "^11.0.0", "any-signal": "^3.0.0", - "dag-jose": "^3.0.0", + "dag-jose": "^3.0.1", "err-code": "^3.0.1", "ipfs-core-types": "^0.12.1", "ipfs-core-utils": "^0.16.1", diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 4f16e6f2c6..8118f046bb 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -99,6 +99,7 @@ "ipfs-utils": "^9.0.6", "ipfsd-ctl": "^12.0.3", "iso-url": "^1.0.0", + "kubo-rpc-client": "^1.0.1", "merge-options": "^3.0.4", "mock-ipfs-pinning-service": "^0.4.2", "url": "^0.11.0",