diff --git a/test/utils/topic.test.ts b/test/utils/topic.test.ts index d28bc379b..1f0879754 100644 --- a/test/utils/topic.test.ts +++ b/test/utils/topic.test.ts @@ -1,4 +1,9 @@ -import { buildContentTopic, isValidTopic } from '../../src/utils/topic' +import { + buildContentTopic, + buildDirectMessageTopicV2, + isValidTopic, +} from '../../src/utils/topic' +import crypto from '../../src/crypto/crypto' describe('topic utils', () => { describe('isValidTopic', () => { @@ -22,5 +27,22 @@ describe('topic utils', () => { false ) }) + + it('validates random topics correctly', () => { + const topics = Array.from({ length: 100 }).map(() => + buildDirectMessageTopicV2( + Buffer.from(crypto.getRandomValues(new Uint8Array(32))) + .toString('base64') + .replace(/=*$/g, '') + // Replace slashes with dashes so that the topic is still easily split by / + // We do not treat this as needing to be valid Base64 anywhere + .replace('/', '-') + ) + ) + + topics.forEach((topic) => { + expect(isValidTopic(topic)).toBe(true) + }) + }) }) })