From 4383f3fc6b1cc038a47686af9240703b0f798c27 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 29 Nov 2024 13:23:20 +0000 Subject: [PATCH] test: better assertions --- packages/upload-client/test/sharding.test.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/upload-client/test/sharding.test.js b/packages/upload-client/test/sharding.test.js index fbd1f1961..1dae6b935 100644 --- a/packages/upload-client/test/sharding.test.js +++ b/packages/upload-client/test/sharding.test.js @@ -103,9 +103,23 @@ describe('ShardingStream', () => { ) assert.equal(shards.length, 2) - assert.ok(shards[0].slices.has(blocks[0].cid.multihash)) - assert.ok(shards[0].slices.has(blocks[1].cid.multihash)) - assert.ok(shards[1].slices.has(blocks[2].cid.multihash)) + + const shard0Bytes = new Uint8Array(await shards[0].arrayBuffer()) + const shard1Bytes = new Uint8Array(await shards[1].arrayBuffer()) + + // block 0 and 1 should be in shard 0 + const slice0 = shards[0].slices.get(blocks[0].cid.multihash) + assert.ok(slice0) + assert(equals(blocks[0].bytes, shard0Bytes.slice(slice0[0], slice0[0] + slice0[1]))) + + const slice1 = shards[0].slices.get(blocks[1].cid.multihash) + assert.ok(slice1) + assert(equals(blocks[1].bytes, shard0Bytes.slice(slice1[0], slice1[0] + slice1[1]))) + + // block 2 should be in shard 1 + const slice2 = shards[1].slices.get(blocks[2].cid.multihash) + assert.ok(slice2) + assert(equals(blocks[2].bytes, shard1Bytes.slice(slice2[0], slice2[0] + slice2[1]))) }) it('exceeds shard size when block is encoded with root CID', async () => {