@@ -9,8 +9,9 @@ jest.mock("inquirer");
99// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1010// @ts -ignore
1111const promptMock : jest . Mock = prompt ;
12+ // Note: This is a dummy password used only for testing mock wallet encryption/decryption.
13+ const mockedPassword = "password123" ;
1214const privateKey = "0xcd27dc84c82c5814e7edac518edd5f263e7db7f25adb7a1afe13996a95583cf2" ;
13- const password = "password123" ;
1415
1516describe ( "create wallet" , ( ) => {
1617 // increase timeout because ethers is throttling
@@ -19,15 +20,15 @@ describe("create wallet", () => {
1920 promptMock . mockRestore ( ) ;
2021 } ) ;
2122 it ( "shoud throw an error when no key is provided" , async ( ) => {
22- promptMock . mockReturnValue ( { password } ) ;
23+ promptMock . mockReturnValue ( { password : mockedPassword } ) ;
2324 const file = tmp . fileSync ( ) ;
2425 await expect ( encrypt ( { outputFile : file . name , progress : ( ) => void 0 } ) ) . rejects . toStrictEqual (
2526 new Error ( "No private key found in OA_PRIVATE_KEY, key, key-file, please supply at least one" )
2627 ) ;
2728 } ) ;
2829
2930 it ( "shoud encrypt the wallet when the key is provided with the key option" , async ( ) => {
30- promptMock . mockReturnValue ( { password } ) ;
31+ promptMock . mockReturnValue ( { password : mockedPassword } ) ;
3132 const file = tmp . fileSync ( ) ;
3233 await encrypt ( { key : privateKey , outputFile : file . name , progress : ( ) => void 0 } ) ;
3334 const walletAsString = fs . readFileSync ( file . name , "utf-8" ) ;
@@ -54,7 +55,7 @@ describe("create wallet", () => {
5455 } )
5556 ) ;
5657
57- const decryptedWallet = await ethers . Wallet . fromEncryptedJson ( walletAsString , password ) ;
58+ const decryptedWallet = await ethers . Wallet . fromEncryptedJson ( walletAsString , mockedPassword ) ;
5859 expect ( decryptedWallet . address ) . toBe ( "0xB26B4941941C51a4885E5B7D3A1B861E54405f90" ) ;
5960 expect ( decryptedWallet . privateKey ) . toStrictEqual ( privateKey ) ;
6061 } ) ;
0 commit comments