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

Commit

Permalink
fix: ipns go -> js interoperable
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Aug 30, 2018
1 parent c3c2d2b commit 1528185
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 66 deletions.
76 changes: 21 additions & 55 deletions test/ipns.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ describe('ipns', () => {
let jsDaemon
let jsId

console.log('ipfsRepo', dir)

series([
(cb) => jsDf.spawn({
repoPath: dir,
Expand All @@ -53,7 +51,7 @@ describe('ipns', () => {
})
},
(cb) => jsDaemon.stop(cb)
// (cb) => setTimeout(cb, 10500)
// TODO cleanup repo
], done)
})

Expand Down Expand Up @@ -101,49 +99,23 @@ describe('ipns', () => {
},
(cb) => goDaemon1.stop(cb),
(cb) => goDaemon2.stop(cb)
// TODO cleanup repo
// TODO check need for 2 daemons
], done)
})
})

// Error: failed to find any peer in table
/*
series([
(cb) => goDf.spawn({
repoPath: dir,
initOptions: { bits: 1024 },
}, (err, node) => {
expect(err).to.not.exist()
goDaemon1 = node
cb()
}),
(cb) => goDaemon1.start(cb),
(cb) => goDaemon1.api.id((err, res) => {
expect(err).to.not.exist()
goId1 = res
cb()
}),
(cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb),
(cb) => {
goDaemon1.api.name.resolve(jsId, (err, res) => {
expect(err).to.not.exist()
expect(res).to.equal(ipfsRef)
cb()
})
},
(cb) => goDaemon1.stop(cb),
], done) */
})

it('should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo', function (done) {
this.timeout(100 * 1000)
this.timeout(1000 * 1000)

const dir = path.join(os.tmpdir(), hat())
const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'

let goDaemon1
let goDaemon2
let jsDaemon
let jsId
let peerId

series([
(cb) => jsDf.spawn({
Expand All @@ -152,21 +124,23 @@ describe('ipns', () => {
initOptions: { bits: 512 }
}, (err, node) => {
expect(err).to.not.exist()

jsDaemon = node
jsDaemon.init(cb)
}),
(cb) => jsDaemon.start(cb),
(cb) => jsDaemon.api.id((err, res) => {
expect(err).to.not.exist()
jsId = res.id
peerId = res.id

cb()
}),
(cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb),
(cb) => jsDaemon.stop(cb),
(cb) => setTimeout(cb, 2000),
(cb) => goDf.spawn({
repoPath: dir,
// disposable: false, // SHOULD BE NON DISPOSABLE BUT THE START FAILS (CHECK repo.js)
disposable: false,
initOptions: { bits: 1024 }
}, (err, node) => {
expect(err).to.not.exist()
Expand All @@ -180,27 +154,23 @@ describe('ipns', () => {
}),
(cb) => goDaemon1.start(cb),
(cb) => goDaemon2.start(cb),
(cb) => goDaemon1.api.id((err, res) => {
expect(err).to.not.exist()
console.log('diff id', res.id, res.id === jsId) // ID different because of non disposable
cb()
}),
(cb) => {
goDaemon1.api.name.resolve(jsId, (err, res) => {
console.log('err', err) // Different repo
console.log('res', res)
goDaemon1.api.name.resolve(peerId, { resolve: false, local: true }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.equal(ipfsRef)
cb()
})
},
(cb) => goDaemon1.stop(cb),
(cb) => goDaemon2.stop(cb)
// TODO cleanup repo
], done)
})

it('should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo', function (done) {
this.timeout(50 * 1000)
this.timeout(1000 * 1000)

const dir = path.join(os.tmpdir(), `test-ipfs-${hat()}`)
const dir = path.join(os.tmpdir(), hat())
const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'

let goDaemon1
Expand All @@ -227,6 +197,7 @@ describe('ipns', () => {
(cb) => goDaemon2.start(cb),
(cb) => goDaemon1.api.id((err, res) => {
expect(err).to.not.exist()

peerId = res.id
cb()
}),
Expand All @@ -239,26 +210,21 @@ describe('ipns', () => {
initOptions: { bits: 512 }
}, (err, node) => {
expect(err).to.not.exist()

jsDaemon = node
cb()
}),
(cb) => jsDaemon.start(cb),
(cb) => jsDaemon.api.id((err, res) => {
expect(err).to.not.exist()
console.log('peer id js', res.id, peerId === res.id)
cb()
}),
(cb) => {
jsDaemon.api.name.resolve(peerId, (err, res) => {
console.log('peerId', peerId)
console.log('res', res)
console.log('err', err)
expect(err).to.not.exist()
expect(res).to.equal(ipfsRef)
cb()
})
},
(cb) => jsDaemon.stop(cb),
(cb) => setTimeout(cb, 2000),
(cb) => jsDaemon.cleanup(cb)
(cb) => setTimeout(cb, 2000)
// TODO cleanup repo
], done)
})
})
Expand Down
1 change: 1 addition & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ require('./exchange-files')
require('./kad-dht')
require('./pin')
require('./files')
require('./ipns')
31 changes: 20 additions & 11 deletions test/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ describe.skip('repo', () => {
], done)
})

// This was last due to an update on go-ipfs that changed how datastore is
// configured
it('read repo: js -> go', function (done) {
this.timeout(50 * 1000)
this.timeout(80 * 1000)
const dir = path.join(os.tmpdir(), hat())
const data = crypto.randomBytes(1024 * 5)

Expand All @@ -91,26 +93,33 @@ describe.skip('repo', () => {
series([
(cb) => jsDf.spawn({
repoPath: dir,
disposable: false,
initOptions: { bits: 512 }
}, cb),
(node, cb) => {
}, (err, node) => {
expect(err).to.not.exist()

jsDaemon = node
cb()
},
(cb) => jsDaemon.api.add(data, cb),
(res, cb) => {
jsDaemon.init(cb)
}),
(cb) => jsDaemon.start(cb),
(cb) => jsDaemon.api.add(data, (err, res) => {
expect(err).to.not.exist()

hash = res[0].hash
catAndCheck(jsDaemon.api, hash, data, cb)
},
}),
(cb) => jsDaemon.stop(cb),
(cb) => goDf.spawn({
repoPath: dir,
disposable: false,
initOptions: { bits: 1024 }
}, cb),
(node, cb) => {
}, (err, node) => {
expect(err).to.not.exist()

goDaemon = node
cb()
},
}),
(cb) => goDaemon.start(cb),
(cb) => catAndCheck(goDaemon.api, hash, data, cb),
(cb) => goDaemon.stop(cb)
], done)
Expand Down

0 comments on commit 1528185

Please sign in to comment.