@@ -59,7 +59,7 @@ func newChaintreeWithNodes(t *testing.T, ctx context.Context, name string, treeN
5959 root := sw .WrapObject (map [string ]interface {}{
6060 "chain" : chain .Cid (),
6161 "tree" : tree .Cid (),
62- "id" : "did:tupelo:" + name ,
62+ "id" : "did:tupelo:" + name ,
6363 })
6464
6565 store := nodestore .MustMemoryStore (ctx )
@@ -88,7 +88,7 @@ func newChaintreeOwnedBy(t *testing.T, ctx context.Context, name string, owners
8888 })
8989}
9090
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 {
9292 dagGetter := & TestDagGetter {
9393 chaintrees : make (map [string ]* chaintree.ChainTree ),
9494 }
@@ -275,7 +275,7 @@ func TestResolveOwnersArbitraryPath(t *testing.T) {
275275 did , err := ct1 .Id (ctx )
276276 require .Nil (t , err )
277277
278- ct2 := newChaintreeOwnedBy (t , ctx , "dos" , []string {did + "/tree/data/otherChaintreeOwners" , "otheraddr" })
278+ ct2 := newChaintreeOwnedBy (t , ctx , "dos" , []string {did + "/tree/data/otherChaintreeOwners" , "otheraddr" })
279279 did , err = ct2 .Id (ctx )
280280 require .Nil (t , err )
281281
@@ -297,6 +297,41 @@ func TestResolveOwnersArbitraryPath(t *testing.T) {
297297 assert .Contains (t , owners , "otheraddr" )
298298}
299299
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+
300335func TestResolveOwnersLoop (t * testing.T ) {
301336 ctx , cancel := context .WithCancel (context .Background ())
302337 defer cancel ()
0 commit comments