Skip to content

Commit 9f3c1ce

Browse files
committed
remove jasmine's fail() global from tests
1 parent dd9e97a commit 9f3c1ce

File tree

11 files changed

+38
-38
lines changed

11 files changed

+38
-38
lines changed

packages/crypto/src/libsodium.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,23 @@ describe("Libsodium", () => {
129129
// 8 bytes
130130
await Argon2id.execute(password, fromHex("aabbccddeeff0011"), options)
131131
.then(() => {
132-
fail("Argon2id with invalid salt length must not resolve");
132+
throw new Error("Argon2id with invalid salt length must not resolve");
133133
})
134134
.catch((e) => {
135135
expect(e).toMatch(/invalid salt length/);
136136
});
137137
// 15 bytes
138138
await Argon2id.execute(password, fromHex("aabbccddeeff001122334455667788"), options)
139139
.then(() => {
140-
fail("Argon2id with invalid salt length must not resolve");
140+
throw new Error("Argon2id with invalid salt length must not resolve");
141141
})
142142
.catch((e) => {
143143
expect(e).toMatch(/invalid salt length/);
144144
});
145145
// 17 bytes
146146
await Argon2id.execute(password, fromHex("aabbccddeeff00112233445566778899aa"), options)
147147
.then(() => {
148-
fail("Argon2id with invalid salt length must not resolve");
148+
throw new Error("Argon2id with invalid salt length must not resolve");
149149
})
150150
.catch((e) => {
151151
expect(e).toMatch(/invalid salt length/);
@@ -157,7 +157,7 @@ describe("Libsodium", () => {
157157
options,
158158
)
159159
.then(() => {
160-
fail("Argon2id with invalid salt length must not resolve");
160+
throw new Error("Argon2id with invalid salt length must not resolve");
161161
})
162162
.catch((e) => {
163163
expect(e).toMatch(/invalid salt length/);
@@ -235,7 +235,7 @@ describe("Libsodium", () => {
235235
const seed = fromHex("43a9c17ccbb0e767ea29ce1f10813afde5f1e0a7a504e89b4d2cc2b952b8e0");
236236
await Ed25519.makeKeypair(seed)
237237
.then(() => {
238-
fail("promise must not resolve");
238+
throw new Error("promise must not resolve");
239239
})
240240
.catch((error) => {
241241
expect(error.message).toContain("key of length 32 expected");
@@ -247,7 +247,7 @@ describe("Libsodium", () => {
247247
const seed = fromHex("43a9c17ccbb0e767ea29ce1f10813afde5f1e0a7a504e89b4d2cc2b952b8e0b9aa");
248248
await Ed25519.makeKeypair(seed)
249249
.then(() => {
250-
fail("promise must not resolve");
250+
throw new Error("promise must not resolve");
251251
})
252252
.catch((error) => {
253253
expect(error.message).toContain("key of length 32 expected");
@@ -423,7 +423,7 @@ describe("Libsodium", () => {
423423
const key = fromHex("");
424424
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
425425
.then(() => {
426-
fail("encryption must not succeed");
426+
throw new Error("encryption must not succeed");
427427
})
428428
.catch((error) => {
429429
expect(error).toMatch(/key, got length=0/);
@@ -434,7 +434,7 @@ describe("Libsodium", () => {
434434
const key = fromHex("1324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916");
435435
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
436436
.then(() => {
437-
fail("encryption must not succeed");
437+
throw new Error("encryption must not succeed");
438438
})
439439
.catch((error) => {
440440
expect(error).toMatch(/key, got length=31/);
@@ -445,7 +445,7 @@ describe("Libsodium", () => {
445445
const key = fromHex("1324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916d8aa");
446446
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
447447
.then(() => {
448-
fail("encryption must not succeed");
448+
throw new Error("encryption must not succeed");
449449
})
450450
.catch((error) => {
451451
expect(error).toMatch(/key, got length=33/);
@@ -458,7 +458,7 @@ describe("Libsodium", () => {
458458
);
459459
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
460460
.then(() => {
461-
fail("encryption must not succeed");
461+
throw new Error("encryption must not succeed");
462462
})
463463
.catch((error) => {
464464
expect(error).toMatch(/key, got length=64/);
@@ -484,7 +484,7 @@ describe("Libsodium", () => {
484484
const corruptedCiphertext = ciphertext.map((x, i) => (i === 0 ? x ^ 0x01 : x));
485485
await Xchacha20poly1305Ietf.decrypt(corruptedCiphertext, key, nonce).then(
486486
() => {
487-
fail("promise must not resolve");
487+
throw new Error("promise must not resolve");
488488
},
489489
(error) => {
490490
expect(error.message).toMatch(/invalid tag/i);
@@ -496,7 +496,7 @@ describe("Libsodium", () => {
496496
const corruptedKey = key.map((x, i) => (i === 0 ? x ^ 0x01 : x));
497497
await Xchacha20poly1305Ietf.decrypt(ciphertext, corruptedKey, nonce).then(
498498
() => {
499-
fail("promise must not resolve");
499+
throw new Error("promise must not resolve");
500500
},
501501
(error) => {
502502
expect(error.message).toMatch(/invalid tag/i);
@@ -508,7 +508,7 @@ describe("Libsodium", () => {
508508
const corruptedNonce = nonce.map((x, i) => (i === 0 ? x ^ 0x01 : x));
509509
await Xchacha20poly1305Ietf.decrypt(ciphertext, key, corruptedNonce).then(
510510
() => {
511-
fail("promise must not resolve");
511+
throw new Error("promise must not resolve");
512512
},
513513
(error) => {
514514
expect(error.message).toMatch(/invalid tag/i);

packages/crypto/src/secp256k1.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,37 @@ describe("Secp256k1", () => {
7070
// too short and too long
7171
await Secp256k1.makeKeypair(fromHex("e4ade2a5232a7c6f37e7b854a774e25e6047ee7c6d63e8304ae04fa190bc17"))
7272
.then(() => {
73-
fail("promise must be rejected");
73+
throw new Error("promise must be rejected");
7474
})
7575
.catch((error) => {
7676
expect(error.message).toContain("not a valid secp256k1 private key");
7777
});
7878
await Secp256k1.makeKeypair(fromHex("e4ade2a5232a7c6f37e7b854a774e25e6047ee7c6d63e8304ae04fa190bc1732aa"))
7979
.then(() => {
80-
fail("promise must be rejected");
80+
throw new Error("promise must be rejected");
8181
})
8282
.catch((error) => {
8383
expect(error.message).toContain("not a valid secp256k1 private key");
8484
});
8585
// value out of range (too small)
8686
await Secp256k1.makeKeypair(fromHex("0000000000000000000000000000000000000000000000000000000000000000"))
8787
.then(() => {
88-
fail("promise must be rejected");
88+
throw new Error("promise must be rejected");
8989
})
9090
.catch((error) => {
9191
expect(error.message).toContain("not a valid secp256k1 private key");
9292
});
9393
// value out of range (>= n)
9494
await Secp256k1.makeKeypair(fromHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
9595
.then(() => {
96-
fail("promise must be rejected");
96+
throw new Error("promise must be rejected");
9797
})
9898
.catch((error) => {
9999
expect(error.message).toContain("not a valid secp256k1 private key");
100100
});
101101
await Secp256k1.makeKeypair(fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"))
102102
.then(() => {
103-
fail("promise must be rejected");
103+
throw new Error("promise must be rejected");
104104
})
105105
.catch((error) => {
106106
expect(error.message).toContain("not a valid secp256k1 private key");
@@ -133,7 +133,7 @@ describe("Secp256k1", () => {
133133
const messageHash = new Uint8Array([]);
134134
await Secp256k1.createSignature(messageHash, keypair.privkey)
135135
.then(() => {
136-
fail("must not resolve");
136+
throw new Error("must not resolve");
137137
})
138138
.catch((error) => {
139139
expect(error).toMatch(/message hash must not be empty/i);
@@ -146,7 +146,7 @@ describe("Secp256k1", () => {
146146
const messageHash = fromHex("11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff11");
147147
await Secp256k1.createSignature(messageHash, keypair.privkey)
148148
.then(() => {
149-
fail("must not resolve");
149+
throw new Error("must not resolve");
150150
})
151151
.catch((error) => {
152152
expect(error).toMatch(/message hash length must not exceed 32 bytes/i);
@@ -202,7 +202,7 @@ describe("Secp256k1", () => {
202202
const messageHash = new Uint8Array([]);
203203
await Secp256k1.verifySignature(dummySignature, messageHash, keypair.pubkey)
204204
.then(() => {
205-
fail("must not resolve");
205+
throw new Error("must not resolve");
206206
})
207207
.catch((error) => {
208208
expect(error).toMatch(/message hash must not be empty/i);
@@ -221,7 +221,7 @@ describe("Secp256k1", () => {
221221
const messageHash = fromHex("11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff11");
222222
await Secp256k1.verifySignature(dummySignature, messageHash, keypair.privkey)
223223
.then(() => {
224-
fail("must not resolve");
224+
throw new Error("must not resolve");
225225
})
226226
.catch((error) => {
227227
expect(error).toMatch(/message hash length must not exceed 32 bytes/i);

packages/faucet-client/src/faucetclient.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("FaucetClient", () => {
4242
const faucet = new FaucetClient(faucetUrl);
4343
await faucet.credit(defaultAddress, "ETH").then(
4444
() => {
45-
fail("must not resolve");
45+
throw new Error("must not resolve");
4646
},
4747
(error) => {
4848
expect(error).toMatch(/token is not available/i);
@@ -57,7 +57,7 @@ describe("FaucetClient", () => {
5757
for (const address of ["be5cc2cc05db2cdb4313c18306a5157291cfdcd1", "1234L"]) {
5858
await faucet.credit(address, primaryToken).then(
5959
() => {
60-
fail("must not resolve");
60+
throw new Error("must not resolve");
6161
},
6262
(error) => {
6363
expect(error).toMatch(/address is not in the expected format for this chain/i);

packages/socket/src/socketwrapper.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,24 @@ describe("SocketWrapper", () => {
138138
const socket = new SocketWrapper(
139139
socketServerUrlSlow,
140140
() => {
141-
fail("Got unexpected message event");
141+
throw new Error("Got unexpected message event");
142142
},
143143
(error) => {
144-
fail(error.message || "Unknown socket error");
144+
throw new Error(error.message || "Unknown socket error");
145145
},
146146
() => {
147-
fail("Got unexpected opened event");
147+
throw new Error("Got unexpected opened event");
148148
},
149149
() => {
150-
fail("Got unexpected closed event");
150+
throw new Error("Got unexpected closed event");
151151
},
152152
2_000,
153153
);
154154
socket.connect();
155155

156156
await socket.connected
157157
.then(() => {
158-
fail("must not resolve");
158+
throw new Error("must not resolve");
159159
})
160160
.catch((error) => {
161161
expect(error).toMatch(/connection attempt timed out/i);

packages/socket/src/streamingsocket.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("StreamingSocket", () => {
4949

5050
await socket.connected
5151
.then(() => {
52-
fail("must not resolve");
52+
throw new Error("must not resolve");
5353
})
5454
.catch((error) => {
5555
expect(error).toMatch(/connection attempt timed out/i);

packages/stream/src/promise.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("promise", () => {
8080
it("rejects for simple stream with less events than count", async () => {
8181
await toListPromise(Stream.fromArray([1, 6, 92]), 5)
8282
.then(() => {
83-
fail("must not resolve");
83+
throw new Error("must not resolve");
8484
})
8585
.catch((error) => {
8686
expect(error).toMatch(/stream completed before all events could be collected/i);
@@ -120,7 +120,7 @@ describe("promise", () => {
120120
it("rejects for stream with no events", async () => {
121121
await firstEvent(Stream.fromArray([]))
122122
.then(() => {
123-
fail("must not resolve");
123+
throw new Error("must not resolve");
124124
})
125125
.catch((error) => {
126126
expect(error).toMatch(/stream completed before all events could be collected/i);

packages/stream/src/reducer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("Test stream helpers", () => {
4747
try {
4848
const result = asArray<number>(stream);
4949
await result.finished();
50-
fail("This should have thrown an error");
50+
throw new Error("This should have thrown an error");
5151
} catch (err) {
5252
expect(err).toEqual("error");
5353
}

packages/stream/src/valueandupdates.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe("ValueAndUpdates", () => {
269269
}, 10);
270270
await vau.waitFor(3).then(
271271
() => {
272-
fail("must not resolve");
272+
throw new Error("must not resolve");
273273
},
274274
(error) => {
275275
expect(error).toMatch(/something went wrong/);

packages/tendermint-rpc/src/rpcclients/httpbatchclient.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("HttpBatchClient", () => {
2525
await client
2626
.execute(createJsonRpcRequest("no-such-method"))
2727
.then(() => {
28-
fail("must not resolve");
28+
throw new Error("must not resolve");
2929
})
3030
.catch((error) => {
3131
expect(error).toBeTruthy();

packages/tendermint-rpc/src/rpcclients/httpclient.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("HttpClient", () => {
2525
await client
2626
.execute(createJsonRpcRequest("no-such-method"))
2727
.then(() => {
28-
fail("must not resolve");
28+
throw new Error("must not resolve");
2929
})
3030
.catch((error) => {
3131
expect(error).toBeTruthy();

0 commit comments

Comments
 (0)