|
| 1 | +import { expect, suite, test } from "vitest"; |
| 2 | +import WalletsEthereum from "./WalletsEthereum"; |
| 3 | + |
| 4 | +const key1 = new Uint8Array([ |
| 5 | + 132, 205, 117, 44, 180, 113, 245, 200, 213, 19, 97, 187, 70, 157, 86, 111, 19, |
| 6 | + 131, 14, 18, 196, 57, 9, 203, 64, 196, 19, 26, 73, 35, 126, 80, |
| 7 | +]); |
| 8 | +const key2 = new Uint8Array([ |
| 9 | + 133, 205, 117, 44, 180, 113, 245, 200, 213, 19, 97, 187, 70, 157, 86, 111, 19, |
| 10 | + 131, 14, 18, 196, 57, 9, 203, 64, 196, 19, 26, 73, 35, 126, 80, |
| 11 | +]); |
| 12 | + |
| 13 | +const notValidKey1 = new Uint8Array([ |
| 14 | + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 15 | + 255, 19, 131, 14, 18, 196, 57, 9, 203, 64, 196, 19, 26, 73, 35, 126, 80, |
| 16 | +]); |
| 17 | + |
| 18 | +const notValidKey2 = new Uint8Array([ |
| 19 | + 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, |
| 20 | + 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, |
| 21 | + 1, 1, 1, 1, 1, 1, 1, |
| 22 | +]); |
| 23 | + |
| 24 | +suite("WalletsEthereum", () => { |
| 25 | + test("should generate wallet correctly", async () => { |
| 26 | + const walletGenerator = new WalletsEthereum(); |
| 27 | + const wallet1 = await walletGenerator.makeWallet(null, key1); |
| 28 | + expect(JSON.stringify(wallet1)).toMatchSnapshot(); |
| 29 | + |
| 30 | + const wallet2 = await walletGenerator.makeWallet(null, key2); |
| 31 | + expect(JSON.stringify(wallet2)).toMatchSnapshot(); |
| 32 | + }); |
| 33 | + |
| 34 | + test("should generate wallet correctly without initialPrivateKey", async () => { |
| 35 | + const walletGenerator = new WalletsEthereum(); |
| 36 | + |
| 37 | + const wallet = await walletGenerator.makeWallet(null); |
| 38 | + |
| 39 | + expect(typeof wallet.address).toBe("string"); |
| 40 | + expect(wallet.address.length).not.toBe(0); |
| 41 | + expect(typeof wallet.privateKey).toBe("string"); |
| 42 | + expect(wallet.privateKey.length).not.toBe(0); |
| 43 | + }); |
| 44 | + |
| 45 | + test("should throw error for invalid initialPrivateKey", async () => { |
| 46 | + const walletGenerator = new WalletsEthereum(); |
| 47 | + |
| 48 | + await expect( |
| 49 | + walletGenerator.makeWallet(null, notValidKey1), |
| 50 | + ).rejects.toThrow("Invalid private key"); |
| 51 | + await expect( |
| 52 | + walletGenerator.makeWallet(null, notValidKey2), |
| 53 | + ).rejects.toThrow("offset is out of bounds"); |
| 54 | + }); |
| 55 | +}); |
0 commit comments