-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This seems to be not spec'd...there's a `ttl` field in w3up but it is optional and unused. Hence I've just remove it from here for now. PR also exposes the caveat readers and adds 2 round trip tests.
- Loading branch information
Showing
8 changed files
with
153 additions
and
62 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,32 @@ | ||
package blob | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/storacha/go-capabilities/pkg/internal/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRoundTripAcceptCaveats(t *testing.T) { | ||
digest, bytes := testutil.RandomBytes(t, 256) | ||
nb := AcceptCaveats{ | ||
Space: testutil.RandomPrincipal(t).DID(), | ||
Blob: Blob{ | ||
Digest: digest, | ||
Size: uint64(len(bytes)), | ||
}, | ||
Put: Promise{ | ||
UcanAwait: Await{ | ||
Selector: ".out.ok", | ||
Link: testutil.RandomCID(t), | ||
}, | ||
}, | ||
} | ||
|
||
node, err := nb.ToIPLD() | ||
require.NoError(t, err) | ||
|
||
rnb, err := AcceptCaveatsReader.Read(node) | ||
require.NoError(t, err) | ||
require.Equal(t, nb, rnb) | ||
} |
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,27 @@ | ||
package blob | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/storacha/go-capabilities/pkg/internal/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRoundTripAllocateCaveats(t *testing.T) { | ||
digest, bytes := testutil.RandomBytes(t, 256) | ||
nb := AllocateCaveats{ | ||
Space: testutil.RandomPrincipal(t).DID(), | ||
Blob: Blob{ | ||
Digest: digest, | ||
Size: uint64(len(bytes)), | ||
}, | ||
Cause: testutil.RandomCID(t), | ||
} | ||
|
||
node, err := nb.ToIPLD() | ||
require.NoError(t, err) | ||
|
||
rnb, err := AllocateCaveatsReader.Read(node) | ||
require.NoError(t, err) | ||
require.Equal(t, nb, rnb) | ||
} |
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,39 @@ | ||
package testutil | ||
|
||
import ( | ||
crand "crypto/rand" | ||
"testing" | ||
|
||
"github.com/ipfs/go-cid" | ||
"github.com/ipld/go-ipld-prime" | ||
cidlink "github.com/ipld/go-ipld-prime/linking/cid" | ||
"github.com/multiformats/go-multihash" | ||
"github.com/storacha/go-ucanto/principal" | ||
"github.com/storacha/go-ucanto/principal/ed25519/signer" | ||
"github.com/storacha/go-ucanto/ucan" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func RandomCID(t *testing.T) ipld.Link { | ||
digest, _ := RandomBytes(t, 10) | ||
return cidlink.Link{Cid: cid.NewCidV1(cid.Raw, digest)} | ||
} | ||
|
||
func RandomBytes(t *testing.T, size int) (multihash.Multihash, []byte) { | ||
bytes := make([]byte, size) | ||
_, err := crand.Read(bytes) | ||
require.NoError(t, err) | ||
digest, err := multihash.Sum(bytes, multihash.SHA2_256, -1) | ||
require.NoError(t, err) | ||
return digest, bytes | ||
} | ||
|
||
func RandomPrincipal(t *testing.T) ucan.Principal { | ||
return RandomSigner(t) | ||
} | ||
|
||
func RandomSigner(t *testing.T) principal.Signer { | ||
id, err := signer.Generate() | ||
require.NoError(t, err) | ||
return id | ||
} |