Skip to content

Commit d53d20a

Browse files
Merge pull request #46 from ipfs/fix/deferred-kv-nil
update cbor-gen code to fix nested nil deferred unmarshals
2 parents f354769 + 620412a commit d53d20a

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

cbor_gen.go

Lines changed: 7 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/ipfs/go-ipld-cbor v0.0.4
77
github.com/ipfs/go-ipld-format v0.0.2 // indirect
88
github.com/spaolacci/murmur3 v1.1.0
9-
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158
9+
github.com/whyrusleeping/cbor-gen v0.0.0-20200501014322-5f9941ef88e0
1010
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect
1111
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
1212
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436 h1:qOpVTI+BrstcjT
5353
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
5454
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 h1:WXhVOwj2USAXB5oMDwRl3piOux2XMV9TANaYxXHdkoE=
5555
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
56+
github.com/whyrusleeping/cbor-gen v0.0.0-20200414195334-429a0b5e922e h1:JY8o/ebUUrCYetWmjRCNghxC59cOEaili83rxPRQCLw=
57+
github.com/whyrusleeping/cbor-gen v0.0.0-20200414195334-429a0b5e922e/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
58+
github.com/whyrusleeping/cbor-gen v0.0.0-20200501014322-5f9941ef88e0 h1:dmdwCOVtJAm7qwONARangN4jgCisVFmSJ486JZ1LYaA=
59+
github.com/whyrusleeping/cbor-gen v0.0.0-20200501014322-5f9941ef88e0/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
5660
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
5761
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
5862
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

hamt_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
block "github.com/ipfs/go-block-format"
1414
cid "github.com/ipfs/go-cid"
1515
cbor "github.com/ipfs/go-ipld-cbor"
16+
cbg "github.com/whyrusleeping/cbor-gen"
1617
)
1718

1819
type mockBlocks struct {
@@ -596,3 +597,49 @@ func TestValueLinking(t *testing.T) {
596597
fmt.Println("thingy1", c1)
597598
fmt.Println(nd.Links()[0])
598599
}
600+
601+
func TestSetNilValues(t *testing.T) {
602+
ctx := context.Background()
603+
cs := cbor.NewCborStore(newMockBlocks())
604+
605+
n := NewNode(cs)
606+
607+
k := make([]byte, 1)
608+
609+
for i := 0; i < 500; i++ {
610+
k[0] = byte(i)
611+
var um cbg.CBORMarshaler
612+
if err := n.Set(ctx, string(k), um); err != nil {
613+
t.Fatal(err)
614+
}
615+
}
616+
617+
nn := NewNode(cs)
618+
619+
rc, err := cs.Put(ctx, nn)
620+
if err != nil {
621+
t.Fatal(err)
622+
}
623+
624+
for i := 0; i < 500; i++ {
625+
tn, err := LoadNode(ctx, cs, rc)
626+
if err != nil {
627+
t.Fatal(err)
628+
}
629+
630+
k[0] = byte(i)
631+
var n cbg.CBORMarshaler
632+
if err := tn.Set(ctx, string(k), n); err != nil {
633+
t.Fatal(err)
634+
}
635+
636+
if err := tn.Flush(ctx); err != nil {
637+
t.Fatal(err)
638+
}
639+
640+
rc, err = cs.Put(ctx, tn)
641+
if err != nil {
642+
t.Fatal(err)
643+
}
644+
}
645+
}

0 commit comments

Comments
 (0)