From aa122331f6bf5f4e86acde7c9353a87be8fff5c1 Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:16:17 +0100 Subject: [PATCH 1/5] test data preservers deposit --- .../test-data-preservers.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/suites/smoke-test-dancebox/test-data-preservers.ts diff --git a/test/suites/smoke-test-dancebox/test-data-preservers.ts b/test/suites/smoke-test-dancebox/test-data-preservers.ts new file mode 100644 index 000000000..f4a2a9126 --- /dev/null +++ b/test/suites/smoke-test-dancebox/test-data-preservers.ts @@ -0,0 +1,37 @@ +import "@tanssi/api-augment"; +import { ApiDecoration } from "@polkadot/api/types"; +import { describeSuite, expect, beforeAll } from "@moonwall/cli"; +import { ApiPromise } from "@polkadot/api"; + +describeSuite({ + id: "S16", + title: "Verify data preservers consistency", + foundationMethods: "read_only", + testCases: ({ context, it, log }) => { + let atBlockNumber: number = 0; + let apiAt: ApiDecoration<"promise">; + let paraApi: ApiPromise; + + beforeAll(async function () { + paraApi = context.polkadotJs("para"); + atBlockNumber = (await paraApi.rpc.chain.getHeader()).number.toNumber(); + apiAt = await paraApi.at(await paraApi.rpc.chain.getBlockHash(atBlockNumber)); + }); + + it({ + id: "C01", + title: "all profiles should have a deposit of either 0 or value fixed in the runtime", + test: async function () { + // Add more if we change ProfileDeposit value. Keep previous values for profiles + // created before the change. + const validDeposits = [0, 11330000000000]; + + const entries = await paraApi.query.dataPreservers.profiles.entries(); + + for (const [key, entry] of entries) { + expect(validDeposits.includes(entry.deposit)); + } + }, + }); + }, +}); From 8d1c96c881ca1888efd2ae5d34d00702c51225ae Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:57:08 +0100 Subject: [PATCH 2/5] matching request and witness --- .../test-data-preservers.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/suites/smoke-test-dancebox/test-data-preservers.ts b/test/suites/smoke-test-dancebox/test-data-preservers.ts index f4a2a9126..d421fe6c6 100644 --- a/test/suites/smoke-test-dancebox/test-data-preservers.ts +++ b/test/suites/smoke-test-dancebox/test-data-preservers.ts @@ -33,5 +33,35 @@ describeSuite({ } }, }); + + it({ + id: "C02", + title: "all assigned profile have assignement witness corresponding to request and whished para id", + test: async function () { + const entries = await paraApi.query.dataPreservers.profiles.entries(); + + for (const [key, entry] of entries) { + console.log(JSON.stringify(entry)); + + if (entry.assignment == null) { + continue; + } + + const [para_id, witness] = entry.assignment; + + if (entry.profile.paraIds.whitelist != null) { + expect(entry.profile.paraIds.whitelist.includes(para_id)); + } else if (entry.profile.paraIds.blacklist != null) { + expect(!entry.profile.paraIds.blacklist.includes(para_id)); + } + + if (entry.profile.assignmentRequest == "Free") { + expect(witness).to.be.eq("Free"); + } else if (entry.profile.assignmentRequest.streamPayment != null) { + expect(witness.streamPayment).to.not.be.undefined(); + } + } + }, + }); }, }); From 1379ae0aea9d179328827c5e5de933bc01506623 Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Mon, 18 Nov 2024 14:31:26 +0100 Subject: [PATCH 3/5] lint --- .../smoke-test-dancebox/test-data-preservers.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/suites/smoke-test-dancebox/test-data-preservers.ts b/test/suites/smoke-test-dancebox/test-data-preservers.ts index d421fe6c6..6356d427f 100644 --- a/test/suites/smoke-test-dancebox/test-data-preservers.ts +++ b/test/suites/smoke-test-dancebox/test-data-preservers.ts @@ -1,5 +1,4 @@ import "@tanssi/api-augment"; -import { ApiDecoration } from "@polkadot/api/types"; import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { ApiPromise } from "@polkadot/api"; @@ -7,15 +6,11 @@ describeSuite({ id: "S16", title: "Verify data preservers consistency", foundationMethods: "read_only", - testCases: ({ context, it, log }) => { - let atBlockNumber: number = 0; - let apiAt: ApiDecoration<"promise">; + testCases: ({ context, it }) => { let paraApi: ApiPromise; beforeAll(async function () { paraApi = context.polkadotJs("para"); - atBlockNumber = (await paraApi.rpc.chain.getHeader()).number.toNumber(); - apiAt = await paraApi.at(await paraApi.rpc.chain.getBlockHash(atBlockNumber)); }); it({ @@ -28,7 +23,7 @@ describeSuite({ const entries = await paraApi.query.dataPreservers.profiles.entries(); - for (const [key, entry] of entries) { + for (const [, entry] of entries) { expect(validDeposits.includes(entry.deposit)); } }, @@ -40,7 +35,7 @@ describeSuite({ test: async function () { const entries = await paraApi.query.dataPreservers.profiles.entries(); - for (const [key, entry] of entries) { + for (const [, entry] of entries) { console.log(JSON.stringify(entry)); if (entry.assignment == null) { From 4b3fcc4561f95b1900d155252b5e350a30ef9caf Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:09:02 +0100 Subject: [PATCH 4/5] smoke test for all chains + fail on unknown payment mode --- .../test-data-preservers.ts | 4 ++++ 1 file changed, 4 insertions(+) rename test/suites/{smoke-test-dancebox => smoke-test-common-all}/test-data-preservers.ts (90%) diff --git a/test/suites/smoke-test-dancebox/test-data-preservers.ts b/test/suites/smoke-test-common-all/test-data-preservers.ts similarity index 90% rename from test/suites/smoke-test-dancebox/test-data-preservers.ts rename to test/suites/smoke-test-common-all/test-data-preservers.ts index 6356d427f..9684fe4e3 100644 --- a/test/suites/smoke-test-dancebox/test-data-preservers.ts +++ b/test/suites/smoke-test-common-all/test-data-preservers.ts @@ -54,6 +54,10 @@ describeSuite({ expect(witness).to.be.eq("Free"); } else if (entry.profile.assignmentRequest.streamPayment != null) { expect(witness.streamPayment).to.not.be.undefined(); + } else { + // Make test fail on unknown assignment modes. + // This force use to update this test when we add new modes. + expect.fail("unknown assignment mode"); } } }, From 5974880ae37e6f30a8b99fccec996fe01dfd124c Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:39:21 +0100 Subject: [PATCH 5/5] test profile urls have expected prefix --- .../test-data-preservers.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/suites/smoke-test-common-all/test-data-preservers.ts b/test/suites/smoke-test-common-all/test-data-preservers.ts index 9684fe4e3..f561f91c0 100644 --- a/test/suites/smoke-test-common-all/test-data-preservers.ts +++ b/test/suites/smoke-test-common-all/test-data-preservers.ts @@ -36,8 +36,6 @@ describeSuite({ const entries = await paraApi.query.dataPreservers.profiles.entries(); for (const [, entry] of entries) { - console.log(JSON.stringify(entry)); - if (entry.assignment == null) { continue; } @@ -62,5 +60,24 @@ describeSuite({ } }, }); + + it({ + id: "C03", + title: "all profiles should have valid url", + test: async function () { + const entries = await paraApi.query.dataPreservers.profiles.entries(); + + for (const [, entry] of entries) { + const profile = entry.unwrap().profile; + expect(isValidEndpointUrl(profile.url.toHuman()), `Invalid URL {profile.url}`); + } + }, + }); }, }); + +function isValidEndpointUrl(string) { + const prefixes = ["/dns4/", "https://", "http://", "wss://", "ws://"]; + + return prefixes.some((prefix) => string.startsWith(prefix)); +}