Skip to content

Commit

Permalink
chore: pull in Uint8Array|Buffer test
Browse files Browse the repository at this point in the history
Not strictly necessary but this test was added to ipld-dag-cbor and it's
nice for completeness and holds us strictly to the promise of Uint8Arrays
being the primary byte holder

Ref: ipld/js-ipld-dag-cbor#129
  • Loading branch information
rvagg authored and mikeal committed Jun 18, 2020
1 parent 4bae794 commit a6736c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"garbage": "0.0.0",
"hundreds": "0.0.2",
"mocha": "^7.2.0",
"multiformats": "0.0.4",
"multiformats": "0.0.11",
"polendina": "^1.0.0",
"standard": "^14.3.4"
},
Expand Down
20 changes: 20 additions & 0 deletions test/test-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,30 @@ describe('util', () => {
same(decoded, original)
}
})

test('CIDv1', () => {
const cid = new CID('zdj7Wd8AMwqnhJGQCbFxBVodGSBG84TM7Hs1rcJuQMwTyfEDS')
const encoded = encode({ link: cid })
const decoded = decode(encoded)
same(decoded, { link: cid })
})

it('encode and decode consistency with Uint8Array and Buffer fields', () => {
const buffer = Buffer.from('some data')
const bytes = Uint8Array.from(buffer)

const s1 = encode({ data: buffer })
const s2 = encode({ data: bytes })

same(s1, s2)

const verify = (s) => {
same(typeof s, 'object')
same(Object.keys(s), ['data'])
assert(s.data instanceof Uint8Array)
same(s.data.buffer, bytes.buffer)
}
verify(decode(s1))
verify(decode(s2))
})
})

0 comments on commit a6736c7

Please sign in to comment.