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