diff --git a/src/__tests__/wallet-manager.test.ts b/src/__tests__/wallet-manager.test.ts index 45578b3..c87e969 100644 --- a/src/__tests__/wallet-manager.test.ts +++ b/src/__tests__/wallet-manager.test.ts @@ -7,15 +7,19 @@ import * as walletModule from "../wallet.js"; import * as transactionModule from "../transaction.js"; // Mock data for tests -// BLS12381 public key is 48 bytes = 96 hex characters +// BLS12381 public keys are 48 bytes = 96 hex characters const mockBls12381PublicKey = "2f469f1af9a0419c09f11e6609a36a27806d2ba201eb0982d150433c7fad68c579a42789cbbb70c8063909a0f85e4233"; +const mockBls12381Address = "ef3b75eb336323222ed6f4ca64cffbf696f9fb63"; +const mockSecondaryBls12381PublicKey = + "3f469f1af9a0419c09f11e6609a36a27806d2ba201eb0982d150433c7fad68c579a42789cbbb70c8063909a0f85e4233"; +const mockSecondaryBls12381Address = "9db5a855ce499d55eb7a01c0c24822aca00dc6ce"; const mockGoKeystoreEntry = { publicKey: mockBls12381PublicKey, salt: "b4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9", encrypted: "d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6", - keyAddress: "0x1234567890abcdef1234567890abcdef12345678", + keyAddress: mockBls12381Address, keyNickname: "test-key", }; @@ -35,10 +39,10 @@ const mockKeystoreJson = { entries: [ mockGoKeystoreEntry, { - publicKey: mockBls12381PublicKey, + publicKey: mockSecondaryBls12381PublicKey, salt: "c5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0", encrypted: "e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6", - keyAddress: "0xabcdef0123456789abcdef0123456789abcdef01", + keyAddress: mockSecondaryBls12381Address, keyNickname: "secondary-key", }, ], @@ -113,7 +117,7 @@ describe("WalletManager", () => { entries: [ { ...mockGoKeystoreEntry, - keyAddress: "0x1234567890ABCDEF1234567890ABCDEF12345678", + keyAddress: mockBls12381Address.toUpperCase(), }, ], }; @@ -121,7 +125,7 @@ describe("WalletManager", () => { walletManager.loadKeystoreJson(mixedCaseEntry); const accounts = walletManager.getAccounts(); - expect(accounts[0]).toBe("0x1234567890abcdef1234567890abcdef12345678"); + expect(accounts[0]).toBe(mockBls12381Address); }); it("should throw error on invalid keystore format - missing entries", () => { @@ -198,7 +202,7 @@ describe("WalletManager", () => { }); it("should handle mixed case address lookup", () => { - const mixedCaseAddress = "0x1234567890ABCDEF1234567890ABCDEF12345678"; + const mixedCaseAddress = mockBls12381Address.toUpperCase(); const account = walletManager.getAccount(mixedCaseAddress); expect(account).toBeDefined(); @@ -273,7 +277,7 @@ describe("WalletManager", () => { mockPrivateKeyHex ); - const mixedCaseAddress = "0x1234567890ABCDEF1234567890ABCDEF12345678"; + const mixedCaseAddress = mockBls12381Address.toUpperCase(); const privateKey = await walletManager.unlockAccount( mixedCaseAddress, "password" @@ -356,7 +360,7 @@ describe("WalletManager", () => { mockSignedTransaction as any ); - const mixedCaseAddress = "0x1234567890ABCDEF1234567890ABCDEF12345678"; + const mixedCaseAddress = mockBls12381Address.toUpperCase(); const tx = walletManager.buildTransaction( mixedCaseAddress, mockTransactionParams, @@ -456,7 +460,7 @@ describe("WalletManager", () => { }); it("should handle mixed case address", () => { - const mixedCaseAddress = "0x1234567890ABCDEF1234567890ABCDEF12345678"; + const mixedCaseAddress = mockBls12381Address.toUpperCase(); const isValid = walletManager.isValidAccount(mixedCaseAddress); expect(isValid).toBe(true); }); @@ -484,7 +488,7 @@ describe("WalletManager", () => { }); it("should handle mixed case address", () => { - const mixedCaseAddress = "0x1234567890ABCDEF1234567890ABCDEF12345678"; + const mixedCaseAddress = mockBls12381Address.toUpperCase(); const curveType = walletManager.getCurveType(mixedCaseAddress); expect(curveType).toBe(CurveTypeEnum.BLS12381); }); @@ -570,7 +574,7 @@ describe("WalletManager", () => { it("should handle multiple accounts independently", async () => { vi.spyOn(keystoreModule, "decryptEntry").mockImplementation( async (entry) => { - return entry.address.includes("1234") + return entry.address === mockBls12381Address ? "privatekey1" : "privatekey2"; }