Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dag-pb fixtures #2

Merged
merged 1 commit into from
Aug 5, 2021
Merged
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
Binary file added _fixtures_src/dagpb_11unnamedlinks+data.dag-pb
Binary file not shown.
2 changes: 2 additions & 0 deletions _fixtures_src/dagpb_1link.dag-pb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$
" u!��t�wY"m����t�9P�!}Ӷ����Q
4 changes: 4 additions & 0 deletions _fixtures_src/dagpb_2link+data.dag-pb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
4
" �����G7���8c�vs��fm�NWV�U���_C some link���/7
" �����G7���8c�vs��fm�NWV�U���_Dsome other link
some data
7 changes: 7 additions & 0 deletions _fixtures_src/dagpb_4namedlinks+data.dag-pb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
9
" �9|�UV=3����h�����J�iV�=r�5�audio_only.m4aͨ� 1
" \�Ѩ��DOd��*&��g��h�g�X��I2chat.txt�4
" ]D���(��E�r�*{�v<_��2u���H playback.m3ut6
" %9�n��� }��l�ԛ�.����J<�Bԝ�"
zoom_0.mp4����

Expand Down
Binary file added _fixtures_src/dagpb_7unnamedlinks+data.dag-pb
Binary file not shown.
Binary file added _fixtures_src/dagpb_Data_some.dag-pb
Binary file not shown.
Binary file added _fixtures_src/dagpb_Data_zero.dag-pb
Binary file not shown.
Binary file added _fixtures_src/dagpb_Links_Hash_some.dag-pb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
2 changes: 2 additions & 0 deletions _fixtures_src/dagpb_simple_forms_1.dag-pb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Binary file added _fixtures_src/dagpb_simple_forms_2.dag-pb
Binary file not shown.
Binary file added _fixtures_src/dagpb_simple_forms_3.dag-pb
Binary file not shown.
Binary file added _fixtures_src/dagpb_simple_forms_4.dag-pb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Data":{"/":{"bytes":"c29tZSBkYXRh"}},"Links":[{"Hash":{"/":"QmUGhP2X8xo9dsj45vqx1H6i5WqPqLqmLQsHTTxd3ke8mp"},"Name":"","Tsize":262158},{"Hash":{"/":"QmP7SrR76KHK9A916RbHG1ufy2TzNABZgiE23PjZDMzZXy"},"Name":"","Tsize":262158},{"Hash":{"/":"QmQg1v4o9xdT3Q14wh4S7dxZkDjyZ9ssFzFzyep1YrVJBY"},"Name":"","Tsize":262158},{"Hash":{"/":"QmdP6fartWRrydZCUjHgrJ4XpxSE4SAoRsWJZ1zJ4MWiuf"},"Name":"","Tsize":262158},{"Hash":{"/":"QmNNjUStxtMC1WaSZYiDW6CmAUrvd5Q2e17qnxPgVdwrwW"},"Name":"","Tsize":262158},{"Hash":{"/":"QmWJwqZBJWerHsN1b7g4pRDYmzGNnaMYuD3KSbnpaxsB2h"},"Name":"","Tsize":262158},{"Hash":{"/":"QmRXPSdysBS3dbUXe6w8oXevZWHdPQWaR2d3fggNsjvieL"},"Name":"","Tsize":262158},{"Hash":{"/":"QmTUZAXfws6zrhEksnMqLxsbhXZBQs4FNiarjXSYQqVrjC"},"Name":"","Tsize":262158},{"Hash":{"/":"QmNNk7dTdh8UofwgqLNauq6N78DPc6LKK2yBs1MFdx7Mbg"},"Name":"","Tsize":262158},{"Hash":{"/":"QmW5mrJfyqh7B4ywSvraZgnWjS3q9CLiYURiJpCX3aro5i"},"Name":"","Tsize":262158},{"Hash":{"/":"QmTFHZL5CkgNz19MdPnSuyLAi6AVq9fFp81zmPpaL2amED"},"Name":"","Tsize":262158}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$
" u!��t�wY"m����t�9P�!}Ӷ����Q
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"QmWDtUQj38YLW8v3q4A6LwPn4vYKEbuKWpgSm6bjKW6Xfe"}}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
4
" �����G7���8c�vs��fm�NWV�U���_C some link���/7
" �����G7���8c�vs��fm�NWV�U���_Dsome other link
some data
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Data":{"/":{"bytes":"c29tZSBkYXRh"}},"Links":[{"Hash":{"/":"QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U"},"Name":"some link","Tsize":100000000},{"Hash":{"/":"QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V"},"Name":"some other link","Tsize":8}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
9
" �9|�UV=3����h�����J�iV�=r�5�audio_only.m4aͨ� 1
" \�Ѩ��DOd��*&��g��h�g�X��I2chat.txt�4
" ]D���(��E�r�*{�v<_��2u���H playback.m3ut6
" %9�n��� }��l�ԛ�.����J<�Bԝ�"
zoom_0.mp4����

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Data":{"/":{"bytes":"CAE"}},"Links":[{"Hash":{"/":"QmaUAwAQJNtvUdJB42qNbTTgDpzPYD1qdsKNtctM5i7DGB"},"Name":"audio_only.m4a","Tsize":23319629},{"Hash":{"/":"QmNVrxbB25cKTRuKg2DuhUmBVEK9NmCwWEHtsHPV6YutHw"},"Name":"chat.txt","Tsize":996},{"Hash":{"/":"QmUcjKzDLXBPmB6BKHeKSh6ZoFZjss4XDhMRdLYRVuvVfu"},"Name":"playback.m3u","Tsize":116},{"Hash":{"/":"QmQqy2SiEkKgr2cw5UbQ93TtLKEMsD8TdcWggR8q9JabjX"},"Name":"zoom_0.mp4","Tsize":306281879}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Data":{"/":{"bytes":"CAIYy8GBkgEggIDgFSCAgOAVIICA4BUggIDgFSCAgOAVIICA4BUgy8HBDw"}},"Links":[{"Hash":{"/":"QmSbCgdsX12C4KDw3PDmpBN9iCzS87a5DjgSCoW9esqzXk"},"Name":"","Tsize":45623854},{"Hash":{"/":"Qma4GxWNhywSvWFzPKtEswPGqeZ9mLs2Kt76JuBq9g3fi2"},"Name":"","Tsize":45623854},{"Hash":{"/":"QmQfyxyys7a1e3mpz9XsntSsTGc8VgpjPj5BF1a1CGdGNc"},"Name":"","Tsize":45623854},{"Hash":{"/":"QmSh2wTTZT4N8fuSeCFw7wterzdqbE93j1XDhfN3vQHzDV"},"Name":"","Tsize":45623854},{"Hash":{"/":"QmVXsSVjwxMsCwKRCUxEkGb4f4B98gXVy3ih3v4otvcURK"},"Name":"","Tsize":45623854},{"Hash":{"/":"QmZjhH97MEYwQXzCqSQbdjGDhXWuwW4RyikR24pNqytWLj"},"Name":"","Tsize":45623854},{"Hash":{"/":"QmRs6U5YirCqC7taTynz3x2GNaHJZ3jDvMVAzaiXppwmNJ"},"Name":"","Tsize":32538395}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Data":{"/":{"bytes":"AAECAwQ"}},"Links":[]}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�dData@eLinks�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Data":{"/":{"bytes":""}},"Links":[]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"}}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"},"Name":"some name"}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"},"Name":""}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"},"Tsize":9007199254740991}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"},"Tsize":0}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�eLinks�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�dDataCeLinks�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Data":{"/":{"bytes":"AQID"}},"Links":[]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"}},{"Hash":{"/":"bafkqabiaaebagba"},"Name":"bar"},{"Hash":{"/":"bafkqabiaaebagba"},"Name":"foo"}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"}},{"Hash":{"/":"bafkqabiaaebagba"},"Name":"a"},{"Hash":{"/":"bafkqabiaaebagba"},"Name":"a"}]}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Links":[{"Hash":{"/":"bafkqabiaaebagba"},"Name":"a"},{"Hash":{"/":"bafkqabiaaebagba"},"Name":"a"}]}
10 changes: 6 additions & 4 deletions go/codecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ func TestCodecs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
verifyCid(t, "decode(dag-json)->encode(dag-json)", data.dagjson.value, dagJsonLp, data.dagjson.cid)
verifyCid(t, "decode(dag-json)->encode(dag-cbor)", data.dagjson.value, dagCborLp, data.dagcbor.cid)
verifyCid(t, "decode(dag-cbor)->encode(dag-json)", data.dagcbor.value, dagJsonLp, data.dagjson.cid)
verifyCid(t, "decode(dag-cbor)->encode(dag-cbor)", data.dagcbor.value, dagCborLp, data.dagcbor.cid)
for fromCodec := range data {
for toCodec := range data {
msg := fmt.Sprintf("decode(%v)->encode(%v)", fromCodec, toCodec)
verifyCid(t, msg, data[fromCodec].value, codecs[toCodec], data[toCodec].cid)
}
}
})
}
}
Expand Down
60 changes: 34 additions & 26 deletions go/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@ import (
"strings"

"github.com/ipfs/go-cid"
_ "github.com/ipld/go-codec-dagpb"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/codec/dagcbor"
"github.com/ipld/go-ipld-prime/codec/dagjson"
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
_ "github.com/ipld/go-ipld-prime/codec/dagjson"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
basicnode "github.com/ipld/go-ipld-prime/node/basic"
)

