From df090d55c512bb7245dda99b0bf1e9fcf6b3f23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Bruus=20Zeppelin?= Date: Tue, 10 Sep 2024 14:27:16 +0200 Subject: [PATCH] Non-blocking wasm compilation --- packages/sdk/CHANGELOG.md | 1 - packages/sdk/src/types/VersionedModuleSource.ts | 7 +++++-- packages/sdk/test/ci/module-schema.test.ts | 8 ++++---- packages/sdk/test/ci/util.test.ts | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index a2b832a0..a0498c75 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -5,7 +5,6 @@ ### Breaking changes - `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema. - It also no longer is `async` because there isn't any need for it to be so. - `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema` (which was removed as it was just a less capable version of `getEmbeddedModuleSchema`). This means that it returns the complete `RawModuleSchema` instead of only the schema bytes. diff --git a/packages/sdk/src/types/VersionedModuleSource.ts b/packages/sdk/src/types/VersionedModuleSource.ts index 2d4f9323..19b4a41f 100644 --- a/packages/sdk/src/types/VersionedModuleSource.ts +++ b/packages/sdk/src/types/VersionedModuleSource.ts @@ -101,8 +101,11 @@ export async function parseModuleInterface(moduleSource: VersionedModuleSource): * @returns {RawModuleSchema | null} The raw module schema if found. * @throws If the module source cannot be parsed or contains duplicate schema sections. */ -export function getEmbeddedModuleSchema({ source, version }: VersionedModuleSource): RawModuleSchema | undefined { - const sections = findCustomSections(new WebAssembly.Module(source), version); +export async function getEmbeddedModuleSchema({ + source, + version, +}: VersionedModuleSource): Promise { + const sections = findCustomSections(await WebAssembly.compile(source), version); if (sections === undefined) { return undefined; } diff --git a/packages/sdk/test/ci/module-schema.test.ts b/packages/sdk/test/ci/module-schema.test.ts index 32f00491..3f3d9a4d 100644 --- a/packages/sdk/test/ci/module-schema.test.ts +++ b/packages/sdk/test/ci/module-schema.test.ts @@ -12,7 +12,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { path.join(testFileDir, 'cis2-wccd-embedded-schema-v1-versioned.wasm.v1') ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } @@ -24,7 +24,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { path.join(testFileDir, 'cis1-wccd-embedded-schema-v0-versioned.wasm.v0') ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } @@ -39,7 +39,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { version: 0, source: Buffer.from(unversionedContractModule), } as const; - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } @@ -51,7 +51,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => { path.join(testFileDir, 'cis2-wccd-embedded-schema-v1-unversioned.wasm.v1') ); const moduleSource = versionedModuleSourceFromBuffer(contractModule); - const moduleSchema = getEmbeddedModuleSchema(moduleSource); + const moduleSchema = await getEmbeddedModuleSchema(moduleSource); if (moduleSchema === undefined) { fail('Failed to find module schame'); } diff --git a/packages/sdk/test/ci/util.test.ts b/packages/sdk/test/ci/util.test.ts index 178434a6..efa9d4d8 100644 --- a/packages/sdk/test/ci/util.test.ts +++ b/packages/sdk/test/ci/util.test.ts @@ -26,13 +26,13 @@ test('stringToInt will not change the string if no keys match', () => { expect(transformed).toEqual(input); }); -test('Embedded schema is the same as a seperate schema file', () => { +test('Embedded schema is the same as a seperate schema file', async () => { const versionedWasmModule = readFileSync('test/ci/resources/icecream-with-schema.wasm'); // Strip module version information const wasmModule = versionedWasmModule.subarray(8); const seperateSchema = readFileSync('test/ci/resources/icecream-schema.bin'); - const embeddedSchema = getEmbeddedModuleSchema({ + const embeddedSchema = await getEmbeddedModuleSchema({ source: wasmModule, version: 1, });