tests/index.jsView |
---|
1 | 1 | const tape = require('tape') |
2 | 2 | const fs = require('fs') |
3 | 3 | const Hypervisor = require('primea-hypervisor') |
| 4 | +const Message = require('primea-message') |
4 | 5 | const WasmContainer = require('../index.js') |
5 | 6 | const testInterface = require('./testInterface.js') |
6 | 7 | const IPFS = require('ipfs') |
7 | 8 | const ReferanceMap = require('../referanceMap.js') |
66 | 67 | const main = fs.readFileSync(`${__dirname}/wasm/main.wasm`) |
67 | 68 | hypervisor.registerContainer('wasm', WasmContainer, { |
68 | 69 | test: testInterface(t) |
69 | 70 | }) |
70 | | - const instance = await hypervisor.createInstance('wasm', main) |
| 71 | + const instance = await hypervisor.createInstance('wasm', new Message({ |
| 72 | + data: main |
| 73 | + })) |
71 | 74 | instance.run(instance.createMessage()) |
72 | 75 | }) |
73 | 76 | |
74 | 77 | tape('wasm container - mem', async t => { |
78 | 81 | hypervisor.registerContainer('wasm', WasmContainer, { |
79 | 82 | env: ContainerTestInterface, |
80 | 83 | test: testInterface(t) |
81 | 84 | }) |
82 | | - await hypervisor.createInstance('wasm', readMem) |
| 85 | + await hypervisor.createInstance('wasm', new Message({ |
| 86 | + data: readMem |
| 87 | + })) |
83 | 88 | }) |
84 | 89 | |
85 | 90 | tape('wasm container - callbacks', async t => { |
86 | 91 | t.plan(1) |
89 | 94 | hypervisor.registerContainer('wasm', WasmContainer, { |
90 | 95 | env: ContainerTestInterface, |
91 | 96 | test: testInterface(t) |
92 | 97 | }) |
93 | | - hypervisor.createInstance('wasm', callBackWasm) |
| 98 | + hypervisor.createInstance('wasm', new Message({ |
| 99 | + data: callBackWasm |
| 100 | + })) |
94 | 101 | }) |
95 | 102 | |
96 | | - tape.only('wasm container - invalid', async t => { |
| 103 | + tape('wasm container - invalid', async t => { |
97 | 104 | t.plan(1) |
98 | 105 | const hypervisor = new Hypervisor(node.dag) |
99 | 106 | hypervisor.registerContainer('wasm', WasmContainer, { |
100 | 107 | env: ContainerTestInterface, |
101 | 108 | test: testInterface(t) |
102 | 109 | }) |
103 | 110 | |
104 | | - await hypervisor.createInstance('wasm', Buffer.from([0x00])) |
| 111 | + const message = new Message({ |
| 112 | + data: Buffer.from([0x00]) |
| 113 | + }) |
| 114 | + |
| 115 | + const rp = message.responsePort = {destPort: {messages: []}} |
| 116 | + |
| 117 | + await hypervisor.createInstance('wasm', message) |
| 118 | + t.equals(rp.destPort.messages[0].data.exception, true) |
105 | 119 | }) |
106 | 120 | }) |