-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1711 from waku-org/adklempner/validate-content-to…
…pics feat: add function to validate autoshard content topic
- Loading branch information
Showing
6 changed files
with
164 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
"ahadns", | ||
"Alives", | ||
"asym", | ||
"autoshard", | ||
"autosharding", | ||
"backoff", | ||
"backoffs", | ||
"bitauth", | ||
|
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,6 @@ | ||
{ | ||
"reporterEnabled": "spec, allure-mocha", | ||
"allureMochaReporter": { | ||
"outputDir": "allure-results" | ||
} | ||
} |
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,26 @@ | ||
const config = { | ||
extension: ['ts'], | ||
spec: 'src/**/*.spec.ts', | ||
require: ['ts-node/register', 'isomorphic-fetch'], | ||
loader: 'ts-node/esm', | ||
'node-option': [ | ||
'experimental-specifier-resolution=node', | ||
'loader=ts-node/esm' | ||
], | ||
exit: true | ||
}; | ||
|
||
if (process.env.CI) { | ||
console.log("Running tests in parallel"); | ||
config.parallel = true; | ||
config.jobs = 6; | ||
console.log("Activating allure reporting"); | ||
config.reporter = 'mocha-multi-reporters'; | ||
config.reporterOptions = { | ||
configFile: '.mocha.reporters.json' | ||
}; | ||
} else { | ||
console.log("Running tests serially. To enable parallel execution update mocha config"); | ||
} | ||
|
||
module.exports = config; |
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
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,88 @@ | ||
import { expect } from "chai"; | ||
|
||
import { ensureValidContentTopic } from "./sharding"; | ||
|
||
const testInvalidCases = ( | ||
contentTopics: string[], | ||
expectedError: string | ||
): void => { | ||
for (const invalidTopic of contentTopics) { | ||
expect(() => ensureValidContentTopic(invalidTopic)).to.throw(expectedError); | ||
} | ||
}; | ||
|
||
describe("ensureValidContentTopic", () => { | ||
it("does not throw on valid cases", () => { | ||
const validTopics = [ | ||
"/0/myapp/1/mytopic/cbor", | ||
"/myapp/1/mytopic/cbor", | ||
"/myapp/v1.1/mytopic/cbor" | ||
]; | ||
for (const validTopic of validTopics) { | ||
expect(() => ensureValidContentTopic(validTopic)).to.not.throw; | ||
} | ||
}); | ||
it("throws on empty content topic", () => { | ||
testInvalidCases(["", " ", " "], "Content topic format is invalid"); | ||
}); | ||
|
||
it("throws on content topic with too few or too many fields", () => { | ||
testInvalidCases( | ||
[ | ||
"myContentTopic", | ||
"myapp1mytopiccbor/", | ||
" /myapp/1/mytopic", | ||
"/myapp/1/mytopic", | ||
"/0/myapp/1/mytopic/cbor/extra" | ||
], | ||
"Content topic format is invalid" | ||
); | ||
}); | ||
|
||
it("throws on content topic with non-number generation field", () => { | ||
testInvalidCases( | ||
[ | ||
"/a/myapp/1/mytopic/cbor", | ||
"/ /myapp/1/mytopic/cbor", | ||
"/_/myapp/1/mytopic/cbor", | ||
"/$/myapp/1/mytopic/cbor" | ||
], | ||
"Invalid generation field in content topic" | ||
); | ||
}); | ||
|
||
// Note that this test case should be removed once Waku supports other generations | ||
it("throws on content topic with generation field greater than 0", () => { | ||
testInvalidCases( | ||
[ | ||
"/1/myapp/1/mytopic/cbor", | ||
"/2/myapp/1/mytopic/cbor", | ||
"/3/myapp/1/mytopic/cbor", | ||
"/1000/myapp/1/mytopic/cbor" | ||
], | ||
"Generation greater than 0 is not supported" | ||
); | ||
}); | ||
|
||
it("throws on content topic with empty application field", () => { | ||
testInvalidCases( | ||
["/0//1/mytopic/cbor"], | ||
"Application field cannot be empty" | ||
); | ||
}); | ||
|
||
it("throws on content topic with empty version field", () => { | ||
testInvalidCases( | ||
["/0/myapp//mytopic/cbor"], | ||
"Version field cannot be empty" | ||
); | ||
}); | ||
|
||
it("throws on content topic with empty topic name field", () => { | ||
testInvalidCases(["/0/myapp/1//cbor"], "Topic name field cannot be empty"); | ||
}); | ||
|
||
it("throws on content topic with empty encoding field", () => { | ||
testInvalidCases(["/0/myapp/1/mytopic/"], "Encoding field cannot be empty"); | ||
}); | ||
}); |
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