@@ -28,15 +28,17 @@ type TestIdentityDAG struct {
2828 t testing.TB
2929 loader ipld.BlockReadOpener
3030
31- RootLink ipld.Link
32- AllLinks []ipld.Link
31+ RootLink ipld.Link
32+ AllLinks []ipld.Link
33+ AllLinksNoIdent []ipld.Link
3334}
3435
3536/* ugly, but it makes a DAG with paths that look like this but doesn't involved dag-pb or unixfs */
36- var identityDagPaths = []string {
37+ var identityDagLinkPaths = []string {
3738 "" ,
3839 "a/!foo" ,
3940 "a/b/!bar" ,
41+ "a/b/c/!baz" , // identity
4042 "a/b/c/!baz/identity jump" ,
4143 "a/b/c/!baz/identity jump/these are my children/blip" ,
4244 "a/b/c/!baz/identity jump/these are my children/bloop" ,
@@ -49,13 +51,15 @@ var identityDagPaths = []string{
4951func SetupIdentityDAG (
5052 ctx context.Context ,
5153 t testing.TB ,
52- lsys ipld.LinkSystem ) * TestIdentityDAG {
53-
54+ lsys ipld.LinkSystem ,
55+ ) * TestIdentityDAG {
5456 allLinks := make ([]ipld.Link , 0 )
57+ allLinksNoIdent := make ([]ipld.Link , 0 )
5558 store := func (lp datamodel.LinkPrototype , n datamodel.Node ) datamodel.Link {
5659 l , err := lsys .Store (linking.LinkContext {}, lp , n )
5760 require .NoError (t , err )
5861 allLinks = append (allLinks , l )
62+ allLinksNoIdent = append (allLinksNoIdent , l )
5963 return l
6064 }
6165
@@ -98,6 +102,11 @@ func SetupIdentityDAG(
98102 identBytes := must (ipld .Encode (ident , dagjson .Encode ))(t )
99103 mh := must (multihash .Sum (identBytes , multihash .IDENTITY , len (identBytes )))(t )
100104 bazIdent = cidlink.Link {Cid : cid .NewCidV1 (cid .DagJSON , mh )}
105+ w , wc , err := lsys .StorageWriteOpener (linking.LinkContext {})
106+ require .NoError (t , err )
107+ w .Write (identBytes )
108+ require .NoError (t , wc (bazIdent ))
109+ allLinks = append (allLinks , bazIdent )
101110 }
102111 bar := store (djlp , basicnode .NewInt (2020202020202020 ))
103112 foo := store (djlp , basicnode .NewInt (1010101010101010 ))
@@ -117,10 +126,11 @@ func SetupIdentityDAG(
117126 }))(t ))
118127
119128 return & TestIdentityDAG {
120- t : t ,
121- loader : lsys .StorageReadOpener ,
122- RootLink : root ,
123- AllLinks : reverse (allLinks ), // TODO: slices.Reverse post 1.21
129+ t : t ,
130+ loader : lsys .StorageReadOpener ,
131+ RootLink : root ,
132+ AllLinks : reverse (allLinks ), // TODO: slices.Reverse post 1.21
133+ AllLinksNoIdent : reverse (allLinksNoIdent ),
124134 }
125135}
126136
@@ -150,15 +160,15 @@ func (tid *TestIdentityDAG) checkResponses(responses []graphsync.ResponseProgres
150160 for ii , response := range responses {
151161 // only check the paths that have links, assume the rest are just describing
152162 // the non-link nodes of the DAG
153- if response .Path .String () == identityDagPaths [pathIndex ] {
163+ if response .Path .String () == identityDagLinkPaths [pathIndex ] {
154164 if response .LastBlock .Link != nil {
155165 expectedLink := tid .AllLinks [pathIndex ]
156166 require .Equal (tid .t , expectedLink .String (), response .LastBlock .Link .String (), fmt .Sprintf ("response %d has correct link (%d)" , ii , pathIndex ))
157167 }
158168 pathIndex ++
159169 }
160170 }
161- require .Equal (tid .t , len (identityDagPaths ), pathIndex , "traverses all nodes" )
171+ require .Equal (tid .t , len (identityDagLinkPaths ), pathIndex , "traverses all nodes" )
162172}
163173
164174func must [T any ](v T , err error ) func (t testing.TB ) T {
0 commit comments