This example package demonstrates compiling a simple AssemblyScript program, host.ts
which access various constants and functions made available by the host environment.
from the project root:
npm install
To compile the host.ts
code to a WASM binary:
npm run build
A host.wasm
file will be produced in the build
directory
Test the module outside of the context of the blockchain:
npm test
This will run NodeJS based tests in the test
directory. For example in host.unit.spec.js
test instantiation of the compiled WASM module, and assertions to verify its API and behavior:
describe('Host Constant', function () {
it('Get Count Constant', async function () {
const count = module.getHostCount();
assert.strictEqual(count, 9001);
});
...
});
Return the count constant exposed by the host
Return the result of adding x and y on the host
Returns a pointer to the message string exposed by the host