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
+37 -3
View File
@@ -1,5 +1,39 @@
// The entry file of your WebAssembly module.
import {
// ethereum,
// store,
log
// ipfs,
// json,
// crypto,
export function add (a: i32, b: i32): i32 {
return a + b;
// dataSource,
// ens,
// typeConversion,
// bigDecimal,
// bigInt,
// Address,
// BigDecimal,
// BigInt,
// ByteArray,
// Bytes,
// DataSourceContext,
// DataSourceTemplate,
// Entity,
// JSONValue,
// JSONValueKind,
// JSONValuePayload,
// Result,
// TypedMap,
// TypedMapEntry,
// Value,
// ValueKind,
// ValuePayload,
// Wrapped
} from '@graphprotocol/graph-ts';
export function callGraphAPI (): void {
log.debug('hello {}', ['world']);
}
+6 -5
View File
@@ -4,6 +4,7 @@
"main": "index.js",
"license": "AGPL-3.0",
"devDependencies": {
"@graphprotocol/graph-ts": "^0.22.0",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"assemblyscript": "^0.19.16",
@@ -14,17 +15,17 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"typescript": "^4.3.2",
"nodemon": "^2.0.7",
"ts-node": "^10.0.0"
"ts-node": "^10.0.0",
"typescript": "^4.3.2"
},
"scripts": {
"lint": "eslint .",
"build": "tsc",
"asbuild:debug": "asc assembly/index.ts --target debug",
"asbuild:release": "asc assembly/index.ts --target release",
"asbuild:debug": "asc assembly/index.ts --lib ./node_modules --target debug",
"asbuild:release": "asc assembly/index.ts --lib ./node_modules --target release",
"asbuild": "yarn asbuild:debug && yarn asbuild:release",
"test": "mocha src/**/*.test.ts"
"test": "yarn asbuild:debug && mocha src/**/*.test.ts"
},
"dependencies": {
"@assemblyscript/loader": "^0.19.16"
+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);
};