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

test for struct with both a cid and a bigint #51

Merged
merged 2 commits into from
Nov 2, 2018
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
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 @@ -45,9 +45,9 @@
},
{
"author": "why",
"hash": "QmPAdjGx1huCjnrR26qy9QUUNSqA6EStyZ68RrwbtCTDML",
"hash": "QmfWqohMtbivn5NRJvtrLzCW3EU4QmoLvVNtmvo9vbdtVA",
"name": "refmt",
"version": "1.1.1"
"version": "1.1.2"
}
],
"gxVersion": "0.10.0",
Expand Down