Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

fix: use ProtoNode with CIDv1 #119

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hamt/hamt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestDirBuilding(t *testing.T) {

k := nd.Cid()

if k.String() != "QmY89TkSEVHykWMHDmyejSWFj9CYNtvzw4UwnT9xbc4Zjc" {
if k.String() != "QmWd277BEJs7VKLpd6Ki6mC12ESnKcFQAqF5JDJW4TpUjY" {
t.Fatalf("output didnt match what we expected (got %s)", k.String())
}
}
Expand Down
6 changes: 3 additions & 3 deletions io/dagreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestTypeFailures(t *testing.T) {
if err != nil {
t.Fatal(err)
}
node = mdag.NodeWithData(data)
node = unixfs.ProtoNodeCIDv1WithData(data)

if _, err := NewDagReader(ctx, node, dserv); err != ErrCantReadSymlinks {
t.Fatalf("excepted to get %v, got %v", ErrCantReadSymlinks, err)
Expand All @@ -216,7 +216,7 @@ func TestBadPBData(t *testing.T) {
ctx, closer := context.WithCancel(context.Background())
defer closer()

node := mdag.NodeWithData([]byte{42})
node := unixfs.ProtoNodeCIDv1WithData([]byte{42})
_, err := NewDagReader(ctx, node, dserv)
if err == nil {
t.Fatal("excepted error, got nil")
Expand All @@ -241,7 +241,7 @@ func TestMetadataNode(t *testing.T) {
if err != nil {
t.Fatal(err)
}
node := mdag.NodeWithData(data)
node := unixfs.ProtoNodeCIDv1WithData(data)

_, err = NewDagReader(ctx, node, dserv)
if err == nil {
Expand Down
6 changes: 3 additions & 3 deletions io/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ func TestProductionLinkSize(t *testing.T) {
link, err := ipld.MakeLink(ft.EmptyDirNode())
assert.NoError(t, err)
link.Name = "directory_link_name"
assert.Equal(t, 53, productionLinkSize(link.Name, link.Cid))
assert.Equal(t, 55, productionLinkSize(link.Name, link.Cid))

link, err = ipld.MakeLink(ft.EmptyFileNode())
assert.NoError(t, err)
link.Name = "file_link_name"
assert.Equal(t, 48, productionLinkSize(link.Name, link.Cid))
assert.Equal(t, 50, productionLinkSize(link.Name, link.Cid))

ds := mdtest.Mock()
basicDir := newEmptyBasicDirectory(ds)
Expand All @@ -240,7 +240,7 @@ func TestProductionLinkSize(t *testing.T) {
link, err = ipld.MakeLink(basicDirNode)
assert.NoError(t, err)
link.Name = "basic_dir"
assert.Equal(t, 43, productionLinkSize(link.Name, link.Cid))
assert.Equal(t, 45, productionLinkSize(link.Name, link.Cid))
}

// Test HAMTDirectory <-> BasicDirectory switch based on directory size. The
Expand Down
3 changes: 1 addition & 2 deletions mod/dagmodifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"testing"

dag "github.com/ipfs/go-merkledag"
h "github.com/ipfs/go-unixfs/importer/helpers"
trickle "github.com/ipfs/go-unixfs/importer/trickle"
uio "github.com/ipfs/go-unixfs/io"
Expand Down Expand Up @@ -416,7 +415,7 @@ func testDagTruncate(t *testing.T, opts testu.NodeOpts) {
// if offset > curNode's size.
func TestDagSync(t *testing.T) {
dserv := testu.GetDAGServ()
nd := dag.NodeWithData(unixfs.FilePBData(nil, 0))
nd := unixfs.ProtoNodeCIDv1WithData(unixfs.FilePBData(nil, 0))

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
14 changes: 12 additions & 2 deletions unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,24 @@ func BytesForMetadata(m *Metadata) ([]byte, error) {
return proto.Marshal(pbd)
}

// ProtoNodeCIDv1WithData returns a ProtoNode with the given data and CIDv1.
// FIXME: Switch to CIDv1 here until we decide if the switch should happen
// in `go-merkledag` itself (see https://github.com/ipfs/go-merkledag/issues/86).
func ProtoNodeCIDv1WithData(data []byte) *dag.ProtoNode {
n := &dag.ProtoNode{}
n.SetData(data)
n.SetCidBuilder(dag.V1CidPrefix())
return n
}

// EmptyDirNode creates an empty folder Protonode.
func EmptyDirNode() *dag.ProtoNode {
return dag.NodeWithData(FolderPBData())
return ProtoNodeCIDv1WithData(FolderPBData())
}

// EmptyFileNode creates an empty file Protonode.
func EmptyFileNode() *dag.ProtoNode {
return dag.NodeWithData(FilePBData(nil, 0))
return ProtoNodeCIDv1WithData(FilePBData(nil, 0))
}

// ReadUnixFSNodeData extracts the UnixFS data from an IPLD node.
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.3.1"
"version": "v0.4.0"
}