Skip to content

Commit

Permalink
fix: add more test check for accountIndex
Browse files Browse the repository at this point in the history
update feature request error to propagate error message
  • Loading branch information
ieow committed Mar 1, 2024
1 parent 493a212 commit 58ab46e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/mpcCoreKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,8 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
if (result.status !== 200) {
// reset state on no mpc access
this.resetState();
throw new Error("MPC access denied, please subscribe to our plan to use MPC");
const errMessage = (await result.json()) as { error: string };
throw new Error(errMessage.error);
}
return result.json();
}
Expand Down
49 changes: 48 additions & 1 deletion tests/factors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export const FactorManipulationTest = async (newInstance: () => Promise<Web3Auth
await t.test("should able to create factor", async function () {
const coreKitInstance = await newInstance();
coreKitInstance.setTssWalletIndex(1);

coreKitInstance.setTssWalletIndex(0);
const tssPubKeyIndex0 = coreKitInstance.getTssPublicKey();

coreKitInstance.setTssWalletIndex(1);
const tssPubKeyIndex1 = coreKitInstance.getTssPublicKey();

coreKitInstance.setTssWalletIndex(99);
const tssPubKeyIndex99 = coreKitInstance.getTssPublicKey();

const firstFactor = coreKitInstance.getCurrentFactorKey();
// try delete hash factor factor
try {
Expand All @@ -51,6 +61,7 @@ export const FactorManipulationTest = async (newInstance: () => Promise<Web3Auth
shareType: TssShareType.DEVICE,
});

coreKitInstance.setTssWalletIndex(2);
const factorKey2 = await coreKitInstance.createFactor({
shareType: TssShareType.RECOVERY,
});
Expand All @@ -59,28 +70,64 @@ export const FactorManipulationTest = async (newInstance: () => Promise<Web3Auth
if (testVariable.manualSync) {
await coreKitInstance.commitChanges();
}

coreKitInstance.setTssWalletIndex(0);
const tssPubKeyIndexPost0 = coreKitInstance.getTssPublicKey();

coreKitInstance.setTssWalletIndex(1);
const tssPubKeyIndexPost1 = coreKitInstance.getTssPublicKey();

coreKitInstance.setTssWalletIndex(99);
const tssPubKeyIndexPost99 = coreKitInstance.getTssPublicKey();

// clear session prevent rehydration
await coreKitInstance.logout();

// new instance
const instance2 = await newInstance();
instance2.setTssWalletIndex(1);
assert.strictEqual(instance2.getTssFactorPub().length, 3);

// try inputFactor ( set as active factor )

// delete factor
instance2.setTssWalletIndex(0);
const pt = Point.fromPrivateKey(factorKey1);
await instance2.deleteFactor(pt.toTkeyPoint());

// delete factor
instance2.setTssWalletIndex(1);
const pt2 = Point.fromPrivateKey(factorKey2);
await instance2.deleteFactor(pt2.toTkeyPoint());

if (testVariable.manualSync) {
await instance2.commitChanges();
}

instance2.setTssWalletIndex(0);
const tssPubKey2IndexPost0 = instance2.getTssPublicKey();

instance2.setTssWalletIndex(1);
const tssPubKey2IndexPost1 = instance2.getTssPublicKey();

instance2.setTssWalletIndex(99);
const tssPubKey2IndexPost99 = instance2.getTssPublicKey();

assert.equal(tssPubKeyIndex0.x.toString("hex"), tssPubKeyIndexPost0.x.toString("hex"));
assert.equal(tssPubKeyIndex1.x.toString("hex"), tssPubKeyIndexPost1.x.toString("hex"));
assert.equal(tssPubKeyIndex99.x.toString("hex"), tssPubKeyIndexPost99.x.toString("hex"));

assert.equal(tssPubKeyIndex0.y.toString("hex"), tssPubKeyIndexPost0.y.toString("hex"));
assert.equal(tssPubKeyIndex1.y.toString("hex"), tssPubKeyIndexPost1.y.toString("hex"));
assert.equal(tssPubKeyIndex99.y.toString("hex"), tssPubKeyIndexPost99.y.toString("hex"));

assert.equal(tssPubKey2IndexPost0.x.toString("hex"), tssPubKeyIndex0.x.toString("hex"));
assert.equal(tssPubKey2IndexPost1.x.toString("hex"), tssPubKeyIndex1.x.toString("hex"));
assert.equal(tssPubKey2IndexPost99.x.toString("hex"), tssPubKeyIndex99.x.toString("hex"));

assert.equal(tssPubKey2IndexPost0.y.toString("hex"), tssPubKeyIndex0.y.toString("hex"));
assert.equal(tssPubKey2IndexPost1.y.toString("hex"), tssPubKeyIndex1.y.toString("hex"));
assert.equal(tssPubKey2IndexPost99.y.toString("hex"), tssPubKeyIndex99.y.toString("hex"));

// new instance
const instance3 = await newInstance();
assert.strictEqual(instance3.getTssFactorPub().length, 1);
Expand Down

0 comments on commit 58ab46e

Please sign in to comment.