Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

WebAssembly Backend #773

Draft
wants to merge 73 commits into
base: release-1.0
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a1b9df8
(WIP) New backend compiler, new code org, new build
jeromesimeon Jan 14, 2020
d8dc92c
(WIP) Get the JavaScript extraction for the compiler back
jeromesimeon Jan 14, 2020
962e581
(WIP) Refactor OCaml code
jeromesimeon Jan 15, 2020
badf7c3
Fix to Make clean
jeromesimeon Jan 15, 2020
0b15107
Small fixes to build
jeromesimeon Jan 15, 2020
38bead8
(WIP) Switch back to new backend CodeGeneration for JS
jeromesimeon Jan 16, 2020
3e2ee3b
Remove ES5 support
jeromesimeon Jan 16, 2020
9be34fe
Somewhat properly hooks up new JavaScript backend
jeromesimeon Jan 16, 2020
4edeeb1
fix(compiler) Various adjustments to JS runtime and execution engine …
jeromesimeon Jan 17, 2020
a9ea6e8
Cleanup of JavaScript runtime for new backend
jeromesimeon Jan 17, 2020
0a3e650
(WIP) ergo-compiler package tests now work again
jeromesimeon Jan 17, 2020
f26d3fc
Some initial fixes for ergo-engine, switch to new concerto
jeromesimeon Jan 17, 2020
b3c7b22
Sanitize contract name in Cicero target
jeromesimeon Jan 18, 2020
500f980
Fix to the DateTime component of the runtime
jeromesimeon Jan 18, 2020
3338ee8
More fixes to DateTime runtime and tests
jeromesimeon Jan 18, 2020
348466f
Fix to doubleToInteger runtime
jeromesimeon Jan 18, 2020
41fa53d
Several fixes to the compiler for optional values
jeromesimeon Jan 19, 2020
a18824c
Temporary fixes to cast and unbrand for new runtime
jeromesimeon Jan 19, 2020
8f08fdb
Fixes runtime for enums, fixes tests
jeromesimeon Jan 19, 2020
871a303
Further cleanup and refactoring of JavaScript runtime
jeromesimeon Jan 20, 2020
e64b17b
Further cleanup of JavaScript code emit
jeromesimeon Jan 21, 2020
962a897
Various fixes for new compiler
jeromesimeon Jan 25, 2020
1f370f7
chore(dep) Upgrade to latest dev version of Concerto
jeromesimeon Jan 25, 2020
ec1a8fc
chore(dep) Upgrade fast stringify
jeromesimeon Jan 25, 2020
6e6bece
Remove temp config; Rename atd files
jeromesimeon Jan 26, 2020
c1afe77
proof(backend) Discharges some of the proof obligations in the backen…
jeromesimeon Jan 26, 2020
e8c8937
fix(runtime) Update to JavaScript runtime; Small refactor
jeromesimeon Jan 27, 2020
e7a94c7
fix(doc) Update makefile for documentation build
jeromesimeon Jan 27, 2020
ffc183e
fix(build) Add qcert to opam description
jeromesimeon Jan 27, 2020
e47d522
feature(compiler) Consolidate ES6 and Cicero target into a new single…
jeromesimeon Jan 27, 2020
3a348f1
refactor(compiler) Reorganization and renaming for internal types
jeromesimeon Jan 29, 2020
37cfff0
refactor(types) In ErgoCT and ErgoNNRC, always use internal in functi…
jeromesimeon Jan 29, 2020
838d7a7
refactor(nnrc) ErgoNNRC function tables are now properly represented …
jeromesimeon Jan 29, 2020
c05a49f
feature(semantic) Add eval-based semantic for ErgoNNRC
jeromesimeon Jan 29, 2020
cdb8e6c
refactor(compiler) Add ErgoImp AST with eval, breakdown ErgoNNRC->ES6…
jeromesimeon Jan 30, 2020
359e46a
feature(proof) Now with a proof of correctness for the compilation fr…
jeromesimeon Jan 31, 2020
ce98cd6
fix(build) Updates for latest master version of Q*cert
jeromesimeon Feb 18, 2020
1581e1f
chore(rebase) Fixes after rebase with master: mostly re-enable moneta…
jeromesimeon Jul 16, 2020
3016cea
chore(build) Switch to OCaml 4.09 and Qcert 2.0
jeromesimeon Jul 25, 2020
bf32c1d
chore(rebase) Adjust tests and code after rebase with master
jeromesimeon Aug 13, 2020
00fd109
fix(doc) Update DEVELOPERS for 1.0
jeromesimeon Aug 13, 2020
ceef513
fix(test) Rebuild assets and fixes tests
jeromesimeon Aug 13, 2020
9e64c94
chore(upgrade) Ergo compiler code switched to Coq 8.12
jeromesimeon Aug 13, 2020
816ff8b
WIP(Wasm) Some initial compiler extension for Wasm
jeromesimeon Jan 14, 2020
9eb7c45
feature(wasm) Add, almost, compilation path from Ergo to Wasm
jeromesimeon Jul 20, 2020
e91e7ac
fix(test) license check and some tests
jeromesimeon Jul 20, 2020
da2a1dc
fix(rebase) Adjust code after rebase with master
jeromesimeon Jul 23, 2020
8da4009
Use QCert's new Wasm backend functor
pkel Aug 2, 2020
480ef41
chore(dep) Fixes for Coq 8.12 + license check fixes
jeromesimeon Aug 13, 2020
146f698
fix(Wasm) Update to new compile call with type hierarchy
jeromesimeon Aug 14, 2020
c069bc2
fix(engine) Make calls async yet again...
jeromesimeon Aug 14, 2020
8c63e7a
feature(wasm) Some initial code for the new Ergo to Wasm compiler
jeromesimeon Aug 17, 2020
0f63761
fix(Wasm) --target wasm in the compiler now generates binary wasm for…
jeromesimeon Aug 17, 2020
47a768c
feature(engine) trigger is now just invoking main
jeromesimeon Aug 17, 2020
1d61a02
refactor(compiler) Remove unneeded dispatch/init boiler plates in ES6…
jeromesimeon Aug 17, 2020
8172ea5
refactor(engine) Updates to API calls / terminology in the engine
jeromesimeon Aug 17, 2020
066c676
feature(wasm) Gets first end to end Wasm backed with lots of hacks
jeromesimeon Aug 18, 2020
aa24e1a
Return B64 from wasm backend.
pkel Aug 18, 2020
930668a
Avoid Base64 on JS/Ocaml interop
pkel Aug 18, 2020
1dcb43c
chore(dep) Add wasm to OCaml dependencies in CI and DEVELOPERS.md
jeromesimeon Aug 18, 2020
edf2f94
fix(wasm) Various fixes to tests
jeromesimeon Aug 18, 2020
e93d6e8
fix(wasm) Various fixes to engine and tests, factor out error handlimg
jeromesimeon Aug 19, 2020
4fa6ad1
fix(build) Remove base64 from js_of_ocaml build dependencies
jeromesimeon Aug 19, 2020
dcab51c
refactor(runtime) Remove error unwrap from ES6 runtime
jeromesimeon Aug 19, 2020
f06b956
fix(dep) dependency for assemblyscript loader
jeromesimeon Aug 19, 2020
69b2b96
fix(runtime) Temporarily remove copy of WASM runtime -- until we know…
jeromesimeon Aug 19, 2020
c130eb0
fix(engine) Some initial WASM test harness
jeromesimeon Aug 19, 2020
cb24fcf
fix(wasm) More tests for WASM + engine
jeromesimeon Aug 19, 2020
2e7d3d7
fix(wasm) Update with latest Wasm compiler + volumediscount test
jeromesimeon Aug 19, 2020
fa4c660
fix(tests) Fixes broken tests
jeromesimeon Aug 19, 2020
a864a1b
fix(compiler) Fix to logic manager for ES6 compiled archives
jeromesimeon Aug 19, 2020
d53e5cd
fix(wasm) Add runtime and test for float -> integer coercion
jeromesimeon Aug 20, 2020
04c7ccf
fix(wasm) Update to latest Q*cert WASM backend/runtime + pyth test
jeromesimeon Aug 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(wasm) Various fixes to engine and tests, factor out error handlimg
Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
  • Loading branch information
