From c2acc6140b7955a02ad7bef4ca493b8a3b310617 Mon Sep 17 00:00:00 2001
From: Piotr Roslaniec
Date: Tue, 27 Jun 2023 15:33:50 +0200
Subject: [PATCH] fix tests
---
src/characters/cbd-recipient.ts | 11 ++++++++---
test/unit/cbd-strategy.test.ts | 2 +-
test/utils.ts | 10 ++++++----
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/characters/cbd-recipient.ts b/src/characters/cbd-recipient.ts
index f9ed96c55..482eeb501 100644
--- a/src/characters/cbd-recipient.ts
+++ b/src/characters/cbd-recipient.ts
@@ -120,9 +120,14 @@ export class CbdTDecDecrypter {
variant: number,
expectedRitualId: number
) {
- const decryptedResponses = Object.entries(encryptedResponses).map(
- ([ursula, encryptedResponse]) =>
- encryptedResponse.decrypt(sessionSharedSecret[ursula])
+ const decryptedResponses = Object.entries(sessionSharedSecret).map(
+ ([ursula, sharedSecret]) => {
+ const encryptedResponse = encryptedResponses[ursula];
+ if (!encryptedResponse) {
+ throw new Error(`Missing encrypted response from ${ursula}`);
+ }
+ return encryptedResponse.decrypt(sharedSecret);
+ }
);
const ritualIds = decryptedResponses.map(({ ritualId }) => ritualId);
diff --git a/test/unit/cbd-strategy.test.ts b/test/unit/cbd-strategy.test.ts
index d33e9d456..36a8f216b 100644
--- a/test/unit/cbd-strategy.test.ts
+++ b/test/unit/cbd-strategy.test.ts
@@ -49,7 +49,7 @@ const makeCbdStrategy = async () => {
async function makeDeployedCbdStrategy() {
const strategy = await makeCbdStrategy();
- const mockedDkg = fakeDkgFlow(variant, 0);
+ const mockedDkg = fakeDkgFlow(variant, 0, 4, 4);
const mockedDkgRitual = fakeDkgRitual(mockedDkg, mockedDkg.threshold);
const web3Provider = fakeWeb3Provider(aliceSecretKey.toBEBytes());
const getUrsulasSpy = mockGetUrsulas(ursulas);
diff --git a/test/utils.ts b/test/utils.ts
index bdd0b0414..b79ca46d6 100644
--- a/test/utils.ts
+++ b/test/utils.ts
@@ -216,8 +216,8 @@ export const mockDetectEthereumProvider = () => {
export const fakeDkgFlow = (
variant: FerveoVariant | FerveoVariant.Precomputed,
ritualId: number,
- sharesNum = 4,
- threshold = 3
+ sharesNum: number,
+ threshold: number
) => {
if (
variant !== FerveoVariant.Simple &&
@@ -358,9 +358,11 @@ export const fakeDkgTDecFlowE2e = (
variant: FerveoVariant,
message = toBytes('fake-message'),
aad = toBytes('fake-aad'),
- ritualId = 0
+ ritualId = 0,
+ sharesNum = 4,
+ threshold = 4
) => {
- const ritual = fakeDkgFlow(variant, ritualId, 4, 3);
+ const ritual = fakeDkgFlow(variant, ritualId, sharesNum, threshold);
// In the meantime, the client creates a ciphertext and decryption request
const ciphertext = ferveoEncrypt(message, aad, ritual.dkg.publicKey());