Skip to content

Commit

Permalink
chore: add test for set_data()
Browse files Browse the repository at this point in the history
Part of WPB-10919.
  • Loading branch information
SimonThormeyer committed Nov 12, 2024
1 parent 45fb16a commit 07b97f5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
48 changes: 48 additions & 0 deletions crypto-ffi/bindings/js/test/CoreCrypto.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,54 @@ test("can use groupInfo enums", async () => {
await ctx.close();
});

test("Setting data persists to DB", async () => {
const [ctx, page] = await initBrowser();

const [firstResult, expectedSecondResult, secondResult] =
await page.evaluate(async () => {
const { CoreCrypto, Ciphersuite } = await import("./corecrypto.js");
const ciphersuite =
Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519;

const client2Config = {
databaseName: "test",
key: "test",
ciphersuites: [ciphersuite],
clientId: "test",
};

const cc = await CoreCrypto.init(client2Config);

const text = "my message processing checkpoint";
const encoder = new TextEncoder();
const expectedSecondResult = encoder.encode(text);

let firstResult;
await cc.transaction(async (ctx) => {
firstResult = await ctx.getData();
await ctx.setData(expectedSecondResult);
});

let secondResult;
await cc.transaction(async (ctx) => {
secondResult = await ctx.getData();
});

// To be sure we're not obscuring the case in which firstResult would be null, as when it gets
// passed out of this closure, undefined becomes null.
firstResult = firstResult === null ? "null" : firstResult;

return [firstResult, expectedSecondResult, secondResult];
});

// Undefined becomes null.
expect(firstResult).toBe(null);
expect(secondResult).toEqual(expectedSecondResult);

await page.close();
await ctx.close();
});

test("Using invalid context throws error", async () => {
const [ctx, page] = await initBrowser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ class MLSTest {
internal val carolId = "carol"
}

@Test
fun set_client_data_persists() = runTest {
val cc = initCc()

val data = "my message processing checkpoint".toByteArray()

cc.transaction { ctx ->
assertThat(ctx.getData()).isNull()
ctx.setData(data)
}

cc.transaction { ctx ->
assertThat(ctx.getData()).isEqualTo(data)
}

}

@Test
fun externally_generated_ClientId_should_init_the_MLS_client() = runTest {
val (alice, handle) = initCc().externallyGeneratedMlsClient()
Expand Down

0 comments on commit 07b97f5

Please sign in to comment.