Commit f019f1d8c91c4a7427df520e819cf78f0fdd7a77
add creation test
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 3/31/2018, 3:01:54 AM
Parent: 3a404bebd50b72c99fee87e44047a1129695ff64
Files changed
index.js | changed |
tests/index.js | changed |
tests/wasm/i64.wasm | changed |
tests/wasm/creation.wasm | added |
tests/wast/i64.wast | changed |
tests/wast/creation.json | added |
tests/wast/creation.wast | added |
index.js | ||
---|---|---|
@@ -142,10 +142,11 @@ | ||
142 | 142 | } |
143 | 143 | }, |
144 | 144 | module: { |
145 | 145 | new: dataRef => { |
146 | - const mod = self.actor.createActor(dataRef) | |
147 | - return self.refs.add(mod, 'mod') | |
146 | + const bin = self.refs.get(dataRef, 'data') | |
147 | + const {module} = self.actor.createActor(WasmContainer.typeId, bin) | |
148 | + return self.refs.add(module, 'mod') | |
148 | 149 | }, |
149 | 150 | export: (modRef, dataRef) => { |
150 | 151 | const mod = self.refs.get(modRef, 'mod') |
151 | 152 | let name = self.refs.get(dataRef, 'data') |
tests/index.js | ||
---|---|---|
@@ -4,13 +4,12 @@ | ||
4 | 4 | const {Message} = require('primea-objects') |
5 | 5 | const Hypervisor = require('primea-hypervisor') |
6 | 6 | const WasmContainer = require('../') |
7 | 7 | |
8 | -const annotations = require('primea-annotations') | |
9 | 8 | const level = require('level-browserify') |
10 | 9 | const RadixTree = require('dfinity-radix-tree') |
11 | -const db = level('./testdb') | |
12 | 10 | |
11 | +const db = level(__dirname + '/testdb') | |
13 | 12 | const WASM_PATH = path.join(__dirname, 'wasm') |
14 | 13 | |
15 | 14 | let tester |
16 | 15 | |
@@ -299,4 +298,27 @@ | ||
299 | 298 | }) |
300 | 299 | hypervisor.send(message) |
301 | 300 | }) |
302 | 301 | }) |
302 | + | |
303 | +tape('creation', async t => { | |
304 | + t.plan(1) | |
305 | + tester = t | |
306 | + const tree = new RadixTree({db}) | |
307 | + let wasm = fs.readFileSync(WASM_PATH + '/creation.wasm') | |
308 | + let receiver = fs.readFileSync(WASM_PATH + '/reciever.wasm') | |
309 | + | |
310 | + const hypervisor = new Hypervisor(tree) | |
311 | + hypervisor.registerContainer(TestWasmContainer) | |
312 | + | |
313 | + const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) | |
314 | + const funcRef = module.getFuncRef('main') | |
315 | + funcRef.gas = 322000 | |
316 | + | |
317 | + const message = new Message({ | |
318 | + funcRef, | |
319 | + funcArguments: [receiver] | |
320 | + }).on('execution:error', e => { | |
321 | + console.log(e) | |
322 | + }) | |
323 | + hypervisor.send(message) | |
324 | +}) |
tests/wasm/i64.wasm | ||
---|---|---|
@@ -1,2 +1,2 @@ | ||
1 | - asm types`~m typeMap ` ` ` `` `~ vfuncinternalize testcheck testprint moduleself moduleexport memoryexternalize memoryinternalize p $memory table main callback | |
1 | + asm types`~m typeMap ` ` ` `` `~ afuncinternalize testcheck testprint moduleself moduleexport memoryexternalize p $memory table main callback | |
2 | 2 | -A A A" |