type codecName = string

type codecFixture struct {
codec codecName
cid cid.Cid
value ipld.Node
}

type fixtureSet struct {
dagcbor codecFixture
dagjson codecFixture
}
type fixtureSet = map[codecName]codecFixture

var dagPbLp = cidlink.LinkPrototype{Prefix: cid.Prefix{
Version: 1,
Codec: 0x70, // "dag-pb"
MhType: 0x12, // "sha2-256"
MhLength: 32,
}}
var dagCborLp = cidlink.LinkPrototype{Prefix: cid.Prefix{
Version: 1,
Codec: 0x71, // "dag-cbor"
Expand All @@ -37,11 +44,16 @@ var dagJsonLp = cidlink.LinkPrototype{Prefix: cid.Prefix{
MhType: 0x12, // "sha2-256"
MhLength: 32,
}}
var codecs = map[codecName]ipld.LinkPrototype{
"dag-pb": dagPbLp,
"dag-cbor": dagCborLp,
"dag-json": dagJsonLp,
}
var linkSystem = cidlink.DefaultLinkSystem()

func loadFixture(dir string) (fixtureSet, error) {
files, err := ioutil.ReadDir("../fixtures/" + dir)
fixtures := fixtureSet{}
fixtures := make(fixtureSet)
if err != nil {
return fixtures, err
}
Expand All @@ -61,27 +73,23 @@ func loadFixture(dir string) (fixtureSet, error) {
}
ext = strings.TrimLeft(ext, ".")
na := basicnode.Prototype.Any.NewBuilder()
if ext == "dag-json" {
err := dagjson.Decode(na, bytes.NewReader(byts))
if err != nil {
return fixtures, err
}
fixtures.dagjson = codecFixture{
cid: cid,
value: na.Build(),
}
} else if ext == "dag-cbor" {
err := dagcbor.Decode(na, bytes.NewReader(byts))
if err != nil {
return fixtures, err
}
fixtures.dagcbor = codecFixture{
cid: cid,
value: na.Build(),
}
} else {
lp, ok := codecs[ext]
if !ok {
fmt.Printf("unknown codec '%v' for fixture '%v'\n", ext, dir)
}
decoder, err := linkSystem.DecoderChooser(lp.BuildLink(make([]byte, 32)))
if err != nil {
return fixtures, err
}
err = decoder(na, bytes.NewReader(byts))
if err != nil {
return fixtures, err
}
fixtures[ext] = codecFixture{
codec: ext,
cid: cid,
value: na.Build(),
}
}
return fixtures, nil
}
Expand Down
1 change: 1 addition & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.16

require (
github.com/ipfs/go-cid v0.0.7
github.com/ipld/go-codec-dagpb v1.2.0
github.com/ipld/go-ipld-prime v0.10.1-0.20210804050446-dc21a0c863d0
)
7 changes: 6 additions & 1 deletion go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M=
github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY=
github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
github.com/ipld/go-codec-dagpb v1.2.0 h1:2umV7ud8HBMkRuJgd8gXw95cLhwmcYrihS3cQEy9zpI=
github.com/ipld/go-codec-dagpb v1.2.0/go.mod h1:6nBN7X7h8EOsEejZGqC7tej5drsdBAXbMHyBT+Fne5s=
github.com/ipld/go-ipld-prime v0.9.0/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8=
github.com/ipld/go-ipld-prime v0.10.1-0.20210804050446-dc21a0c863d0 h1:IUh81Ngd6wanfCFACWZDj+tI8IHx2aBvNgfeWRJ+Vz4=
github.com/ipld/go-ipld-prime v0.10.1-0.20210804050446-dc21a0c863d0/go.mod h1:+WIAkokurHmZ/KwzDOMUuoeJgaRQktHtEaLglS3ZeV8=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
Expand Down Expand Up @@ -42,6 +45,7 @@ github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJ
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY=
github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e h1:ZOcivgkkFRnjfoTcGsDq3UQYiBmekwLA+qg0OjyB/ls=
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
Expand All @@ -65,5 +69,6 @@ golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=