diff --git a/src/__tests__/wallet.test.ts b/src/__tests__/wallet.test.ts index f224946d..0b14ac52 100644 --- a/src/__tests__/wallet.test.ts +++ b/src/__tests__/wallet.test.ts @@ -9,6 +9,9 @@ jest.mock("inquirer"); const promptMock = mocked(prompt); +// Note: This is a dummy password used only for testing mock wallet encryption/decryption. +const mockedPassword = "password123"; + describe("wallet", () => { // increase timeout because ethers is throttling jest.setTimeout(30000); @@ -29,7 +32,7 @@ describe("wallet", () => { it("should work when user consent correctly", async () => { const signaleSuccessSpy = jest.spyOn(signale, "success"); promptMock.mockResolvedValueOnce({ ack: "yes" }); // what the user type - promptMock.mockResolvedValueOnce({ password: "password123" }); // wallet password + promptMock.mockResolvedValueOnce({ password: mockedPassword }); // wallet password await decrypt({ inputFile: path.resolve("src", "implementations", "utils", "__tests__", "wallet.json").toString(), yes: false, @@ -59,7 +62,7 @@ describe("wallet", () => { }); it("should work when user consent automatically", async () => { const signaleSuccessSpy = jest.spyOn(signale, "success"); - promptMock.mockResolvedValueOnce({ password: "password123" }); // wallet password + promptMock.mockResolvedValueOnce({ password: mockedPassword }); // wallet password await decrypt({ inputFile: path.resolve("src", "implementations", "utils", "__tests__", "wallet.json").toString(), yes: true, diff --git a/src/implementations/utils/__tests__/wallet-astron.test.ts b/src/implementations/utils/__tests__/wallet-astron.test.ts index 6e274203..ea0a9e5c 100644 --- a/src/implementations/utils/__tests__/wallet-astron.test.ts +++ b/src/implementations/utils/__tests__/wallet-astron.test.ts @@ -11,6 +11,10 @@ const promptMock: jest.Mock = prompt; const privateKey = "0xcd27dc84c82c5814e7edac518edd5f263e7db7f25adb7a1afe13996a95583cf2"; const walletAddress = "0xB26B4941941C51a4885E5B7D3A1B861E54405f90"; +// Note: This is a dummy password used only for testing mock wallet encryption/decryption. +const mockedPassword = "password123"; +const mockedInvalidPassword = "invalid"; + describe("wallet", () => { // increase timeout because ethers is throttling jest.setTimeout(30_000); @@ -48,7 +52,7 @@ describe("wallet", () => { expect(wallet.privateKey).toStrictEqual(privateKey); }); it("should return the wallet when providing an encrypted wallet", async () => { - promptMock.mockReturnValue({ password: "password123" }); + promptMock.mockReturnValue({ password: mockedPassword }); const wallet = await getWalletOrSigner({ network: "astron", @@ -59,7 +63,7 @@ describe("wallet", () => { expect(wallet.privateKey).toStrictEqual(privateKey); }); it("should throw an error when the wallet password is invalid", async () => { - promptMock.mockReturnValue({ password: "invalid" }); + promptMock.mockReturnValue({ password: mockedInvalidPassword }); await expect( getWalletOrSigner({ diff --git a/src/implementations/utils/__tests__/wallet-astrontestnet.test.ts b/src/implementations/utils/__tests__/wallet-astrontestnet.test.ts index c34dee34..feec559d 100644 --- a/src/implementations/utils/__tests__/wallet-astrontestnet.test.ts +++ b/src/implementations/utils/__tests__/wallet-astrontestnet.test.ts @@ -11,6 +11,10 @@ const promptMock: jest.Mock = prompt; const privateKey = "0xcd27dc84c82c5814e7edac518edd5f263e7db7f25adb7a1afe13996a95583cf2"; const walletAddress = "0xB26B4941941C51a4885E5B7D3A1B861E54405f90"; +// Note: This is a dummy password used only for testing mock wallet encryption/decryption. +const mockedPassword = "password123"; +const mockedInvalidPassword = "invalid"; + describe("wallet", () => { // increase timeout because ethers is throttling jest.setTimeout(30_000); @@ -51,7 +55,7 @@ describe("wallet", () => { expect(wallet.privateKey).toStrictEqual(privateKey); }); it("should return the wallet when providing an encrypted wallet", async () => { - promptMock.mockReturnValue({ password: "password123" }); + promptMock.mockReturnValue({ password: mockedPassword }); const wallet = await getWalletOrSigner({ network: "astrontestnet", @@ -62,7 +66,7 @@ describe("wallet", () => { expect(wallet.privateKey).toStrictEqual(privateKey); }); it("should throw an error when the wallet password is invalid", async () => { - promptMock.mockReturnValue({ password: "invalid" }); + promptMock.mockReturnValue({ password: mockedInvalidPassword }); await expect( getWalletOrSigner({ diff --git a/src/implementations/utils/__tests__/wallet.test.ts b/src/implementations/utils/__tests__/wallet.test.ts index 990be78c..e54189b2 100644 --- a/src/implementations/utils/__tests__/wallet.test.ts +++ b/src/implementations/utils/__tests__/wallet.test.ts @@ -19,6 +19,9 @@ jest.mock("ethers", () => ({ const promptMock: jest.Mock = prompt; const getSupportedNetworkMock = getSupportedNetwork as jest.MockedFunction; +// Note: This is a dummy password used only for testing mock wallet encryption/decryption. +const mockedPassword = "password123"; +const mockedInvalidPassword = "invalid"; const privateKey = "0xcd27dc84c82c5814e7edac518edd5f263e7db7f25adb7a1afe13996a95583cf2"; const walletAddress = "0xB26B4941941C51a4885E5B7D3A1B861E54405f90"; @@ -90,7 +93,7 @@ describe("wallet", () => { expect(wallet.privateKey).toStrictEqual(privateKey); }); it("should return the wallet when providing an encrypted wallet", async () => { - promptMock.mockReturnValue({ password: "password123" }); + promptMock.mockReturnValue({ password: mockedPassword }); const wallet = await getWalletOrSigner({ network: "sepolia", @@ -101,7 +104,7 @@ describe("wallet", () => { expect(wallet.privateKey).toStrictEqual(privateKey); }); it("should throw an error when the wallet password is invalid", async () => { - promptMock.mockReturnValue({ password: "invalid" }); + promptMock.mockReturnValue({ password: mockedInvalidPassword }); await expect( getWalletOrSigner({ @@ -173,7 +176,7 @@ describe("wallet", () => { }); it("should use custom RPC URL when provided with encrypted wallet", async () => { - promptMock.mockReturnValue({ password: "password123" }); + promptMock.mockReturnValue({ password: mockedPassword }); const wallet = await getWalletOrSigner({ network: "sepolia", diff --git a/src/implementations/wallet/__tests__/create.test.ts b/src/implementations/wallet/__tests__/create.test.ts index b5a5d18a..1ab862ee 100644 --- a/src/implementations/wallet/__tests__/create.test.ts +++ b/src/implementations/wallet/__tests__/create.test.ts @@ -4,7 +4,9 @@ import tmp from "tmp"; import fs from "fs"; import { ethers } from "ethers"; jest.mock("inquirer"); -const password = "password123"; + +// Note: This is a dummy password used only for testing mock wallet encryption/decryption. +const mockedPassword = "password123"; // assigning the mock so that we get correct typing // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -18,7 +20,7 @@ describe("create wallet", () => { promptMock.mockRestore(); }); it("shoud save the wallet into the provided path", async () => { - promptMock.mockReturnValue({ password }); + promptMock.mockReturnValue({ password: mockedPassword }); const file = tmp.fileSync(); await create({ outputFile: file.name, progress: () => void 0 }); const walletAsString = fs.readFileSync(file.name, "utf-8"); @@ -45,7 +47,7 @@ describe("create wallet", () => { }) ); - const decryptedWallet = await ethers.Wallet.fromEncryptedJson(walletAsString, password); + const decryptedWallet = await ethers.Wallet.fromEncryptedJson(walletAsString, mockedPassword); expect(decryptedWallet.address).toStrictEqual(expect.any(String)); expect(decryptedWallet.privateKey).toStrictEqual(expect.any(String)); }); diff --git a/src/implementations/wallet/__tests__/encrypt.test.ts b/src/implementations/wallet/__tests__/encrypt.test.ts index 3589ece3..9831bcfc 100644 --- a/src/implementations/wallet/__tests__/encrypt.test.ts +++ b/src/implementations/wallet/__tests__/encrypt.test.ts @@ -9,8 +9,9 @@ jest.mock("inquirer"); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const promptMock: jest.Mock = prompt; +// Note: This is a dummy password used only for testing mock wallet encryption/decryption. +const mockedPassword = "password123"; const privateKey = "0xcd27dc84c82c5814e7edac518edd5f263e7db7f25adb7a1afe13996a95583cf2"; -const password = "password123"; describe("create wallet", () => { // increase timeout because ethers is throttling @@ -19,7 +20,7 @@ describe("create wallet", () => { promptMock.mockRestore(); }); it("shoud throw an error when no key is provided", async () => { - promptMock.mockReturnValue({ password }); + promptMock.mockReturnValue({ password: mockedPassword }); const file = tmp.fileSync(); await expect(encrypt({ outputFile: file.name, progress: () => void 0 })).rejects.toStrictEqual( new Error("No private key found in OA_PRIVATE_KEY, key, key-file, please supply at least one") @@ -27,7 +28,7 @@ describe("create wallet", () => { }); it("shoud encrypt the wallet when the key is provided with the key option", async () => { - promptMock.mockReturnValue({ password }); + promptMock.mockReturnValue({ password: mockedPassword }); const file = tmp.fileSync(); await encrypt({ key: privateKey, outputFile: file.name, progress: () => void 0 }); const walletAsString = fs.readFileSync(file.name, "utf-8"); @@ -54,7 +55,7 @@ describe("create wallet", () => { }) ); - const decryptedWallet = await ethers.Wallet.fromEncryptedJson(walletAsString, password); + const decryptedWallet = await ethers.Wallet.fromEncryptedJson(walletAsString, mockedPassword); expect(decryptedWallet.address).toBe("0xB26B4941941C51a4885E5B7D3A1B861E54405f90"); expect(decryptedWallet.privateKey).toStrictEqual(privateKey); });