Host API stubs (#12)

This commit is contained in:
Ashwin Phatak
2021-12-28 16:08:04 +05:30
committed by nabarun
parent 1421ba5a9b
commit 889e96572d
6 changed files with 139 additions and 18 deletions
+3 -5
View File
@@ -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();
});
+69 -2
View File
@@ -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);
};