git ssb

0+

wanderer🌟 / js-primea-wasm-container



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.jschanged
tests/index.jschanged
tests/wasm/i64.wasmchanged
tests/wasm/creation.wasmadded
tests/wast/i64.wastchanged
tests/wast/creation.jsonadded
tests/wast/creation.wastadded
index.jsView
@@ -142,10 +142,11 @@
142142 }
143143 },
144144 module: {
145145 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')
148149 },
149150 export: (modRef, dataRef) => {
150151 const mod = self.refs.get(modRef, 'mod')
151152 let name = self.refs.get(dataRef, 'data')
tests/index.jsView
@@ -4,13 +4,12 @@
44 const {Message} = require('primea-objects')
55 const Hypervisor = require('primea-hypervisor')
66 const WasmContainer = require('../')
77
8-const annotations = require('primea-annotations')
98 const level = require('level-browserify')
109 const RadixTree = require('dfinity-radix-tree')
11-const db = level('./testdb')
1210
11+const db = level(__dirname + '/testdb')
1312 const WASM_PATH = path.join(__dirname, 'wasm')
1413
1514 let tester
1615
@@ -299,4 +298,27 @@
299298 })
300299 hypervisor.send(message)
301300 })
302301 })
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.wasmView
@@ -1,2 +1,2 @@
1-asm types`~m typeMap``````~vfunc internalizetestchecktestprintmoduleselfmoduleexportmemory externalizememory internalizep$memorytablemaincallback
1+asm types`~m typeMap``````~afunc internalizetestchecktestprintmoduleselfmoduleexportmemory externalizep$memorytablemaincallback
22 -AAA"B A A �  A callback
tests/wasm/creation.wasmView
@@ -1,0 +1,2 @@
1+asm types`m typeMap````Fmoduleexportmodulenewmemory externalizefunc internalizepmemorytablemain
2+A AAAA A receive
tests/wast/i64.wastView
@@ -4,9 +4,8 @@
44 (import "test" "print" (func $print (param i32)))
55 (import "module" "self" (func $self (result i32)))
66 (import "module" "export" (func $exports (param i32 i32) (result i32)))
77 (import "memory" "externalize" (func $mem.externalize (param i32 i32) (result i32)))
8- (import "memory" "internalize" (func $mem.internalize (param i32 i32) (result i32)))
98 (memory (export "memory") 1)
109 (data (i32.const 0) "callback")
1110 (table (export "table") 1 1 anyfunc)
1211 (func $main
tests/wast/creation.jsonView
@@ -1,0 +1,12 @@
1+{
2+ "types": [{
3+ "form": "func",
4+ "params": [
5+ "data"
6+ ]
7+ }],
8+ "typeMap": [{
9+ "func": 0,
10+ "type": 0
11+ }]
12+}
tests/wast/creation.wastView
@@ -1,0 +1,20 @@
1+(module
2+ (import "module" "export" (func $mod.exports (param i32 i32) (result i32)))
3+ (import "module" "new" (func $mod.new (param i32) (result i32)))
4+ (import "memory" "externalize" (func $mem.externalize (param i32 i32) (result i32)))
5+ (import "func" "internalize" (func $func.internalize (param i32 i32)))
6+ (memory (export "memory") 1)
7+ (data (i32.const 0) "receive")
8+ (table (export "table") 1 1 anyfunc)
9+ (func $main (param $bin i32)
10+ (call $func.internalize
11+ (i32.const 0)
12+ (call $mod.exports
13+ (call $mod.new (get_local $bin))
14+ (call $mem.externalize (i32.const 0) (i32.const 7))))
15+
16+ (call_indirect (param i32)
17+ (i32.const 5)
18+ (i32.const 0)))
19+
20+ (export "main" (func $main)))

Built with git-ssb-web