Skip to content

Commit 45a2ec2

Browse files
committed
chore: replace node:assert
Signed-off-by: Timo Glastra <timo@animo.id>
1 parent c79cf22 commit 45a2ec2

File tree

7 files changed

+130
-147
lines changed

7 files changed

+130
-147
lines changed

packages/askar-nodejs/tests/cryptoBox.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { deepStrictEqual } from 'node:assert'
21
import { CryptoBox, Key, KeyAlgorithm } from '@openwallet-foundation/askar-shared'
3-
import { describe, test } from 'vitest'
2+
import { describe, expect, test } from 'vitest'
43

54
describe('CryptoBox', () => {
65
test('seal', () => {
@@ -14,7 +13,7 @@ describe('CryptoBox', () => {
1413
ciphertext: sealed,
1514
})
1615

17-
deepStrictEqual(opened, message)
16+
expect(opened).toEqual(message)
1817

1918
x25519Key.handle.free()
2019
})
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
import { doesNotReject, doesNotThrow, rejects, throws } from 'node:assert'
21
import { AskarError, askar, KeyAlgorithm } from '@openwallet-foundation/askar-shared'
3-
import { describe, test } from 'vitest'
2+
import { describe, expect, test } from 'vitest'
43
import { setupWallet } from './utils'
54

65
describe('Error', () => {
76
test('set error code to 0 after correct call', () => {
8-
doesNotThrow(() =>
7+
expect(() =>
98
askar.keyGenerate({
109
algorithm: KeyAlgorithm.AesA128CbcHs256,
1110
ephemeral: true,
1211
})
13-
)
12+
).not.toThrow()
1413
})
1514

1615
test('set error code to non 0 after incorrect call', () => {
17-
throws(
18-
() => askar.keyGenerate({ algorithm: 'incorrect-alg' as KeyAlgorithm, ephemeral: true }),
16+
expect(() => askar.keyGenerate({ algorithm: 'incorrect-alg' as KeyAlgorithm, ephemeral: true })).toThrow(
1917
new AskarError({ code: 8, message: 'Unknown key algorithm' })
2018
)
2119
})
2220

2321
test('set error code to 0 correct async call', async () => {
2422
const store = await setupWallet()
2523

26-
await doesNotReject(() => store.openSession())
24+
await expect(store.openSession()).resolves.toBeDefined()
2725
})
2826

2927
test('set error code to non 0 incorrect async call where the error is outside the callback', async () => {
3028
const store = await setupWallet()
3129

3230
// @ts-expect-error: testing invalid call
33-
await rejects(() => store.removeProfile(), { code: 5, message: 'Profile name not provided' })
31+
await expect(store.removeProfile()).rejects.toMatchObject({ code: 5, message: 'Profile name not provided' })
3432
})
3533

3634
test('set error code to non 0 incorrect async call where the error is inside the callback', async () => {
3735
const store = await setupWallet()
3836
await store.close()
3937

40-
await rejects(() => store.close(), { code: 5, message: 'Invalid store handle' })
38+
await expect(store.close()).rejects.toMatchObject({ code: 5, message: 'Invalid store handle' })
4139
})
4240
})

packages/askar-nodejs/tests/joseEcdh.test.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { deepStrictEqual, strictEqual } from 'node:assert'
21
import { Ecdh1PU, EcdhEs, Jwk, Key, KeyAlgorithm } from '@openwallet-foundation/askar-shared'
3-
import { describe, test } from 'vitest'
2+
import { describe, expect, test } from 'vitest'
43
import { base64url } from './utils'
54

65
describe('jose ecdh', () => {
@@ -53,7 +52,7 @@ describe('jose ecdh', () => {
5352
aad: Uint8Array.from(Buffer.from(protectedB64)),
5453
})
5554

56-
strictEqual(Buffer.from(messageReceived).toString(), messageString)
55+
expect(Buffer.from(messageReceived).toString()).toBe(messageString)
5756

5857
ephemeralKey.handle.free()
5958
bobKey.handle.free()
@@ -110,7 +109,7 @@ describe('jose ecdh', () => {
110109

111110
const messageReceived = cekReceiver.aeadDecrypt({ ciphertext, tag, nonce, aad: protectedB64Bytes })
112111

113-
deepStrictEqual(messageReceived, message)
112+
expect(messageReceived).toEqual(message)
114113

115114
ephemeralKey.handle.free()
116115
bobKey.handle.free()
@@ -171,7 +170,7 @@ describe('jose ecdh', () => {
171170
aad: protectedB64Bytes,
172171
})
173172

174-
deepStrictEqual(messageReceived, message)
173+
expect(messageReceived).toEqual(message)
175174

176175
aliceKey.handle.free()
177176
bobKey.handle.free()
@@ -218,8 +217,8 @@ describe('jose ecdh', () => {
218217
const base64urlApu = base64url(apu)
219218
const base64urlApv = base64url(apv)
220219

221-
strictEqual(base64urlApu, 'QWxpY2U')
222-
strictEqual(base64urlApv, 'Qm9iIGFuZCBDaGFybGll')
220+
expect(base64urlApu).toBe('QWxpY2U')
221+
expect(base64urlApv).toBe('Qm9iIGFuZCBDaGFybGll')
223222

224223
const protectedJson = {
225224
alg: 'ECDH-1PU+A128KW',
@@ -249,8 +248,8 @@ describe('jose ecdh', () => {
249248

250249
const { ciphertext, tag: ccTag } = enc.parts
251250

252-
strictEqual(Buffer.from(ciphertext).toString('base64url'), 'Az2IWsISEMDJvyc5XRL-3-d-RgNBOGolCsxFFoUXFYw')
253-
strictEqual(Buffer.from(ccTag).toString('base64url'), 'HLb4fTlm8spGmij3RyOs2gJ4DpHM4hhVRwdF_hGb3WQ')
251+
expect(Buffer.from(ciphertext).toString('base64url')).toBe('Az2IWsISEMDJvyc5XRL-3-d-RgNBOGolCsxFFoUXFYw')
252+
expect(Buffer.from(ccTag).toString('base64url')).toBe('HLb4fTlm8spGmij3RyOs2gJ4DpHM4hhVRwdF_hGb3WQ')
254253

255254
const derived = new Ecdh1PU({
256255
apv: Uint8Array.from(Buffer.from(apv)),
@@ -265,11 +264,10 @@ describe('jose ecdh', () => {
265264
receive: false,
266265
})
267266

268-
deepStrictEqual(derived.secretBytes, Uint8Array.from(Buffer.from('df4c37a0668306a11e3d6b0074b5d8df', 'hex')))
267+
expect(derived.secretBytes).toEqual(Uint8Array.from(Buffer.from('df4c37a0668306a11e3d6b0074b5d8df', 'hex')))
269268

270269
const encryptedKey = derived.wrapKey({ other: cek }).ciphertextWithTag
271-
deepStrictEqual(
272-
encryptedKey,
270+
expect(encryptedKey).toEqual(
273271
Uint8Array.from(
274272
Buffer.from(
275273
'pOMVA9_PtoRe7xXW1139NzzN1UhiFoio8lGto9cf0t8PyU-sjNXH8-LIRLycq8CHJQbDwvQeU1cSl55cQ0hGezJu2N9IY0QN',
@@ -291,7 +289,7 @@ describe('jose ecdh', () => {
291289
recipientKey: bob,
292290
})
293291

294-
deepStrictEqual(encryptedKey2.ciphertextWithTag, encryptedKey)
292+
expect(encryptedKey2.ciphertextWithTag).toEqual(encryptedKey)
295293

296294
const derivedReceiver = new Ecdh1PU({
297295
apv: Uint8Array.from(Buffer.from(apv)),
@@ -315,7 +313,7 @@ describe('jose ecdh', () => {
315313
tag: ccTag,
316314
})
317315

318-
deepStrictEqual(messageReceived, message)
316+
expect(messageReceived).toEqual(message)
319317

320318
const cekReceiver2 = new Ecdh1PU({
321319
apv: Uint8Array.from(Buffer.from(apv)),
@@ -331,7 +329,7 @@ describe('jose ecdh', () => {
331329
ccTag,
332330
})
333331

334-
deepStrictEqual(cekReceiver2.jwkSecret, cek.jwkSecret)
332+
expect(cekReceiver2.jwkSecret).toEqual(cek.jwkSecret)
335333

336334
cek.handle.free()
337335
cekReceiver.handle.free()
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { ok } from 'node:assert'
21
import { Argon2, Argon2Parameters } from '@openwallet-foundation/askar-shared'
3-
import { describe, test } from 'vitest'
2+
import { describe, expect, test } from 'vitest'
43

54
describe('Argon2', () => {
65
test('derive password', () => {
@@ -12,9 +11,8 @@ describe('Argon2', () => {
1211

1312
const derivedPassword = Argon2.derivePassword(Argon2Parameters.Interactive, passwordBytes, saltBytes)
1413

15-
ok(
16-
Buffer.from(derivedPassword).toString('hex') ===
17-
'9ef87bcf828c46c0136a0d1d9e391d713f75b327c6dc190455bd36c1bae33259'
14+
expect(Buffer.from(derivedPassword).toString('hex')).toBe(
15+
'9ef87bcf828c46c0136a0d1d9e391d713f75b327c6dc190455bd36c1bae33259'
1816
)
1917
})
2018
})
Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
import { deepStrictEqual, ok, strictEqual } from 'node:assert'
21
import { Jwk, Key, KeyAlgorithm } from '@openwallet-foundation/askar-shared'
3-
import { describe, test } from 'vitest'
2+
import { describe, expect, test } from 'vitest'
43
import { askarNodeJS } from '../src'
54

65
describe('keys', () => {
76
test('supported backends', () => {
87
const backends = askarNodeJS.keyGetSupportedBackends()
98

10-
strictEqual(backends.length, 1)
11-
ok(backends.includes('software'))
9+
expect(backends.length).toBe(1)
10+
expect(backends.includes('software')).toBe(true)
1211
})
1312

1413
test('aes cbc hmac', () => {
1514
const key = Key.generate(KeyAlgorithm.AesA128CbcHs256)
1615

17-
strictEqual(key.algorithm, KeyAlgorithm.AesA128CbcHs256)
16+
expect(key.algorithm).toBe(KeyAlgorithm.AesA128CbcHs256)
1817

1918
const messageString = 'test message'
2019
const message = Uint8Array.from(Buffer.from(messageString))
2120
const aeadNonce = key.aeadRandomNonce
2221
const params = key.aeadParams
2322

24-
strictEqual(params.nonceLength, 16)
25-
strictEqual(params.tagLength, 16)
23+
expect(params.nonceLength).toBe(16)
24+
expect(params.tagLength).toBe(16)
2625

2726
const enc = key.aeadEncrypt({ message, nonce: aeadNonce })
2827
const dec = key.aeadDecrypt(enc.parts)
2928

30-
deepStrictEqual(dec, message)
29+
expect(dec).toEqual(message)
3130
})
3231

3332
test('Bls G2 Keygen', () => {
3433
const seed = Uint8Array.from(Buffer.from('testseed000000000000000000000001'))
3534
const key = Key.fromSeed({ algorithm: KeyAlgorithm.Bls12381G2, seed })
3635

37-
deepStrictEqual(
38-
key.jwkPublic,
36+
expect(key.jwkPublic).toEqual(
3937
new Jwk({
4038
crv: 'BLS12381G2',
4139
kty: 'EC',
@@ -49,8 +47,7 @@ describe('keys', () => {
4947
const seed = Uint8Array.from(Buffer.from('testseed000000000000000000000001'))
5048
const key = Key.fromSeed({ algorithm: KeyAlgorithm.Bls12381G1, seed })
5149

52-
deepStrictEqual(
53-
key.jwkPublic,
50+
expect(key.jwkPublic).toEqual(
5451
new Jwk({
5552
crv: 'BLS12381G1',
5653
kty: 'EC',
@@ -63,36 +60,33 @@ describe('keys', () => {
6360
test('ed25519', () => {
6461
const key = Key.generate(KeyAlgorithm.Ed25519)
6562

66-
strictEqual(key.algorithm, KeyAlgorithm.Ed25519)
63+
expect(key.algorithm).toBe(KeyAlgorithm.Ed25519)
6764

6865
const message = Uint8Array.from(Buffer.from('test message'))
6966
const messageBuffer = Buffer.from('test message')
7067
const signature = key.signMessage({ message })
7168

72-
strictEqual(key.verifySignature({ message, signature }), true)
73-
strictEqual(key.verifySignature({ message: messageBuffer, signature }), true)
74-
strictEqual(key.verifySignature({ message: Buffer.from('other message'), signature }), false)
75-
strictEqual(
69+
expect(key.verifySignature({ message, signature })).toBe(true)
70+
expect(key.verifySignature({ message: messageBuffer, signature })).toBe(true)
71+
expect(key.verifySignature({ message: Buffer.from('other message'), signature })).toBe(false)
72+
expect(
7673
key.verifySignature({
7774
message: Uint8Array.from(Buffer.from('other message')),
7875
signature,
79-
}),
80-
false
81-
)
82-
strictEqual(
76+
})
77+
).toBe(false)
78+
expect(
8379
key.verifySignature({
8480
message,
8581
signature: Uint8Array.from([8, 1, 1, 1]),
86-
}),
87-
false
88-
)
89-
strictEqual(
82+
})
83+
).toBe(false)
84+
expect(
9085
key.verifySignature({
9186
message,
9287
signature: Buffer.from('random signature'),
93-
}),
94-
false
95-
)
88+
})
89+
).toBe(false)
9690

9791
const x25519Key = key.convertkey({ algorithm: KeyAlgorithm.X25519 })
9892
const x25519Key2 = Key.generate(KeyAlgorithm.X25519)
@@ -102,29 +96,29 @@ describe('keys', () => {
10296
publicKey: x25519Key2,
10397
})
10498

105-
ok(kex instanceof Key)
99+
expect(kex instanceof Key).toBe(true)
106100

107-
strictEqual(key.jwkPublic.kty, 'OKP')
108-
strictEqual(key.jwkPublic.crv, 'Ed25519')
101+
expect(key.jwkPublic.kty).toBe('OKP')
102+
expect(key.jwkPublic.crv).toBe('Ed25519')
109103

110-
strictEqual(key.jwkSecret.kty, 'OKP')
111-
strictEqual(key.jwkSecret.crv, 'Ed25519')
104+
expect(key.jwkSecret.kty).toBe('OKP')
105+
expect(key.jwkSecret.crv).toBe('Ed25519')
112106
})
113107

114108
test('p384', () => {
115109
const key = Key.generate(KeyAlgorithm.EcSecp384r1)
116110

117-
strictEqual(key.algorithm, KeyAlgorithm.EcSecp384r1)
111+
expect(key.algorithm).toBe(KeyAlgorithm.EcSecp384r1)
118112

119113
const message = Uint8Array.from(Buffer.from('test message'))
120114
const signature = key.signMessage({ message })
121115

122-
strictEqual(key.verifySignature({ message, signature }), true)
116+
expect(key.verifySignature({ message, signature })).toBe(true)
123117

124-
strictEqual(key.jwkPublic.kty, 'EC')
125-
strictEqual(key.jwkPublic.crv, 'P-384')
118+
expect(key.jwkPublic.kty).toBe('EC')
119+
expect(key.jwkPublic.crv).toBe('P-384')
126120

127-
strictEqual(key.jwkSecret.kty, 'EC')
128-
strictEqual(key.jwkSecret.crv, 'P-384')
121+
expect(key.jwkSecret.kty).toBe('EC')
122+
expect(key.jwkSecret.crv).toBe('P-384')
129123
})
130124
})

packages/askar-nodejs/tests/migration.test.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { doesNotReject, rejects } from 'node:assert'
21
import fs from 'node:fs'
32
import path from 'node:path'
43
import { Migration } from '@openwallet-foundation/askar-shared'
5-
import { beforeEach, describe, test } from 'vitest'
4+
import { beforeEach, describe, expect, test } from 'vitest'
65

76
const DB_TEMPLATE_PATH = path.join(__dirname, 'indy_wallet_sqlite.db')
87
const DB_UPGRADE_PATH = path.join(__dirname, 'indy_wallet_sqlite_upgraded.db')
@@ -26,25 +25,23 @@ describe('migration', () => {
2625
})
2726

2827
test('migrate', async () => {
29-
await doesNotReject(() =>
28+
await expect(
3029
Migration.migrate({
3130
specUri: DB_UPGRADE_PATH,
3231
kdfLevel: 'RAW',
3332
walletName: 'walletwallet.0',
3433
walletKey: 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A',
3534
})
36-
)
35+
).resolves.toBeUndefined()
3736

3837
// Double migrate should not work
39-
await rejects(
40-
() =>
41-
Migration.migrate({
42-
specUri: DB_UPGRADE_PATH,
43-
kdfLevel: 'RAW',
44-
walletName: 'walletwallet.0',
45-
walletKey: 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A',
46-
}),
47-
{ code: 1, message: 'Database is already migrated' }
48-
)
38+
await expect(
39+
Migration.migrate({
40+
specUri: DB_UPGRADE_PATH,
41+
kdfLevel: 'RAW',
42+
walletName: 'walletwallet.0',
43+
walletKey: 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A',
44+
})
45+
).rejects.toMatchObject({ code: 1, message: 'Database is already migrated' })
4946
})
5047
})

0 commit comments

Comments
 (0)