@@ -59,7 +59,7 @@ func newChaintreeWithNodes(t *testing.T, ctx context.Context, name string, treeN
59
59
root := sw .WrapObject (map [string ]interface {}{
60
60
"chain" : chain .Cid (),
61
61
"tree" : tree .Cid (),
62
- "id" : "did:tupelo:" + name ,
62
+ "id" : "did:tupelo:" + name ,
63
63
})
64
64
65
65
store := nodestore .MustMemoryStore (ctx )
@@ -88,7 +88,7 @@ func newChaintreeOwnedBy(t *testing.T, ctx context.Context, name string, owners
88
88
})
89
89
}
90
90
91
- func newDagGetter (t * testing.T , ctx context.Context , chaintrees ... * chaintree.ChainTree ) * TestDagGetter {
91
+ func newDagGetter (t * testing.T , ctx context.Context , chaintrees ... * chaintree.ChainTree ) * TestDagGetter {
92
92
dagGetter := & TestDagGetter {
93
93
chaintrees : make (map [string ]* chaintree.ChainTree ),
94
94
}
@@ -275,7 +275,7 @@ func TestResolveOwnersArbitraryPath(t *testing.T) {
275
275
did , err := ct1 .Id (ctx )
276
276
require .Nil (t , err )
277
277
278
- ct2 := newChaintreeOwnedBy (t , ctx , "dos" , []string {did + "/tree/data/otherChaintreeOwners" , "otheraddr" })
278
+ ct2 := newChaintreeOwnedBy (t , ctx , "dos" , []string {did + "/tree/data/otherChaintreeOwners" , "otheraddr" })
279
279
did , err = ct2 .Id (ctx )
280
280
require .Nil (t , err )
281
281
@@ -297,6 +297,41 @@ func TestResolveOwnersArbitraryPath(t *testing.T) {
297
297
assert .Contains (t , owners , "otheraddr" )
298
298
}
299
299
300
+ // TestResolveOwnersThroughIntermediary sets up a test where an organization
301
+ // has many users (listed in its ChainTree as DIDs) and then an asset is owned by
302
+ // the path to the organization's list of users (and the organization itself).
303
+ func TestResolveOwnersThroughIntermediary (t * testing.T ) {
304
+ ctx , cancel := context .WithCancel (context .Background ())
305
+ defer cancel ()
306
+
307
+ userTree := newChaintree (t , ctx , "user" )
308
+ did , err := userTree .Id (ctx )
309
+ require .Nil (t , err )
310
+
311
+ organizationTree := newChaintreeWithNodes (t , ctx , "org" , map [string ]interface {}{
312
+ "data" : map [string ]interface {}{
313
+ "users" : []string {did },
314
+ },
315
+ })
316
+ orgDid , err := organizationTree .Id (ctx )
317
+ require .Nil (t , err )
318
+
319
+ assetTree := newChaintreeOwnedBy (t , ctx , "asset" , []string {orgDid + "/tree/data/users" , orgDid })
320
+ dg := newDagGetter (t , ctx , userTree , organizationTree , assetTree )
321
+
322
+ originDag := assetTree .Dag
323
+
324
+ gro , err := NewGraftedOwnership (originDag , dg )
325
+ require .Nil (t , err )
326
+
327
+ owners , err := gro .ResolveOwners (ctx )
328
+ require .Nil (t , err )
329
+
330
+ assert .Equal (t , 2 , len (owners ))
331
+ assert .Contains (t , owners , "user" )
332
+ assert .Contains (t , owners , "org" )
333
+ }
334
+
300
335
func TestResolveOwnersLoop (t * testing.T ) {
301
336
ctx , cancel := context .WithCancel (context .Background ())
302
337
defer cancel ()
0 commit comments