git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit f4180d83c1c1401e1e4afc64aa897387ef4e8fdf

Merge branch 'creationContainer'

wanderer committed on 8/22/2017, 8:16:22 PM
Parent: 9757e55d0c365901b8de39045c84bc6556c69e83
Parent: d577a28a042f4ebf1025240c70acdecfbf7bac56

Files changed

index.jschanged
kernel.jschanged
portManager.jschanged
tests/index.jschanged
index.jsView
@@ -1,8 +1,7 @@
11 const Tree = require('merkle-radix-tree')
22 const Graph = require('ipld-graph-builder')
33 const chunk = require('chunk')
4-const Message = require('primea-message')
54 const Kernel = require('./kernel.js')
65 const Scheduler = require('./scheduler.js')
76 const DFSchecker = require('./dfsChecker.js')
87
@@ -24,8 +23,10 @@
2423 this._containerTypes = {}
2524 this._nodesToCheck = new Set()
2625
2726 this.ROOT_ID = 'zdpuAm6aTdLVMUuiZypxkwtA7sKm7BWERy8MPbaCrFsmiyzxr'
27+ this.CREATION_ID = 0
28+ this.ROUTING_ID = 1
2829 this.MAX_DATA_BYTES = 65533
2930 }
3031
3132 /**
@@ -124,18 +125,18 @@
124125 * @param {object} id.nonce
125126 * @param {object} id.parent
126127 * @returns {Promise}
127128 */
128- async createInstance (type, message = new Message(), id = {nonce: 0, parent: null}) {
129+ async createInstance (message, id = {nonce: 0, parent: null}) {
129130 const idHash = await this._getHashFromObj(id)
130131 const state = {
131132 nonce: [0],
132133 ports: {},
133- type: type
134+ type: message.data.type
134135 }
135136
136- if (message.data.length) {
137- state.code = message.data
137+ if (message.data.code && message.data.code.length) {
138+ state.code = message.data.code
138139 }
139140
140141 // create the container instance
141142 const instance = await this._loadInstance(idHash, state)
kernel.jsView
@@ -148,9 +148,9 @@
148148 * @param {String} type
149149 * @param {*} data - the data to populate the initail state with
150150 * @returns {Object}
151151 */
152- createInstance (type, message) {
152+ createInstance (message) {
153153 let nonce = this.state.nonce
154154
155155 const id = {
156156 nonce: nonce,
@@ -160,14 +160,11 @@
160160 // incerment the nonce
161161 nonce = new BN(nonce)
162162 nonce.iaddn(1)
163163 this.state.nonce = nonce.toArray()
164+ this.ports.removeSentPorts(message)
164165
165- if (message) {
166- this.ports.removeSentPorts(message)
167- }
168-
169- return this.hypervisor.createInstance(type, message, id)
166+ return this.hypervisor.createInstance(message, id)
170167 }
171168
172169 /**
173170 * sends a message to a given port
@@ -178,10 +175,18 @@
178175 message._hops++
179176 message._fromTicks = this.ticks
180177 this.ports.removeSentPorts(message)
181178
179+ const copyPort = this.hypervisor.copyNativePort(port, message)
180+ if (copyPort) {
181+ this.queue(port.destName, new Message({ports: [copyPort]}))
182+ } else if (port.destId === this.hypervisor.CREATION_ID) {
183+ return this.createInstance(message)
184+ } else {
185+ return this.hypervisor.send(port, message)
186+ }
187+
182188 // if (this.currentMessage !== message && !message.responsePort) {
183189 // this.currentMessage._addSubMessage(message)
184190 // }
185- return this.hypervisor.send(port, message)
186191 }
187192 }
portManager.jsView
@@ -85,11 +85,13 @@
8585 this.hypervisor.addNodeToCheck(this.id)
8686
8787 // update the destination port
8888 const destPort = await this.hypervisor.getDestPort(port)
89- delete destPort.destName
90- delete destPort.destId
91- destPort.destPort = port
89+ if (destPort) {
90+ delete destPort.destName
91+ delete destPort.destId
92+ destPort.destPort = port
93+ }
9294 return port
9395 }
9496
9597 /**
@@ -97,9 +99,11 @@
9799 * @param {string} name
98100 */
99101 async delete (name) {
100102 const port = this.ports[name]
101- await this.kernel.send(port, new DeleteMessage())
103+ if (port.destID !== this.hypervisor.CREATION_ID) {
104+ await this.kernel.send(port, new DeleteMessage())
105+ }
102106 this._delete(name)
103107 }
104108
105109 _delete (name) {
tests/index.jsView
@@ -10,9 +10,8 @@
1010 })
1111
1212 class BaseContainer extends AbstractContainer {
1313 onCreation (message) {
14- this.kernel.state.code = message.data.byteLength ? message.data : undefined
1514 const port = message.ports[0]
1615 if (port) {
1716 return this.kernel.ports.bind('root', port)
1817 }
@@ -26,9 +25,9 @@
2625 tape('basic', async t => {
2726 t.plan(3)
2827 let message
2928 const expectedState = {
30- '/': 'zdpuApGUFnjcY3eBeVPFfnEgGunPz8vyXVJbrkgBmYwrbVDpA'
29+ '/': 'zdpuAqbcQhgu2T2MBgHbYu1MtHXyZzNsCaQjTPTR6NN9s5hbk'
3130 }
3231
3332 class testVMContainer extends BaseContainer {
3433 onMessage (m) {
@@ -39,24 +38,33 @@
3938 try {
4039 const hypervisor = new Hypervisor(node.dag)
4140 hypervisor.registerContainer(testVMContainer)
4241
43- const rootContainer = await hypervisor.createInstance(testVMContainer.typeId)
42+ const rootContainer = await hypervisor.createInstance(new Message({
43+ data: {
44+ type: testVMContainer.typeId
45+ }
46+ }))
4447
4548 const [portRef1, portRef2] = rootContainer.ports.createChannel()
4649 const initMessage = rootContainer.createMessage({
47- data: Buffer.from('test code'),
50+ data: {
51+ code: Buffer.from('test code'),
52+ type: testVMContainer.typeId
53+ },
4854 ports: [portRef2]
4955 })
5056
51- await rootContainer.createInstance(testVMContainer.typeId, initMessage)
57+ await rootContainer.createInstance(initMessage)
5258
5359 await rootContainer.ports.bind('first', portRef1)
5460 message = rootContainer.createMessage()
55- rootContainer.send(portRef1, message)
61+ await rootContainer.send(portRef1, message)
5662
63+ // console.log(JSON.stringify(hypervisor.state, null, 2))
5764 const stateRoot = await hypervisor.createStateRoot(Infinity)
5865 t.deepEquals(stateRoot, expectedState, 'expected root!')
66+
5967 t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0)
6068 } catch (e) {
6169 console.log(e)
6270 }
@@ -75,13 +83,20 @@
7583 try {
7684 const hypervisor = new Hypervisor(node.dag)
7785 hypervisor.registerContainer(testVMContainer)
7886
79- const root = await hypervisor.createInstance(testVMContainer.typeId)
87+ const root = await hypervisor.createInstance(new Message({
88+ data: {
89+ type: testVMContainer.typeId
90+ }
91+ }))
8092 const [portRef1, portRef2] = root.ports.createChannel()
8193
8294 await root.ports.bind('one', portRef1)
83- await root.createInstance(testVMContainer.typeId, root.createMessage({
95+ await root.createInstance(root.createMessage({
96+ data: {
97+ type: testVMContainer.typeId
98+ },
8499 ports: [portRef2]
85100 }))
86101
87102 const stateRoot = await hypervisor.createStateRoot(Infinity)
@@ -97,9 +112,9 @@
97112 tape('one child contract', async t => {
98113 t.plan(4)
99114 let message
100115 const expectedState = {
101- '/': 'zdpuArCqpDZtEqjrXrRhMiYLE7QQ1szVr1qLVkiwtDLincGWU'
116+ '/': 'zdpuB2Huo3ro3Fv9mpMhnUcL3jjd37T6MJ6jEd8GvA2cpvaYR'
102117 }
103118 let hasResolved = false
104119
105120 class testVMContainer2 extends BaseContainer {
@@ -121,9 +136,12 @@
121136
122137 class testVMContainer extends BaseContainer {
123138 async onMessage (m) {
124139 const [portRef1, portRef2] = this.kernel.ports.createChannel()
125- await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({
140+ await this.kernel.createInstance(this.kernel.createMessage({
141+ data: {
142+ type: testVMContainer2.typeId
143+ },
126144 ports: [portRef2]
127145 }))
128146 await this.kernel.send(portRef1, m)
129147 this.kernel.incrementTicks(1)
@@ -134,12 +152,19 @@
134152 const hypervisor = new Hypervisor(node.dag)
135153 hypervisor.registerContainer(testVMContainer)
136154 hypervisor.registerContainer(testVMContainer2)
137155
138- let root = await hypervisor.createInstance(testVMContainer.typeId)
156+ let root = await hypervisor.createInstance(new Message({
157+ data: {
158+ type: testVMContainer.typeId
159+ }
160+ }))
139161 const rootId = root.id
140162 const [portRef1, portRef2] = root.ports.createChannel()
141- await root.createInstance(testVMContainer.typeId, root.createMessage({
163+ await root.createInstance(root.createMessage({
164+ data: {
165+ type: testVMContainer.typeId
166+ },
142167 ports: [portRef2]
143168 }))
144169
145170 await root.ports.bind('first', portRef1)
@@ -182,21 +207,30 @@
182207 this.kernel.ports.bind('three', portRef5)
183208 )
184209
185210 const message1 = this.kernel.createMessage({
211+ data: {
212+ type: Root.typeId
213+ },
186214 ports: [portRef2]
187215 })
188216 const message2 = this.kernel.createMessage({
217+ data: {
218+ type: Root.typeId
219+ },
189220 ports: [portRef4]
190221 })
191222 const message3 = this.kernel.createMessage({
223+ data: {
224+ type: Root.typeId
225+ },
192226 ports: [portRef6]
193227 })
194228
195229 await Promise.all([
196- this.kernel.createInstance(Root.typeId, message1),
197- this.kernel.createInstance(Root.typeId, message2),
198- this.kernel.createInstance(Root.typeId, message3)
230+ this.kernel.createInstance(message1),
231+ this.kernel.createInstance(message2),
232+ this.kernel.createInstance(message3)
199233 ])
200234
201235 throw new Error('it is a trap!!!')
202236 }
@@ -204,14 +238,18 @@
204238
205239 const hypervisor = new Hypervisor(node.dag)
206240
207241 hypervisor.registerContainer(Root)
208- const root = await hypervisor.createInstance(Root.typeId)
242+ const root = await hypervisor.createInstance(new Message({
243+ data: {
244+ type: Root.typeId
245+ }
246+ }))
209247 await root.message(root.createMessage())
210248 const stateRoot = await hypervisor.createStateRoot()
211249
212250 t.deepEquals(stateRoot, {
213- '/': 'zdpuAoifKuJkWz9Fjvt79NmGq3tcefhfCyq8iM8YhcFdV9bmZ'
251+ '/': 'zdpuAwAZnRgD7ZKH8ssU9UdpFTsw3Q4gecKKyRoDsD4obhpJm'
214252 }, 'should revert the state')
215253 })
216254
217255 tape('recieving older messages', async t => {
@@ -225,22 +263,28 @@
225263 const [portRef1, portRef2] = this.kernel.ports.createChannel()
226264 const [portRef3, portRef4] = this.kernel.ports.createChannel()
227265
228266 const message1 = this.kernel.createMessage({
267+ data: {
268+ type: First.typeId
269+ },
229270 ports: [portRef2]
230271 })
231272 const message2 = this.kernel.createMessage({
273+ data: {
274+ type: Waiter.typeId
275+ },
232276 ports: [portRef4]
233277 })
234278
235279 await Promise.all([
236- this.kernel.createInstance(First.typeId, message1),
280+ this.kernel.createInstance(message1),
237281 this.kernel.send(portRef1, this.kernel.createMessage()),
238282 this.kernel.send(portRef3, this.kernel.createMessage()),
239283 this.kernel.ports.bind('one', portRef1),
240284 this.kernel.ports.bind('two', portRef3)
241285 ])
242- return this.kernel.createInstance(Waiter.typeId, message2)
286+ return this.kernel.createInstance(message2)
243287 } else if (runs === 1) {
244288 runs++
245289 t.equals(m.data, 'first', 'should recive the first message')
246290 } else if (runs === 2) {
@@ -286,16 +330,23 @@
286330 hypervisor.registerContainer(Root)
287331 hypervisor.registerContainer(First)
288332 hypervisor.registerContainer(Waiter)
289333
290- const root = await hypervisor.createInstance(Root.typeId)
334+ const root = await hypervisor.createInstance(new Message({
335+ data: {
336+ type: Root.typeId
337+ }
338+ }))
291339 const [portRef1, portRef2] = root.ports.createChannel()
292340
293341 const message = root.createMessage()
294342 await Promise.all([
295343 root.send(portRef1, message),
296344 root.ports.bind('first', portRef1),
297- root.createInstance(Root.typeId, root.createMessage({
345+ root.createInstance(root.createMessage({
346+ data: {
347+ type: Root.typeId
348+ },
298349 ports: [portRef2]
299350 }))
300351 ])
301352 } catch (e) {
@@ -315,18 +366,24 @@
315366 const [portRef1, portRef2] = this.kernel.ports.createChannel()
316367 const [portRef3, portRef4] = this.kernel.ports.createChannel()
317368
318369 const message1 = this.kernel.createMessage({
370+ data: {
371+ type: First.typeId
372+ },
319373 ports: [portRef2]
320374 })
321375 const message2 = this.kernel.createMessage({
376+ data: {
377+ type: Second.typeId
378+ },
322379 ports: [portRef4]
323380 })
324381
325382 this.kernel.incrementTicks(6)
326383 return Promise.all([
327- this.kernel.createInstance(First.typeId, message1),
328- this.kernel.createInstance(Second.typeId, message2),
384+ this.kernel.createInstance(message1),
385+ this.kernel.createInstance(message2),
329386 this.kernel.send(portRef1, this.kernel.createMessage()),
330387 this.kernel.send(portRef3, this.kernel.createMessage()),
331388 this.kernel.ports.bind('one', portRef1),
332389 this.kernel.ports.bind('two', portRef3)
@@ -390,28 +447,40 @@
390447 hypervisor.registerContainer(First)
391448 hypervisor.registerContainer(Second)
392449 hypervisor.registerContainer(Waiter)
393450
394- let root = await hypervisor.createInstance(Root.typeId)
451+ let root = await hypervisor.createInstance(new Message({
452+ data: {
453+ type: Root.typeId
454+ }
455+ }))
395456 const [portRef1, portRef2] = root.ports.createChannel()
396457 const [portRef3, portRef4] = root.ports.createChannel()
397458
398459 const message = root.createMessage()
399460 await Promise.all([
400461 root.send(portRef1, message),
401462 root.ports.bind('first', portRef1),
402- root.createInstance(Root.typeId, root.createMessage({
463+ root.createInstance(root.createMessage({
464+ data: {
465+ type: Root.typeId
466+ },
403467 ports: [portRef2]
404468 })),
405469 root.ports.bind('sencond', portRef3),
406- root.createInstance(Waiter.typeId, root.createMessage({
470+ root.createInstance(root.createMessage({
471+ data: {
472+ type: Waiter.typeId
473+ },
407474 ports: [portRef4]
408475 }))
409476 ])
410477
411478 // root = await hypervisor.getInstance(root.id)
412479 root.incrementTicks(100)
413- await root.send(portRef1, root.createMessage({data: 'testss'}))
480+ await root.send(portRef1, root.createMessage({
481+ data: 'testss'
482+ }))
414483 root.shutdown()
415484 } catch (e) {
416485 console.log(e)
417486 }
@@ -428,11 +497,14 @@
428497 let one = this.kernel.ports.get('one')
429498 if (!one) {
430499 const [portRef1, portRef2] = this.kernel.ports.createChannel()
431500 const message1 = this.kernel.createMessage({
501+ data: {
502+ type: First.typeId
503+ },
432504 ports: [portRef2]
433505 })
434- await this.kernel.createInstance(First.typeId, message1)
506+ await this.kernel.createInstance(message1)
435507 return this.kernel.ports.bind('one', portRef1)
436508 } else {
437509 return Promise.all([
438510 this.kernel.send(one, this.kernel.createMessage()),
@@ -461,13 +533,20 @@
461533
462534 hypervisor.registerContainer(Root)
463535 hypervisor.registerContainer(First)
464536
465- const root = await hypervisor.createInstance(Root.typeId)
537+ const root = await hypervisor.createInstance(new Message({
538+ data: {
539+ type: Root.typeId
540+ }
541+ }))
466542 const [portRef1, portRef2] = root.ports.createChannel()
467543 await Promise.all([
468544 root.ports.bind('first', portRef1),
469- root.createInstance(Root.typeId, root.createMessage({
545+ root.createInstance(root.createMessage({
546+ data: {
547+ type: Root.typeId
548+ },
470549 ports: [portRef2]
471550 }))
472551 ])
473552
@@ -486,12 +565,19 @@
486565 t.plan(4)
487566 const hypervisor = new Hypervisor(node.dag)
488567 hypervisor.registerContainer(BaseContainer)
489568
490- const root = await hypervisor.createInstance(BaseContainer.typeId)
569+ const root = await hypervisor.createInstance(new Message({
570+ data: {
571+ type: BaseContainer.typeId
572+ }
573+ }))
491574
492575 const [portRef1, portRef2] = root.ports.createChannel()
493- root.createInstance(BaseContainer.typeId, root.createMessage({
576+ root.createInstance(root.createMessage({
577+ data: {
578+ type: BaseContainer.typeId
579+ },
494580 ports: [portRef2]
495581 }))
496582 await root.ports.bind('test', portRef1)
497583
@@ -524,18 +610,21 @@
524610 })
525611
526612 tape('port deletion', async t => {
527613 const expectedSr = {
528- '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md'
614+ '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
529615 }
530616 class Root extends BaseContainer {
531617 async onMessage (m) {
532618 const [portRef1, portRef2] = this.kernel.ports.createChannel()
533619 const message1 = this.kernel.createMessage({
620+ data: {
621+ type: First.typeId
622+ },
534623 ports: [portRef2]
535624 })
536625
537- await this.kernel.createInstance(First.typeId, message1)
626+ await this.kernel.createInstance(message1)
538627 await this.kernel.send(portRef1, this.kernel.createMessage())
539628 this.kernel.incrementTicks(6)
540629 return this.kernel.ports.bind('one', portRef1)
541630 }
@@ -555,12 +644,19 @@
555644
556645 hypervisor.registerContainer(Root)
557646 hypervisor.registerContainer(First)
558647
559- const root = await hypervisor.createInstance(Root.typeId)
648+ const root = await hypervisor.createInstance(new Message({
649+ data: {
650+ type: Root.typeId
651+ }
652+ }))
560653 const [portRef1, portRef2] = root.ports.createChannel()
561654 await root.ports.bind('first', portRef1)
562- await root.createInstance(Root.typeId, root.createMessage({
655+ await root.createInstance(root.createMessage({
656+ data: {
657+ type: Root.typeId
658+ },
563659 ports: [portRef2]
564660 }))
565661
566662 const message = root.createMessage()
@@ -574,23 +670,35 @@
574670 })
575671
576672 tape('clear unbounded ports', async t => {
577673 const expectedSr = {
578- '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md'
674+ '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
579675 }
676+
580677 class Root extends BaseContainer {
581678 onMessage (m) {
582- return this.kernel.createInstance(Root.typeId)
679+ return this.kernel.createInstance(new Message({
680+ data: {
681+ type: Root.typeId
682+ }
683+ }))
583684 }
584685 }
585686
586687 const hypervisor = new Hypervisor(node.dag)
587688 hypervisor.registerContainer(Root)
588689
589- const root = await hypervisor.createInstance(Root.typeId)
690+ const root = await hypervisor.createInstance(new Message({
691+ data: {
692+ type: Root.typeId
693+ }
694+ }))
590695 const [portRef1, portRef2] = root.ports.createChannel()
591696 await root.ports.bind('first', portRef1)
592- await root.createInstance(Root.typeId, root.createMessage({
697+ await root.createInstance(root.createMessage({
698+ data: {
699+ type: Root.typeId
700+ },
593701 ports: [portRef2]
594702 }))
595703
596704 const message = root.createMessage()
@@ -602,14 +710,17 @@
602710 })
603711
604712 tape('should remove subgraphs', async t => {
605713 const expectedSr = {
606- '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md'
714+ '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop'
607715 }
608716 class Root extends BaseContainer {
609717 onMessage (m) {
610718 const [, portRef2] = this.kernel.ports.createChannel()
611- return this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({
719+ return this.kernel.createInstance(this.kernel.createMessage({
720+ data: {
721+ type: Sub.typeId
722+ },
612723 ports: [portRef2]
613724 }))
614725 }
615726 }
@@ -618,9 +729,12 @@
618729 async onInitailize (message) {
619730 await this.kernel.ports.bind('root', message.ports[0])
620731 const [portRef1, portRef2] = this.kernel.ports.createChannel()
621732 await this.kernel.ports.bind('child', portRef1)
622- await this.kernel.createInstance(Root.typeId, this.kernel.createMessage({
733+ await this.kernel.createInstance(this.kernel.createMessage({
734+ data: {
735+ type: Root.typeId
736+ },
623737 ports: [portRef2]
624738 }))
625739 }
626740 static get typeId () {
@@ -633,12 +747,19 @@
633747
634748 hypervisor.registerContainer(Root)
635749 hypervisor.registerContainer(Sub)
636750
637- const root = await hypervisor.createInstance(Root.typeId)
751+ const root = await hypervisor.createInstance(new Message({
752+ data: {
753+ type: Root.typeId
754+ }
755+ }))
638756 const [portRef1, portRef2] = root.ports.createChannel()
639757 await root.ports.bind('first', portRef1)
640- await root.createInstance(Root.typeId, root.createMessage({
758+ await root.createInstance(root.createMessage({
759+ data: {
760+ type: Root.typeId
761+ },
641762 ports: [portRef2]
642763 }))
643764
644765 await root.send(portRef1, root.createMessage())
@@ -652,9 +773,9 @@
652773 })
653774
654775 tape('should not remove connected nodes', async t => {
655776 const expectedSr = {
656- '/': 'zdpuApKrsvsWknDML2Mme9FyZfRnVZ1hTCoKzkooYAWT3dUDV'
777+ '/': 'zdpuAr4A3i1t6B7BkLT9C7DoxwvFnNg74gEzyqhpFj7nqVBy6'
657778 }
658779 class Root extends BaseContainer {
659780 async onMessage (m) {
660781 if (m.ports.length) {
@@ -662,15 +783,21 @@
662783 await this.kernel.send(port, m)
663784 return this.kernel.ports.unbind('test1')
664785 } else {
665786 const [portRef1, portRef2] = this.kernel.ports.createChannel()
666- await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({
787+ await this.kernel.createInstance(this.kernel.createMessage({
788+ data: {
789+ type: Sub.typeId
790+ },
667791 ports: [portRef2]
668792 }))
669793 await this.kernel.ports.bind('test1', portRef1)
670794
671795 const [portRef3, portRef4] = this.kernel.ports.createChannel()
672- await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({
796+ await this.kernel.createInstance(this.kernel.createMessage({
797+ data: {
798+ type: Sub.typeId
799+ },
673800 ports: [portRef4]
674801 }))
675802 await this.kernel.ports.bind('test2', portRef3)
676803 await this.kernel.send(portRef3, this.kernel.createMessage({
@@ -702,12 +829,19 @@
702829
703830 hypervisor.registerContainer(Root)
704831 hypervisor.registerContainer(Sub)
705832
706- const root = await hypervisor.createInstance(Root.typeId)
833+ const root = await hypervisor.createInstance(new Message({
834+ data: {
835+ type: Root.typeId
836+ }
837+ }))
707838 const [portRef1, portRef2] = root.ports.createChannel()
708839 await root.ports.bind('first', portRef1)
709- await root.createInstance(Root.typeId, root.createMessage({
840+ await root.createInstance(root.createMessage({
841+ data: {
842+ type: Root.typeId
843+ },
710844 ports: [portRef2]
711845 }))
712846
713847 await root.send(portRef1, root.createMessage())
@@ -719,9 +853,9 @@
719853 })
720854
721855 tape('should remove multiple subgraphs', async t => {
722856 const expectedSr = {
723- '/': 'zdpuArkZ5yNowNnU4qJ8vayAUncgibQP9goDP1CwFxdmPJF9D'
857+ '/': 'zdpuAzYGmZeZsi5Zer7LXCTm1AsmqpUMJAXZnEeFW2UVDZj2P'
724858 }
725859 class Root extends BaseContainer {
726860 onMessage (m) {
727861 if (m.ports.length) {
@@ -734,13 +868,19 @@
734868 } else {
735869 const [portRef1, portRef2] = this.kernel.ports.createChannel()
736870 const [portRef3, portRef4] = this.kernel.ports.createChannel()
737871 return Promise.all([
738- this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({
872+ this.kernel.createInstance(this.kernel.createMessage({
873+ data: {
874+ type: Sub.typeId
875+ },
739876 ports: [portRef2]
740877 })),
741878 this.kernel.ports.bind('test1', portRef1),
742- this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({
879+ this.kernel.createInstance(this.kernel.createMessage({
880+ data: {
881+ type: Sub.typeId
882+ },
743883 ports: [portRef4]
744884 })),
745885 this.kernel.ports.bind('test2', portRef3),
746886 this.kernel.send(portRef3, this.kernel.createMessage({
@@ -774,14 +914,21 @@
774914
775915 hypervisor.registerContainer(Root)
776916 hypervisor.registerContainer(Sub)
777917
778- const root = await hypervisor.createInstance(Root.typeId)
918+ const root = await hypervisor.createInstance(new Message({
919+ data: {
920+ type: Root.typeId
921+ }
922+ }))
779923
780924 const [portRef1, portRef2] = root.ports.createChannel()
781925 await Promise.all([
782926 root.ports.bind('first', portRef1),
783- root.createInstance(Root.typeId, root.createMessage({
927+ root.createInstance(root.createMessage({
928+ data: {
929+ type: Root.typeId
930+ },
784931 ports: [portRef2]
785932 })),
786933 root.send(portRef1, root.createMessage())
787934 ])
@@ -814,16 +961,23 @@
814961 const hypervisor = new Hypervisor(node.dag)
815962
816963 hypervisor.registerContainer(testVMContainer)
817964
818- const rootContainer = await hypervisor.createInstance(testVMContainer.typeId)
965+ const rootContainer = await hypervisor.createInstance(new Message({
966+ data: {
967+ type: testVMContainer.typeId
968+ }
969+ }))
819970
820971 const [portRef1, portRef2] = rootContainer.ports.createChannel()
821972 const initMessage = rootContainer.createMessage({
973+ data: {
974+ type: testVMContainer.typeId
975+ },
822976 ports: [portRef2]
823977 })
824978
825- rootContainer.createInstance(testVMContainer.typeId, initMessage)
979+ rootContainer.createInstance(initMessage)
826980
827981 await rootContainer.ports.bind('first', portRef1)
828982 const message = rootContainer.createMessage()
829983 const rPort = rootContainer.getResponsePort(message)
@@ -845,9 +999,13 @@
845999 }
8461000
8471001 const hypervisor = new Hypervisor(node.dag)
8481002 hypervisor.registerContainer(testVMContainer)
849- await hypervisor.createInstance(testVMContainer.typeId)
1003+ await hypervisor.createInstance(new Message({
1004+ data: {
1005+ type: testVMContainer.typeId
1006+ }
1007+ }))
8501008 hypervisor.getInstance(hypervisor.ROOT_ID)
8511009 })
8521010
8531011 tape('large code size', async t => {
@@ -858,9 +1016,14 @@
8581016 }
8591017
8601018 const hypervisor = new Hypervisor(node.dag)
8611019 hypervisor.registerContainer(testVMContainer)
862- await hypervisor.createInstance(testVMContainer.typeId, new Message({data: content}))
1020+ await hypervisor.createInstance(new Message({
1021+ data: {
1022+ type: testVMContainer.typeId,
1023+ code: content
1024+ }
1025+ }))
8631026 const instance = await hypervisor.getInstance(hypervisor.ROOT_ID)
8641027 t.equals(content.length, instance.code.length)
8651028 })
8661029 })

Built with git-ssb-web