1
+ /* eslint max-nested-callbacks: ["error", 6] */
1
2
/* eslint-env mocha */
2
3
'use strict'
3
4
4
- const each = require ( 'async/each' )
5
5
const hat = require ( 'hat' )
6
6
7
- const { fixtures } = require ( './utils' )
7
+ const { fixture } = require ( './utils' )
8
+ const { spawnNodeWithId } = require ( '../utils/spawn' )
8
9
const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
9
10
10
11
module . exports = ( createCommon , options ) => {
@@ -13,80 +14,68 @@ module.exports = (createCommon, options) => {
13
14
const common = createCommon ( )
14
15
15
16
describe ( '.name.resolve' , function ( ) {
16
- this . timeout ( 50 * 1000 )
17
-
18
17
const keyName = hat ( )
19
18
let ipfs
20
19
let nodeId
21
20
let keyId
22
21
23
22
before ( function ( done ) {
23
+ // CI takes longer to instantiate the daemon, so we need to increase the
24
+ // timeout for the before step
24
25
this . timeout ( 60 * 1000 )
25
26
26
27
common . setup ( ( err , factory ) => {
27
28
expect ( err ) . to . not . exist ( )
28
29
29
- factory . spawnNode ( ( err , node ) => {
30
+ spawnNodeWithId ( factory , ( err , node ) => {
30
31
expect ( err ) . to . not . exist ( )
31
32
32
33
ipfs = node
33
- ipfs . id ( ) . then ( ( res ) => {
34
- expect ( res . id ) . to . exist ( )
35
-
36
- nodeId = res . id
37
-
38
- ipfs . key . gen ( keyName , { type : 'rsa' , size : 2048 } , ( err , key ) => {
39
- expect ( err ) . to . not . exist ( )
40
- expect ( key ) . to . exist ( )
41
- expect ( key ) . to . have . property ( 'name' , keyName )
42
- expect ( key ) . to . have . property ( 'id' )
34
+ nodeId = node . peerId . id
43
35
44
- keyId = key . id
45
- populate ( )
46
- } )
47
- } )
36
+ ipfs . files . add ( fixture . data , { pin : false } , done )
48
37
} )
49
38
} )
50
-
51
- function populate ( ) {
52
- each ( fixtures . files , ( file , cb ) => {
53
- ipfs . files . add ( file . data , { pin : false } , cb )
54
- } , done )
55
- }
56
39
} )
57
40
58
41
after ( ( done ) => common . teardown ( done ) )
59
42
60
- it ( 'name resolve should resolve correctly after a publish' , ( done ) => {
61
- this . timeout ( 60 * 1000 )
43
+ it ( 'should resolve a record with the default params after a publish' , ( done ) => {
44
+ this . timeout ( 50 * 1000 )
62
45
63
- const value = fixtures . files [ 0 ] . cid
46
+ const value = fixture . cid
64
47
65
- ipfs . name . publish ( value , true , '1m' , '10s' , 'self' , ( err , res ) => {
48
+ ipfs . name . publish ( value , ( err , res ) => {
66
49
expect ( err ) . to . not . exist ( )
67
50
expect ( res ) . to . exist ( )
68
51
69
- ipfs . name . resolve ( nodeId , false , false , ( err , res ) => {
52
+ ipfs . name . resolve ( nodeId , ( err , res ) => {
70
53
expect ( err ) . to . not . exist ( )
71
54
expect ( res ) . to . exist ( )
72
- expect ( res ) . to . equal ( `/ipfs/${ value } ` )
55
+ expect ( res . Path ) . to . equal ( `/ipfs/${ value } ` )
73
56
74
57
done ( )
75
58
} )
76
59
} )
77
60
} )
78
61
79
- it ( 'name resolve should not get the entry correctly if its validity time expired' , ( done ) => {
80
- this . timeout ( 60 * 1000 )
62
+ it ( 'should not get the entry if its validity time expired' , ( done ) => {
63
+ this . timeout ( 50 * 1000 )
81
64
82
- const value = fixtures . files [ 0 ] . cid
65
+ const value = fixture . cid
66
+ const publishOptions = {
67
+ resolve : true ,
68
+ lifetime : '1ms' ,
69
+ ttl : '10s' ,
70
+ key : 'self'
71
+ }
83
72
84
- ipfs . name . publish ( value , true , '10ns' , '10s' , 'self' , ( err , res ) => {
73
+ ipfs . name . publish ( value , publishOptions , ( err , res ) => {
85
74
expect ( err ) . to . not . exist ( )
86
75
expect ( res ) . to . exist ( )
87
76
88
77
setTimeout ( function ( ) {
89
- ipfs . name . resolve ( nodeId , false , false , ( err , res ) => {
78
+ ipfs . name . resolve ( nodeId , ( err , res ) => {
90
79
expect ( err ) . to . exist ( )
91
80
expect ( res ) . to . not . exist ( )
92
81
@@ -96,25 +85,48 @@ module.exports = (createCommon, options) => {
96
85
} )
97
86
} )
98
87
99
- it ( 'name resolve should should go recursively until finding an ipfs hash' , ( done ) => {
100
- this . timeout ( 60 * 1000 )
88
+ it ( 'should recursively resolve to an IPFS hash' , ( done ) => {
89
+ this . timeout ( 100 * 1000 )
101
90
102
- const value = fixtures . files [ 0 ] . cid
91
+ const value = fixture . cid
92
+ const publishOptions = {
93
+ resolve : true ,
94
+ lifetime : '24h' ,
95
+ ttl : '10s' ,
96
+ key : 'self'
97
+ }
103
98
104
- ipfs . name . publish ( value , true , '24h' , '10s' , 'self' , ( err , res ) => {
99
+ // Generate new key
100
+ ipfs . key . gen ( keyName , { type : 'rsa' , size : 2048 } , ( err , key ) => {
105
101
expect ( err ) . to . not . exist ( )
106
- expect ( res ) . to . exist ( )
107
102
108
- ipfs . name . publish ( `/ipns/${ nodeId } ` , true , '24h' , '10s' , keyName , ( err , res ) => {
103
+ keyId = key . id
104
+
105
+ // publish ipfs
106
+ ipfs . name . publish ( value , publishOptions , ( err , res ) => {
109
107
expect ( err ) . to . not . exist ( )
110
108
expect ( res ) . to . exist ( )
111
109
112
- ipfs . name . resolve ( keyId , false , true , ( err , res ) => {
110
+ publishOptions . key = keyName
111
+
112
+ // publish ipns with the generated key
113
+ ipfs . name . publish ( `/ipns/${ nodeId } ` , publishOptions , ( err , res ) => {
113
114
expect ( err ) . to . not . exist ( )
114
115
expect ( res ) . to . exist ( )
115
- expect ( res ) . to . equal ( `/ipfs/${ value } ` )
116
116
117
- done ( )
117
+ const resolveOptions = {
118
+ nocache : false ,
119
+ recursive : true
120
+ }
121
+
122
+ // recursive resolve (will get ipns first, and will resolve again to find the ipfs)
123
+ ipfs . name . resolve ( keyId , resolveOptions , ( err , res ) => {
124
+ expect ( err ) . to . not . exist ( )
125
+ expect ( res ) . to . exist ( )
126
+ expect ( res . Path ) . to . equal ( `/ipfs/${ value } ` )
127
+
128
+ done ( )
129
+ } )
118
130
} )
119
131
} )
120
132
} )
0 commit comments