Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
feat: enable relay v2 tests for js-ipfs
Browse files Browse the repository at this point in the history
Circuit Relay v2 is being implemented in libp2p/js-libp2p#1533
so enable the tests
  • Loading branch information
achingbrain committed Jan 18, 2023
1 parent 6e54c07 commit 8b2c6e6
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 76 deletions.
50 changes: 0 additions & 50 deletions test/circuit/v1/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,55 +67,5 @@ export default {
createJs([randomWsAddr], factory)
])
}
},

// Below are legacy tests that use js-ipfs as v1 relay
// (no tests for go-ipfs as relay v1, because since 0.11 it only supports v2)
// FIXME: remove after js-ipfs migrates to v2

'go-js-go': {
/**
* @param {Factory} factory
*/
create: async (factory) => {
return Promise.all([
createGo([randomWsAddr], factory),
createJs([randomWsAddr], factory),
createGo([randomWsAddr], factory)
])
}
},
'js-js-go': {
/**
* @param {Factory} factory
*/
create: async (factory) => {
return Promise.all([
createJs([randomWsAddr], factory),
createJs([randomWsAddr], factory),
createGo([randomWsAddr], factory)
])
}
},
'go-js-js': {
/**
* @param {Factory} factory
*/
create: (factory) => Promise.all([
createGo([randomWsAddr], factory),
createJs([randomWsAddr], factory),
createJs([randomWsAddr], factory)
])
},
'js-js-js': {
/**
* @param {Factory} factory
*/
create: (factory) => Promise.all([
createJs([randomWsAddr], factory),
createJs([randomWsAddr], factory),
createJs([randomWsAddr], factory)
])
}

}
123 changes: 111 additions & 12 deletions test/circuit/v2/all.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */

import { createGo, createGoRelay, randomWsAddr } from '../../utils/circuit.js'
import { createGo, createJs, createGoRelay, createJsRelay, randomWsAddr } from '../../utils/circuit.js'
import { getRelayV } from '../../utils/relayd.js'

/**
Expand All @@ -28,15 +28,45 @@ export default {
},

'js-rv2-js': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await getRelayV(2)
return Promise.all([
createJs([randomWsAddr], factory),
relay,
createJs([randomWsAddr], factory, relay)
])
}
},

'js-rv2-go': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await getRelayV(2)
return Promise.all([
createJs([randomWsAddr], factory),
relay,
createGo([randomWsAddr], factory, relay)
])
}
},

'go-rv2-js': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await getRelayV(2)
return Promise.all([
createGo([randomWsAddr], factory),
relay,
createJs([randomWsAddr], factory, relay)
])
}
},

// relay v2 implementation in go-ipfs 0.11+
Expand All @@ -55,28 +85,97 @@ export default {
}
},
'js-go-go': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await createGoRelay([randomWsAddr], factory)
return Promise.all([
createJs([randomWsAddr], factory),
relay,
createGo([randomWsAddr], factory, relay)
])
}
},
'go-go-js': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await createGoRelay([randomWsAddr], factory)
return Promise.all([
createGo([randomWsAddr], factory),
relay,
createJs([randomWsAddr], factory, relay)
])
}
},
'js-go-js': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await createGoRelay([randomWsAddr], factory)
return Promise.all([
createJs([randomWsAddr], factory),
relay,
createJs([randomWsAddr], factory, relay)
])
}
},

// relay v2 implementation in js-ipfs

'go-js-go': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await createJsRelay([randomWsAddr], factory)
return Promise.all([
createGo([randomWsAddr], factory),
relay,
createGo([randomWsAddr], factory, relay)
])
}
},
'js-js-go': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await createJsRelay([randomWsAddr], factory)
return Promise.all([
createJs([randomWsAddr], factory),
relay,
createGo([randomWsAddr], factory, relay)
])
}
},
'go-js-js': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await createJsRelay([randomWsAddr], factory)
return Promise.all([
createGo([randomWsAddr], factory),
relay,
createJs([randomWsAddr], factory, relay)
])
}
},
'js-js-js': {
skip: () => true // FIXME when we have circuit v2 in js-ipfs
/**
* @param {Factory} factory
*/
create: async (factory) => {
const relay = await createJsRelay([randomWsAddr], factory)
return Promise.all([
createJs([randomWsAddr], factory),
relay,
createJs([randomWsAddr], factory, relay)
])
}
}

}
83 changes: 69 additions & 14 deletions test/utils/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const randomWsAddr = '/ip4/127.0.0.1/tcp/0/ws'
* @param {Factory} factory
* @param {Controller} [relay]
*/
export function createProc (addrs, factory, relay) {
export async function createProc (addrs, factory, relay) {
let StaticRelays
if (relay) {
throw new Error('createProc missing support for static relay v2')
StaticRelays = [await getWsAddr(relay.api)]
}
return factory.spawn({
type: 'proc',
Expand All @@ -32,14 +33,23 @@ export function createProc (addrs, factory, relay) {
Addresses: {
Swarm: addrs
},
Routing: {
Type: 'none'
Swarm: {
RelayClient: {
Enabled: true,
StaticRelays
},
RelayService: {
Enabled: false
}
},
relay: { // FIXME: this is circuit v1, needs support of v2
enabled: true,
hop: {
enabled: true
Bootstraps: [],
Discovery: {
MDNS: {
Enabled: false
}
},
Routing: {
Type: 'none'
}
},
libp2p: {
Expand All @@ -58,9 +68,10 @@ export function createProc (addrs, factory, relay) {
* @param {Factory} factory
* @param {Controller} [relay]
*/
export function createJs (addrs, factory, relay) {
export async function createJs (addrs, factory, relay) {
let StaticRelays
if (relay) {
throw new Error('createJs missing support for static relay v2')
StaticRelays = [await getWsAddr(relay.api)]
}
return factory.spawn({
type: 'js',
Expand All @@ -69,14 +80,58 @@ export function createJs (addrs, factory, relay) {
Addresses: {
Swarm: addrs
},
Swarm: {
RelayClient: {
Enabled: true,
StaticRelays
},
RelayService: {
Enabled: false
}
},
Bootstraps: [],
Discovery: {
MDNS: {
Enabled: false
}
},
Routing: {
Type: 'none'
}
}
}
})
}

/**
* @param {string[]} addrs
* @param {Factory} factory
*/
export async function createJsRelay (addrs, factory) {
return factory.spawn({
type: 'js',
ipfsOptions: {
config: {
Addresses: {
Swarm: addrs
},
relay: { // FIXME: this is circuit v1, needs support of v2
enabled: true,
hop: {
enabled: true
Swarm: {
// go uses circuit v2
RelayClient: {
Enabled: false
},
RelayService: {
Enabled: true
}
},
Bootstraps: [],
Discovery: {
MDNS: {
Enabled: false
}
},
Routing: {
Type: 'none'
}
}
}
Expand Down

0 comments on commit 8b2c6e6

Please sign in to comment.