git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: d9ae973728a3a94e651aa65697ce88b319c67c44

Files: d9ae973728a3a94e651aa65697ce88b319c67c44 / tests / apiTests.js

1179 bytesRaw
1const tape = require('tape')
2const Hypervisor = require('../hypervisor.js')
3const Message = require('../message.js')
4const Vertex = require('merkle-trie')
5
6tape('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
25tape('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