Skip to content

Commit dea4e35

Browse files
committed
test: ffi: ts: adjust to ArrayBuffer
1 parent 37ea7eb commit dea4e35

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

crypto-ffi/bindings/js/test/wdio/database.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ describe("database", () => {
2020

2121
await window.ccModule.openDatabase(
2222
databaseName,
23-
new window.ccModule.DatabaseKey(key)
23+
new window.ccModule.DatabaseKey(key.buffer)
2424
);
2525

2626
const db = await window.ccModule.openDatabase(
2727
databaseName,
28-
new window.ccModule.DatabaseKey(key)
28+
new window.ccModule.DatabaseKey(key.buffer)
2929
);
3030

3131
return { dbIsDefined: db !== undefined };
@@ -36,7 +36,7 @@ describe("database", () => {
3636
it("key must have correct length", async () => {
3737
expect(() =>
3838
browser.execute(async () => {
39-
new window.ccModule.DatabaseKey(new Uint8Array(11));
39+
new window.ccModule.DatabaseKey(new Uint8Array(11).buffer);
4040
})
4141
).rejects.toThrow();
4242
});
@@ -48,15 +48,15 @@ describe("database", () => {
4848

4949
const makeClientId = () => {
5050
const array = new Uint8Array([1, 2]);
51-
return new window.ccModule.ClientId(array);
51+
return new window.ccModule.ClientId(array.buffer);
5252
};
5353

5454
const key = new Uint8Array(32);
5555
window.crypto.getRandomValues(key);
5656

5757
const database = await window.ccModule.openDatabase(
5858
databaseName,
59-
new window.ccModule.DatabaseKey(key)
59+
new window.ccModule.DatabaseKey(key.buffer)
6060
);
6161

6262
let cc = await window.ccModule.CoreCrypto.init(database);
@@ -75,13 +75,13 @@ describe("database", () => {
7575

7676
await window.ccModule.updateDatabaseKey(
7777
databaseName,
78-
new window.ccModule.DatabaseKey(key),
79-
new window.ccModule.DatabaseKey(newKey)
78+
new window.ccModule.DatabaseKey(key.buffer),
79+
new window.ccModule.DatabaseKey(newKey.buffer)
8080
);
8181

8282
const newDatabase = await window.ccModule.openDatabase(
8383
databaseName,
84-
new window.ccModule.DatabaseKey(newKey)
84+
new window.ccModule.DatabaseKey(newKey.buffer)
8585
);
8686

8787
cc = await window.ccModule.CoreCrypto.init(newDatabase);
@@ -143,18 +143,20 @@ describe("database", () => {
143143
}
144144
}
145145

146+
console.log("before close")
146147
// It is important to close the database here since otherwise the migration process
147148
// will be stuck because we'd be holding a connection to the same database open.
148149
db.close();
149150

150151
// Migrate the whole database to use the new key type.
151152
const old_key = clientName;
152-
const new_key = new window.ccModule.DatabaseKey(new Uint8Array(32));
153+
const new_key = new window.ccModule.DatabaseKey(new Uint8Array(32).buffer);
153154
await window.ccModule.migrateDatabaseKeyTypeToBytes(
154155
clientName,
155156
old_key,
156157
new_key
157158
);
159+
console.log("before open db")
158160

159161
// Reconstruct the client based on the migrated database and fetch the epoch.
160162
const encoder = new TextEncoder();
@@ -165,7 +167,7 @@ describe("database", () => {
165167

166168
const instance = await window.ccModule.CoreCrypto.init(database);
167169
const epoch = await instance.conversationEpoch(
168-
new window.ccModule.ConversationId(encoder.encode("convId"))
170+
new window.ccModule.ConversationId(encoder.encode("convId").buffer)
169171
);
170172
return epoch;
171173
}, JSON.stringify(stores));

0 commit comments

Comments
 (0)