-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attach blocks to delegation (#27)
This PR adds a method `Attach` to `Delegation` that allows additional blocks to be attached. The primary usecase is to allow blocks linked from capabilities or facts to be included in the delegation payload. Note: this feature exists in JS Ucanto already and it actually validates the blocks you attach are referenced from capabilities/facts. I will open an issue to track feature parity here assuming this is approved.
- Loading branch information
Showing
6 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package delegation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/storacha/go-ucanto/core/ipld/block" | ||
"github.com/storacha/go-ucanto/testing/fixtures" | ||
"github.com/storacha/go-ucanto/testing/helpers" | ||
"github.com/storacha/go-ucanto/ucan" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAttach(t *testing.T) { | ||
dlg, err := Delegate( | ||
fixtures.Alice, | ||
fixtures.Bob, | ||
[]ucan.Capability[ucan.NoCaveats]{ | ||
ucan.NewCapability("test/attach", fixtures.Alice.DID().String(), ucan.NoCaveats{}), | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
blk := block.NewBlock(helpers.RandomCID(), helpers.RandomBytes(32)) | ||
err = dlg.Attach(blk) | ||
require.NoError(t, err) | ||
|
||
found := false | ||
for b, err := range dlg.Blocks() { | ||
require.NoError(t, err) | ||
if b.Link().String() == blk.Link().String() { | ||
found = true | ||
break | ||
} | ||
} | ||
require.True(t, found) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters