mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-12 10:37:32 +00:00
Host API stubs (#12)
This commit is contained in:
@@ -2,16 +2,14 @@
|
||||
// Copyright 2021 Vulcanize, Inc.
|
||||
//
|
||||
|
||||
import { expect } from 'chai';
|
||||
import path from 'path';
|
||||
import 'mocha';
|
||||
|
||||
import { getExports } from './index';
|
||||
import { instantiate } 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);
|
||||
const { exports } = await instantiate(filePath);
|
||||
exports.callGraphAPI();
|
||||
});
|
||||
|
||||
@@ -5,9 +5,76 @@
|
||||
import fs from 'fs/promises';
|
||||
import loader from '@assemblyscript/loader';
|
||||
|
||||
const imports = { /* imports go here */ };
|
||||
const imports = {
|
||||
index: {
|
||||
'store.get': () => {
|
||||
console.log('store.get');
|
||||
},
|
||||
'store.set': () => {
|
||||
console.log('store.set');
|
||||
},
|
||||
|
||||
export const getExports = async (filePath: string): Promise<loader.ResultObject & { exports: any }> => {
|
||||
'typeConversion.stringToH160': () => {
|
||||
console.log('typeConversion.stringToH160');
|
||||
},
|
||||
'typeConversion.bytesToHex': () => {
|
||||
console.log('typeConversion.bytesToHex');
|
||||
},
|
||||
'typeConversion.bytesToString': () => {
|
||||
console.log('typeConversion.bytesToString');
|
||||
},
|
||||
'typeConversion.bigIntToString': () => {
|
||||
console.log('typeConversion.bigIntToString');
|
||||
},
|
||||
|
||||
'bigDecimal.fromString': () => {
|
||||
console.log('bigDecimal.fromString');
|
||||
},
|
||||
'bigDecimal.times': () => {
|
||||
console.log('bigDecimal.times');
|
||||
},
|
||||
'bigDecimal.dividedBy': () => {
|
||||
console.log('bigDecimal.dividedBy');
|
||||
},
|
||||
'bigDecimal.plus': () => {
|
||||
console.log('bigDecimal.plus');
|
||||
},
|
||||
'bigDecimal.minus': () => {
|
||||
console.log('bigDecimal.minus');
|
||||
},
|
||||
|
||||
'bigInt.plus': () => {
|
||||
console.log('bigInt.plus');
|
||||
},
|
||||
'bigInt.minus': () => {
|
||||
console.log('bigInt.minus');
|
||||
},
|
||||
'bigInt.times': () => {
|
||||
console.log('bigInt.times');
|
||||
},
|
||||
'bigInt.dividedBy': () => {
|
||||
console.log('bigInt.dividedBy');
|
||||
},
|
||||
'bigInt.mod': () => {
|
||||
console.log('bigInt.mod');
|
||||
},
|
||||
|
||||
'log.log': () => {
|
||||
console.log('log.log');
|
||||
},
|
||||
|
||||
'dataSource.create': () => {
|
||||
console.log('dataSource.create');
|
||||
}
|
||||
},
|
||||
ethereum: {
|
||||
'ethereum.call': () => {
|
||||
console.log('ethereum.call');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const instantiate = 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