Skip to content

Commit 8ac1aff

Browse files
chore: add test for set_data()
Part of WPB-10919.
1 parent e56c0c0 commit 8ac1aff

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

crypto-ffi/bindings/js/test/CoreCrypto.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,54 @@ test("can use groupInfo enums", async () => {
225225
await ctx.close();
226226
});
227227

228+
test("Setting data persists to DB", async () => {
229+
const [ctx, page] = await initBrowser();
230+
231+
const [firstResult, expectedSecondResult, secondResult] =
232+
await page.evaluate(async () => {
233+
const { CoreCrypto, Ciphersuite } = await import("./corecrypto.js");
234+
const ciphersuite =
235+
Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519;
236+
237+
const client2Config = {
238+
databaseName: "test",
239+
key: "test",
240+
ciphersuites: [ciphersuite],
241+
clientId: "test",
242+
};
243+
244+
const cc = await CoreCrypto.init(client2Config);
245+
246+
const text = "my message processing checkpoint";
247+
const encoder = new TextEncoder();
248+
const expectedSecondResult = encoder.encode(text);
249+
250+
let firstResult;
251+
await cc.transaction(async (ctx) => {
252+
firstResult = await ctx.getData();
253+
await ctx.setData(expectedSecondResult);
254+
});
255+
256+
let secondResult;
257+
await cc.transaction(async (ctx) => {
258+
secondResult = await ctx.getData();
259+
});
260+
261+
// To be sure we're not obscuring the case in which firstResult would be null, as when it gets
262+
// passed out of this closure, undefined becomes null.
263+
firstResult = firstResult === null ? "null" : firstResult;
264+
265+
return [firstResult, expectedSecondResult, secondResult];
266+
});
267+
268+
// Undefined becomes null.
269+
expect(firstResult).toBe(null);
270+
expect(secondResult).toEqual(expectedSecondResult);
271+
272+
await page.close();
273+
await ctx.close();
274+
});
275+
228276
test("Using invalid context throws error", async () => {
229277
const [ctx, page] = await initBrowser();
230278

crypto-ffi/bindings/jvm/src/test/kotlin/com/wire/crypto/client/MLSTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ class MLSTest {
4040
internal val carolId = "carol"
4141
}
4242

43+
@Test
44+
fun set_client_data_persists() = runTest {
45+
val cc = initCc()
46+
47+
val data = "my message processing checkpoint".toByteArray()
48+
49+
cc.transaction { ctx ->
50+
assertThat(ctx.getData()).isNull()
51+
ctx.setData(data)
52+
}
53+
54+
cc.transaction { ctx ->
55+
assertThat(ctx.getData()).isEqualTo(data)
56+
}
57+
58+
}
59+
4360
@Test
4461
fun externally_generated_ClientId_should_init_the_MLS_client() = runTest {
4562
val (alice, handle) = initCc().externallyGeneratedMlsClient()

0 commit comments

Comments
 (0)