ts-mls
Version:
[](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [](https://badge.fury.io/js/ts-mls) [ {
const encoder = new TextEncoder();
const updatedGroups = [...clients];
for (const [senderIndex, senderState] of updatedGroups.entries()) {
const messageText = `Hello from member ${senderIndex}`;
const encodedMessage = encoder.encode(messageText);
const { privateMessage, newState: newSenderState } = await createApplicationMessage(senderState, encodedMessage, impl);
updatedGroups[senderIndex] = newSenderState;
for (const [receiverIndex, receiverGroup] of updatedGroups.entries()) {
if (receiverIndex === senderIndex)
continue;
const result = await processPrivateMessage(receiverGroup, privateMessage, makePskIndex(receiverGroup, {}), impl);
if (result.kind === "newState") {
throw new Error(`Expected application message for member ${receiverIndex} from ${senderIndex}`);
}
expect(result.message).toStrictEqual(encodedMessage);
updatedGroups[receiverIndex] = result.newState;
}
}
return { updatedGroups };
}
export async function cannotMessageAnymore(state, impl) {
await expect(createApplicationMessage(state, new TextEncoder().encode("hello"), impl)).rejects.toThrow(UsageError);
}
export function shuffledIndices(arr) {
const indices = arr.map((_, i) => i);
for (let i = indices.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[indices[i], indices[j]] = [indices[j], indices[i]];
}
return indices;
}
export function getRandomElement(arr) {
const index = Math.floor(Math.random() * arr.length);
return arr[index];
}
//# sourceMappingURL=common.js.map