Files: c2c35a4216304056cc0acac26cf1f3791353f429 / tests / apiTests.js
1179 bytesRaw
1 | const tape = require('tape') |
2 | const Hypervisor = require('../hypervisor.js') |
3 | const Message = require('../message.js') |
4 | const Vertex = require('merkle-trie') |
5 | |
6 | tape('send and reciving messages', async t => { |
7 | try { |
8 | const hypervisor = new Hypervisor() |
9 | const path = ['one', 'two', 'three'] |
10 | hypervisor.set(path, { |
11 | run: message => { |
12 | t.pass('got message') |
13 | t.end() |
14 | return {} |
15 | } |
16 | }) |
17 | hypervisor.send(new Message({ |
18 | to: path |
19 | })) |
20 | } catch (e) { |
21 | console.log(e) |
22 | } |
23 | }) |
24 | |
25 | tape('reverts', async t => { |
26 | const hypervisor = new Hypervisor() |
27 | const path = ['one', 'two', 'three'] |
28 | const path2 = ['one', 'two', 'three', 'four'] |
29 | hypervisor.set(path, { |
30 | run: async (message, kernel) => { |
31 | await kernel.send(new Message({ |
32 | to: ['four'] |
33 | })) |
34 | throw new Error('vm exception') |
35 | } |
36 | }) |
37 | |
38 | hypervisor.set(path2, { |
39 | run: (message, kernel) => { |
40 | kernel.stateInterface.set('key', new Vertex({ |
41 | value: 'value' |
42 | })) |
43 | } |
44 | }) |
45 | |
46 | const message = new Message({ |
47 | to: path |
48 | }) |
49 | hypervisor.send(message) |
50 | const result = await message.result() |
51 | t.equals(result.exception, true) |
52 | t.end() |
53 | }) |
54 |
Built with git-ssb-web