Skip to content

Commit

Permalink
test: use encryption as example
Browse files Browse the repository at this point in the history
  • Loading branch information
sparten11740 committed Jan 23, 2025
1 parent efac0f5 commit 1f82441
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions features/keychain/module/__tests__/sodium.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { mnemonicToSeed } from 'bip39'
import { mock } from 'node:test'
import crypto from 'node:crypto'

import { mnemonicToSeed } from 'bip39'
import KeyIdentifier from '@exodus/key-identifier'
import { getSeedId } from '../crypto/seed-id.js'
import { getSodiumKeysFromSeed } from '@exodus/crypto/sodium'

import { getSeedId } from '../crypto/seed-id.js'

const getSodiumKeysFromSeedMock = jest.fn(getSodiumKeysFromSeed)

mock.module('@exodus/crypto/sodium', {
Expand Down Expand Up @@ -36,21 +38,19 @@ const BOB_KEY = new KeyIdentifier({
describe('libsodium', () => {
it('should cache sodium keys', async () => {
const keychain = createKeychain({ seed })

await keychain.sodium.getSodiumKeysFromSeed({
seedId,
keyId: BOB_KEY,
})

await keychain.sodium.getSodiumKeysFromSeed({
seedId,
keyId: BOB_KEY,
})

await keychain.sodium.getSodiumKeysFromSeed({
seedId,
keyId: BOB_KEY,
})
const toPublicKey = crypto.randomBytes(32)

const encrypt = () =>
keychain.sodium.encryptBox({
seedId,
keyId: BOB_KEY,
data: Buffer.from('Batman is Bruce Wayne - or is he Harvey Dent?', 'utf8'),
toPublicKey,
})

await encrypt()
await encrypt()
await encrypt()

expect(getSodiumKeysFromSeedMock).toHaveBeenCalledOnce()
})
Expand Down

0 comments on commit 1f82441

Please sign in to comment.