This commit is contained in:
DieMyst 2019-03-27 12:03:02 +03:00
commit f9a4308070
9 changed files with 4805 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.idea
build
node_modules

26
assembly/index.ts Normal file
View File

@ -0,0 +1,26 @@
import {getStringInvoker} from "./signature";
let stringInvoker = getStringInvoker();
export class Result {
checkPassed: bool;
payload: string | null;
errorMessage: string | null;
constructor(result: string) {
if (result.includes("[Error]")) {
this.checkPassed = false;
this.errorMessage = result;
} else {
this.checkPassed = true;
this.payload = result;
}
}
}
export function checkSignature(request: string): Result {
let result = stringInvoker.invoke(request);
return new Result(result);
}

13
assembly/signature.ts Normal file
View File

@ -0,0 +1,13 @@
import {StringInvoke, API} from "../node_modules/crossmodule/assembly/index"
export declare function allocate(size: i32): i32;
export declare function deallocate(ptr: i32, size: i32): void;
export declare function invoke(ptr: i32, size: i32): i32;
export declare function store(ptr: i32, byte: u8): void;
export declare function load(ptr: i32): u8;
export function getStringInvoker(): StringInvoke {
let api = new API(invoke, allocate, deallocate, store, load);
return new StringInvoke(api);
}

6
assembly/tsconfig.json Normal file
View File

@ -0,0 +1,6 @@
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}

4691
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

39
package.json Normal file
View File

@ -0,0 +1,39 @@
{
"name": "crossmodule",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --sourceMap --validate --optimize",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
"asbuild:test": "npm run asbuild:test:signature",
"asbuild:test:signature": "npx asc tests/assembly/signature-test.spec.as.ts -b tests/build/signature-test.wasm -t tests/build/signature-test.wat --validate --sourceMap --importMemory --debug",
"test": "npm run asbuild:test && ava -v --serial",
"test:ci": "npm run asbuild:test && ava --fail-fast --serial"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^10.12.3",
"assemblyscript": "AssemblyScript/assemblyscript",
"ts-node": "^7.0.1",
"ava": "^1.4.0",
"typescript": "^3.1.6"
},
"dependencies": {
"crossmodule": "github:fluencelabs/crossmodule"
},
"ava": {
"compileEnhancements": true,
"extensions": [
"ts"
],
"require": [
"ts-node/register/transpile-only"
],
"files": [
"tests/**/*.spec.ts"
]
}
}

View File

@ -0,0 +1,18 @@
import {Result} from "../../assembly/index";
import "allocator/arena";
declare function logStr(str: string): void;
export class CrossModuleTest {
//TODO fix error: TypeError: WebAssembly Instantiation: Import #0 module="signature" error: module is not an object or function
//TODO that caused by importing methods from nonexisted module `signature` in test
/*static shouldReturnResultWithError(): bool {
let message = "[Error] Some error.";
let result = new Result(message);
assert(!result.checkPassed, "The message should be qualified as error.");
assert(result.payload == null, "Payload should be null on error.");
assert(result.errorMessage == message, "An error message should exist.");
return true;
}*/
}

View File

@ -0,0 +1,6 @@
{
"extends": "../../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts","*.ts"
]
}

3
tests/signature.spec.ts Normal file
View File

@ -0,0 +1,3 @@
import { defineTestsFromModule } from './utils/spec';
defineTestsFromModule('signature-test');