Skip to content

Commit

Permalink
feat: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
guru-web3 committed Feb 23, 2024
1 parent cc6f71e commit c24561e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ export interface Web3AuthOptions {
* Setup Provider after `login success` reconstruct.
*/
setupProviderOnInit?: boolean;

}

export type Web3AuthOptionsWithDefaults = Required<Web3AuthOptions>;
Expand Down
2 changes: 1 addition & 1 deletion src/mpcCoreKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
if (!tkey.metadata) return COREKIT_STATUS.INITIALIZED;
if (!tkey.privKey || !this.state.factorKey) return COREKIT_STATUS.REQUIRED_SHARE;
return COREKIT_STATUS.LOGGED_IN;
} catch (e) { }
} catch (e) {}
return COREKIT_STATUS.NOT_INITIALIZED;
}

Expand Down
34 changes: 31 additions & 3 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as TssLib from "@toruslabs/tss-lib-node";
import BN from "bn.js";
import { ec as EC } from "elliptic";

import { BrowserStorage, COREKIT_STATUS, WEB3AUTH_NETWORK, WEB3AUTH_NETWORK_TYPE, Web3AuthMPCCoreKit } from "../src";
import { BrowserStorage, COREKIT_STATUS, DEFAULT_CHAIN_CONFIG, WEB3AUTH_NETWORK, WEB3AUTH_NETWORK_TYPE, Web3AuthMPCCoreKit } from "../src";
import { criticalResetAccount, mockLogin } from "./setup";

type TestVariable = {
Expand Down Expand Up @@ -47,6 +47,16 @@ variable.forEach((testVariable) => {
storageKey: "memory",
manualSync,
});
const coreKitInstanceWithoutProvider = new Web3AuthMPCCoreKit({
web3AuthClientId: "torus-key-test",
web3AuthNetwork,
baseUrl: "http://localhost:3000",
uxMode,
tssLib: TssLib,
storageKey: "memory",
manualSync,
setupProviderOnInit: false,
});

const testNameSuffix = JSON.stringify(testVariable);
test(`#Login Test with JWT + logout : ${testNameSuffix}`, async (t) => {
Expand All @@ -64,7 +74,7 @@ variable.forEach((testVariable) => {
// // redirect flow
// // not testable
// });
await t.test("#Login ", async function () {
await t.test("#Login with default provider", async function () {
// mocklogin
const { idToken, parsedToken } = await mockLogin(email);
await coreKitInstance.init({ handleRedirectResult: false });
Expand All @@ -73,9 +83,27 @@ variable.forEach((testVariable) => {
verifierId: parsedToken.email,
idToken,
});

// get key details
await checkLogin(coreKitInstance);
const result = await coreKitInstance.provider.request({ method: "eth_chainId", params: [] });
assert.strictEqual(result, DEFAULT_CHAIN_CONFIG.chainId);
});

await t.test("#Login without provider", async function () {
// mocklogin
const { idToken, parsedToken } = await mockLogin(email);
await coreKitInstanceWithoutProvider.init({ handleRedirectResult: false });
await coreKitInstanceWithoutProvider.loginWithJWT({
verifier: "torus-test-health",
verifierId: parsedToken.email,
idToken,
});
// get key details
await checkLogin(coreKitInstanceWithoutProvider);
try {
await coreKitInstanceWithoutProvider.provider.request({ method: "eth_chainId", params: [] });
throw new Error("should not reach here");
} catch (error) {}
});

await t.test("#relogin ", async function () {
Expand Down

0 comments on commit c24561e

Please sign in to comment.