Skip to content

Commit

Permalink
Merge pull request #4 from ipld/rvagg/verify-uint8array
Browse files Browse the repository at this point in the history
chore: pull in Uint8Array|Buffer test
  • Loading branch information
mikeal authored Jun 11, 2020
2 parents c73108e + 0bf1138 commit ab546d3
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 ab546d3

Please sign in to comment.