From 04f44cc13dda5749aeb4ffefa66c1edd050fbe9c Mon Sep 17 00:00:00 2001 From: Michael Assaf <94772640+snowmead@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:39:42 -0500 Subject: [PATCH] feat: Add test for checking BSP skipping volunteer if file key is already stored (#313) * add test for checking bsp skipping volunteer if file key is already stored * change back to describeBspNet --- .../integration/bsp/single-volunteer.test.ts | 75 +++++++++++-------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/test/suites/integration/bsp/single-volunteer.test.ts b/test/suites/integration/bsp/single-volunteer.test.ts index d21c2a9f0..93255809e 100644 --- a/test/suites/integration/bsp/single-volunteer.test.ts +++ b/test/suites/integration/bsp/single-volunteer.test.ts @@ -1,10 +1,21 @@ import assert, { notEqual, strictEqual } from "node:assert"; import { describeBspNet, shUser, sleep, type EnrichedBspApi } from "../../../util"; +import type { H256 } from "@polkadot/types/interfaces"; +import type { Bytes, u64, U8aFixed } from "@polkadot/types"; describeBspNet("Single BSP Volunteering", ({ before, createBspApi, it, createUserApi }) => { let userApi: EnrichedBspApi; let bspApi: EnrichedBspApi; + const source = "res/whatsup.jpg"; + const destination = "test/whatsup.jpg"; + const bucketName = "nothingmuch-2"; + + let file_size: u64; + let fingerprint: U8aFixed; + let location: Bytes; + let bucketId: H256; + before(async () => { userApi = await createUserApi(); bspApi = await createBspApi(); @@ -18,38 +29,7 @@ describeBspNet("Single BSP Volunteering", ({ before, createBspApi, it, createUse strictEqual(bspNodePeerId.toString(), userApi.shConsts.NODE_INFOS.bsp.expectedPeerId); }); - it("file is finger printed correctly", async () => { - const source = "res/adolphus.jpg"; - const destination = "test/adolphus.jpg"; - const bucketName = "nothingmuch-0"; - - const newBucketEventEvent = await userApi.createBucket(bucketName); - const newBucketEventDataBlob = - userApi.events.fileSystem.NewBucket.is(newBucketEventEvent) && newBucketEventEvent.data; - - if (!newBucketEventDataBlob) { - throw new Error("Event doesn't match Type"); - } - - const { - file_metadata: { location, fingerprint, file_size } - } = await userApi.rpc.storagehubclient.loadFileInStorage( - source, - destination, - userApi.shConsts.NODE_INFOS.user.AddressId, - newBucketEventDataBlob.bucketId - ); - - strictEqual(location.toHuman(), destination); - strictEqual(fingerprint.toString(), userApi.shConsts.TEST_ARTEFACTS[source].fingerprint); - strictEqual(file_size.toBigInt(), userApi.shConsts.TEST_ARTEFACTS[source].size); - }); - it("bsp volunteers when issueStorageRequest sent", async () => { - const source = "res/whatsup.jpg"; - const destination = "test/whatsup.jpg"; - const bucketName = "nothingmuch-2"; - const initialBspForestRoot = await bspApi.rpc.storagehubclient.getForestRoot(null); strictEqual( @@ -63,8 +43,10 @@ describeBspNet("Single BSP Volunteering", ({ before, createBspApi, it, createUse assert(newBucketEventDataBlob, "Event doesn't match Type"); + bucketId = newBucketEventDataBlob.bucketId; + const { - file_metadata: { location, fingerprint, file_size } + file_metadata: { location: loc, fingerprint: fp, file_size: s } } = await userApi.rpc.storagehubclient.loadFileInStorage( source, destination, @@ -72,6 +54,10 @@ describeBspNet("Single BSP Volunteering", ({ before, createBspApi, it, createUse newBucketEventDataBlob.bucketId ); + location = loc; + fingerprint = fp; + file_size = s; + await userApi.sealBlock( userApi.tx.fileSystem.issueStorageRequest( newBucketEventDataBlob.bucketId, @@ -80,7 +66,7 @@ describeBspNet("Single BSP Volunteering", ({ before, createBspApi, it, createUse file_size, userApi.shConsts.DUMMY_MSP_ID, [userApi.shConsts.NODE_INFOS.user.expectedPeerId], - null + 1 ), shUser ); @@ -156,6 +142,29 @@ describeBspNet("Single BSP Volunteering", ({ before, createBspApi, it, createUse strictEqual(sha, userApi.shConsts.TEST_ARTEFACTS["res/whatsup.jpg"].checksum); }); }); + + it("bsp skips volunteering for the same file key already being stored", async () => { + await userApi.sealBlock( + userApi.tx.fileSystem.issueStorageRequest( + bucketId, + location, + fingerprint, + file_size, + userApi.shConsts.DUMMY_MSP_ID, + [userApi.shConsts.NODE_INFOS.user.expectedPeerId], + 1 + ), + shUser + ); + + await userApi.assert.eventPresent("fileSystem", "NewStorageRequest"); + + await bspApi.docker.waitForLog({ + containerName: "docker-sh-bsp-1", + searchString: "Skipping file key", + timeout: 15000 + }); + }); }); describeBspNet("Single BSP multi-volunteers", ({ before, createBspApi, createUserApi, it }) => {