jeromesimeon authored and pkel committed Aug 20, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e93d6e8bf08742a41d7511c894cbf81aea0fb7af
10,452 changes: 5,231 additions & 5,221 deletions packages/ergo-cli/extracted/ergoccore.js

Large diffs are not rendered by default.

8,834 changes: 4,422 additions & 4,412 deletions packages/ergo-cli/extracted/ergotopcore.js

Large diffs are not rendered by default.

20,038 changes: 9,954 additions & 10,084 deletions packages/ergo-compiler/extracted/compilercore.js

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions packages/ergo-compiler/lib/script.js
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ class Script {
* @param {ModelManager} modelManager - The ModelManager associated with this Script
* @param {string} identifier - The identifier of the script
* @param {string} language - The language type of the script
* @param {string} contents - The contents of the script
* @param {Buffer} contents - The contents of the script
* @param {string} contractName - The name of the contract if known or null
*/
constructor(modelManager, identifier, language, contents, contractName) {
@@ -54,8 +54,7 @@ class Script {
let parser;

try {
// XXX this.contents is now a Buffer
parser = new JavaScriptParser(this.contents.toString(), false, 8);
parser = new JavaScriptParser(this.getContents(), false, 8);
} catch (cause) {
// consider adding a toHex method in the exception to put out the pure hex values of the file.
const error = new SyntaxError('Failed to parse ' + this.identifier + ': ' + cause.message+'\n'+data.errorStatement);
@@ -113,10 +112,14 @@ class Script {

/**
* Returns the contents of the script
* @return {string} the content of the script
* @return {*} the content of the script
*/
getContents() {
return this.contents;
if (this.language === '.js' || this.language === '.java') {
return Buffer.from(this.contents, 'utf8').toString();
} else {
return this.contents;
}
}

/**
42 changes: 21 additions & 21 deletions packages/ergo-compiler/test/logicmanager.js
Original file line number Diff line number Diff line change
@@ -74,9 +74,9 @@ describe('LogicManager', () => {
const logicManager = new LogicManager('es6');
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});

it('should succeed creating a dispatch call for a JS logic file with a contract class (ES6)', () => {
@@ -160,9 +160,9 @@ describe('LogicManager', () => {
const logicManager = new LogicManager('es6');
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.compileLogic(false).then((logicCode) => {
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});
});

@@ -177,16 +177,16 @@ describe('LogicManager', () => {
logicManager.addErgoBuiltin();
logicManager.addLogicFile(ergoSample,'test3.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});

it('should load a logic file (without extension) to the script manager', () => {
const logicManager = new LogicManager('es6');
logicManager.addLogicFile(ergoSample,'test');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});

it('should set the contract name', () => {
@@ -202,30 +202,30 @@ describe('LogicManager', () => {
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.getTarget().should.equal('es6');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
logicManager.setTarget('es6', true);
logicManager.getTarget().should.equal('es6');
const contractName = 'org.accordproject.helloemit.HelloWorld';
logicManager.setContractName(contractName);
logicManager.getContractName().should.equal(ErgoCompiler.contractCallName(contractName));
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});

it('should fail to create init and dispatch for ES6 without a contract name', () => {
const logicManager = new LogicManager('es6');
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.getTarget().should.equal('es6');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});

it('should set the compilation target to ES6 but not recompile the logic', () => {
const logicManager = new LogicManager('es6');
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
logicManager.setTarget('es6', false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});

it('should fail to create init code for Java', () => {
@@ -257,7 +257,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(138466);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(138438);
});

it('should load a directory with grammar', async function () {
@@ -271,7 +271,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(69535);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(69507);
});
});

@@ -288,7 +288,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(138466);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(138438);
});

it('should load a Zip with formula', async function () {
@@ -303,7 +303,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(68167);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(68139);
});
});

@@ -324,7 +324,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(138466);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(138438);
});

it('should load a Zip with formula', async function () {
@@ -343,7 +343,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(69535);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(69507);
});
});

@@ -379,15 +379,15 @@ describe('LogicManager', () => {
const logicManager = new LogicManager('es6');
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
logicManager.updateLogic(ergoSample,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.updateLogic(ergoSample,'testNEW.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
logicManager.updateLogic(ergoSample3,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50153);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(50125);
});

});
12 changes: 6 additions & 6 deletions packages/ergo-compiler/test/scriptmanager.js
Original file line number Diff line number Diff line change
@@ -59,8 +59,8 @@ describe('ScriptManager', () => {
scriptManager.getLogic().map(x => x.name).should.deep.equal(['test.ergo']);
scriptManager.allFunctionDeclarations().length.should.equal(2);
scriptManager.allFunctionDeclarations().map(x => x.getName()).should.deep.equal(['paymentClause','__dispatch']);
scriptManager.getCompiledScript().getContents().length.should.equal(50153);
scriptManager.getCompiledModule().length.should.equal(50153);
scriptManager.getCompiledScript().getContents().length.should.equal(50125);
scriptManager.getCompiledModule().length.should.equal(50125);
scriptManager.allFunctionDeclarations().length.should.equal(150);
});

@@ -70,8 +70,8 @@ describe('ScriptManager', () => {
const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);
scriptManager.addScript(script1);
scriptManager.addScript(script2);
scriptManager.compileLogic().getContents().length.should.equal(50153);
scriptManager.getCompiledScript().getContents().length.should.equal(50153);
scriptManager.compileLogic().getContents().length.should.equal(50125);
scriptManager.getCompiledScript().getContents().length.should.equal(50125);
scriptManager.getAllScripts().length.should.equal(3);
});

@@ -176,8 +176,8 @@ describe('ScriptManager', () => {
const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);
scriptManager.addScript(script1);
scriptManager.addScript(script2);
scriptManager.compileLogic().getContents().length.should.equal(50153);
scriptManager.getCompiledModule().length.should.equal(50153);
scriptManager.compileLogic().getContents().length.should.equal(50125);
scriptManager.getCompiledModule().length.should.equal(50125);
scriptManager.clearScripts();
return (() => scriptManager.getCompiledModule()).should.throw('Did not find any compiled logic');
});
20 changes: 19 additions & 1 deletion packages/ergo-engine/lib/engine.js
Original file line number Diff line number Diff line change
@@ -134,7 +134,8 @@ class Engine {
};

// execute the logic
const result = await this.invokeCall(utcOffset,now,validOptions,context,module,contractName,clauseName);
const wrappedResult = await this.invokeCall(utcOffset,now,validOptions,context,module,contractName,clauseName);
const result = this.unwrapError(wrappedResult);
const validResponse = logic.validateOutput(result.__response); // ensure the response is valid
const validNewState = logic.validateOutput(result.__state); // ensure the new state is valid
const validEmit = logic.validateOutputArray(result.__emit); // ensure all the emits are valid
@@ -279,6 +280,23 @@ class Engine {
return await this.trigger(logic, contractId, contract, request, state, currentTime, options);
}

/**
* Handle success/failure
* @param {object} result - the result from invokation
* @return {object} the value if success or throws an error
*/
unwrapError(result) {
if (Object.prototype.hasOwnProperty.call(result,'$left')) {
return result.$left;
} else {
const failure = result.$right;
let message = 'Unknown Ergo Logic Error (Please file a GitHub issue)';
if (failure && failure.$data && failure.$data.message) {
message = failure.$data.message;
}
throw new Error('[Ergo] ' + message);
}
}
}

module.exports = Engine;
3 changes: 1 addition & 2 deletions packages/ergo-engine/lib/evalengine.js
Original file line number Diff line number Diff line change
@@ -86,8 +86,7 @@ class EvalEngine extends Engine {
let code;
if (contractName) {
code = `
const __result = ${contractName}.${clauseName}(Object.assign({}, {__now:now,__options:options,__contract:context.data,__state:context.state,__emit:{$coll:[],$length:0}},context.params));
unwrapError(__result);
${contractName}.${clauseName}(Object.assign({}, {__now:now,__options:options,__contract:context.data,__state:context.state,__emit:{$coll:[],$length:0}},context.params));
`;
} else {
throw new Error('Cannot invoke contract without a contract name');
3 changes: 1 addition & 2 deletions packages/ergo-engine/lib/vmengine.js
Original file line number Diff line number Diff line change
@@ -101,8 +101,7 @@ class VMEngine extends Engine {
let code;
if (contractName) {
code = `
const __result = ${contractName}.${clauseName}(Object.assign({__now:now,__options:options,__contract:context.data,__state:context.state,__emit:{$coll:[],$length:0}}, context.params));
unwrapError(__result);
${contractName}.${clauseName}(Object.assign({__now:now,__options:options,__contract:context.data,__state:context.state,__emit:{$coll:[],$length:0}}, context.params));
`;
} else {
throw new Error('Cannot invoke contract without a contract name');
4 changes: 1 addition & 3 deletions packages/ergo-engine/lib/wasmengine.js
Original file line number Diff line number Diff line change
@@ -62,12 +62,10 @@ function read(mod, ptr) {
* @return {*} a pointer to the result
*/
async function invoke(rt, m, fn_name, arg) {
// console.log('INVOKE ' + fn_name + '(' + JSON.stringify(arg) + ')');
let arg_ptr = write(rt, arg);
let res_ptr = m.exports[fn_name](arg_ptr);
let res = read(rt, res_ptr);
//console.log('RES ' + JSON.stringify(res,null,2));
return res.$left;
return res;
}

// XXX Hack! load runtime explicitely here
3 changes: 2 additions & 1 deletion packages/ergo-engine/test/engine.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
'use strict';

const Chai = require('chai');
const expect = Chai.expect;

Chai.should();
Chai.use(require('chai-things'));
@@ -25,7 +26,7 @@ const Engine = require('../lib/engine');
describe('#engine', () => {
it('should fail running when using a base Engine', async () => {
const engine = new Engine();
(() => engine.instantiate('const a = 1;')).should.throw('[instantiate] Cannot instantiate module: create engine for a specific platform');
await expect(engine.instantiate('const a = 1;')).to.be.rejectedWith('[instantiate] Cannot instantiate module: create engine for a specific platform');
return engine.invokeCall(2,{ a : 1 },'function f() { return context.a + utcOffset; }','f()').should.be.rejectedWith('[invokeCall] Cannot create invoke call for contract: create engine for a specific platform');
});
});
10 changes: 6 additions & 4 deletions packages/ergo-engine/test/evalengine.js
Original file line number Diff line number Diff line change
@@ -18,23 +18,25 @@ const runWorkload = require('./commonengine').runWorkload;
const EvalEngine = require('../lib/evalengine');
const LogicManager = require('@accordproject/ergo-compiler').LogicManager;

describe.only('#evalengine', () => {
describe('#evalengine', () => {
it('should behave as a proper Eval Engine', () => {
const engine = new EvalEngine();
engine.kind().should.equal('eval');
engine.instantiate('const a = 1;').should.not.be.null;
engine.invokeCall(2,null,null,{ a : 1 },'class C { static f() { return context.a + utcOffset; } }','C','f').should.equal(3);
});

it('should cache a script', () => {
it('should cache a script', async () => {
const engine = new EvalEngine();
const logicManager = new LogicManager('es6', null);
const script = 'const a = 1';
logicManager.addLogicFile(script,'test2.js');
logicManager.compileLogicSync(false);
const scriptManager = logicManager.getScriptManager();
engine.cacheModule(scriptManager,'test2.js').should.equal(script);
engine.cacheModule(scriptManager,'test2.js').should.equal(script);
let script1 = await engine.cacheModule(scriptManager,'test2.js');
script1.should.equal(script);
script1 = await engine.cacheModule(scriptManager,'test2.js');
script1.should.equal(script);
});
});

11 changes: 9 additions & 2 deletions packages/ergo-engine/test/vmengine.js
Original file line number Diff line number Diff line change
@@ -14,16 +14,23 @@

'use strict';

const Chai = require('chai');
const expect = Chai.expect;

Chai.should();
Chai.use(require('chai-things'));
Chai.use(require('chai-as-promised'));

const runWorkload = require('./commonengine').runWorkload;
const VMEngine = require('../lib/vmengine');
const LogicManager = require('@accordproject/ergo-compiler').LogicManager;

describe('#vmengine', () => {
it('should behave as a proper VM engine', () => {
it('should behave as a proper VM engine', async () => {
const engine = new VMEngine();
engine.kind().should.equal('vm2');
engine.instantiate('const a = 1;').should.not.be.null;
engine.invokeCall(2,null,null,{ a : 1 },'function f() { return context.a + utcOffset; }','f()').should.equal(3);
expect (await engine.invokeCall(2,null,null,{ a : 1 },'class C { static f() { return context.a + utcOffset; } }','C','f')).to.equal(3);
});

it('should cache a script', () => {
1 change: 0 additions & 1 deletion qcert

This file was deleted.

4 changes: 4 additions & 0 deletions tests/helloworldenforce/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$class": "org.accordproject.helloworld.TemplateModel",
"name": "Fred Blogs"
}
Loading