Skip to content

Commit c0fa4ad

Browse files
chore: add test for set_client_data()
Part of WPB-10919.
1 parent fb9ec3a commit c0fa4ad

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,53 @@ 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 expectedSecondResult = new Uint8Array(32);
247+
console.log(expectedSecondResult.toString());
248+
249+
let firstResult;
250+
await cc.transaction(async (ctx) => {
251+
firstResult = await ctx.getData();
252+
await ctx.setData(expectedSecondResult);
253+
});
254+
255+
let secondResult;
256+
await cc.transaction(async (ctx) => {
257+
secondResult = await ctx.getData();
258+
});
259+
260+
// To be sure we're not obscuring the case in which firstResult would be null, as when it gets
261+
// passed out of this closure, undefined becomes null.
262+
firstResult = firstResult === null ? "null" : firstResult;
263+
264+
return [firstResult, expectedSecondResult, secondResult];
265+
});
266+
267+
// Undefined becomes null.
268+
expect(firstResult).toBe(null);
269+
expect(secondResult).toEqual(expectedSecondResult);
270+
271+
await page.close();
272+
await ctx.close();
273+
});
274+
228275
test("Using invalid context throws error", async () => {
229276
const [ctx, page] = await initBrowser();
230277

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 = ByteArray(32) { (it + 1).toByte() }
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)