-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smoke tests for Data Preservers pallet (#751)
* test data preservers deposit * matching request and witness * lint * smoke test for all chains + fail on unknown payment mode * test profile urls have expected prefix
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import "@tanssi/api-augment"; | ||
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 }) => { | ||
let paraApi: ApiPromise; | ||
|
||
beforeAll(async function () { | ||
paraApi = context.polkadotJs("para"); | ||
}); | ||
|
||
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 [, entry] of entries) { | ||
expect(validDeposits.includes(entry.deposit)); | ||
} | ||
}, | ||
}); | ||
|
||
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 [, entry] of entries) { | ||
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(); | ||
} 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"); | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
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)); | ||
} |