Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 2b7a3ec

Browse files
authored
Add test for password creation and adjust mocks (#1764)
Add passwordCreatedOnFirstImport test that verifies a keystore password is initialized on the first wallet import (asserts empty before import and 64-char password after). Also modify concurrentImportAndDelete test to pass an explicit MockKeystorePassword (memoryPassword) when creating the mock keystore and set isWalletsEmpty to false for imports to make the concurrent test deterministic.
1 parent 571e1fe commit 2b7a3ec

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

Packages/Keystore/Tests/LocalKeystoreTests.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,34 @@ struct LocalKeystoreTests {
268268
}
269269
}
270270

271+
@Test
272+
func passwordCreatedOnFirstImport() async throws {
273+
let mockPassword = MockKeystorePassword()
274+
let keystore = LocalKeystore.mock(keystorePassword: mockPassword)
275+
276+
#expect(try mockPassword.getPassword().isEmpty)
277+
278+
let _ = try await keystore.importWallet(
279+
name: "First Wallet",
280+
type: .phrase(words: LocalKeystore.words, chains: [.ethereum]),
281+
isWalletsEmpty: true,
282+
source: .import
283+
)
284+
285+
#expect(try mockPassword.getPassword().count == 64)
286+
}
287+
271288
@Test
272289
func concurrentImportAndDelete() async throws {
273-
let keystore = LocalKeystore.mock()
290+
let keystore = LocalKeystore.mock(keystorePassword: MockKeystorePassword(memoryPassword: "test-password"))
274291

275292
let wallets = try await withThrowingTaskGroup(of: Primitives.Wallet.self) { group in
276293
for index in 0 ..< 5 {
277294
group.addTask {
278295
try await keystore.importWallet(
279296
name: "Wallet \(index)",
280297
type: .phrase(words: LocalKeystore.words, chains: [.ethereum]),
281-
isWalletsEmpty: index == 0 ? true : false,
298+
isWalletsEmpty: false,
282299
source: .import
283300
)
284301
}

0 commit comments

Comments
 (0)