-
Notifications
You must be signed in to change notification settings - Fork 3
fix: mnemonic not found crash #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dde3f71
fix: handle missing mnemonic during VSS backup setup
piotr-iohk 6421346
test: verify VssBackupClient handles missing mnemonic gracefully
piotr-iohk 1950109
Merge branch 'master' into fix/MnemonicNotFound-crash
ovitrif f9320d1
fix: address PR review comments for mnemonic crash fix
ovitrif 14679f0
Merge pull request #684 from synonymdev/fix/MnemonicNotFound-crash-re…
ovitrif f5a3c15
Merge branch 'master' into fix/MnemonicNotFound-crash
ovitrif ba248a9
chore: update ai rules for logger
ovitrif a172afb
fix: use named context param in logger call
ovitrif b3b7e5a
refactor: simplify setup return types to Result<Unit>
ovitrif 0d22ad6
fix: prevent concurrent vss setup calls
ovitrif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/src/test/java/to/bitkit/data/backup/VssBackupClientTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package to.bitkit.data.backup | ||
|
|
||
| import kotlinx.coroutines.runBlocking | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.mockito.kotlin.any | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.never | ||
| import org.mockito.kotlin.verify | ||
| import org.mockito.kotlin.whenever | ||
| import to.bitkit.data.keychain.Keychain | ||
| import to.bitkit.test.BaseUnitTest | ||
| import kotlin.test.assertFalse | ||
|
|
||
| class VssBackupClientTest : BaseUnitTest() { | ||
|
|
||
| private lateinit var sut: VssBackupClient | ||
|
|
||
| private val vssStoreIdProvider = mock<VssStoreIdProvider>() | ||
| private val keychain = mock<Keychain>() | ||
|
|
||
| @Before | ||
| fun setUp() = runBlocking { | ||
| sut = VssBackupClient( | ||
| ioDispatcher = testDispatcher, | ||
| vssStoreIdProvider = vssStoreIdProvider, | ||
| keychain = keychain, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setup returns false when mnemonic is not available`() = test { | ||
| whenever(keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name)).thenReturn(null) | ||
|
|
||
| val result = sut.setup() | ||
|
|
||
| assertFalse(result.getOrThrow()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setup does not call vssStoreIdProvider when mnemonic is not available`() = test { | ||
| whenever(keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name)).thenReturn(null) | ||
|
|
||
| sut.setup() | ||
|
|
||
| verify(vssStoreIdProvider, never()).getVssStoreId(any()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setup checks mnemonic before proceeding with vss initialization`() = test { | ||
| val testMnemonic = "abandon abandon abandon abandon abandon abandon " + | ||
| "abandon abandon abandon abandon abandon about" | ||
| whenever(keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name)).thenReturn(testMnemonic) | ||
| whenever(vssStoreIdProvider.getVssStoreId(any())).thenReturn("test-store-id") | ||
|
|
||
| // Setup will fail on native VSS calls, but we verify we passed the mnemonic check | ||
| runCatching { sut.setup() } | ||
|
|
||
| verify(vssStoreIdProvider).getVssStoreId(any()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setup can be called multiple times when mnemonic not available`() = test { | ||
| whenever(keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name)).thenReturn(null) | ||
|
|
||
| // Multiple calls should all return false without crashing | ||
| assertFalse(sut.setup().getOrThrow()) | ||
| assertFalse(sut.setup().getOrThrow()) | ||
| assertFalse(sut.setup().getOrThrow()) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.