Skip to content

Commit

Permalink
feat: attach claim to claim/cache invocation (#11)
Browse files Browse the repository at this point in the history
Attaches the claim block(s) to the `claim/cache` invocation and changes
to tests to ensure they are included.

Also a small refactor to use the `Unit` type from Ucanto.
  • Loading branch information
alanshaw authored Oct 22, 2024
1 parent 6f51c2e commit 21c0486
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/multiformats/go-multihash v0.2.3
github.com/storacha/go-capabilities v0.0.0-20241021134022-7144600f5aeb
github.com/storacha/go-metadata v0.0.0-20241021141939-f94d93dcda78
github.com/storacha/go-ucanto v0.1.1-0.20241018155815-175193fb3b33
github.com/storacha/go-ucanto v0.1.1-0.20241022082502-7edcd3716f2d
github.com/storacha/ipni-publisher v0.0.0-20241018055706-032286a2dc3f
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.4
Expand Down
10 changes: 10 additions & 0 deletions pkg/service/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ func CacheClaim(
return fmt.Errorf("creating invocation: %w", err)
}

for b, err := range clm.Blocks() {
if err != nil {
return fmt.Errorf("iterating claim blocks: %w", err)
}
err = inv.Attach(b)
if err != nil {
return fmt.Errorf("attaching block: %s: %w", b.Link(), err)
}
}

res, err := client.Execute([]invocation.Invocation{inv}, indexingService)
if err != nil {
return fmt.Errorf("executing invocation: %w", err)
Expand Down
9 changes: 2 additions & 7 deletions pkg/service/publisher/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func TestPublisherService(t *testing.T) {
dstore := dssync.MutexWrap(datastore.NewMapDatastore())
publisherStore := store.FromDatastore(dstore)

<<<<<<< HEAD
idxSvc := mockIndexingService(t, testutil.Bob)
=======
handlerCalled := false
handler := func(cap ucan.Capability[claim.CacheCaveats], inv invocation.Invocation, ctx server.InvocationContext) (ok.Unit, receipt.Effects, error) {
handlerCalled = true
Expand All @@ -118,7 +115,6 @@ func TestPublisherService(t *testing.T) {
}

idxSvc := mockIndexingService(t, testutil.Bob, handler)
>>>>>>> d01698c (refactor: use Unit type from ucanto)
idxConn, err := client.NewConnection(testutil.Bob, idxSvc)
require.NoError(t, err)

Expand Down Expand Up @@ -165,6 +161,7 @@ func TestPublisherService(t *testing.T) {

err = svc.Publish(ctx, claim)
require.NoError(t, err)
require.True(t, handlerCalled)
})
}

Expand All @@ -177,9 +174,7 @@ func mockIndexingService(t *testing.T, id principal.Signer, handler server.Handl
claim.CacheAbility,
server.Provide(
claim.Cache,
func(cap ucan.Capability[claim.CacheCaveats], inv invocation.Invocation, ctx server.InvocationContext) (capability.Unit, receipt.Effects, error) {
return capability.Unit{}, nil, nil
},
handler,
),
),
),
Expand Down

0 comments on commit 21c0486

Please sign in to comment.