Skip to content
Open
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
28 changes: 16 additions & 12 deletions src/__tests__/wallet-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand All @@ -35,10 +39,10 @@ const mockKeystoreJson = {
entries: [
mockGoKeystoreEntry,
{
publicKey: mockBls12381PublicKey,
publicKey: mockSecondaryBls12381PublicKey,
salt: "c5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0",
encrypted: "e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
keyAddress: "0xabcdef0123456789abcdef0123456789abcdef01",
keyAddress: mockSecondaryBls12381Address,
keyNickname: "secondary-key",
},
],
Expand Down Expand Up @@ -113,15 +117,15 @@ describe("WalletManager", () => {
entries: [
{
...mockGoKeystoreEntry,
keyAddress: "0x1234567890ABCDEF1234567890ABCDEF12345678",
keyAddress: mockBls12381Address.toUpperCase(),
},
],
};

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", () => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -273,7 +277,7 @@ describe("WalletManager", () => {
mockPrivateKeyHex
);

const mixedCaseAddress = "0x1234567890ABCDEF1234567890ABCDEF12345678";
const mixedCaseAddress = mockBls12381Address.toUpperCase();
const privateKey = await walletManager.unlockAccount(
mixedCaseAddress,
"password"
Expand Down Expand Up @@ -356,7 +360,7 @@ describe("WalletManager", () => {
mockSignedTransaction as any
);

const mixedCaseAddress = "0x1234567890ABCDEF1234567890ABCDEF12345678";
const mixedCaseAddress = mockBls12381Address.toUpperCase();
const tx = walletManager.buildTransaction(
mixedCaseAddress,
mockTransactionParams,
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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";
}
Expand Down