Skip to content

Commit

Permalink
fix(providerindex): produce correct metdata for identity cids
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed Jan 11, 2025
1 parent 493fdb8 commit 3d57c83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions pkg/service/providerindex/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (ls LegacyClaimsStore) Find(ctx context.Context, contentHash multihash.Mult
return nil, err
}

pr, err := ls.synthetizeProviderResult(claim)
pr, err := ls.synthetizeProviderResult(claimCid, claim)
if err != nil {
log.Warnf("error synthetizing provider result for claim %s: %s", claimCid, err)
continue
Expand All @@ -98,14 +98,12 @@ func (ls LegacyClaimsStore) Find(ctx context.Context, contentHash multihash.Mult
}

// synthetizeProviderResult synthetizes a provider result, including metadata, from a given claim
func (ls LegacyClaimsStore) synthetizeProviderResult(claim delegation.Delegation) (model.ProviderResult, error) {
func (ls LegacyClaimsStore) synthetizeProviderResult(claimCid cid.Cid, claim delegation.Delegation) (model.ProviderResult, error) {
expiration := int64(0)
if claim.Expiration() != nil {
expiration = int64(*claim.Expiration())
}

claimCid := link.ToCID(claim.Link())

if len(claim.Capabilities()) != 1 {
return model.ProviderResult{}, fmt.Errorf("claim %s has an unexpected number of capabilities (%d)", claimCid, len(claim.Capabilities()))
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/providerindex/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestSynthetizeProviderResult(t *testing.T) {
})
locationDelegation := testutil.Must(delegation.Delegate(testutil.Service, testutil.Alice, []ucan.Capability[assert.LocationCaveats]{locationClaim}))(t)

result, err := legacyClaims.synthetizeProviderResult(locationDelegation)
result, err := legacyClaims.synthetizeProviderResult(link.ToCID(locationDelegation.Link()), locationDelegation)

require.NoError(t, err)

Expand Down Expand Up @@ -142,7 +142,7 @@ func TestSynthetizeProviderResult(t *testing.T) {
})
indexDelegation := testutil.Must(delegation.Delegate(testutil.Service, testutil.Service, []ucan.Capability[assert.IndexCaveats]{indexClaim}))(t)

result, err := legacyClaims.synthetizeProviderResult(indexDelegation)
result, err := legacyClaims.synthetizeProviderResult(link.ToCID(indexDelegation.Link()), indexDelegation)

require.NoError(t, err)

Expand Down Expand Up @@ -177,7 +177,7 @@ func TestSynthetizeProviderResult(t *testing.T) {

equalsDelegation := testutil.Must(delegation.Delegate(testutil.Service, testutil.Service, []ucan.Capability[assert.EqualsCaveats]{equalsClaim}))(t)

result, err := legacyClaims.synthetizeProviderResult(equalsDelegation)
result, err := legacyClaims.synthetizeProviderResult(link.ToCID(equalsDelegation.Link()), equalsDelegation)

require.NoError(t, err)

Expand Down Expand Up @@ -211,7 +211,7 @@ func TestSynthetizeProviderResult(t *testing.T) {

partitionDelegation := testutil.Must(delegation.Delegate(testutil.Service, testutil.Service, []ucan.Capability[assert.PartitionCaveats]{partitionClaim}))(t)

_, err := legacyClaims.synthetizeProviderResult(partitionDelegation)
_, err := legacyClaims.synthetizeProviderResult(link.ToCID(partitionDelegation.Link()), partitionDelegation)

require.Error(t, err)
})
Expand Down

0 comments on commit 3d57c83

Please sign in to comment.