git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 0b60f6ffa1bef52d1491a87e1d7aa604092d0af2

added test for caps manager

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 11/16/2017, 9:48:01 PM
Parent: ce9d7d51405b9e45388197443ff818f21fafee7a

Files changed

actor.jschanged
index.jschanged
tests/index.jschanged
actor.jsView
@@ -121,8 +121,13 @@
121121 this.ticks += count
122122 this.hypervisor.scheduler.update(this)
123123 }
124124
125+ createInstance (type, message) {
126+ const id = this.generateNextId()
127+ return this.hypervisor.createInstance(type, message, id)
128+ }
129+
125130 generateNextId () {
126131 const id = {
127132 nonce: this.state.nonce,
128133 parent: this.id
index.jsView
@@ -98,9 +98,8 @@
9898 * @returns {Promise}
9999 */
100100 async createStateRoot (ticks) {
101101 await this.scheduler.wait(ticks)
102- // console.log(JSON.stringify(this.tree.root, null, 2))
103102 return this.tree.flush()
104103 }
105104
106105 /**
tests/index.jsView
@@ -1,8 +1,9 @@
11 const tape = require('tape')
22 const AbstractContainer = require('primea-abstract-container')
33 const Message = require('primea-message')
44 const Hypervisor = require('../')
5+const CapsManager = require('../capsManager.js')
56
67 const level = require('level')
78 const RadixTree = require('dfinity-radix-tree')
89 const db = level('./testdb')
@@ -44,8 +45,20 @@
4445
4546 t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0)
4647 })
4748
49+tape('caps manager', async t => {
50+ const capsManager = new CapsManager({})
51+ const cap = {}
52+ capsManager.store('test', cap)
53+ const c = capsManager.get('test')
54+ t.equals(cap, c)
55+ capsManager.delete('test')
56+ const empty = capsManager.get('test')
57+ t.equals(empty, undefined)
58+ t.end()
59+})
60+
4861 tape('two communicating actors', async t => {
4962 t.plan(3)
5063 let message
5164 const expectedState = {
@@ -284,4 +297,54 @@
284297
285298 t.deepEquals(stateRoot, expectedState, 'expected root!')
286299 t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0)
287300 })
301+
302+tape('actor creation', async t => {
303+ t.plan(3)
304+ let message
305+ const expectedState = {
306+ '/': Buffer.from('8e809b10d473ef4592dc5c1683e89bc7001e5e3e', 'hex')
307+ }
308+
309+ const tree = new RadixTree({
310+ db: db
311+ })
312+
313+ class testVMContainerA extends BaseContainer {
314+ onCreation (m) {
315+ message = new Message()
316+ const cap = this.kernel.mintCap()
317+ message.caps.push(cap)
318+ return this.kernel.createInstance(testVMContainerB.typeId, message)
319+ }
320+
321+ onMessage (m) {
322+ t.true(m, 'should recive a response message')
323+ }
324+ }
325+
326+ class testVMContainerB extends BaseContainer {
327+ onCreation (m) {
328+ const cap = m.caps[0]
329+ return this.kernel.send(cap, new Message())
330+ }
331+
332+ onMessage (m) {
333+ }
334+
335+ static get typeId () {
336+ return 8
337+ }
338+ }
339+
340+ const hypervisor = new Hypervisor(tree)
341+ hypervisor.registerContainer(testVMContainerA)
342+ hypervisor.registerContainer(testVMContainerB)
343+
344+ await hypervisor.createInstance(testVMContainerA.typeId, new Message())
345+
346+ const stateRoot = await hypervisor.createStateRoot(Infinity)
347+
348+ t.deepEquals(stateRoot, expectedState, 'expected root!')
349+ t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0)
350+})

Built with git-ssb-web