Skip to content

Commit

Permalink
Merge pull request #51 from ipfs/fix/50
Browse files Browse the repository at this point in the history
test for struct with both a cid and a bigint
  • Loading branch information
Stebalien authored Nov 2, 2018
2 parents fd4ef7b + c76b93d commit f12b83b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 25 additions & 1 deletion node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
mh "github.com/multiformats/go-multihash"
)

func init() {
RegisterCborType(BigIntAtlasEntry)
}

func assertCid(c cid.Cid, exp string) error {
if c.String() != exp {
return fmt.Errorf("expected cid of %s, got %s", exp, c)
Expand Down Expand Up @@ -504,6 +508,27 @@ func TestStableCID(t *testing.T) {
}
}

func TestCidAndBigInt(t *testing.T) {
type Foo struct {
B *big.Int
A cid.Cid
}
RegisterCborType(Foo{})

nd, err := WrapObject("", mh.SHA2_256, -1)
if err != nil {
t.Fatal(err)
}
c := nd.Cid()
_, err = WrapObject(&Foo{
A: c,
B: big.NewInt(1),
}, mh.SHA2_256, -1)
if err != nil {
t.Fatal(err)
}
}

func TestCanonicalStructEncoding(t *testing.T) {
type Foo struct {
Zebra string
Expand All @@ -512,7 +537,6 @@ func TestCanonicalStructEncoding(t *testing.T) {
Whale string
Cat bool
}
RegisterCborType(BigIntAtlasEntry)
RegisterCborType(Foo{})

s := Foo{
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
},
{
"author": "why",
"hash": "QmPAdjGx1huCjnrR26qy9QUUNSqA6EStyZ68RrwbtCTDML",
"hash": "QmfWqohMtbivn5NRJvtrLzCW3EU4QmoLvVNtmvo9vbdtVA",
"name": "refmt",
"version": "1.1.1"
"version": "1.1.2"
}
],
"gxVersion": "0.10.0",
Expand Down

0 comments on commit f12b83b

Please sign in to comment.