From 4bcc7669029a93746cd58dcf5726ff4bdd7d4548 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 13 Dec 2024 15:54:38 +0000 Subject: [PATCH 1/2] test: add location caveats roundtrip test --- pkg/assert/assert_test.go | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 pkg/assert/assert_test.go diff --git a/pkg/assert/assert_test.go b/pkg/assert/assert_test.go new file mode 100644 index 0000000..ec57e93 --- /dev/null +++ b/pkg/assert/assert_test.go @@ -0,0 +1,47 @@ +package assert + +import ( + "bytes" + "fmt" + "net/url" + "testing" + + "github.com/ipld/go-ipld-prime/codec/dagjson" + basicnode "github.com/ipld/go-ipld-prime/node/basic" + "github.com/storacha/go-capabilities/pkg/internal/testutil" + "github.com/stretchr/testify/require" +) + +func TestRoundTripLocationCaveats(t *testing.T) { + digest, _ := testutil.RandomBytes(t, 256) + location, err := url.Parse("http://localhost") + require.NoError(t, err) + + length := uint64(20) + nb := LocationCaveats{ + Content: FromHash(digest), + Space: testutil.RandomPrincipal(t).DID(), + Location: []url.URL{*location}, + Range: &Range{ + Offset: 100, + Length: &length, + }, + } + + node, err := nb.ToIPLD() + require.NoError(t, err) + + buf := bytes.NewBuffer([]byte{}) + err = dagjson.Encode(node, buf) + require.NoError(t, err) + + fmt.Println(buf.String()) + + builder := basicnode.Prototype.Any.NewBuilder() + err = dagjson.Decode(builder, buf) + require.NoError(t, err) + + rnb, err := LocationCaveatsReader.Read(builder.Build()) + require.NoError(t, err) + require.Equal(t, nb, rnb) +} From 842a081c57daadf1c3df026bec0ba9e36d19448c Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 13 Dec 2024 16:06:56 +0000 Subject: [PATCH 2/2] fix: fromhash is not in types package --- pkg/assert/assert_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/assert/assert_test.go b/pkg/assert/assert_test.go index ec57e93..c954087 100644 --- a/pkg/assert/assert_test.go +++ b/pkg/assert/assert_test.go @@ -9,6 +9,7 @@ import ( "github.com/ipld/go-ipld-prime/codec/dagjson" basicnode "github.com/ipld/go-ipld-prime/node/basic" "github.com/storacha/go-capabilities/pkg/internal/testutil" + "github.com/storacha/go-capabilities/pkg/types" "github.com/stretchr/testify/require" ) @@ -19,7 +20,7 @@ func TestRoundTripLocationCaveats(t *testing.T) { length := uint64(20) nb := LocationCaveats{ - Content: FromHash(digest), + Content: types.FromHash(digest), Space: testutil.RandomPrincipal(t).DID(), Location: []url.URL{*location}, Range: &Range{