diff --git a/test/index.html b/test/index.html
deleted file mode 100644
index 9a63e6b..0000000
--- a/test/index.html
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
- Metadata helpers test
-
-
-
-
-
diff --git a/test/test.ts b/test/index.test.ts
similarity index 67%
rename from test/test.ts
rename to test/index.test.ts
index fbdf014..7091060 100644
--- a/test/test.ts
+++ b/test/index.test.ts
@@ -1,6 +1,6 @@
import { generatePrivate } from "@toruslabs/eccrypto";
-import assert from "assert";
import { ec as EC } from "elliptic";
+import { describe, expect, it } from "vitest";
import { MetadataStorageLayer } from "../src/MetadataStorageLayer";
import { keccak256 } from "../src/utils";
@@ -16,26 +16,26 @@ const privKey2 = generatePrivate();
const keyPair2 = ec.keyFromPrivate(privKey2);
const pubKey2 = keyPair2.getPublic();
-describe("Metadata", function () {
+describe("Metadata", () => {
let randomMessage: string;
- it("should get nothing by default", async function () {
+ it("should get nothing by default", async () => {
const res = await storage.getMetadata({ pub_key_X: pubKey.getX().toString(16), pub_key_Y: pubKey.getY().toString(16) }, null);
- assert.strictEqual(res, "");
+ expect(res).toBe("");
});
- it("should set", async function () {
+ it("should set and get", async () => {
+ // Set metadata
randomMessage = JSON.stringify({ message: keccak256(Buffer.from(Date.now().toString(), "utf-8")).toString("hex") });
const params = storage.generateMetadataParams(randomMessage, privKey.toString("hex"));
await storage.setMetadata(params, "metadata-test");
- });
- it("should get", async function () {
+ // Get and verify metadata
const message = await storage.getMetadata(storage.generatePubKeyParams(privKey.toString("hex")), "metadata-test");
- assert.strictEqual(message, randomMessage);
+ expect(message).toBe(randomMessage);
});
- it("should set and get WebAuthn Torus Share", async function () {
+ it("should set and get WebAuthn Torus Share", async () => {
await setTorusShare(
storage,
{ pub_key_X: pubKey2.getX().toString(16), pub_key_Y: pubKey2.getY().toString(16) },
@@ -44,20 +44,19 @@ describe("Metadata", function () {
"customTorusShare"
);
const googleShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), "google");
- assert.strictEqual(googleShare, "customTorusShare");
+ expect(googleShare).toBe("customTorusShare");
});
- it("should set and get WebAuthn Device Share", async function () {
+ it("should set and get WebAuthn Device Share", async () => {
let googleShare = await getDeviceShare(storage, privKey.toString("hex"), "google");
- if (googleShare) {
- throw new Error("get Torus share should have nothing");
- }
+ expect(googleShare).toBeNull();
+
await setDeviceShare(storage, privKey.toString("hex"), "google", "customDeviceShare");
googleShare = await getDeviceShare(storage, privKey.toString("hex"), "google");
- assert.strictEqual(googleShare, "customDeviceShare");
+ expect(googleShare).toBe("customDeviceShare");
});
- it("should set and get multiple WebAuthn Torus Shares", async function () {
+ it("should set and get multiple WebAuthn Torus Shares", async () => {
const subspaces = ["facebook", "twitter", "github"];
const shares = ["fbShare", "twitterShare", "githubShare"];
@@ -75,16 +74,16 @@ describe("Metadata", function () {
// Get and verify shares for each subspace
for (let i = 0; i < subspaces.length; i++) {
const retrievedShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), subspaces[i]);
- assert.strictEqual(retrievedShare, shares[i], `Share for ${subspaces[i]} should match`);
+ expect(retrievedShare).toBe(shares[i]);
}
});
- it("should handle non-existent WebAuthn Torus Share", async function () {
+ it("should handle non-existent WebAuthn Torus Share", async () => {
const nonExistentShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), "nonexistent");
- assert.strictEqual(nonExistentShare, null, "Non-existent share should return null");
+ expect(nonExistentShare).toBeNull();
});
- it("should update existing WebAuthn Torus Share", async function () {
+ it("should update existing WebAuthn Torus Share", async () => {
const initialShare = "initialShare";
const updatedShare = "updatedShare";
const subspace = "updateTest";
@@ -98,7 +97,7 @@ describe("Metadata", function () {
);
let retrievedShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), subspace);
- assert.strictEqual(retrievedShare, initialShare, "Initial share should be set correctly");
+ expect(retrievedShare).toBe(initialShare);
await setTorusShare(
storage,
@@ -109,10 +108,10 @@ describe("Metadata", function () {
);
retrievedShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), subspace);
- assert.strictEqual(retrievedShare, updatedShare, "Share should be updated");
+ expect(retrievedShare).toBe(updatedShare);
});
- it("should handle multiple subspaces with different data types", async function () {
+ it("should handle multiple subspaces with different data types", async () => {
const subspaces = ["stringSpace", "numberSpace", "objectSpace"];
const shares = ["testString", 42, { key: "value" }];
@@ -128,11 +127,11 @@ describe("Metadata", function () {
for (let i = 0; i < subspaces.length; i++) {
const retrievedShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), subspaces[i]);
- assert.deepStrictEqual(retrievedShare, shares[i], `Share for ${subspaces[i]} should match and maintain its data type`);
+ expect(retrievedShare).toEqual(shares[i]);
}
});
- it("should handle empty string as share data", async function () {
+ it("should handle empty string as share data", async () => {
const emptyShare = "";
const subspace = "emptySpace";
@@ -145,23 +144,27 @@ describe("Metadata", function () {
);
const retrievedShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), subspace);
- assert.strictEqual(retrievedShare, emptyShare, "Empty string share should be retrieved correctly");
+ expect(retrievedShare).toBe(emptyShare);
});
- it("should handle large data in WebAuthn Torus Share", async function () {
- const largeData = "x".repeat(1000000); // 1MB of data
- const subspace = "largeDataSpace";
+ it(
+ "should handle large data in WebAuthn Torus Share",
+ async () => {
+ const largeData = "x".repeat(1000000); // 1MB of data
+ const subspace = "largeDataSpace";
- await setTorusShare(
- storage,
- { pub_key_X: pubKey2.getX().toString(16), pub_key_Y: pubKey2.getY().toString(16) },
- privKey.toString("hex"),
- subspace,
- largeData
- );
+ await setTorusShare(
+ storage,
+ { pub_key_X: pubKey2.getX().toString(16), pub_key_Y: pubKey2.getY().toString(16) },
+ privKey.toString("hex"),
+ subspace,
+ largeData
+ );
- const retrievedShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), subspace);
- assert.strictEqual(retrievedShare, largeData, "Large data should be retrieved correctly");
- assert.strictEqual(retrievedShare?.length, 1000000, "Retrieved data should maintain its size");
- });
+ const retrievedShare = await getTorusShare(storage, privKey2.toString("hex"), privKey.toString("hex"), subspace);
+ expect(retrievedShare).toBe(largeData);
+ expect(retrievedShare?.length).toBe(1000000);
+ },
+ { timeout: 60000 }
+ );
});