This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: interop testing and bug fixing (#40)
- Loading branch information
Showing
19 changed files
with
261 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Extracted from: https://github.com/ipfs/go-ipld-cbor/tree/master/test_objects |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"/":"QmRgutAxd8t7oGkSm4wmeuByG6M51wcTso6cubDdQtuEfL"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"array-link": {"/":"zdpuAsZ8roJvCazJFXUnSULspbXfxrLkUkNxy6SToaiDpEiap"}, | ||
"empty-array": {"/":"zdpuAtQy7GSHNcZxdBfmtowdL1d2WAFjJBwb6WAEfFJ6T4Gbi"}, | ||
"empty-obj": {"/":"zdpuAyTBnYSugBZhqJuLsNpzjmAjSmxDqBbtAqXMtsvxiN2v3"}, | ||
"foo": {"/":"zdpuAtu6ZgHLyiGZAX743EurWhSr9ixbVbrtFaxbr8Z8Q16gW"}, | ||
"obj-with-link": {"/":"zdpuAp1WRqfq8w953Dep9pz7nNYUbQPKX9duW71G5C4doiPFK"}, | ||
"obj-no-link": {"/":"zdpuAtHFXfzgXBSoq5GSn3NTrK2ToYwj4tRZiMTfe2mVApYLa"} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"foo": "bar", | ||
"cats": [ | ||
{"/": "QmRgutAxd8t7oGkSm4wmeuByG6M51wcTso6cubDdQtuEfL"}, | ||
{ | ||
"something": "interesting" | ||
}, | ||
[ | ||
"fish", | ||
{"/": "QmRgutAxd8t7oGkSm4wmeuByG6M51wcTso6cubDdQtuEfL"}, | ||
9 | ||
] | ||
], | ||
"other": {"/": "QmRgutAxd8t7oGkSm4wmeuByG6M51wcTso6cubDdQtuEfL"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�isassafrashand cats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"sassafras": "and cats" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"foo": {"/":"QmRgutAxd8t7oGkSm4wmeuByG6M51wcTso6cubDdQtuEfL"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
|
||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const dagCBOR = require('../src') | ||
const loadFixture = require('aegir/fixtures') | ||
const bs58 = require('bs58') | ||
const isNode = require('detect-node') | ||
|
||
const arrayLinkCBOR = loadFixture(__dirname, '/fixtures/array-link.cbor') | ||
const arrayLinkJSON = require('./fixtures/array-link.json') | ||
|
||
const emptyArrayCBOR = loadFixture(__dirname, '/fixtures/empty-array.cbor') | ||
const emptyArrayJSON = require('./fixtures/empty-array.json') | ||
|
||
const emptyObjCBOR = loadFixture(__dirname, '/fixtures/empty-obj.cbor') | ||
const emptyObjJSON = require('./fixtures/empty-obj.json') | ||
|
||
const fooCBOR = loadFixture(__dirname, '/fixtures/foo.cbor') | ||
const fooJSON = require('./fixtures/foo.json') | ||
|
||
const objNoLinkCBOR = loadFixture(__dirname, '/fixtures/obj-no-link.cbor') | ||
const objNoLinkJSON = require('./fixtures/obj-no-link.json') | ||
|
||
const objWithLinkCBOR = loadFixture(__dirname, '/fixtures/obj-with-link.cbor') | ||
const objWithLinkJSON = require('./fixtures/obj-with-link.json') | ||
|
||
const expectedCIDs = require('./fixtures/expected.json') | ||
|
||
describe('dag-cbor interop tests', () => { | ||
// the fixtures feature needs to be fixed | ||
if (!isNode) { return } | ||
|
||
describe('deserialize and compare', () => { | ||
it('array-link', (done) => { | ||
dagCBOR.util.deserialize(arrayLinkCBOR, (err, node) => { | ||
expect(err).to.not.exist | ||
// the JSON version that gets out of go-ipfs stringifies the CID | ||
const bs58Str = bs58.encode(node[0]['/']) | ||
|
||
node[0]['/'] = bs58Str | ||
expect(node).to.eql(arrayLinkJSON) | ||
|
||
// put it back to bytes | ||
node[0]['/'] = bs58.decode(arrayLinkJSON[0]['/']) | ||
|
||
dagCBOR.util.cid(node, (err, cid) => { | ||
expect(err).to.not.exist | ||
const cidStr = cid.toBaseEncodedString() | ||
expect(cidStr).to.eql(expectedCIDs['array-link']['/']) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('empty-array', (done) => { | ||
dagCBOR.util.deserialize(emptyArrayCBOR, (err, node) => { | ||
expect(err).to.not.exist | ||
expect(node).to.eql(emptyArrayJSON) | ||
|
||
dagCBOR.util.cid(node, (err, cid) => { | ||
expect(err).to.not.exist | ||
const cidStr = cid.toBaseEncodedString() | ||
expect(cidStr).to.eql(expectedCIDs['empty-array']['/']) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('empty-obj', (done) => { | ||
dagCBOR.util.deserialize(emptyObjCBOR, (err, node) => { | ||
expect(err).to.not.exist | ||
expect(node).to.eql(emptyObjJSON) | ||
|
||
dagCBOR.util.cid(node, (err, cid) => { | ||
expect(err).to.not.exist | ||
const cidStr = cid.toBaseEncodedString() | ||
expect(cidStr).to.eql(expectedCIDs['empty-obj']['/']) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it.skip('foo', (done) => { | ||
dagCBOR.util.deserialize(fooCBOR, (err, node) => { | ||
expect(err).to.not.exist | ||
expect(node).to.eql(fooJSON) | ||
|
||
dagCBOR.util.cid(node, (err, cid) => { | ||
expect(err).to.not.exist | ||
const cidStr = cid.toBaseEncodedString() | ||
expect(cidStr).to.eql(expectedCIDs['foo']['/']) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('obj-no-link', (done) => { | ||
dagCBOR.util.deserialize(objNoLinkCBOR, (err, node) => { | ||
expect(err).to.not.exist | ||
expect(node).to.eql(objNoLinkJSON) | ||
|
||
dagCBOR.util.cid(node, (err, cid) => { | ||
expect(err).to.not.exist | ||
const cidStr = cid.toBaseEncodedString() | ||
expect(cidStr).to.eql(expectedCIDs['obj-no-link']['/']) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('obj-with-link', (done) => { | ||
if (!isNode) { done() } | ||
|
||
dagCBOR.util.deserialize(objWithLinkCBOR, (err, node) => { | ||
expect(err).to.not.exist | ||
|
||
dagCBOR.util.cid(node, (err, cid) => { | ||
expect(err).to.not.exist | ||
const cidStr = cid.toBaseEncodedString() | ||
expect(cidStr).to.eql(expectedCIDs['obj-with-link']['/']) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('serialise and compare', () => { | ||
it('array-link', (done) => { | ||
arrayLinkJSON[0]['/'] = bs58.decode(arrayLinkJSON[0]['/']) | ||
|
||
dagCBOR.util.serialize(arrayLinkJSON, (err, serialized) => { | ||
expect(err).to.not.exist | ||
|
||
expect(serialized).to.eql(arrayLinkCBOR) | ||
done() | ||
}) | ||
}) | ||
|
||
it('empty-array', (done) => { | ||
dagCBOR.util.serialize(emptyArrayJSON, (err, serialized) => { | ||
expect(err).to.not.exist | ||
expect(serialized).to.eql(emptyArrayCBOR) | ||
done() | ||
}) | ||
}) | ||
|
||
it('empty-obj', (done) => { | ||
dagCBOR.util.serialize(emptyObjJSON, (err, serialized) => { | ||
expect(err).to.not.exist | ||
expect(serialized).to.eql(emptyObjCBOR) | ||
done() | ||
}) | ||
}) | ||
|
||
it.skip('foo', (done) => {}) | ||
|
||
it('obj-no-link', (done) => { | ||
dagCBOR.util.serialize(objNoLinkJSON, (err, serialized) => { | ||
expect(err).to.not.exist | ||
expect(serialized).to.eql(objNoLinkCBOR) | ||
done() | ||
}) | ||
}) | ||
|
||
it('obj-with-link', (done) => { | ||
objWithLinkJSON.foo['/'] = bs58.decode(objWithLinkJSON.foo['/']) | ||
|
||
dagCBOR.util.serialize(objWithLinkJSON, (err, serialized) => { | ||
expect(err).to.not.exist | ||
expect(serialized).to.eql(objWithLinkCBOR) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters