mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-12 02:27:31 +00:00
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:
@@ -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);
|
||||
});
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user