From 0bf1138312f9ecf73a2e5a13bafd2b2199566590 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 11 Jun 2020 17:29:34 +1000 Subject: [PATCH] chore: pull in Uint8Array|Buffer test 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: https://github.com/ipld/js-ipld-dag-cbor/pull/129 --- package.json | 2 +- test/test-basics.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index bb6967c..b4d02ef 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/test-basics.js b/test/test-basics.js index 1d433a4..669f5e4 100644 --- a/test/test-basics.js +++ b/test/test-basics.js @@ -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)) + }) })