-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c074579
commit 7fe85d5
Showing
28 changed files
with
6,922 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
ARG VARIANT=18 | ||
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:${VARIANT} | ||
RUN apt-get update | ||
RUN apt-get -y install --no-install-recommends zsh | ||
RUN apt-get -y install --no-install-recommends zsh | ||
RUN apt-get -y install binaryen | ||
RUN apt-get -y install build-essential cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"extends": "../../node_modules/@assemblyscript/wasi-shim/asconfig.json", | ||
"targets": { | ||
"debug": { | ||
"outFile": "../../dist/libs/as-sdk-integration-tests/debug.wasm", | ||
"textFile": "../../dist/libs/as-sdk-integration-tests/debug.wat", | ||
"sourceMap": true, | ||
"debug": true | ||
}, | ||
"release": { | ||
"outFile": "../../dist/libs/as-sdk-integration-tests/release.wasm", | ||
"textFile": "../../dist/libs/as-sdk-integration-tests/release.wat", | ||
"sourceMap": false, | ||
"optimizeLevel": 3, | ||
"shrinkLevel": 2, | ||
"converge": true, | ||
"noAssert": true | ||
} | ||
}, | ||
"options": { | ||
"bindings": "esm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// The entry file of your WebAssembly module. | ||
|
||
import { httpFetch, Process } from '../../as-sdk/assembly/index'; | ||
|
||
const args = Process.args()[0]; | ||
|
||
if (args === 'testHttpRejection') { | ||
testHttpRejection(); | ||
} else if (args === 'testHttpSuccess') { | ||
testHttpSuccess(); | ||
} | ||
|
||
export function testHttpRejection(): void { | ||
const response = httpFetch('example.com/'); | ||
const rejected = response.rejected; | ||
|
||
if (rejected !== null) { | ||
const msg = String.UTF8.encode('ok'); | ||
const buffer = Uint8Array.wrap(msg); | ||
|
||
Process.exit_with_result(0, buffer); | ||
} | ||
} | ||
|
||
export function testHttpSuccess(): void { | ||
const response = httpFetch('http://example.com/'); | ||
const fulfilled = response.fulfilled; | ||
|
||
if (fulfilled !== null) { | ||
const msg = String.UTF8.encode('ok'); | ||
const buffer = Uint8Array.wrap(msg); | ||
|
||
Process.exit_with_result(0, buffer); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../../node_modules/assemblyscript/std/assembly.json", | ||
"include": ["./**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'vm', | ||
preset: '../../jest.preset.mjs', | ||
coverageDirectory: '../../coverage/libs/as-sdk-integration-tests', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@seda/as-sdk-integration-tests", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "as-sdk-integration-tests", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/as-sdk-integration-tests/assembly", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "asc ./assembly/index.ts --target debug", | ||
"cwd": "libs/as-sdk-integration-tests" | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "libs/as-sdk-integration-tests/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { callVm, } from '../../../dist/libs/vm'; | ||
import { jest } from '@jest/globals'; | ||
import { readFile } from 'node:fs/promises'; | ||
import { HttpFetchResponse } from '../../../dist/libs/vm/src/types/vm-actions'; | ||
import { PromiseStatus } from '../../../dist/libs/vm/src/types/vm-promise'; | ||
|
||
const mockHttpFetch = jest.fn(); | ||
|
||
const TestVmAdapter = jest.fn().mockImplementation(() => { | ||
return { httpFetch: mockHttpFetch }; | ||
}); | ||
|
||
describe('Http', () => { | ||
it('Test SDK HTTP Rejection', async () => { | ||
|
||
const wasmBinary = await readFile('dist/libs/as-sdk-integration-tests/debug.wasm'); | ||
const result = await callVm({ | ||
args: ['testHttpRejection'], | ||
envs: {}, | ||
binary: new Uint8Array(wasmBinary), | ||
}); | ||
|
||
expect(result.exitCode).toBe(0); | ||
expect(result.result).toEqual(new TextEncoder().encode("ok")); | ||
}); | ||
|
||
it('Test SDK HTTP Success', async () => { | ||
const wasmBinary = await readFile( | ||
'dist/libs/as-sdk-integration-tests/debug.wasm' | ||
); | ||
|
||
const mockResponse = new HttpFetchResponse({ | ||
content_length: 1, | ||
bytes: [1], | ||
headers: {}, | ||
status: 200, | ||
url: 'http://example.com', | ||
}); | ||
|
||
mockHttpFetch.mockResolvedValue(PromiseStatus.fulfilled(mockResponse)); | ||
|
||
const result = await callVm({ | ||
args: ['testHttpSuccess'], | ||
envs: {}, | ||
binary: new Uint8Array(wasmBinary), | ||
}, undefined, new TestVmAdapter()); | ||
|
||
expect(result.exitCode).toBe(0); | ||
expect(result.result).toEqual(new TextEncoder().encode('ok')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"targets": { | ||
"coverage": { | ||
"lib": ["../../node_modules/@as-covers/assembly/index.ts"], | ||
"transform": ["@as-covers/transform", "@as-pect/transform"] | ||
}, | ||
"noCoverage": { | ||
"transform": ["@as-pect/transform"] | ||
} | ||
}, | ||
"options": { | ||
"exportMemory": true, | ||
"outFile": "output.wasm", | ||
"textFile": "output.wat", | ||
"bindings": "raw", | ||
"exportStart": "_start", | ||
"exportRuntime": true, | ||
"use": ["RTRACE=1"], | ||
"debug": true, | ||
"exportTable": true | ||
}, | ||
"extends": "./asconfig.json", | ||
"entries": ["../../node_modules/@as-pect/assembly/assembly/index.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export default { | ||
/** | ||
* A set of globs passed to the glob package that qualify typescript files for testing. | ||
*/ | ||
entries: ['./assembly/__test__/**/*.spec.ts'], | ||
/** | ||
* A set of globs passed to the glob package that quality files to be added to each test. | ||
*/ | ||
include: ['./assembly/__test__/**/*.include.ts'], | ||
/** | ||
* A set of regexp that will disclude source files from testing. | ||
*/ | ||
disclude: [/node_modules/], | ||
/** | ||
* Add your required AssemblyScript imports here. | ||
*/ | ||
async instantiate(memory, createImports, instantiate, binary) { | ||
let instance; // Imports can reference this | ||
const myImports = { | ||
env: { memory }, | ||
// put your web assembly imports here, and return the module promise | ||
}; | ||
instance = instantiate(binary, createImports(myImports)); | ||
return instance; | ||
}, | ||
/** Enable code coverage. */ | ||
// coverage: ["assembly/**/*.ts"], | ||
/** | ||
* Specify if the binary wasm file should be written to the file system. | ||
*/ | ||
outputBinary: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"extends": "../../node_modules/@assemblyscript/wasi-shim/asconfig.json", | ||
"targets": { | ||
"debug": { | ||
"outFile": "../../dist/libs/as-sdk/debug.wasm", | ||
"textFile": "../../dist/libs/as-sdk/debug.wat", | ||
"sourceMap": true, | ||
"debug": true | ||
}, | ||
"release": { | ||
"outFile": "../../dist/libs/as-sdk/release.wasm", | ||
"textFile": "../../dist/libs/as-sdk/release.wat", | ||
"sourceMap": true, | ||
"optimizeLevel": 3, | ||
"shrinkLevel": 0, | ||
"converge": false, | ||
"noAssert": false | ||
} | ||
}, | ||
"options": { | ||
"bindings": "esm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="@as-pect/assembly/types/as-pect" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { httpFetch, HttpFetchOptions } from '../http'; | ||
|
||
describe('http', () => { | ||
it('do a http fetch', () => { | ||
const options = new HttpFetchOptions(); | ||
const headers = new Map<string, string>(); | ||
|
||
headers.set('Content-Type', 'application/json'); | ||
options.headers = headers; | ||
|
||
const result = httpFetch('http://example.com', options); | ||
|
||
expect(result.toString()).toBe("{}"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export declare function http_fetch( | ||
action_ptr: usize, | ||
action_length: u32 | ||
): u32; | ||
|
||
export declare function call_result_write( | ||
result: usize, | ||
result_length: u32 | ||
): void; | ||
|
||
export declare function execution_result(result: usize, result_length: u32): void; |
Oops, something went wrong.