tests/index.jsView |
---|
10 | 10 | }) |
11 | 11 | |
12 | 12 | class BaseContainer extends AbstractContainer { |
13 | 13 | onCreation (message) { |
14 | | - this.kernel.state.code = message.data.byteLength ? message.data : undefined |
15 | 14 | const port = message.ports[0] |
16 | 15 | if (port) { |
17 | 16 | return this.kernel.ports.bind('root', port) |
18 | 17 | } |
26 | 25 | tape('basic', async t => { |
27 | 26 | t.plan(3) |
28 | 27 | let message |
29 | 28 | const expectedState = { |
30 | | - '/': 'zdpuApGUFnjcY3eBeVPFfnEgGunPz8vyXVJbrkgBmYwrbVDpA' |
| 29 | + '/': 'zdpuAqbcQhgu2T2MBgHbYu1MtHXyZzNsCaQjTPTR6NN9s5hbk' |
31 | 30 | } |
32 | 31 | |
33 | 32 | class testVMContainer extends BaseContainer { |
34 | 33 | onMessage (m) { |
39 | 38 | try { |
40 | 39 | const hypervisor = new Hypervisor(node.dag) |
41 | 40 | hypervisor.registerContainer(testVMContainer) |
42 | 41 | |
43 | | - const rootContainer = await hypervisor.createInstance(testVMContainer.typeId) |
| 42 | + const rootContainer = await hypervisor.createInstance(new Message({ |
| 43 | + data: { |
| 44 | + type: testVMContainer.typeId |
| 45 | + } |
| 46 | + })) |
44 | 47 | |
45 | 48 | const [portRef1, portRef2] = rootContainer.ports.createChannel() |
46 | 49 | const initMessage = rootContainer.createMessage({ |
47 | | - data: Buffer.from('test code'), |
| 50 | + data: { |
| 51 | + code: Buffer.from('test code'), |
| 52 | + type: testVMContainer.typeId |
| 53 | + }, |
48 | 54 | ports: [portRef2] |
49 | 55 | }) |
50 | 56 | |
51 | | - await rootContainer.createInstance(testVMContainer.typeId, initMessage) |
| 57 | + await rootContainer.createInstance(initMessage) |
52 | 58 | |
53 | 59 | await rootContainer.ports.bind('first', portRef1) |
54 | 60 | message = rootContainer.createMessage() |
55 | | - rootContainer.send(portRef1, message) |
| 61 | + await rootContainer.send(portRef1, message) |
56 | 62 | |
| 63 | + |
57 | 64 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
58 | 65 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 66 | + |
59 | 67 | t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
60 | 68 | } catch (e) { |
61 | 69 | console.log(e) |
62 | 70 | } |
75 | 83 | try { |
76 | 84 | const hypervisor = new Hypervisor(node.dag) |
77 | 85 | hypervisor.registerContainer(testVMContainer) |
78 | 86 | |
79 | | - const root = await hypervisor.createInstance(testVMContainer.typeId) |
| 87 | + const root = await hypervisor.createInstance(new Message({ |
| 88 | + data: { |
| 89 | + type: testVMContainer.typeId |
| 90 | + } |
| 91 | + })) |
80 | 92 | const [portRef1, portRef2] = root.ports.createChannel() |
81 | 93 | |
82 | 94 | 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 | + }, |
84 | 99 | ports: [portRef2] |
85 | 100 | })) |
86 | 101 | |
87 | 102 | const stateRoot = await hypervisor.createStateRoot(Infinity) |
97 | 112 | tape('one child contract', async t => { |
98 | 113 | t.plan(4) |
99 | 114 | let message |
100 | 115 | const expectedState = { |
101 | | - '/': 'zdpuArCqpDZtEqjrXrRhMiYLE7QQ1szVr1qLVkiwtDLincGWU' |
| 116 | + '/': 'zdpuB2Huo3ro3Fv9mpMhnUcL3jjd37T6MJ6jEd8GvA2cpvaYR' |
102 | 117 | } |
103 | 118 | let hasResolved = false |
104 | 119 | |
105 | 120 | class testVMContainer2 extends BaseContainer { |
121 | 136 | |
122 | 137 | class testVMContainer extends BaseContainer { |
123 | 138 | async onMessage (m) { |
124 | 139 | 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 | + }, |
126 | 144 | ports: [portRef2] |
127 | 145 | })) |
128 | 146 | await this.kernel.send(portRef1, m) |
129 | 147 | this.kernel.incrementTicks(1) |
134 | 152 | const hypervisor = new Hypervisor(node.dag) |
135 | 153 | hypervisor.registerContainer(testVMContainer) |
136 | 154 | hypervisor.registerContainer(testVMContainer2) |
137 | 155 | |
138 | | - let root = await hypervisor.createInstance(testVMContainer.typeId) |
| 156 | + let root = await hypervisor.createInstance(new Message({ |
| 157 | + data: { |
| 158 | + type: testVMContainer.typeId |
| 159 | + } |
| 160 | + })) |
139 | 161 | const rootId = root.id |
140 | 162 | 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 | + }, |
142 | 167 | ports: [portRef2] |
143 | 168 | })) |
144 | 169 | |
145 | 170 | await root.ports.bind('first', portRef1) |
182 | 207 | this.kernel.ports.bind('three', portRef5) |
183 | 208 | ) |
184 | 209 | |
185 | 210 | const message1 = this.kernel.createMessage({ |
| 211 | + data: { |
| 212 | + type: Root.typeId |
| 213 | + }, |
186 | 214 | ports: [portRef2] |
187 | 215 | }) |
188 | 216 | const message2 = this.kernel.createMessage({ |
| 217 | + data: { |
| 218 | + type: Root.typeId |
| 219 | + }, |
189 | 220 | ports: [portRef4] |
190 | 221 | }) |
191 | 222 | const message3 = this.kernel.createMessage({ |
| 223 | + data: { |
| 224 | + type: Root.typeId |
| 225 | + }, |
192 | 226 | ports: [portRef6] |
193 | 227 | }) |
194 | 228 | |
195 | 229 | 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) |
199 | 233 | ]) |
200 | 234 | |
201 | 235 | throw new Error('it is a trap!!!') |
202 | 236 | } |
204 | 238 | |
205 | 239 | const hypervisor = new Hypervisor(node.dag) |
206 | 240 | |
207 | 241 | 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 | + })) |
209 | 247 | await root.message(root.createMessage()) |
210 | 248 | const stateRoot = await hypervisor.createStateRoot() |
211 | 249 | |
212 | 250 | t.deepEquals(stateRoot, { |
213 | | - '/': 'zdpuAoifKuJkWz9Fjvt79NmGq3tcefhfCyq8iM8YhcFdV9bmZ' |
| 251 | + '/': 'zdpuAwAZnRgD7ZKH8ssU9UdpFTsw3Q4gecKKyRoDsD4obhpJm' |
214 | 252 | }, 'should revert the state') |
215 | 253 | }) |
216 | 254 | |
217 | 255 | tape('recieving older messages', async t => { |
225 | 263 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
226 | 264 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
227 | 265 | |
228 | 266 | const message1 = this.kernel.createMessage({ |
| 267 | + data: { |
| 268 | + type: First.typeId |
| 269 | + }, |
229 | 270 | ports: [portRef2] |
230 | 271 | }) |
231 | 272 | const message2 = this.kernel.createMessage({ |
| 273 | + data: { |
| 274 | + type: Waiter.typeId |
| 275 | + }, |
232 | 276 | ports: [portRef4] |
233 | 277 | }) |
234 | 278 | |
235 | 279 | await Promise.all([ |
236 | | - this.kernel.createInstance(First.typeId, message1), |
| 280 | + this.kernel.createInstance(message1), |
237 | 281 | this.kernel.send(portRef1, this.kernel.createMessage()), |
238 | 282 | this.kernel.send(portRef3, this.kernel.createMessage()), |
239 | 283 | this.kernel.ports.bind('one', portRef1), |
240 | 284 | this.kernel.ports.bind('two', portRef3) |
241 | 285 | ]) |
242 | | - return this.kernel.createInstance(Waiter.typeId, message2) |
| 286 | + return this.kernel.createInstance(message2) |
243 | 287 | } else if (runs === 1) { |
244 | 288 | runs++ |
245 | 289 | t.equals(m.data, 'first', 'should recive the first message') |
246 | 290 | } else if (runs === 2) { |
286 | 330 | hypervisor.registerContainer(Root) |
287 | 331 | hypervisor.registerContainer(First) |
288 | 332 | hypervisor.registerContainer(Waiter) |
289 | 333 | |
290 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 334 | + const root = await hypervisor.createInstance(new Message({ |
| 335 | + data: { |
| 336 | + type: Root.typeId |
| 337 | + } |
| 338 | + })) |
291 | 339 | const [portRef1, portRef2] = root.ports.createChannel() |
292 | 340 | |
293 | 341 | const message = root.createMessage() |
294 | 342 | await Promise.all([ |
295 | 343 | root.send(portRef1, message), |
296 | 344 | root.ports.bind('first', portRef1), |
297 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 345 | + root.createInstance(root.createMessage({ |
| 346 | + data: { |
| 347 | + type: Root.typeId |
| 348 | + }, |
298 | 349 | ports: [portRef2] |
299 | 350 | })) |
300 | 351 | ]) |
301 | 352 | } catch (e) { |
315 | 366 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
316 | 367 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
317 | 368 | |
318 | 369 | const message1 = this.kernel.createMessage({ |
| 370 | + data: { |
| 371 | + type: First.typeId |
| 372 | + }, |
319 | 373 | ports: [portRef2] |
320 | 374 | }) |
321 | 375 | const message2 = this.kernel.createMessage({ |
| 376 | + data: { |
| 377 | + type: Second.typeId |
| 378 | + }, |
322 | 379 | ports: [portRef4] |
323 | 380 | }) |
324 | 381 | |
325 | 382 | this.kernel.incrementTicks(6) |
326 | 383 | 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), |
329 | 386 | this.kernel.send(portRef1, this.kernel.createMessage()), |
330 | 387 | this.kernel.send(portRef3, this.kernel.createMessage()), |
331 | 388 | this.kernel.ports.bind('one', portRef1), |
332 | 389 | this.kernel.ports.bind('two', portRef3) |
390 | 447 | hypervisor.registerContainer(First) |
391 | 448 | hypervisor.registerContainer(Second) |
392 | 449 | hypervisor.registerContainer(Waiter) |
393 | 450 | |
394 | | - let root = await hypervisor.createInstance(Root.typeId) |
| 451 | + let root = await hypervisor.createInstance(new Message({ |
| 452 | + data: { |
| 453 | + type: Root.typeId |
| 454 | + } |
| 455 | + })) |
395 | 456 | const [portRef1, portRef2] = root.ports.createChannel() |
396 | 457 | const [portRef3, portRef4] = root.ports.createChannel() |
397 | 458 | |
398 | 459 | const message = root.createMessage() |
399 | 460 | await Promise.all([ |
400 | 461 | root.send(portRef1, message), |
401 | 462 | root.ports.bind('first', portRef1), |
402 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 463 | + root.createInstance(root.createMessage({ |
| 464 | + data: { |
| 465 | + type: Root.typeId |
| 466 | + }, |
403 | 467 | ports: [portRef2] |
404 | 468 | })), |
405 | 469 | root.ports.bind('sencond', portRef3), |
406 | | - root.createInstance(Waiter.typeId, root.createMessage({ |
| 470 | + root.createInstance(root.createMessage({ |
| 471 | + data: { |
| 472 | + type: Waiter.typeId |
| 473 | + }, |
407 | 474 | ports: [portRef4] |
408 | 475 | })) |
409 | 476 | ]) |
410 | 477 | |
411 | 478 | |
412 | 479 | root.incrementTicks(100) |
413 | | - await root.send(portRef1, root.createMessage({data: 'testss'})) |
| 480 | + await root.send(portRef1, root.createMessage({ |
| 481 | + data: 'testss' |
| 482 | + })) |
414 | 483 | root.shutdown() |
415 | 484 | } catch (e) { |
416 | 485 | console.log(e) |
417 | 486 | } |
428 | 497 | let one = this.kernel.ports.get('one') |
429 | 498 | if (!one) { |
430 | 499 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
431 | 500 | const message1 = this.kernel.createMessage({ |
| 501 | + data: { |
| 502 | + type: First.typeId |
| 503 | + }, |
432 | 504 | ports: [portRef2] |
433 | 505 | }) |
434 | | - await this.kernel.createInstance(First.typeId, message1) |
| 506 | + await this.kernel.createInstance(message1) |
435 | 507 | return this.kernel.ports.bind('one', portRef1) |
436 | 508 | } else { |
437 | 509 | return Promise.all([ |
438 | 510 | this.kernel.send(one, this.kernel.createMessage()), |
461 | 533 | |
462 | 534 | hypervisor.registerContainer(Root) |
463 | 535 | hypervisor.registerContainer(First) |
464 | 536 | |
465 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 537 | + const root = await hypervisor.createInstance(new Message({ |
| 538 | + data: { |
| 539 | + type: Root.typeId |
| 540 | + } |
| 541 | + })) |
466 | 542 | const [portRef1, portRef2] = root.ports.createChannel() |
467 | 543 | await Promise.all([ |
468 | 544 | root.ports.bind('first', portRef1), |
469 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 545 | + root.createInstance(root.createMessage({ |
| 546 | + data: { |
| 547 | + type: Root.typeId |
| 548 | + }, |
470 | 549 | ports: [portRef2] |
471 | 550 | })) |
472 | 551 | ]) |
473 | 552 | |
486 | 565 | t.plan(4) |
487 | 566 | const hypervisor = new Hypervisor(node.dag) |
488 | 567 | hypervisor.registerContainer(BaseContainer) |
489 | 568 | |
490 | | - const root = await hypervisor.createInstance(BaseContainer.typeId) |
| 569 | + const root = await hypervisor.createInstance(new Message({ |
| 570 | + data: { |
| 571 | + type: BaseContainer.typeId |
| 572 | + } |
| 573 | + })) |
491 | 574 | |
492 | 575 | 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 | + }, |
494 | 580 | ports: [portRef2] |
495 | 581 | })) |
496 | 582 | await root.ports.bind('test', portRef1) |
497 | 583 | |
524 | 610 | }) |
525 | 611 | |
526 | 612 | tape('port deletion', async t => { |
527 | 613 | const expectedSr = { |
528 | | - '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
| 614 | + '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop' |
529 | 615 | } |
530 | 616 | class Root extends BaseContainer { |
531 | 617 | async onMessage (m) { |
532 | 618 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
533 | 619 | const message1 = this.kernel.createMessage({ |
| 620 | + data: { |
| 621 | + type: First.typeId |
| 622 | + }, |
534 | 623 | ports: [portRef2] |
535 | 624 | }) |
536 | 625 | |
537 | | - await this.kernel.createInstance(First.typeId, message1) |
| 626 | + await this.kernel.createInstance(message1) |
538 | 627 | await this.kernel.send(portRef1, this.kernel.createMessage()) |
539 | 628 | this.kernel.incrementTicks(6) |
540 | 629 | return this.kernel.ports.bind('one', portRef1) |
541 | 630 | } |
555 | 644 | |
556 | 645 | hypervisor.registerContainer(Root) |
557 | 646 | hypervisor.registerContainer(First) |
558 | 647 | |
559 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 648 | + const root = await hypervisor.createInstance(new Message({ |
| 649 | + data: { |
| 650 | + type: Root.typeId |
| 651 | + } |
| 652 | + })) |
560 | 653 | const [portRef1, portRef2] = root.ports.createChannel() |
561 | 654 | 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 | + }, |
563 | 659 | ports: [portRef2] |
564 | 660 | })) |
565 | 661 | |
566 | 662 | const message = root.createMessage() |
574 | 670 | }) |
575 | 671 | |
576 | 672 | tape('clear unbounded ports', async t => { |
577 | 673 | const expectedSr = { |
578 | | - '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
| 674 | + '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop' |
579 | 675 | } |
| 676 | + |
580 | 677 | class Root extends BaseContainer { |
581 | 678 | onMessage (m) { |
582 | | - return this.kernel.createInstance(Root.typeId) |
| 679 | + return this.kernel.createInstance(new Message({ |
| 680 | + data: { |
| 681 | + type: Root.typeId |
| 682 | + } |
| 683 | + })) |
583 | 684 | } |
584 | 685 | } |
585 | 686 | |
586 | 687 | const hypervisor = new Hypervisor(node.dag) |
587 | 688 | hypervisor.registerContainer(Root) |
588 | 689 | |
589 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 690 | + const root = await hypervisor.createInstance(new Message({ |
| 691 | + data: { |
| 692 | + type: Root.typeId |
| 693 | + } |
| 694 | + })) |
590 | 695 | const [portRef1, portRef2] = root.ports.createChannel() |
591 | 696 | 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 | + }, |
593 | 701 | ports: [portRef2] |
594 | 702 | })) |
595 | 703 | |
596 | 704 | const message = root.createMessage() |
602 | 710 | }) |
603 | 711 | |
604 | 712 | tape('should remove subgraphs', async t => { |
605 | 713 | const expectedSr = { |
606 | | - '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
| 714 | + '/': 'zdpuAxKfu5nMTfpz6uHPqXdHZFQDZdRUer8zcQ6nvC4pTQsop' |
607 | 715 | } |
608 | 716 | class Root extends BaseContainer { |
609 | 717 | onMessage (m) { |
610 | 718 | 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 | + }, |
612 | 723 | ports: [portRef2] |
613 | 724 | })) |
614 | 725 | } |
615 | 726 | } |
618 | 729 | async onInitailize (message) { |
619 | 730 | await this.kernel.ports.bind('root', message.ports[0]) |
620 | 731 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
621 | 732 | 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 | + }, |
623 | 737 | ports: [portRef2] |
624 | 738 | })) |
625 | 739 | } |
626 | 740 | static get typeId () { |
633 | 747 | |
634 | 748 | hypervisor.registerContainer(Root) |
635 | 749 | hypervisor.registerContainer(Sub) |
636 | 750 | |
637 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 751 | + const root = await hypervisor.createInstance(new Message({ |
| 752 | + data: { |
| 753 | + type: Root.typeId |
| 754 | + } |
| 755 | + })) |
638 | 756 | const [portRef1, portRef2] = root.ports.createChannel() |
639 | 757 | 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 | + }, |
641 | 762 | ports: [portRef2] |
642 | 763 | })) |
643 | 764 | |
644 | 765 | await root.send(portRef1, root.createMessage()) |
652 | 773 | }) |
653 | 774 | |
654 | 775 | tape('should not remove connected nodes', async t => { |
655 | 776 | const expectedSr = { |
656 | | - '/': 'zdpuApKrsvsWknDML2Mme9FyZfRnVZ1hTCoKzkooYAWT3dUDV' |
| 777 | + '/': 'zdpuAr4A3i1t6B7BkLT9C7DoxwvFnNg74gEzyqhpFj7nqVBy6' |
657 | 778 | } |
658 | 779 | class Root extends BaseContainer { |
659 | 780 | async onMessage (m) { |
660 | 781 | if (m.ports.length) { |
662 | 783 | await this.kernel.send(port, m) |
663 | 784 | return this.kernel.ports.unbind('test1') |
664 | 785 | } else { |
665 | 786 | 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 | + }, |
667 | 791 | ports: [portRef2] |
668 | 792 | })) |
669 | 793 | await this.kernel.ports.bind('test1', portRef1) |
670 | 794 | |
671 | 795 | 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 | + }, |
673 | 800 | ports: [portRef4] |
674 | 801 | })) |
675 | 802 | await this.kernel.ports.bind('test2', portRef3) |
676 | 803 | await this.kernel.send(portRef3, this.kernel.createMessage({ |
702 | 829 | |
703 | 830 | hypervisor.registerContainer(Root) |
704 | 831 | hypervisor.registerContainer(Sub) |
705 | 832 | |
706 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 833 | + const root = await hypervisor.createInstance(new Message({ |
| 834 | + data: { |
| 835 | + type: Root.typeId |
| 836 | + } |
| 837 | + })) |
707 | 838 | const [portRef1, portRef2] = root.ports.createChannel() |
708 | 839 | 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 | + }, |
710 | 844 | ports: [portRef2] |
711 | 845 | })) |
712 | 846 | |
713 | 847 | await root.send(portRef1, root.createMessage()) |
719 | 853 | }) |
720 | 854 | |
721 | 855 | tape('should remove multiple subgraphs', async t => { |
722 | 856 | const expectedSr = { |
723 | | - '/': 'zdpuArkZ5yNowNnU4qJ8vayAUncgibQP9goDP1CwFxdmPJF9D' |
| 857 | + '/': 'zdpuAzYGmZeZsi5Zer7LXCTm1AsmqpUMJAXZnEeFW2UVDZj2P' |
724 | 858 | } |
725 | 859 | class Root extends BaseContainer { |
726 | 860 | onMessage (m) { |
727 | 861 | if (m.ports.length) { |
734 | 868 | } else { |
735 | 869 | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
736 | 870 | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
737 | 871 | 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 | + }, |
739 | 876 | ports: [portRef2] |
740 | 877 | })), |
741 | 878 | 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 | + }, |
743 | 883 | ports: [portRef4] |
744 | 884 | })), |
745 | 885 | this.kernel.ports.bind('test2', portRef3), |
746 | 886 | this.kernel.send(portRef3, this.kernel.createMessage({ |
774 | 914 | |
775 | 915 | hypervisor.registerContainer(Root) |
776 | 916 | hypervisor.registerContainer(Sub) |
777 | 917 | |
778 | | - const root = await hypervisor.createInstance(Root.typeId) |
| 918 | + const root = await hypervisor.createInstance(new Message({ |
| 919 | + data: { |
| 920 | + type: Root.typeId |
| 921 | + } |
| 922 | + })) |
779 | 923 | |
780 | 924 | const [portRef1, portRef2] = root.ports.createChannel() |
781 | 925 | await Promise.all([ |
782 | 926 | root.ports.bind('first', portRef1), |
783 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 927 | + root.createInstance(root.createMessage({ |
| 928 | + data: { |
| 929 | + type: Root.typeId |
| 930 | + }, |
784 | 931 | ports: [portRef2] |
785 | 932 | })), |
786 | 933 | root.send(portRef1, root.createMessage()) |
787 | 934 | ]) |
814 | 961 | const hypervisor = new Hypervisor(node.dag) |
815 | 962 | |
816 | 963 | hypervisor.registerContainer(testVMContainer) |
817 | 964 | |
818 | | - const rootContainer = await hypervisor.createInstance(testVMContainer.typeId) |
| 965 | + const rootContainer = await hypervisor.createInstance(new Message({ |
| 966 | + data: { |
| 967 | + type: testVMContainer.typeId |
| 968 | + } |
| 969 | + })) |
819 | 970 | |
820 | 971 | const [portRef1, portRef2] = rootContainer.ports.createChannel() |
821 | 972 | const initMessage = rootContainer.createMessage({ |
| 973 | + data: { |
| 974 | + type: testVMContainer.typeId |
| 975 | + }, |
822 | 976 | ports: [portRef2] |
823 | 977 | }) |
824 | 978 | |
825 | | - rootContainer.createInstance(testVMContainer.typeId, initMessage) |
| 979 | + rootContainer.createInstance(initMessage) |
826 | 980 | |
827 | 981 | await rootContainer.ports.bind('first', portRef1) |
828 | 982 | const message = rootContainer.createMessage() |
829 | 983 | const rPort = rootContainer.getResponsePort(message) |
845 | 999 | } |
846 | 1000 | |
847 | 1001 | const hypervisor = new Hypervisor(node.dag) |
848 | 1002 | hypervisor.registerContainer(testVMContainer) |
849 | | - await hypervisor.createInstance(testVMContainer.typeId) |
| 1003 | + await hypervisor.createInstance(new Message({ |
| 1004 | + data: { |
| 1005 | + type: testVMContainer.typeId |
| 1006 | + } |
| 1007 | + })) |
850 | 1008 | hypervisor.getInstance(hypervisor.ROOT_ID) |
851 | 1009 | }) |
852 | 1010 | |
853 | 1011 | tape('large code size', async t => { |
858 | 1016 | } |
859 | 1017 | |
860 | 1018 | const hypervisor = new Hypervisor(node.dag) |
861 | 1019 | 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 | + })) |
863 | 1026 | const instance = await hypervisor.getInstance(hypervisor.ROOT_ID) |
864 | 1027 | t.equals(content.length, instance.code.length) |
865 | 1028 | }) |
866 | 1029 | }) |