OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-wallet / tests / unit / secure-storage.test.js

42 lines · javascript ref:
// test/lib/secure-storage.test.js - Secure Storage Tests

import test from 'brittle'
import { storeMnemonic, loadMnemonic, deleteMnemonic, isInitialized } from '../../lib/secure-storage.js'

const TEST_MNEMONIC = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'

test('secure storage - store and load mnemonic', async t => {
  // Clean up first
  await deleteMnemonic()

  // Should not be initialized
  t.is(await isInitialized(), false, 'not initialized initially')

  // Store mnemonic
  await storeMnemonic(TEST_MNEMONIC)

  // Should be initialized now
  t.is(await isInitialized(), true, 'initialized after storing')

  // Load mnemonic
  const loaded = await loadMnemonic()
  t.is(loaded, TEST_MNEMONIC, 'loaded mnemonic matches stored')

  // Clean up
  await deleteMnemonic()
  t.is(await isInitialized(), false, 'deleted successfully')
})

test('secure storage - load without storing returns null', async t => {
  await deleteMnemonic()

  const loaded = await loadMnemonic()
  t.is(loaded, null, 'returns null when not found')
})

test('secure storage - delete when not exists does not throw', async t => {
  await deleteMnemonic()
  await deleteMnemonic() // Should not throw
  t.pass('delete is idempotent')
})