git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 98afd2ab38292eecc1f7dcb1974fc926ceb7c467

added container-types

wanderer committed on 7/29/2017, 8:35:52 PM
Parent: a89630664241ba4c2fe3f270825798f86985e94d

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -15,9 +15,9 @@
1515 constructor (dag, state = {}) {
1616 this.graph = new Graph(dag)
1717 this.scheduler = new Scheduler()
1818 this.state = state
19- this._containerTypes = {}
19 + this._containerTypes = []
2020 this._nodesToCheck = new Set()
2121
2222 this.ROOT_ID = 'zdpuAm6aTdLVMUuiZypxkwtA7sKm7BWERy8MPbaCrFsmiyzxr'
2323 this.MAX_DATA_BYTES = 65533
@@ -168,15 +168,13 @@
168168 }
169169
170170 /**
171171 * regirsters a container with the hypervisor
172- * @param {String} type - the name of the type
173172 * @param {Class} Constructor - a Class for instantiating the container
174173 * @param {*} args - any args that the contructor takes
175174 */
176- registerContainer (type, Constructor, args) {
177- Constructor.type = type
178- this._containerTypes[type] = {
175 + registerContainer (Constructor, args) {
176 + this._containerTypes[Constructor.type] = {
179177 Constructor: Constructor,
180178 args: args
181179 }
182180 }
tests/index.jsView
@@ -16,16 +16,19 @@
1616 if (port) {
1717 this.kernel.ports.bind('root', port)
1818 }
1919 }
20 + static get type () {
21 + return 9
22 + }
2023 }
2124
2225 node.on('ready', () => {
2326 tape('basic', async t => {
2427 t.plan(3)
2528 let message
2629 const expectedState = {
27- '/': 'zdpuB1wc9Pb6jUzfNt4nAxAEUxB7kNhg4vbq7YLcEyBUb6iAB'
30 + '/': 'zdpuAmN9VSrvNbArWkAEhEYaKhhCT3rk8xMhUam6eUfQmr6aZ'
2831 }
2932
3033 class testVMContainer extends BaseContainer {
3134 onMessage (m) {
@@ -33,19 +36,19 @@
3336 }
3437 }
3538
3639 const hypervisor = new Hypervisor(node.dag)
37- hypervisor.registerContainer('test', testVMContainer)
40 + hypervisor.registerContainer(testVMContainer)
3841
39- const rootContainer = await hypervisor.createInstance('test')
42 + const rootContainer = await hypervisor.createInstance(testVMContainer.type)
4043
4144 const [portRef1, portRef2] = rootContainer.ports.createChannel()
4245 const initMessage = rootContainer.createMessage({
4346 data: Buffer.from('test code'),
4447 ports: [portRef2]
4548 })
4649
47- rootContainer.createInstance('test', initMessage)
50 + rootContainer.createInstance(testVMContainer.type, initMessage)
4851
4952 rootContainer.ports.bind('first', portRef1)
5053 message = rootContainer.createMessage()
5154 rootContainer.send(portRef1, message)
@@ -57,23 +60,23 @@
5760
5861 tape('basic - do not store containers with no ports bound', async t => {
5962 t.plan(1)
6063 const expectedState = {
61- '/': 'zdpuAozDi6tKPbqmHJxo7aNES2xVt1MkaCLyxcioEKzz3M2WH'
64 + '/': 'zdpuAxGvPHM4DRbq7GeyGjwuPA8NT7DZLszcDDX9R5iwHWnTo'
6265 }
6366
6467 class testVMContainer extends BaseContainer {
6568 onCreation () {}
6669 }
6770
6871 const hypervisor = new Hypervisor(node.dag)
69- hypervisor.registerContainer('test', testVMContainer)
72 + hypervisor.registerContainer(testVMContainer)
7073
71- const root = await hypervisor.createInstance('test')
74 + const root = await hypervisor.createInstance(testVMContainer.type)
7275 const [portRef1, portRef2] = root.ports.createChannel()
7376
7477 root.ports.bind('one', portRef1)
75- root.createInstance('test', root.createMessage({
78 + root.createInstance(testVMContainer.type, root.createMessage({
7679 ports: [portRef2]
7780 }))
7881
7982 const stateRoot = await hypervisor.createStateRoot(Infinity)
@@ -83,21 +86,24 @@
8386 tape('one child contract with saturated ports', async t => {
8487 t.plan(2)
8588 let message
8689 const expectedState = {
87- '/': 'zdpuAtVcH6MUnvt2RXnLsDXyLB3CBSQ7aydfh2ogSKGCejJCQ'
90 + '/': 'zdpuAvWT2E1Hg6cvFNLTDbmjGRLSDbMnRtrA6s17oSdBX5EWs'
8891 }
8992
9093 class testVMContainer2 extends BaseContainer {
9194 onMessage (m) {
9295 t.true(m === message, 'should recive a message')
9396 }
97 + static get type () {
98 + return 99
99 + }
94100 }
95101
96102 class testVMContainer extends BaseContainer {
97103 onMessage (m) {
98104 const [portRef1, portRef2] = this.kernel.ports.createChannel()
99- this.kernel.createInstance('test2', this.kernel.createMessage({
105 + this.kernel.createInstance(testVMContainer2.type, this.kernel.createMessage({
100106 ports: [portRef2]
101107 }))
102108 this.kernel.ports.bind('child', portRef1)
103109 this.kernel.incrementTicks(2)
@@ -105,14 +111,14 @@
105111 }
106112 }
107113
108114 const hypervisor = new Hypervisor(node.dag)
109- hypervisor.registerContainer('test', testVMContainer)
110- hypervisor.registerContainer('test2', testVMContainer2)
115 + hypervisor.registerContainer(testVMContainer)
116 + hypervisor.registerContainer(testVMContainer2)
111117
112- const root = await hypervisor.createInstance('test')
118 + const root = await hypervisor.createInstance(testVMContainer.type)
113119 const [portRef1, portRef2] = root.ports.createChannel()
114- root.createInstance('test', root.createMessage({
120 + root.createInstance(testVMContainer.type, root.createMessage({
115121 ports: [portRef2]
116122 }))
117123
118124 root.ports.bind('first', portRef1)
@@ -128,9 +134,9 @@
128134 tape('one child contract', async t => {
129135 t.plan(4)
130136 let message
131137 const expectedState = {
132- '/': 'zdpuAtVcH6MUnvt2RXnLsDXyLB3CBSQ7aydfh2ogSKGCejJCQ'
138 + '/': 'zdpuAvWT2E1Hg6cvFNLTDbmjGRLSDbMnRtrA6s17oSdBX5EWs'
133139 }
134140 let hasResolved = false
135141
136142 class testVMContainer2 extends BaseContainer {
@@ -143,14 +149,18 @@
143149 resolve()
144150 }, 200)
145151 })
146152 }
153 +
154 + static get type () {
155 + return 99
156 + }
147157 }
148158
149159 class testVMContainer extends BaseContainer {
150160 onMessage (m) {
151161 const [portRef1, portRef2] = this.kernel.ports.createChannel()
152- this.kernel.createInstance('test2', this.kernel.createMessage({
162 + this.kernel.createInstance(testVMContainer2.type, this.kernel.createMessage({
153163 ports: [portRef2]
154164 }))
155165 this.kernel.ports.bind('child', portRef1)
156166 this.kernel.send(portRef1, m)
@@ -158,15 +168,15 @@
158168 }
159169 }
160170
161171 const hypervisor = new Hypervisor(node.dag)
162- hypervisor.registerContainer('test', testVMContainer)
163- hypervisor.registerContainer('test2', testVMContainer2)
172 + hypervisor.registerContainer(testVMContainer)
173 + hypervisor.registerContainer(testVMContainer2)
164174
165- let root = await hypervisor.createInstance('test')
175 + let root = await hypervisor.createInstance(testVMContainer.type)
166176 const rootId = root.id
167177 const [portRef1, portRef2] = root.ports.createChannel()
168- root.createInstance('test', root.createMessage({
178 + root.createInstance(testVMContainer.type, root.createMessage({
169179 ports: [portRef2]
170180 }))
171181
172182 root.ports.bind('first', portRef1)
@@ -185,9 +195,9 @@
185195 this.kernel.incrementTicks(1)
186196 }
187197 }
188198
189- hypervisor.registerContainer('test', testVMContainer3)
199 + hypervisor.registerContainer(testVMContainer3)
190200 root = await hypervisor.getInstance(rootId)
191201 const port = root.ports.get('first')
192202 root.send(port, message)
193203 })
@@ -213,25 +223,25 @@
213223 const message3 = this.kernel.createMessage({
214224 ports: [portRef6]
215225 })
216226
217- this.kernel.createInstance('root', message1)
218- this.kernel.createInstance('root', message2)
219- this.kernel.createInstance('root', message3)
227 + this.kernel.createInstance(Root.type, message1)
228 + this.kernel.createInstance(Root.type, message2)
229 + this.kernel.createInstance(Root.type, message3)
220230
221231 throw new Error('it is a trap!!!')
222232 }
223233 }
224234
225235 const hypervisor = new Hypervisor(node.dag)
226236
227- hypervisor.registerContainer('root', Root)
228- const root = await hypervisor.createInstance('root')
237 + hypervisor.registerContainer(Root)
238 + const root = await hypervisor.createInstance(Root.type)
229239 await root.message(root.createMessage())
230240 const stateRoot = await hypervisor.createStateRoot()
231241
232242 t.deepEquals(stateRoot, {
233- '/': 'zdpuAwrMmQXqFusve7zcRYxVUuji4NVzZR5GyjwyStsjteCoW'
243 + '/': 'zdpuAwxK8kAM3SkxSyALurpFHTobp6sFJef9gZJ8ZDQRww1LN'
234244 }, 'should revert the state')
235245 })
236246
237247 tape('message should arrive in the correct oder if sent in order', async t => {
@@ -255,10 +265,10 @@
255265 const message2 = this.kernel.createMessage({
256266 ports: [portRef4]
257267 })
258268
259- this.kernel.createInstance('first', message1)
260- this.kernel.createInstance('second', message2)
269 + this.kernel.createInstance(First.type, message1)
270 + this.kernel.createInstance(Second.type, message2)
261271
262272 this.kernel.send(portRef1, this.kernel.createMessage())
263273 this.kernel.send(portRef3, this.kernel.createMessage())
264274 } else if (runs === 1) {
@@ -276,8 +286,12 @@
276286 this.kernel.send(m.fromPort, this.kernel.createMessage({
277287 data: 'first'
278288 }))
279289 }
290 +
291 + static get type () {
292 + return 99
293 + }
280294 }
281295
282296 class Second extends BaseContainer {
283297 onMessage (m) {
@@ -285,20 +299,24 @@
285299 this.kernel.send(m.fromPort, this.kernel.createMessage({
286300 data: 'second'
287301 }))
288302 }
303 +
304 + static get type () {
305 + return 299
306 + }
289307 }
290308
291309 const hypervisor = new Hypervisor(node.dag)
292310
293- hypervisor.registerContainer('root', Root)
294- hypervisor.registerContainer('first', First)
295- hypervisor.registerContainer('second', Second)
311 + hypervisor.registerContainer(Root)
312 + hypervisor.registerContainer(First)
313 + hypervisor.registerContainer(Second)
296314
297- const root = await hypervisor.createInstance('root')
315 + const root = await hypervisor.createInstance(Root.type)
298316
299317 const [portRef1, portRef2] = root.ports.createChannel()
300- root.createInstance('root', root.createMessage({
318 + root.createInstance(Root.type, root.createMessage({
301319 ports: [portRef2]
302320 }))
303321
304322 root.ports.bind('first', portRef1)
@@ -327,10 +345,10 @@
327345 const message2 = this.kernel.createMessage({
328346 ports: [portRef4]
329347 })
330348
331- this.kernel.createInstance('first', message1)
332- this.kernel.createInstance('second', message2)
349 + this.kernel.createInstance(First.type, message1)
350 + this.kernel.createInstance(Second.type, message2)
333351
334352 this.kernel.send(portRef1, this.kernel.createMessage())
335353 this.kernel.send(portRef3, this.kernel.createMessage())
336354 } else if (runs === 1) {
@@ -339,8 +357,12 @@
339357 } else if (runs === 2) {
340358 t.equals(m.data, 'first', 'should recive the first message')
341359 }
342360 }
361 +
362 + static get type () {
363 + return 99
364 + }
343365 }
344366
345367 class First extends BaseContainer {
346368 onMessage (m) {
@@ -348,8 +370,12 @@
348370 this.kernel.send(m.fromPort, this.kernel.createMessage({
349371 data: 'first'
350372 }))
351373 }
374 +
375 + static get type () {
376 + return 299
377 + }
352378 }
353379
354380 class Second extends BaseContainer {
355381 onMessage (m) {
@@ -361,16 +387,16 @@
361387 }
362388
363389 const hypervisor = new Hypervisor(node.dag)
364390
365- hypervisor.registerContainer('root', Root)
366- hypervisor.registerContainer('first', First)
367- hypervisor.registerContainer('second', Second)
391 + hypervisor.registerContainer(Root)
392 + hypervisor.registerContainer(First)
393 + hypervisor.registerContainer(Second)
368394
369- const root = await hypervisor.createInstance('root')
395 + const root = await hypervisor.createInstance(Root.type)
370396
371397 const [portRef1, portRef2] = root.ports.createChannel()
372- root.createInstance('root', root.createMessage({
398 + root.createInstance(Root.type, root.createMessage({
373399 ports: [portRef2]
374400 }))
375401
376402 root.ports.bind('first', portRef1)
@@ -398,10 +424,10 @@
398424 const message2 = this.kernel.createMessage({
399425 ports: [portRef4]
400426 })
401427
402- this.kernel.createInstance('first', message1)
403- this.kernel.createInstance('second', message2)
428 + this.kernel.createInstance(First.type, message1)
429 + this.kernel.createInstance(Second.type, message2)
404430
405431 this.kernel.send(portRef1, this.kernel.createMessage())
406432 this.kernel.send(portRef3, this.kernel.createMessage())
407433
@@ -412,8 +438,11 @@
412438 } else if (runs === 2) {
413439 t.equals(m.data, 'second', 'should recived the second message')
414440 }
415441 }
442 + static get type () {
443 + return 299
444 + }
416445 }
417446
418447 class First extends BaseContainer {
419448 onMessage (m) {
@@ -421,8 +450,11 @@
421450 this.kernel.send(m.fromPort, this.kernel.createMessage({
422451 data: 'first'
423452 }))
424453 }
454 + static get type () {
455 + return 2
456 + }
425457 }
426458
427459 class Second extends BaseContainer {
428460 onMessage (m) {
@@ -434,15 +466,15 @@
434466 }
435467
436468 const hypervisor = new Hypervisor(node.dag)
437469
438- hypervisor.registerContainer('root', Root)
439- hypervisor.registerContainer('first', First)
440- hypervisor.registerContainer('second', Second)
470 + hypervisor.registerContainer(Root)
471 + hypervisor.registerContainer(First)
472 + hypervisor.registerContainer(Second)
441473
442- const root = await hypervisor.createInstance('root')
474 + const root = await hypervisor.createInstance(Root.type)
443475 const [portRef1, portRef2] = root.ports.createChannel()
444- root.createInstance('root', root.createMessage({
476 + root.createInstance(Root.type, root.createMessage({
445477 ports: [portRef2]
446478 }))
447479
448480 root.ports.bind('first', portRef1)
@@ -470,10 +502,10 @@
470502 const message2 = this.kernel.createMessage({
471503 ports: [portRef4]
472504 })
473505
474- this.kernel.createInstance('first', message1)
475- this.kernel.createInstance('second', message2)
506 + this.kernel.createInstance(First.type, message1)
507 + this.kernel.createInstance(Second.type, message2)
476508
477509 this.kernel.send(portRef1, this.kernel.createMessage())
478510 this.kernel.send(portRef3, this.kernel.createMessage())
479511
@@ -485,8 +517,11 @@
485517 runs++
486518 t.equals(m.data, 'second', 'should recived the second message')
487519 }
488520 }
521 + static get type () {
522 + return 299
523 + }
489524 }
490525
491526 class First extends BaseContainer {
492527 onMessage (m) {
@@ -494,8 +529,11 @@
494529 this.kernel.send(m.fromPort, this.kernel.createMessage({
495530 data: 'first'
496531 }))
497532 }
533 + static get type () {
534 + return 29
535 + }
498536 }
499537
500538 class Second extends BaseContainer {
501539 onMessage (m) {
@@ -503,8 +541,11 @@
503541 this.kernel.send(m.fromPort, this.kernel.createMessage({
504542 data: 'second'
505543 }))
506544 }
545 + static get type () {
546 + return 2
547 + }
507548 }
508549
509550 class Waiter extends BaseContainer {
510551 onCreation () {
@@ -517,26 +558,26 @@
517558 }
518559
519560 const hypervisor = new Hypervisor(node.dag)
520561
521- hypervisor.registerContainer('root', Root)
522- hypervisor.registerContainer('first', First)
523- hypervisor.registerContainer('second', Second)
524- hypervisor.registerContainer('waiter', Waiter)
562 + hypervisor.registerContainer(Root)
563 + hypervisor.registerContainer(First)
564 + hypervisor.registerContainer(Second)
565 + hypervisor.registerContainer(Waiter)
525566
526- const root = await hypervisor.createInstance('root')
567 + const root = await hypervisor.createInstance(Root.type)
527568 const [portRef1, portRef2] = root.ports.createChannel()
528569
529570 const message = root.createMessage()
530571 root.send(portRef1, message)
531572 root.ports.bind('first', portRef1)
532- root.createInstance('root', root.createMessage({
573 + root.createInstance(Root.type, root.createMessage({
533574 ports: [portRef2]
534575 }))
535576
536577 const [portRef3, portRef4] = root.ports.createChannel()
537578 root.ports.bind('sencond', portRef3)
538- root.createInstance('waiter', root.createMessage({
579 + root.createInstance(Waiter.type, root.createMessage({
539580 ports: [portRef4]
540581 }))
541582
542583 root.incrementTicks(100)
@@ -565,10 +606,10 @@
565606 const message2 = this.kernel.createMessage({
566607 ports: [portRef4]
567608 })
568609
569- this.kernel.createInstance('first', message1)
570- this.kernel.createInstance('second', message2)
610 + this.kernel.createInstance(First.type, message1)
611 + this.kernel.createInstance(Second.type, message2)
571612
572613 this.kernel.send(portRef1, this.kernel.createMessage())
573614 this.kernel.send(portRef3, this.kernel.createMessage())
574615
@@ -579,8 +620,11 @@
579620 } else if (runs === 2) {
580621 t.equals(m.data, 'first', 'should recive the first message')
581622 }
582623 }
624 + static get type () {
625 + return 299
626 + }
583627 }
584628
585629 class First extends BaseContainer {
586630 onMessage (m) {
@@ -588,8 +632,11 @@
588632 this.kernel.send(m.fromPort, this.kernel.createMessage({
589633 data: 'first'
590634 }))
591635 }
636 + static get type () {
637 + return 29
638 + }
592639 }
593640
594641 class Second extends BaseContainer {
595642 onMessage (m) {
@@ -597,23 +644,26 @@
597644 this.kernel.send(m.fromPort, this.kernel.createMessage({
598645 data: 'second'
599646 }))
600647 }
648 + static get type () {
649 + return 2
650 + }
601651 }
602652
603653 const hypervisor = new Hypervisor(node.dag)
604654
605- hypervisor.registerContainer('root', Root)
606- hypervisor.registerContainer('first', First)
607- hypervisor.registerContainer('second', Second)
655 + hypervisor.registerContainer(Root)
656 + hypervisor.registerContainer(First)
657 + hypervisor.registerContainer(Second)
608658
609- const root = await hypervisor.createInstance('root')
659 + const root = await hypervisor.createInstance(Root.type)
610660 const [portRef1, portRef2] = root.ports.createChannel()
611661 const message = root.createMessage()
612662
613663 root.send(portRef1, message)
614664 root.ports.bind('first', portRef1)
615- root.createInstance('root', root.createMessage({
665 + root.createInstance(Root.type, root.createMessage({
616666 ports: [portRef2]
617667 }))
618668 })
619669
@@ -638,10 +688,10 @@
638688 const message2 = this.kernel.createMessage({
639689 ports: [portRef4]
640690 })
641691
642- this.kernel.createInstance('first', message1)
643- this.kernel.createInstance('second', message2)
692 + this.kernel.createInstance(First.type, message1)
693 + this.kernel.createInstance(Second.type, message2)
644694
645695 this.kernel.send(portRef1, this.kernel.createMessage())
646696 this.kernel.send(portRef3, this.kernel.createMessage())
647697
@@ -652,8 +702,11 @@
652702 } else if (runs === 2) {
653703 t.equals(m.data, 'second', 'should recived the second message')
654704 }
655705 }
706 + static get type () {
707 + return 299
708 + }
656709 }
657710
658711 class First extends BaseContainer {
659712 onMessage (m) {
@@ -661,8 +714,11 @@
661714 this.kernel.send(m.fromPort, this.kernel.createMessage({
662715 data: 'first'
663716 }))
664717 }
718 + static get type () {
719 + return 29
720 + }
665721 }
666722
667723 class Second extends BaseContainer {
668724 onMessage (m) {
@@ -674,19 +730,19 @@
674730 }
675731
676732 const hypervisor = new Hypervisor(node.dag)
677733
678- hypervisor.registerContainer('root', Root)
679- hypervisor.registerContainer('first', First)
680- hypervisor.registerContainer('second', Second)
734 + hypervisor.registerContainer(Root)
735 + hypervisor.registerContainer(First)
736 + hypervisor.registerContainer(Second)
681737
682- const root = await hypervisor.createInstance('root')
738 + const root = await hypervisor.createInstance(Root.type)
683739 const [portRef1, portRef2] = root.ports.createChannel()
684740 const message = root.createMessage()
685741
686742 root.send(portRef1, message)
687743 root.ports.bind('first', portRef1)
688- root.createInstance('root', root.createMessage({
744 + root.createInstance(Root.type, root.createMessage({
689745 ports: [portRef2]
690746 }))
691747 })
692748
@@ -704,14 +760,17 @@
704760 this.kernel.ports.bind('one', portRef1)
705761 const message1 = this.kernel.createMessage({
706762 ports: [portRef2]
707763 })
708- this.kernel.createInstance('first', message1)
764 + this.kernel.createInstance(First.type, message1)
709765 } else {
710766 this.kernel.send(one, this.kernel.createMessage())
711767 this.kernel.send(one, this.kernel.createMessage())
712768 }
713769 }
770 + static get type () {
771 + return 299
772 + }
714773 }
715774
716775 class First extends BaseContainer {
717776 onMessage (m) {
@@ -725,15 +784,15 @@
725784 }
726785
727786 const hypervisor = new Hypervisor(node.dag)
728787
729- hypervisor.registerContainer('root', Root)
730- hypervisor.registerContainer('first', First)
788 + hypervisor.registerContainer(Root)
789 + hypervisor.registerContainer(First)
731790
732- const root = await hypervisor.createInstance('root')
791 + const root = await hypervisor.createInstance(Root.type)
733792 const [portRef1, portRef2] = root.ports.createChannel()
734793 root.ports.bind('first', portRef1)
735- root.createInstance('root', root.createMessage({
794 + root.createInstance(Root.type, root.createMessage({
736795 ports: [portRef2]
737796 }))
738797
739798 const message = root.createMessage()
@@ -746,14 +805,14 @@
746805
747806 tape('checking ports', async t => {
748807 t.plan(4)
749808 const hypervisor = new Hypervisor(node.dag)
750- hypervisor.registerContainer('base', BaseContainer)
809 + hypervisor.registerContainer(BaseContainer)
751810
752- const root = await hypervisor.createInstance('base')
811 + const root = await hypervisor.createInstance(BaseContainer.type)
753812
754813 const [portRef1, portRef2] = root.ports.createChannel()
755- root.createInstance('base', root.createMessage({
814 + root.createInstance(BaseContainer.type, root.createMessage({
756815 ports: [portRef2]
757816 }))
758817 root.ports.bind('test', portRef1)
759818
@@ -786,9 +845,9 @@
786845 })
787846
788847 tape('port deletion', async t => {
789848 const expectedSr = {
790- '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z'
849 + '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh'
791850 }
792851 class Root extends BaseContainer {
793852 onMessage (m) {
794853 const [portRef1, portRef2] = this.kernel.ports.createChannel()
@@ -796,9 +855,9 @@
796855 const message1 = this.kernel.createMessage({
797856 ports: [portRef2]
798857 })
799858
800- this.kernel.createInstance('first', message1)
859 + this.kernel.createInstance(First.type, message1)
801860 this.kernel.send(portRef1, this.kernel.createMessage())
802861 this.kernel.incrementTicks(6)
803862 }
804863 }
@@ -807,19 +866,22 @@
807866 onMessage (m) {
808867 this.kernel.incrementTicks(2)
809868 this.kernel.ports.delete('root')
810869 }
870 + static get type () {
871 + return 299
872 + }
811873 }
812874
813875 const hypervisor = new Hypervisor(node.dag)
814876
815- hypervisor.registerContainer('root', Root)
816- hypervisor.registerContainer('first', First)
877 + hypervisor.registerContainer(Root)
878 + hypervisor.registerContainer(First)
817879
818- const root = await hypervisor.createInstance('root')
880 + const root = await hypervisor.createInstance(Root.type)
819881 const [portRef1, portRef2] = root.ports.createChannel()
820882 root.ports.bind('first', portRef1)
821- root.createInstance('root', root.createMessage({
883 + root.createInstance(Root.type, root.createMessage({
822884 ports: [portRef2]
823885 }))
824886
825887 const message = root.createMessage()
@@ -832,24 +894,24 @@
832894 })
833895
834896 tape('clear unbounded ports', async t => {
835897 const expectedSr = {
836- '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z'
898 + '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh'
837899 }
838900 class Root extends BaseContainer {
839901 onMessage (m) {
840- this.kernel.createInstance('root')
902 + this.kernel.createInstance(Root.type)
841903 }
842904 }
843905
844906 const hypervisor = new Hypervisor(node.dag)
845907
846- hypervisor.registerContainer('root', Root)
908 + hypervisor.registerContainer(Root)
847909
848- const root = await hypervisor.createInstance('root')
910 + const root = await hypervisor.createInstance(Root.type)
849911 const [portRef1, portRef2] = root.ports.createChannel()
850912 root.ports.bind('first', portRef1)
851- root.createInstance('root', root.createMessage({
913 + root.createInstance(Root.type, root.createMessage({
852914 ports: [portRef2]
853915 }))
854916
855917 const message = root.createMessage()
@@ -861,14 +923,14 @@
861923 })
862924
863925 tape('should remove subgraphs', async t => {
864926 const expectedSr = {
865- '/': 'zdpuB2QXxn1KQtLFfBqaritTRoe5BuKP5sNFSrPtRT6sxkY7Z'
927 + '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh'
866928 }
867929 class Root extends BaseContainer {
868930 onMessage (m) {
869931 const [, portRef2] = this.kernel.ports.createChannel()
870- this.kernel.createInstance('sub', this.kernel.createMessage({
932 + this.kernel.createInstance(Sub.type, this.kernel.createMessage({
871933 ports: [portRef2]
872934 }))
873935 }
874936 }
@@ -877,23 +939,26 @@
877939 onInitailize (message) {
878940 this.kernel.ports.bind('root', message.ports[0])
879941 const [portRef1, portRef2] = root.ports.createChannel()
880942 root.ports.bind('child', portRef1)
881- root.createInstance('root', root.createMessage({
943 + root.createInstance(Root.type, root.createMessage({
882944 ports: [portRef2]
883945 }))
884946 }
947 + static get type () {
948 + return 299
949 + }
885950 }
886951
887952 const hypervisor = new Hypervisor(node.dag)
888953
889- hypervisor.registerContainer('root', Root)
890- hypervisor.registerContainer('sub', Sub)
954 + hypervisor.registerContainer(Root)
955 + hypervisor.registerContainer(Sub)
891956
892- const root = await hypervisor.createInstance('root')
957 + const root = await hypervisor.createInstance(Root.type)
893958 const [portRef1, portRef2] = root.ports.createChannel()
894959 root.ports.bind('first', portRef1)
895- root.createInstance('root', root.createMessage({
960 + root.createInstance(Root.type, root.createMessage({
896961 ports: [portRef2]
897962 }))
898963
899964 root.send(portRef1, root.createMessage())
@@ -904,9 +969,9 @@
904969 })
905970
906971 tape('should not remove connected nodes', async t => {
907972 const expectedSr = {
908- '/': 'zdpuAwsZTd5mRZBCYA1FJSHrpYDPgSZSiaTQp9xkUeajaoMHM'
973 + '/': 'zdpuAppPTaXwHnfU2yjtTyT9XsY7SJAkDwQWUZnkHU7myRzaj'
909974 }
910975 class Root extends BaseContainer {
911976 onMessage (m) {
912977 if (m.ports.length) {
@@ -914,15 +979,15 @@
914979 this.kernel.send(port, m)
915980 this.kernel.ports.unbind('test1')
916981 } else {
917982 const [portRef1, portRef2] = this.kernel.ports.createChannel()
918- this.kernel.createInstance('sub', this.kernel.createMessage({
983 + this.kernel.createInstance(Sub.type, this.kernel.createMessage({
919984 ports: [portRef2]
920985 }))
921986 this.kernel.ports.bind('test1', portRef1)
922987
923988 const [portRef3, portRef4] = this.kernel.ports.createChannel()
924- this.kernel.createInstance('sub', this.kernel.createMessage({
989 + this.kernel.createInstance(Sub.type, this.kernel.createMessage({
925990 ports: [portRef4]
926991 }))
927992 this.kernel.ports.bind('test2', portRef3)
928993 this.kernel.send(portRef3, this.kernel.createMessage({
@@ -944,19 +1009,22 @@
9441009 } else if (message.data === 'bindPort') {
9451010 this.kernel.ports.bind('channel', message.ports[0])
9461011 }
9471012 }
1013 + static get type () {
1014 + return 299
1015 + }
9481016 }
9491017
9501018 const hypervisor = new Hypervisor(node.dag)
9511019
952- hypervisor.registerContainer('root', Root)
953- hypervisor.registerContainer('sub', Sub)
1020 + hypervisor.registerContainer(Root)
1021 + hypervisor.registerContainer(Sub)
9541022
955- const root = await hypervisor.createInstance('root')
1023 + const root = await hypervisor.createInstance(Root.type)
9561024 const [portRef1, portRef2] = root.ports.createChannel()
9571025 root.ports.bind('first', portRef1)
958- root.createInstance('root', root.createMessage({
1026 + root.createInstance(Root.type, root.createMessage({
9591027 ports: [portRef2]
9601028 }))
9611029
9621030 root.send(portRef1, root.createMessage())
@@ -968,9 +1036,9 @@
9681036 })
9691037
9701038 tape('should remove multiple subgraphs', async t => {
9711039 const expectedSr = {
972- '/': 'zdpuAmi9tkYTpoVsZvqQgxpQFRhCgYFVv4W3fjjfVhf1j8swv'
1040 + '/': 'zdpuAvQqoEnojZHaw6dMDy8ACRVqfarfD2RCKTwFBYsj8suRC'
9731041 }
9741042 class Root extends BaseContainer {
9751043 onMessage (m) {
9761044 if (m.ports.length) {
@@ -979,15 +1047,15 @@
9791047 this.kernel.ports.unbind('test1')
9801048 this.kernel.ports.unbind('test2')
9811049 } else {
9821050 const [portRef1, portRef2] = this.kernel.ports.createChannel()
983- this.kernel.createInstance('sub', this.kernel.createMessage({
1051 + this.kernel.createInstance(Sub.type, this.kernel.createMessage({
9841052 ports: [portRef2]
9851053 }))
9861054 this.kernel.ports.bind('test1', portRef1)
9871055
9881056 const [portRef3, portRef4] = this.kernel.ports.createChannel()
989- this.kernel.createInstance('sub', this.kernel.createMessage({
1057 + this.kernel.createInstance(Sub.type, this.kernel.createMessage({
9901058 ports: [portRef4]
9911059 }))
9921060 this.kernel.ports.bind('test2', portRef3)
9931061 this.kernel.send(portRef3, this.kernel.createMessage({
@@ -1009,20 +1077,23 @@
10091077 } else if (message.data === 'bindPort') {
10101078 this.kernel.ports.bind('channel', message.ports[0])
10111079 }
10121080 }
1081 + static get type () {
1082 + return 299
1083 + }
10131084 }
10141085
10151086 const hypervisor = new Hypervisor(node.dag)
10161087
1017- hypervisor.registerContainer('root', Root)
1018- hypervisor.registerContainer('sub', Sub)
1088 + hypervisor.registerContainer(Root)
1089 + hypervisor.registerContainer(Sub)
10191090
1020- const root = await hypervisor.createInstance('root')
1091 + const root = await hypervisor.createInstance(Root.type)
10211092
10221093 const [portRef1, portRef2] = root.ports.createChannel()
10231094 root.ports.bind('first', portRef1)
1024- root.createInstance('root', root.createMessage({
1095 + root.createInstance(Root.type, root.createMessage({
10251096 ports: [portRef2]
10261097 }))
10271098
10281099 root.send(portRef1, root.createMessage())
@@ -1050,18 +1121,18 @@
10501121 }
10511122
10521123 const hypervisor = new Hypervisor(node.dag)
10531124
1054- hypervisor.registerContainer('test', testVMContainer)
1125 + hypervisor.registerContainer(testVMContainer)
10551126
1056- const rootContainer = await hypervisor.createInstance('test')
1127 + const rootContainer = await hypervisor.createInstance(testVMContainer.type)
10571128
10581129 const [portRef1, portRef2] = rootContainer.ports.createChannel()
10591130 const initMessage = rootContainer.createMessage({
10601131 ports: [portRef2]
10611132 })
10621133
1063- rootContainer.createInstance('test', initMessage)
1134 + rootContainer.createInstance(testVMContainer.type, initMessage)
10641135
10651136 rootContainer.ports.bind('first', portRef1)
10661137 const message = rootContainer.createMessage()
10671138 const rPort = rootContainer.getResponsePort(message)
@@ -1082,10 +1153,10 @@
10821153 }
10831154 }
10841155
10851156 const hypervisor = new Hypervisor(node.dag)
1086- hypervisor.registerContainer('test', testVMContainer)
1087- await hypervisor.createInstance('test')
1157 + hypervisor.registerContainer(testVMContainer)
1158 + await hypervisor.createInstance(testVMContainer.type)
10881159 hypervisor.getInstance(hypervisor.ROOT_ID)
10891160 })
10901161
10911162 tape('large code size', async t => {
@@ -1095,10 +1166,10 @@
10951166 onMessage () {}
10961167 }
10971168
10981169 const hypervisor = new Hypervisor(node.dag)
1099- hypervisor.registerContainer('test', testVMContainer)
1100- await hypervisor.createInstance('test', new Message({data: content}))
1170 + hypervisor.registerContainer(testVMContainer)
1171 + await hypervisor.createInstance(testVMContainer.type, new Message({data: content}))
11011172 const instance = await hypervisor.getInstance(hypervisor.ROOT_ID)
11021173 t.equals(content.length, instance.code.length)
11031174 })
11041175 })

Built with git-ssb-web