tests/index.jsView |
---|
13 | 13 … | onCreation (message) { |
14 | 14 … | this.kernel.state.code = message.data.byteLength ? message.data : undefined |
15 | 15 … | const port = message.ports[0] |
16 | 16 … | if (port) { |
17 | | - this.kernel.ports.bind('root', port) |
| 17 … | + return this.kernel.ports.bind('root', port) |
18 | 18 … | } |
19 | 19 … | } |
20 | 20 … | static get typeId () { |
21 | 21 … | return 9 |
26 | 26 … | tape('basic', async t => { |
27 | 27 … | t.plan(3) |
28 | 28 … | let message |
29 | 29 … | const expectedState = { |
30 | | - '/': 'zdpuAmN9VSrvNbArWkAEhEYaKhhCT3rk8xMhUam6eUfQmr6aZ' |
| 30 … | + '/': 'zdpuApGUFnjcY3eBeVPFfnEgGunPz8vyXVJbrkgBmYwrbVDpA' |
31 | 31 … | } |
32 | 32 … | |
33 | 33 … | class testVMContainer extends BaseContainer { |
34 | 34 … | onMessage (m) { |
35 | 35 … | t.true(m === message, 'should recive a message') |
36 | 36 … | } |
37 | 37 … | } |
38 | 38 … | |
39 | | - const hypervisor = new Hypervisor(node.dag) |
40 | | - hypervisor.registerContainer(testVMContainer) |
| 39 … | + try { |
| 40 … | + const hypervisor = new Hypervisor(node.dag) |
| 41 … | + hypervisor.registerContainer(testVMContainer) |
41 | 42 … | |
42 | | - const rootContainer = await hypervisor.createInstance(testVMContainer.typeId) |
| 43 … | + const rootContainer = await hypervisor.createInstance(testVMContainer.typeId) |
43 | 44 … | |
44 | | - const [portRef1, portRef2] = rootContainer.ports.createChannel() |
45 | | - const initMessage = rootContainer.createMessage({ |
46 | | - data: Buffer.from('test code'), |
47 | | - ports: [portRef2] |
48 | | - }) |
| 45 … | + const [portRef1, portRef2] = rootContainer.ports.createChannel() |
| 46 … | + const initMessage = rootContainer.createMessage({ |
| 47 … | + data: Buffer.from('test code'), |
| 48 … | + ports: [portRef2] |
| 49 … | + }) |
49 | 50 … | |
50 | | - rootContainer.createInstance(testVMContainer.typeId, initMessage) |
| 51 … | + rootContainer.createInstance(testVMContainer.typeId, initMessage) |
51 | 52 … | |
52 | | - rootContainer.ports.bind('first', portRef1) |
53 | | - message = rootContainer.createMessage() |
54 | | - rootContainer.send(portRef1, message) |
| 53 … | + await rootContainer.ports.bind('first', portRef1) |
| 54 … | + message = rootContainer.createMessage() |
| 55 … | + rootContainer.send(portRef1, message) |
55 | 56 … | |
56 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
57 | | - t.deepEquals(stateRoot, expectedState, 'expected root!') |
58 | | - t.equals(hypervisor.scheduler.oldest(), 0) |
| 57 … | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 58 … | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 59 … | + t.equals(hypervisor.scheduler.oldest(), 0) |
| 60 … | + } catch (e) { |
| 61 … | + console.log(e) |
| 62 … | + } |
59 | 63 … | }) |
60 | 64 … | |
61 | 65 … | tape('basic - do not store containers with no ports bound', async t => { |
62 | 66 … | t.plan(1) |
63 | 67 … | const expectedState = { |
64 | | - '/': 'zdpuAxGvPHM4DRbq7GeyGjwuPA8NT7DZLszcDDX9R5iwHWnTo' |
| 68 … | + '/': 'zdpuAop4nt8pqzg7duciSYbZmWfDaBiz87RCtGCbb35ewUrbW' |
65 | 69 … | } |
66 | 70 … | |
67 | 71 … | class testVMContainer extends BaseContainer { |
68 | 72 … | onCreation () {} |
69 | 73 … | } |
70 | 74 … | |
71 | | - const hypervisor = new Hypervisor(node.dag) |
72 | | - hypervisor.registerContainer(testVMContainer) |
| 75 … | + try { |
| 76 … | + const hypervisor = new Hypervisor(node.dag) |
| 77 … | + hypervisor.registerContainer(testVMContainer) |
73 | 78 … | |
74 | | - const root = await hypervisor.createInstance(testVMContainer.typeId) |
75 | | - const [portRef1, portRef2] = root.ports.createChannel() |
| 79 … | + const root = await hypervisor.createInstance(testVMContainer.typeId) |
| 80 … | + const [portRef1, portRef2] = root.ports.createChannel() |
76 | 81 … | |
77 | | - root.ports.bind('one', portRef1) |
78 | | - root.createInstance(testVMContainer.typeId, root.createMessage({ |
79 | | - ports: [portRef2] |
80 | | - })) |
| 82 … | + await root.ports.bind('one', portRef1) |
| 83 … | + root.createInstance(testVMContainer.typeId, root.createMessage({ |
| 84 … | + ports: [portRef2] |
| 85 … | + })) |
81 | 86 … | |
82 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
83 | | - t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 87 … | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 88 … | + |
| 89 … | + |
| 90 … | + |
| 91 … | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 92 … | + } catch (e) { |
| 93 … | + console.log(e) |
| 94 … | + } |
84 | 95 … | }) |
85 | 96 … | |
86 | 97 … | tape('one child contract with saturated ports', async t => { |
87 | 98 … | t.plan(2) |
88 | 99 … | let message |
89 | 100 … | const expectedState = { |
90 | | - '/': 'zdpuAvWT2E1Hg6cvFNLTDbmjGRLSDbMnRtrA6s17oSdBX5EWs' |
| 101 … | + '/': 'zdpuArCqpDZtEqjrXrRhMiYLE7QQ1szVr1qLVkiwtDLincGWU' |
91 | 102 … | } |
92 | 103 … | |
93 | 104 … | class testVMContainer2 extends BaseContainer { |
94 | 105 … | onMessage (m) { |
104 | 115 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
105 | 116 … | this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
106 | 117 … | ports: [portRef2] |
107 | 118 … | })) |
108 | | - this.kernel.ports.bind('child', portRef1) |
109 | 119 … | this.kernel.incrementTicks(2) |
110 | 120 … | this.kernel.send(portRef1, m) |
| 121 … | + return this.kernel.ports.bind('child', portRef1) |
111 | 122 … | } |
112 | 123 … | } |
113 | 124 … | |
114 | 125 … | const hypervisor = new Hypervisor(node.dag) |
120 | 131 … | root.createInstance(testVMContainer.typeId, root.createMessage({ |
121 | 132 … | ports: [portRef2] |
122 | 133 … | })) |
123 | 134 … | |
124 | | - root.ports.bind('first', portRef1) |
| 135 … | + await root.ports.bind('first', portRef1) |
125 | 136 … | message = root.createMessage({ |
126 | 137 … | data: 'test' |
127 | 138 … | }) |
128 | 139 … | |
129 | 140 … | root.send(portRef1, message) |
130 | 141 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 142 … | + |
131 | 143 … | t.deepEquals(stateRoot, expectedState, 'expected state') |
| 144 … | + |
| 145 … | + |
132 | 146 … | }) |
133 | 147 … | |
134 | 148 … | tape('one child contract', async t => { |
135 | 149 … | t.plan(4) |
136 | 150 … | let message |
137 | 151 … | const expectedState = { |
138 | | - '/': 'zdpuAvWT2E1Hg6cvFNLTDbmjGRLSDbMnRtrA6s17oSdBX5EWs' |
| 152 … | + '/': 'zdpuArCqpDZtEqjrXrRhMiYLE7QQ1szVr1qLVkiwtDLincGWU' |
139 | 153 … | } |
140 | 154 … | let hasResolved = false |
141 | 155 … | |
142 | 156 … | class testVMContainer2 extends BaseContainer { |
161 | 175 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
162 | 176 … | this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
163 | 177 … | ports: [portRef2] |
164 | 178 … | })) |
165 | | - this.kernel.ports.bind('child', portRef1) |
166 | 179 … | this.kernel.send(portRef1, m) |
167 | 180 … | this.kernel.incrementTicks(1) |
| 181 … | + return this.kernel.ports.bind('child', portRef1) |
168 | 182 … | } |
169 | 183 … | } |
170 | 184 … | |
171 | 185 … | const hypervisor = new Hypervisor(node.dag) |
178 | 192 … | root.createInstance(testVMContainer.typeId, root.createMessage({ |
179 | 193 … | ports: [portRef2] |
180 | 194 … | })) |
181 | 195 … | |
182 | | - root.ports.bind('first', portRef1) |
| 196 … | + await root.ports.bind('first', portRef1) |
183 | 197 … | message = root.createMessage() |
184 | 198 … | |
185 | 199 … | root.send(portRef1, message) |
186 | 200 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
187 | 201 … | t.true(hasResolved, 'should resolve before generating the state root') |
| 202 … | + |
| 203 … | + |
| 204 … | + |
188 | 205 … | t.deepEquals(stateRoot, expectedState, 'expected state') |
189 | 206 … | |
190 | 207 … | |
191 | 208 … | class testVMContainer3 extends BaseContainer { |
209 | 226 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
210 | 227 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
211 | 228 … | const [portRef5, portRef6] = this.kernel.ports.createChannel() |
212 | 229 … | |
213 | | - this.kernel.ports.bind('one', portRef1) |
214 | | - this.kernel.ports.bind('two', portRef3) |
215 | | - this.kernel.ports.bind('three', portRef5) |
| 230 … | + await Promise.all( |
| 231 … | + this.kernel.ports.bind('one', portRef1), |
| 232 … | + this.kernel.ports.bind('two', portRef3), |
| 233 … | + this.kernel.ports.bind('three', portRef5) |
| 234 … | + ) |
216 | 235 … | |
217 | 236 … | const message1 = this.kernel.createMessage({ |
218 | 237 … | ports: [portRef2] |
219 | 238 … | }) |
239 | 258 … | await root.message(root.createMessage()) |
240 | 259 … | const stateRoot = await hypervisor.createStateRoot() |
241 | 260 … | |
242 | 261 … | t.deepEquals(stateRoot, { |
243 | | - '/': 'zdpuAwxK8kAM3SkxSyALurpFHTobp6sFJef9gZJ8ZDQRww1LN' |
| 262 … | + '/': 'zdpuAoifKuJkWz9Fjvt79NmGq3tcefhfCyq8iM8YhcFdV9bmZ' |
244 | 263 … | }, 'should revert the state') |
245 | 264 … | }) |
246 | 265 … | |
247 | 266 … | tape('message should arrive in the correct oder if sent in order', async t => { |
255 | 274 … | |
256 | 275 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
257 | 276 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
258 | 277 … | |
259 | | - this.kernel.ports.bind('two', portRef3) |
260 | | - this.kernel.ports.bind('one', portRef1) |
261 | | - |
262 | 278 … | const message1 = this.kernel.createMessage({ |
263 | 279 … | ports: [portRef2] |
264 | 280 … | }) |
265 | 281 … | const message2 = this.kernel.createMessage({ |
270 | 286 … | this.kernel.createInstance(Second.typeId, message2) |
271 | 287 … | |
272 | 288 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
273 | 289 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
| 290 … | + return Promise.all( |
| 291 … | + this.kernel.ports.bind('two', portRef3), |
| 292 … | + this.kernel.ports.bind('one', portRef1) |
| 293 … | + ) |
274 | 294 … | } else if (runs === 1) { |
275 | 295 … | runs++ |
276 | 296 … | t.equals(m.data, 'first', 'should recive the first message') |
277 | 297 … | } else if (runs === 2) { |
318 | 338 … | root.createInstance(Root.typeId, root.createMessage({ |
319 | 339 … | ports: [portRef2] |
320 | 340 … | })) |
321 | 341 … | |
322 | | - root.ports.bind('first', portRef1) |
| 342 … | + await root.ports.bind('first', portRef1) |
323 | 343 … | const message = root.createMessage() |
324 | 344 … | root.send(portRef1, message) |
325 | 345 … | }) |
326 | 346 … | |
335 | 355 … | |
336 | 356 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
337 | 357 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
338 | 358 … | |
339 | | - this.kernel.ports.bind('one', portRef1) |
340 | | - this.kernel.ports.bind('two', portRef3) |
341 | | - |
342 | 359 … | const message1 = this.kernel.createMessage({ |
343 | 360 … | ports: [portRef2] |
344 | 361 … | }) |
345 | 362 … | const message2 = this.kernel.createMessage({ |
350 | 367 … | this.kernel.createInstance(Second.typeId, message2) |
351 | 368 … | |
352 | 369 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
353 | 370 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
| 371 … | + |
| 372 … | + return Promise.all([ |
| 373 … | + this.kernel.ports.bind('one', portRef1), |
| 374 … | + this.kernel.ports.bind('two', portRef3) |
| 375 … | + ]) |
354 | 376 … | } else if (runs === 1) { |
355 | 377 … | runs++ |
356 | 378 … | t.equals(m.data, 'second', 'should recived the second message') |
357 | 379 … | } else if (runs === 2) { |
398 | 420 … | root.createInstance(Root.typeId, root.createMessage({ |
399 | 421 … | ports: [portRef2] |
400 | 422 … | })) |
401 | 423 … | |
402 | | - root.ports.bind('first', portRef1) |
| 424 … | + await root.ports.bind('first', portRef1) |
403 | 425 … | const message = root.createMessage() |
404 | 426 … | root.send(portRef1, message) |
405 | 427 … | }) |
406 | 428 … | |
414 | 436 … | runs++ |
415 | 437 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
416 | 438 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
417 | 439 … | |
418 | | - this.kernel.ports.bind('one', portRef1) |
419 | | - this.kernel.ports.bind('two', portRef3) |
420 | | - |
421 | 440 … | const message1 = this.kernel.createMessage({ |
422 | 441 … | ports: [portRef2] |
423 | 442 … | }) |
424 | 443 … | const message2 = this.kernel.createMessage({ |
431 | 450 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
432 | 451 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
433 | 452 … | |
434 | 453 … | this.kernel.incrementTicks(6) |
| 454 … | + |
| 455 … | + return Promise.all([ |
| 456 … | + this.kernel.ports.bind('one', portRef1), |
| 457 … | + this.kernel.ports.bind('two', portRef3) |
| 458 … | + ]) |
435 | 459 … | } else if (runs === 1) { |
436 | 460 … | runs++ |
437 | 461 … | t.equals(m.data, 'first', 'should recive the first message') |
438 | 462 … | } else if (runs === 2) { |
476 | 500 … | root.createInstance(Root.typeId, root.createMessage({ |
477 | 501 … | ports: [portRef2] |
478 | 502 … | })) |
479 | 503 … | |
480 | | - root.ports.bind('first', portRef1) |
| 504 … | + await root.ports.bind('first', portRef1) |
481 | 505 … | const message = root.createMessage() |
482 | 506 … | root.send(portRef1, message) |
483 | 507 … | }) |
484 | 508 … | |
492 | 516 … | runs++ |
493 | 517 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
494 | 518 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
495 | 519 … | |
496 | | - this.kernel.ports.bind('one', portRef1) |
497 | | - this.kernel.ports.bind('two', portRef3) |
498 | | - |
499 | 520 … | const message1 = this.kernel.createMessage({ |
500 | 521 … | ports: [portRef2] |
501 | 522 … | }) |
502 | 523 … | const message2 = this.kernel.createMessage({ |
509 | 530 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
510 | 531 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
511 | 532 … | |
512 | 533 … | this.kernel.incrementTicks(6) |
| 534 … | + return Promise.all([ |
| 535 … | + this.kernel.ports.bind('one', portRef1), |
| 536 … | + this.kernel.ports.bind('two', portRef3) |
| 537 … | + ]) |
513 | 538 … | } else if (runs === 1) { |
514 | 539 … | runs++ |
515 | 540 … | t.equals(m.data, 'first', 'should recive the first message') |
516 | 541 … | } else if (runs === 2) { |
568 | 593 … | const [portRef1, portRef2] = root.ports.createChannel() |
569 | 594 … | |
570 | 595 … | const message = root.createMessage() |
571 | 596 … | root.send(portRef1, message) |
572 | | - root.ports.bind('first', portRef1) |
| 597 … | + await root.ports.bind('first', portRef1) |
573 | 598 … | root.createInstance(Root.typeId, root.createMessage({ |
574 | 599 … | ports: [portRef2] |
575 | 600 … | })) |
576 | 601 … | |
577 | 602 … | const [portRef3, portRef4] = root.ports.createChannel() |
578 | | - root.ports.bind('sencond', portRef3) |
| 603 … | + await root.ports.bind('sencond', portRef3) |
579 | 604 … | root.createInstance(Waiter.typeId, root.createMessage({ |
580 | 605 … | ports: [portRef4] |
581 | 606 … | })) |
582 | 607 … | |
596 | 621 … | runs++ |
597 | 622 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
598 | 623 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
599 | 624 … | |
600 | | - this.kernel.ports.bind('two', portRef3) |
601 | | - this.kernel.ports.bind('one', portRef1) |
602 | | - |
603 | 625 … | const message1 = this.kernel.createMessage({ |
604 | 626 … | ports: [portRef2] |
605 | 627 … | }) |
606 | 628 … | const message2 = this.kernel.createMessage({ |
613 | 635 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
614 | 636 … | this.kernel.send(portRef3, this.kernel.createMessage()) |
615 | 637 … | |
616 | 638 … | this.kernel.incrementTicks(6) |
| 639 … | + return Promise.all([ |
| 640 … | + this.kernel.ports.bind('two', portRef3), |
| 641 … | + this.kernel.ports.bind('one', portRef1) |
| 642 … | + ]) |
617 | 643 … | } else if (runs === 1) { |
618 | 644 … | runs++ |
619 | 645 … | t.equals(m.data, 'second', 'should recived the second message') |
620 | 646 … | } else if (runs === 2) { |
660 | 686 … | const [portRef1, portRef2] = root.ports.createChannel() |
661 | 687 … | const message = root.createMessage() |
662 | 688 … | |
663 | 689 … | root.send(portRef1, message) |
664 | | - root.ports.bind('first', portRef1) |
| 690 … | + await root.ports.bind('first', portRef1) |
665 | 691 … | root.createInstance(Root.typeId, root.createMessage({ |
666 | 692 … | ports: [portRef2] |
667 | 693 … | })) |
668 | 694 … | }) |
672 | 698 … | |
673 | 699 … | let runs = 0 |
674 | 700 … | |
675 | 701 … | class Root extends BaseContainer { |
676 | | - onMessage (m) { |
| 702 … | + async onMessage (m) { |
677 | 703 … | if (!runs) { |
678 | 704 … | runs++ |
679 | 705 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
680 | 706 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
681 | 707 … | |
682 | | - this.kernel.ports.bind('one', portRef1) |
683 | | - this.kernel.ports.bind('two', portRef3) |
| 708 … | + await this.kernel.ports.bind('one', portRef1) |
| 709 … | + await this.kernel.ports.bind('two', portRef3) |
684 | 710 … | |
685 | 711 … | const message1 = this.kernel.createMessage({ |
686 | 712 … | ports: [portRef2] |
687 | 713 … | }) |
739 | 765 … | const [portRef1, portRef2] = root.ports.createChannel() |
740 | 766 … | const message = root.createMessage() |
741 | 767 … | |
742 | 768 … | root.send(portRef1, message) |
743 | | - root.ports.bind('first', portRef1) |
| 769 … | + await root.ports.bind('first', portRef1) |
744 | 770 … | root.createInstance(Root.typeId, root.createMessage({ |
745 | 771 … | ports: [portRef2] |
746 | 772 … | })) |
747 | 773 … | }) |
756 | 782 … | onMessage (m) { |
757 | 783 … | let one = this.kernel.ports.get('one') |
758 | 784 … | if (!one) { |
759 | 785 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
760 | | - this.kernel.ports.bind('one', portRef1) |
761 | 786 … | const message1 = this.kernel.createMessage({ |
762 | 787 … | ports: [portRef2] |
763 | 788 … | }) |
764 | 789 … | this.kernel.createInstance(First.typeId, message1) |
| 790 … | + return this.kernel.ports.bind('one', portRef1) |
765 | 791 … | } else { |
766 | 792 … | this.kernel.send(one, this.kernel.createMessage()) |
767 | 793 … | this.kernel.send(one, this.kernel.createMessage()) |
768 | 794 … | } |
789 | 815 … | hypervisor.registerContainer(First) |
790 | 816 … | |
791 | 817 … | const root = await hypervisor.createInstance(Root.typeId) |
792 | 818 … | const [portRef1, portRef2] = root.ports.createChannel() |
793 | | - root.ports.bind('first', portRef1) |
| 819 … | + await root.ports.bind('first', portRef1) |
794 | 820 … | root.createInstance(Root.typeId, root.createMessage({ |
795 | 821 … | ports: [portRef2] |
796 | 822 … | })) |
797 | 823 … | |
813 | 839 … | const [portRef1, portRef2] = root.ports.createChannel() |
814 | 840 … | root.createInstance(BaseContainer.typeId, root.createMessage({ |
815 | 841 … | ports: [portRef2] |
816 | 842 … | })) |
817 | | - root.ports.bind('test', portRef1) |
| 843 … | + await root.ports.bind('test', portRef1) |
818 | 844 … | |
819 | 845 … | try { |
820 | 846 … | root.createMessage({ |
821 | 847 … | ports: [portRef1] |
845 | 871 … | }) |
846 | 872 … | |
847 | 873 … | tape('port deletion', async t => { |
848 | 874 … | const expectedSr = { |
849 | | - '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh' |
| 875 … | + '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
850 | 876 … | } |
851 | 877 … | class Root extends BaseContainer { |
852 | 878 … | onMessage (m) { |
853 | 879 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
854 | | - this.kernel.ports.bind('one', portRef1) |
855 | 880 … | const message1 = this.kernel.createMessage({ |
856 | 881 … | ports: [portRef2] |
857 | 882 … | }) |
858 | 883 … | |
859 | 884 … | this.kernel.createInstance(First.typeId, message1) |
860 | 885 … | this.kernel.send(portRef1, this.kernel.createMessage()) |
861 | 886 … | this.kernel.incrementTicks(6) |
| 887 … | + return this.kernel.ports.bind('one', portRef1) |
862 | 888 … | } |
863 | 889 … | } |
864 | 890 … | |
865 | 891 … | class First extends BaseContainer { |
878 | 904 … | hypervisor.registerContainer(First) |
879 | 905 … | |
880 | 906 … | const root = await hypervisor.createInstance(Root.typeId) |
881 | 907 … | const [portRef1, portRef2] = root.ports.createChannel() |
882 | | - root.ports.bind('first', portRef1) |
| 908 … | + await root.ports.bind('first', portRef1) |
883 | 909 … | root.createInstance(Root.typeId, root.createMessage({ |
884 | 910 … | ports: [portRef2] |
885 | 911 … | })) |
886 | 912 … | |
888 | 914 … | root.send(portRef1, message) |
889 | 915 … | |
890 | 916 … | const sr = await hypervisor.createStateRoot() |
891 | 917 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
| 918 … | + await hypervisor.graph.tree(sr, Infinity, true) |
892 | 919 … | |
893 | 920 … | t.end() |
894 | 921 … | }) |
895 | 922 … | |
896 | 923 … | tape('clear unbounded ports', async t => { |
897 | 924 … | const expectedSr = { |
898 | | - '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh' |
| 925 … | + '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
899 | 926 … | } |
900 | 927 … | class Root extends BaseContainer { |
901 | 928 … | onMessage (m) { |
902 | 929 … | this.kernel.createInstance(Root.typeId) |
908 | 935 … | hypervisor.registerContainer(Root) |
909 | 936 … | |
910 | 937 … | const root = await hypervisor.createInstance(Root.typeId) |
911 | 938 … | const [portRef1, portRef2] = root.ports.createChannel() |
912 | | - root.ports.bind('first', portRef1) |
| 939 … | + await root.ports.bind('first', portRef1) |
913 | 940 … | root.createInstance(Root.typeId, root.createMessage({ |
914 | 941 … | ports: [portRef2] |
915 | 942 … | })) |
916 | 943 … | |
923 | 950 … | }) |
924 | 951 … | |
925 | 952 … | tape('should remove subgraphs', async t => { |
926 | 953 … | const expectedSr = { |
927 | | - '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh' |
| 954 … | + '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
928 | 955 … | } |
929 | 956 … | class Root extends BaseContainer { |
930 | 957 … | onMessage (m) { |
931 | 958 … | const [, portRef2] = this.kernel.ports.createChannel() |
935 | 962 … | } |
936 | 963 … | } |
937 | 964 … | |
938 | 965 … | class Sub extends BaseContainer { |
939 | | - onInitailize (message) { |
940 | | - this.kernel.ports.bind('root', message.ports[0]) |
941 | | - const [portRef1, portRef2] = root.ports.createChannel() |
942 | | - root.ports.bind('child', portRef1) |
943 | | - root.createInstance(Root.typeId, root.createMessage({ |
| 966 … | + async onInitailize (message) { |
| 967 … | + await this.kernel.ports.bind('root', message.ports[0]) |
| 968 … | + const [portRef1, portRef2] = this.kernel.ports.createChannel() |
| 969 … | + await this.kernel.ports.bind('child', portRef1) |
| 970 … | + this.kernel.createInstance(Root.typeId, this.kernel.createMessage({ |
944 | 971 … | ports: [portRef2] |
945 | 972 … | })) |
946 | 973 … | } |
947 | 974 … | static get typeId () { |
955 | 982 … | hypervisor.registerContainer(Sub) |
956 | 983 … | |
957 | 984 … | const root = await hypervisor.createInstance(Root.typeId) |
958 | 985 … | const [portRef1, portRef2] = root.ports.createChannel() |
959 | | - root.ports.bind('first', portRef1) |
| 986 … | + await root.ports.bind('first', portRef1) |
960 | 987 … | root.createInstance(Root.typeId, root.createMessage({ |
961 | 988 … | ports: [portRef2] |
962 | 989 … | })) |
963 | 990 … | |
969 | 996 … | }) |
970 | 997 … | |
971 | 998 … | tape('should not remove connected nodes', async t => { |
972 | 999 … | const expectedSr = { |
973 | | - '/': 'zdpuAppPTaXwHnfU2yjtTyT9XsY7SJAkDwQWUZnkHU7myRzaj' |
| 1000 … | + '/': 'zdpuApKrsvsWknDML2Mme9FyZfRnVZ1hTCoKzkooYAWT3dUDV' |
974 | 1001 … | } |
975 | 1002 … | class Root extends BaseContainer { |
976 | | - onMessage (m) { |
| 1003 … | + async onMessage (m) { |
977 | 1004 … | if (m.ports.length) { |
978 | 1005 … | const port = this.kernel.ports.get('test1') |
979 | 1006 … | this.kernel.send(port, m) |
980 | | - this.kernel.ports.unbind('test1') |
| 1007 … | + return this.kernel.ports.unbind('test1') |
981 | 1008 … | } else { |
982 | 1009 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
983 | 1010 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
984 | 1011 … | ports: [portRef2] |
985 | 1012 … | })) |
986 | | - this.kernel.ports.bind('test1', portRef1) |
| 1013 … | + await this.kernel.ports.bind('test1', portRef1) |
987 | 1014 … | |
988 | 1015 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
989 | 1016 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
990 | 1017 … | ports: [portRef4] |
991 | 1018 … | })) |
992 | | - this.kernel.ports.bind('test2', portRef3) |
| 1019 … | + await this.kernel.ports.bind('test2', portRef3) |
993 | 1020 … | this.kernel.send(portRef3, this.kernel.createMessage({ |
994 | 1021 … | data: 'getChannel' |
995 | 1022 … | })) |
996 | 1023 … | } |
1000 | 1027 … | class Sub extends BaseContainer { |
1001 | 1028 … | onMessage (message) { |
1002 | 1029 … | if (message.data === 'getChannel') { |
1003 | 1030 … | const ports = this.kernel.ports.createChannel() |
1004 | | - this.kernel.ports.bind('channel', ports[0]) |
1005 | 1031 … | this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1006 | 1032 … | data: 'bindPort', |
1007 | 1033 … | ports: [ports[1]] |
1008 | 1034 … | })) |
| 1035 … | + return this.kernel.ports.bind('channel', ports[0]) |
1009 | 1036 … | } else if (message.data === 'bindPort') { |
1010 | | - this.kernel.ports.bind('channel', message.ports[0]) |
| 1037 … | + return this.kernel.ports.bind('channel', message.ports[0]) |
1011 | 1038 … | } |
1012 | 1039 … | } |
1013 | 1040 … | static get typeId () { |
1014 | 1041 … | return 299 |
1021 | 1048 … | hypervisor.registerContainer(Sub) |
1022 | 1049 … | |
1023 | 1050 … | const root = await hypervisor.createInstance(Root.typeId) |
1024 | 1051 … | const [portRef1, portRef2] = root.ports.createChannel() |
1025 | | - root.ports.bind('first', portRef1) |
| 1052 … | + await root.ports.bind('first', portRef1) |
1026 | 1053 … | root.createInstance(Root.typeId, root.createMessage({ |
1027 | 1054 … | ports: [portRef2] |
1028 | 1055 … | })) |
1029 | 1056 … | |
1036 | 1063 … | }) |
1037 | 1064 … | |
1038 | 1065 … | tape('should remove multiple subgraphs', async t => { |
1039 | 1066 … | const expectedSr = { |
1040 | | - '/': 'zdpuAvQqoEnojZHaw6dMDy8ACRVqfarfD2RCKTwFBYsj8suRC' |
| 1067 … | + '/': 'zdpuAohccQTxM82d8N6Q82z234nQskeQoJGJu3eAVmxoQwWde' |
1041 | 1068 … | } |
1042 | 1069 … | class Root extends BaseContainer { |
1043 | | - onMessage (m) { |
| 1070 … | + async onMessage (m) { |
1044 | 1071 … | if (m.ports.length) { |
1045 | 1072 … | const port = this.kernel.ports.get('test1') |
1046 | 1073 … | this.kernel.send(port, m) |
1047 | | - this.kernel.ports.unbind('test1') |
1048 | | - this.kernel.ports.unbind('test2') |
| 1074 … | + await this.kernel.ports.unbind('test1') |
| 1075 … | + await this.kernel.ports.unbind('test2') |
1049 | 1076 … | } else { |
1050 | 1077 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1051 | 1078 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1052 | 1079 … | ports: [portRef2] |
1053 | 1080 … | })) |
1054 | | - this.kernel.ports.bind('test1', portRef1) |
| 1081 … | + await this.kernel.ports.bind('test1', portRef1) |
1055 | 1082 … | |
1056 | 1083 … | const [portRef3, portRef4] = this.kernel.ports.createChannel() |
1057 | 1084 … | this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1058 | 1085 … | ports: [portRef4] |
1059 | 1086 … | })) |
1060 | | - this.kernel.ports.bind('test2', portRef3) |
| 1087 … | + await this.kernel.ports.bind('test2', portRef3) |
1061 | 1088 … | this.kernel.send(portRef3, this.kernel.createMessage({ |
1062 | 1089 … | data: 'getChannel' |
1063 | 1090 … | })) |
1064 | 1091 … | } |
1068 | 1095 … | class Sub extends BaseContainer { |
1069 | 1096 … | onMessage (message) { |
1070 | 1097 … | if (message.data === 'getChannel') { |
1071 | 1098 … | const ports = this.kernel.ports.createChannel() |
1072 | | - this.kernel.ports.bind('channel', ports[0]) |
1073 | 1099 … | this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1074 | 1100 … | data: 'bindPort', |
1075 | 1101 … | ports: [ports[1]] |
1076 | 1102 … | })) |
| 1103 … | + return this.kernel.ports.bind('channel', ports[0]) |
1077 | 1104 … | } else if (message.data === 'bindPort') { |
1078 | | - this.kernel.ports.bind('channel', message.ports[0]) |
| 1105 … | + return this.kernel.ports.bind('channel', message.ports[0]) |
1079 | 1106 … | } |
1080 | 1107 … | } |
1081 | 1108 … | static get typeId () { |
1082 | 1109 … | return 299 |
1090 | 1117 … | |
1091 | 1118 … | const root = await hypervisor.createInstance(Root.typeId) |
1092 | 1119 … | |
1093 | 1120 … | const [portRef1, portRef2] = root.ports.createChannel() |
1094 | | - root.ports.bind('first', portRef1) |
| 1121 … | + await root.ports.bind('first', portRef1) |
1095 | 1122 … | root.createInstance(Root.typeId, root.createMessage({ |
1096 | 1123 … | ports: [portRef2] |
1097 | 1124 … | })) |
1098 | 1125 … | |
1132 | 1159 … | }) |
1133 | 1160 … | |
1134 | 1161 … | rootContainer.createInstance(testVMContainer.typeId, initMessage) |
1135 | 1162 … | |
1136 | | - rootContainer.ports.bind('first', portRef1) |
| 1163 … | + await rootContainer.ports.bind('first', portRef1) |
1137 | 1164 … | const message = rootContainer.createMessage() |
1138 | 1165 … | const rPort = rootContainer.getResponsePort(message) |
1139 | 1166 … | const rPort2 = rootContainer.getResponsePort(message) |
1140 | 1167 … | |
1141 | 1168 … | t.equals(rPort2, rPort) |
1142 | 1169 … | |
1143 | 1170 … | rootContainer.send(portRef1, message) |
1144 | | - rootContainer.ports.bind('response', rPort) |
| 1171 … | + await rootContainer.ports.bind('response', rPort) |
1145 | 1172 … | }) |
1146 | 1173 … | |
1147 | 1174 … | tape('start up', async t => { |
1148 | 1175 … | t.plan(1) |