forked from tahowallet/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Jest as our test runner.
- Loading branch information
Showing
4 changed files
with
1,544 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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,37 @@ | ||
import { webcrypto } from "crypto" | ||
import { encryptVault, decryptVault } from "../services/keyring/encryption" | ||
|
||
beforeEach(() => { | ||
// polyfill the WebCrypto API | ||
global.crypto = webcrypto as unknown as Crypto | ||
}) | ||
|
||
afterEach(() => { | ||
delete global.crypto | ||
}) | ||
|
||
test("can encrypt a vault", async () => { | ||
const vault = { a: 1 } | ||
const password = "this-is-a-poor-password" | ||
await encryptVault(vault, password) | ||
}) | ||
|
||
test("can decrypt an encrypted vault", async () => { | ||
const vault = { a: 1 } | ||
const password = "this-is-a-poor-password" | ||
const encryptedVault = await encryptVault(vault, password) | ||
|
||
const newVault = await decryptVault(encryptedVault, password) | ||
|
||
expect(newVault).toEqual(vault) | ||
}) | ||
|
||
test("can decrypt a complex encrypted vault", async () => { | ||
const vault = { a: { b: [1, 2, 3] }, c: null, d: 123 } | ||
const password = "this-is-a-poor-password" | ||
const encryptedVault = await encryptVault(vault, password) | ||
|
||
const newVault = await decryptVault(encryptedVault, password) | ||
|
||
expect(newVault).toEqual(vault) | ||
}) |
This file contains 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 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,4 @@ | ||
// This would be a fantastic spot for an integration test! | ||
test("adds 1 + 2 to equal 3", () => { | ||
expect(1 + 2).toBe(3) | ||
}) |
Oops, something went wrong.