Skip to content

Commit fcc7b41

Browse files
committed
fix: reset account during tests
1 parent ccff02e commit fcc7b41

10 files changed

+15
-16
lines changed

tests/ed25519.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UX_MODE_TYPE } from "@toruslabs/customauth";
66
import { tssLib } from "@toruslabs/tss-frost-lib";
77
import BN from "bn.js";
88

9-
import { AsyncStorage, COREKIT_STATUS, ed25519, MemoryStorage, TssShareType, WEB3AUTH_NETWORK, WEB3AUTH_NETWORK_TYPE, Web3AuthMPCCoreKit } from "../src";
9+
import { AsyncStorage, COREKIT_STATUS, ed25519, MemoryStorage, WEB3AUTH_NETWORK, WEB3AUTH_NETWORK_TYPE, Web3AuthMPCCoreKit } from "../src";
1010
import { bufferToElliptic, criticalResetAccount, mockLogin, mockLogin2 } from "./setup";
1111

1212
type TestVariable = {
@@ -64,7 +64,7 @@ variable.forEach((testVariable) => {
6464
verifierId: parsedToken.email,
6565
idToken,
6666
});
67-
await criticalResetAccount(resetInstance);
67+
await criticalResetAccount(resetInstance, manualSync);
6868
await new AsyncStorage(resetInstance._storageKey, storageInstance).resetStore();
6969
}
7070

tests/factors.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) =
7575

7676
async function beforeTest() {
7777
const resetInstance = await newInstance();
78-
await criticalResetAccount(resetInstance);
78+
await criticalResetAccount(resetInstance, testVariable.manualSync);
7979
await resetInstance.logout();
8080
await new AsyncStorage(resetInstance._storageKey, testVariable.storage).resetStore();
8181
}

tests/gating.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ variable.forEach((testVariable) => {
6060
const testNameSuffix = testVariable.description;
6161
test(`#Gating test : ${testNameSuffix}`, async (t) => {
6262
async function beforeTest() {
63-
if (coreKitInstance.status === COREKIT_STATUS.INITIALIZED) await criticalResetAccount(coreKitInstance);
63+
if (coreKitInstance.status === COREKIT_STATUS.INITIALIZED) await criticalResetAccount(coreKitInstance, manualSync);
6464
}
6565

6666
t.after(async function () {

tests/importRecovery.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import assert from "node:assert";
22
import test from "node:test";
33

44
import { tssLib as tssLibDKLS } from "@toruslabs/tss-dkls-lib";
5-
import { tssLib as tssLibFROST } from "@toruslabs/tss-frost-lib";
65

76
import { MemoryStorage, sigToRSV, TssLibType, TssShareType, WEB3AUTH_NETWORK, Web3AuthMPCCoreKit } from "../src";
87
import { bufferToElliptic, criticalResetAccount, mockLogin } from "./setup";
@@ -55,10 +54,7 @@ export const ImportTest = async (testVariable: ImportKeyTestVariable) => {
5554
async function resetAccount(email: string) {
5655
const kit = await newCoreKitInstance(email);
5756
console.log('tss pub key', kit.state.tssPubKey)
58-
await criticalResetAccount(kit);
59-
if (testVariable.manualSync) {
60-
await kit.commitChanges();
61-
}
57+
await criticalResetAccount(kit, testVariable.manualSync);
6258
await kit.logout();
6359
// await new AsyncStorage(kit._storageKey, storageInstance).resetStore();
6460
}

tests/login-disableHashedFactorKey.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ variable.forEach((testVariable) => {
7878
verifierId: parsedToken.email,
7979
idToken,
8080
});
81-
await criticalResetAccount(resetInstance);
81+
await criticalResetAccount(resetInstance, manualSync);
8282
await new AsyncStorage(resetInstance._storageKey, storageInstance).resetStore();
8383
}
8484

tests/login.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ variable.forEach((testVariable) => {
7676
verifierId: parsedToken.email,
7777
idToken,
7878
});
79-
await criticalResetAccount(resetInstance);
79+
await criticalResetAccount(resetInstance, manualSync);
8080
await new AsyncStorage(resetInstance._storageKey, storageInstance).resetStore();
8181
}
8282

tests/securityQuestion.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const TssSecurityQuestionsTest = async (newInstance: () => Promise<Web3Au
2929
test(`#Tss Security Question - ${testVariable.manualSync} `, async function (t) {
3030
async function beforeTest() {
3131
const coreKitInstance = await newInstance();
32-
await criticalResetAccount(coreKitInstance);
32+
await criticalResetAccount(coreKitInstance, testVariable.manualSync);
3333
await coreKitInstance.logout();
3434

3535
await new AsyncStorage(coreKitInstance._storageKey, storageInstance).resetStore();

tests/sessionTime.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ variable.forEach(async (testVariable) => {
7676
});
7777

7878
async function beforeTest() {
79-
if (coreKitInstance.status === COREKIT_STATUS.INITIALIZED) await criticalResetAccount(coreKitInstance);
79+
if (coreKitInstance.status === COREKIT_STATUS.INITIALIZED) await criticalResetAccount(coreKitInstance, manualSync);
8080
}
8181

8282
t.after(async function () {
@@ -86,7 +86,7 @@ variable.forEach(async (testVariable) => {
8686

8787
await beforeTest();
8888

89-
await t.test("`sessionTime` should be equal to `sessionTokenDuration` from #Login", async function (t) {
89+
await t.test("`sessionTime` should be equal to `sessionTokenDuration` from #Login", async function () {
9090
// mocklogin
9191
const { idToken, parsedToken } = await mockLogin(email);
9292

tests/setup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const mockLogin2 = async (email: string) => {
2222
return { idToken, parsedToken };
2323
};
2424

25-
export const criticalResetAccount = async (coreKitInstance: Web3AuthMPCCoreKit): Promise<void> => {
25+
export const criticalResetAccount = async (coreKitInstance: Web3AuthMPCCoreKit, manualSync: boolean): Promise<void> => {
2626
// This is a critical function that should only be used for testing purposes
2727
// Resetting your account means clearing all the metadata associated with it from the metadata server
2828
// The key details will be deleted from our server and you will not be able to recover your account
@@ -37,6 +37,9 @@ export const criticalResetAccount = async (coreKitInstance: Web3AuthMPCCoreKit):
3737
privKey: new BN(coreKitInstance.state.postBoxKey!, "hex"),
3838
input: { message: "KEY_NOT_FOUND" },
3939
});
40+
if (manualSync) {
41+
await coreKitInstance.commitChanges();
42+
}
4043
}
4144
};
4245

tests/sfaImport.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const ImportSFATest = async (testVariable: ImportKeyTestVariable) => {
2828

2929
async function resetAccount(email: string) {
3030
const kit = await newCoreKitInstance(email);
31-
await criticalResetAccount(kit);
31+
await criticalResetAccount(kit, testVariable.manualSync);
3232
await kit.logout();
3333
await new AsyncStorage(kit._storageKey, storageInstance).resetStore();
3434
}

0 commit comments

Comments
 (0)