Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { expect, suite, test } from "vitest";
import WalletsEthereum from "./WalletsEthereum";

const key1 = new Uint8Array([
132, 205, 117, 44, 180, 113, 245, 200, 213, 19, 97, 187, 70, 157, 86, 111, 19,
131, 14, 18, 196, 57, 9, 203, 64, 196, 19, 26, 73, 35, 126, 80,
]);
const key2 = new Uint8Array([
133, 205, 117, 44, 180, 113, 245, 200, 213, 19, 97, 187, 70, 157, 86, 111, 19,
131, 14, 18, 196, 57, 9, 203, 64, 196, 19, 26, 73, 35, 126, 80,
]);

const notValidKey1 = new Uint8Array([
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 19, 131, 14, 18, 196, 57, 9, 203, 64, 196, 19, 26, 73, 35, 126, 80,
]);

const notValidKey2 = new Uint8Array([
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1,
]);

suite("WalletsEthereum", () => {
test("should generate wallet correctly", async () => {
const walletGenerator = new WalletsEthereum();
const wallet1 = await walletGenerator.makeWallet(null, key1);
expect(JSON.stringify(wallet1)).toMatchSnapshot();

const wallet2 = await walletGenerator.makeWallet(null, key2);
expect(JSON.stringify(wallet2)).toMatchSnapshot();
});

test("should generate wallet correctly without initialPrivateKey", async () => {
const walletGenerator = new WalletsEthereum();

const wallet = await walletGenerator.makeWallet(null);

expect(typeof wallet.address).toBe("string");
expect(wallet.address.length).not.toBe(0);
expect(typeof wallet.privateKey).toBe("string");
expect(wallet.privateKey.length).not.toBe(0);
});

test("should throw error for invalid initialPrivateKey", async () => {
const walletGenerator = new WalletsEthereum();

await expect(
walletGenerator.makeWallet(null, notValidKey1),
).rejects.toThrow("Invalid private key");
await expect(
walletGenerator.makeWallet(null, notValidKey2),
).rejects.toThrow("offset is out of bounds");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`WalletsEthereum > should generate wallet correctly 1`] = `"{"privateKey":"0x84cd752cb471f5c8d51361bb469d566f13830e12c43909cb40c4131a49237e50","address":"0x4a1bab2023db29cc924e475ceffafb81645f1ab5"}"`;

exports[`WalletsEthereum > should generate wallet correctly 2`] = `"{"privateKey":"0x85cd752cb471f5c8d51361bb469d566f13830e12c43909cb40c4131a49237e50","address":"0xd715914e3592c611d0614e4ad53bed7a09755326"}"`;
Loading