This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathipns.js
135 lines (107 loc) · 3.18 KB
/
ipns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* eslint-env mocha */
import os from 'os'
import path from 'path'
import { nanoid } from 'nanoid'
import delay from 'delay'
import last from 'it-last'
import { expect } from 'aegir/chai'
import { daemonFactory } from './utils/daemon-factory.js'
/**
* @typedef {import('ipfsd-ctl').Controller} Controller
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
const dir = path.join(os.tmpdir(), nanoid())
const daemonOptions = {
disposable: false,
args: ['--offline'],
ipfsOptions: {
repo: dir
}
}
const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'
/**
* @param {Controller} publisherDaemon
* @param {Controller} [resolverDaemon]
*/
const publishAndResolve = async (publisherDaemon, resolverDaemon) => {
let sameDaemon = false
if (!resolverDaemon) {
resolverDaemon = publisherDaemon
sameDaemon = true
}
const stopPublisherAndStartResolverDaemon = async () => {
await publisherDaemon.stop()
await delay(2000)
if (resolverDaemon != null) {
await resolverDaemon.start()
}
}
await publisherDaemon.init()
await publisherDaemon.start()
const nodeId = publisherDaemon.peer.id
await publisherDaemon.api.name.publish(ipfsRef, {
resolve: false,
allowOffline: true
})
!sameDaemon && await stopPublisherAndStartResolverDaemon()
const res = await last(resolverDaemon.api.name.resolve(nodeId))
expect(res).to.equal(ipfsRef)
await resolverDaemon.stop()
await delay(2000)
await resolverDaemon.cleanup()
}
describe('ipns locally using the same repo across implementations', function () {
this.timeout(160e3)
/** @type {Factory} */
let factory
before(async () => {
factory = await daemonFactory()
})
afterEach(() => factory.clean())
it('should publish an ipns record to a js daemon and resolve it using the same js daemon', async function () {
const jsDaemon = await factory.spawn({
...daemonOptions,
type: 'js'
})
await publishAndResolve(jsDaemon)
})
it('should publish an ipns record to a go daemon and resolve it using the same go daemon', async function () {
const goDaemon = await factory.spawn({
...daemonOptions,
type: 'go'
})
await publishAndResolve(goDaemon)
})
// FIXME: https://github.com/ipfs/js-ipfs/issues/1467
//
// Repo versions are different.
it.skip('should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo', async function () {
const daemons = await Promise.all([
factory.spawn({
...daemonOptions,
type: 'js'
}),
factory.spawn({
...daemonOptions,
type: 'go'
})
])
await publishAndResolve(daemons[0], daemons[1])
})
// FIXME: https://github.com/ipfs/js-ipfs/issues/1467
//
// Repo versions are different.
it.skip('should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo', async function () {
const daemons = await Promise.all([
factory.spawn({
...daemonOptions,
type: 'go'
}),
factory.spawn({
...daemonOptions,
type: 'js'
})
])
await publishAndResolve(daemons[0], daemons[1])
})
})