WASM instance setup (#11)

* Code for running wasm file.

* Add test for wasm exported function.

* Use target names for build files.

Co-authored-by: nabarun <nabarun@deepstacksoft.com>
This commit is contained in:
Ashwin Phatak
2021-12-28 16:08:04 +05:30
committed by nabarun
co-authored by nabarun
parent 987457992a
commit 1421ba5a9b
9 changed files with 93 additions and 3 deletions
+17
View File
@@ -0,0 +1,17 @@
//
// Copyright 2021 Vulcanize, Inc.
//
import { expect } from 'chai';
import path from 'path';
import 'mocha';
import { getExports } from './index';
const WASM_FILE_PATH = '../build/debug.wasm';
it('should execute exported function', async () => {
const filePath = path.resolve(__dirname, WASM_FILE_PATH);
const { exports } = await getExports(filePath);
expect(exports.add(1, 2)).to.equal(3);
});
+10
View File
@@ -1,3 +1,13 @@
//
// Copyright 2021 Vulcanize, Inc.
//
import fs from 'fs/promises';
import loader from '@assemblyscript/loader';
const imports = { /* imports go here */ };
export const getExports = async (filePath: string): Promise<loader.ResultObject & { exports: any }> => {
const buffer = await fs.readFile(filePath);
return loader.instantiate(buffer, imports);
};