tests/index.jsView |
---|
1 | 1 | const tape = require('tape') |
2 | 2 | const AbstractContainer = require('primea-abstract-container') |
3 | 3 | const Message = require('primea-message') |
4 | 4 | const Hypervisor = require('../') |
5 | | -const CapsStore = require('../capsStore.js') |
6 | 5 | |
7 | 6 | const level = require('level-browserify') |
8 | 7 | const RadixTree = require('dfinity-radix-tree') |
9 | 8 | const db = level('./testdb') |
18 | 17 | tape('basic', async t => { |
19 | 18 | t.plan(2) |
20 | 19 | let message |
21 | 20 | const expectedState = { |
22 | | - '/': Buffer.from('70a9676b7995b108057bd29955e3874401aa5ba7', 'hex') |
| 21 | + '/': Buffer.from('a364c55f9993e0bc63f7155d5eb661ae9ad769d9', 'hex') |
23 | 22 | } |
24 | 23 | |
25 | 24 | const tree = new RadixTree({ |
26 | 25 | db: db |
39 | 38 | |
40 | 39 | message = new Message() |
41 | 40 | hypervisor.send(rootCap, message) |
42 | 41 | |
43 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 42 | + const stateRoot = await hypervisor.createStateRoot() |
44 | 43 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
45 | 44 | }) |
46 | 45 | |
47 | | -tape('caps manager', async t => { |
48 | | - const capsManager = new CapsStore({}) |
49 | | - const cap = {} |
50 | | - capsManager.store('test', cap) |
51 | | - const c = capsManager.load('test') |
52 | | - t.equals(cap, c) |
53 | | - capsManager.delete('test') |
54 | | - const empty = capsManager.load('test') |
55 | | - t.equals(empty, undefined) |
56 | | - t.end() |
57 | | -}) |
58 | | - |
59 | 46 | tape('two communicating actors', async t => { |
60 | 47 | t.plan(2) |
61 | 48 | let message |
62 | 49 | const expectedState = { |
63 | | - '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
| 50 | + '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex') |
64 | 51 | } |
65 | 52 | |
66 | 53 | const tree = new RadixTree({ |
67 | 54 | db: db |
92 | 79 | await hypervisor.createActor(testVMContainerA.typeId, new Message({ |
93 | 80 | caps: [capB] |
94 | 81 | })) |
95 | 82 | |
96 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
97 | | - |
| 83 | + const stateRoot = await hypervisor.createStateRoot() |
98 | 84 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
99 | 85 | }) |
100 | 86 | |
101 | 87 | tape('three communicating actors', async t => { |
102 | 88 | t.plan(3) |
103 | 89 | let message |
104 | 90 | const expectedState = { |
105 | | - '/': Buffer.from('24855a8efa9af536f0f9b319c05b10d6b7cae6c8', 'hex') |
| 91 | + '/': Buffer.from('840607eafe779858648d3311039f986e68f4752e', 'hex') |
106 | 92 | } |
107 | 93 | |
108 | 94 | const tree = new RadixTree({ |
109 | 95 | db: db |
138 | 124 | await hypervisor.createActor(testVMContainerA.typeId, new Message({ |
139 | 125 | caps: [capB] |
140 | 126 | })) |
141 | 127 | |
142 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
143 | | - |
| 128 | + const stateRoot = await hypervisor.createStateRoot() |
144 | 129 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
145 | 130 | }) |
146 | 131 | |
147 | 132 | tape('three communicating actors, with tick counting', async t => { |
148 | 133 | t.plan(3) |
149 | 134 | let message |
150 | 135 | const expectedState = { |
151 | | - '/': Buffer.from('24855a8efa9af536f0f9b319c05b10d6b7cae6c8', 'hex') |
| 136 | + '/': Buffer.from('840607eafe779858648d3311039f986e68f4752e', 'hex') |
152 | 137 | } |
153 | 138 | |
154 | 139 | const tree = new RadixTree({ |
155 | 140 | db: db |
188 | 173 | await hypervisor.createActor(testVMContainerA.typeId, new Message({ |
189 | 174 | caps: [capB] |
190 | 175 | })) |
191 | 176 | |
192 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 177 | + const stateRoot = await hypervisor.createStateRoot() |
193 | 178 | |
194 | 179 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
195 | 180 | }) |
196 | 181 | |
197 | 182 | tape('response caps', async t => { |
198 | 183 | t.plan(3) |
199 | 184 | let message |
200 | 185 | const expectedState = { |
201 | | - '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
| 186 | + '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex') |
202 | 187 | } |
203 | 188 | |
204 | 189 | const tree = new RadixTree({ |
205 | 190 | db: db |
235 | 220 | await hypervisor.createActor(testVMContainerA.typeId, new Message({ |
236 | 221 | caps: [capB] |
237 | 222 | })) |
238 | 223 | |
239 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 224 | + const stateRoot = await hypervisor.createStateRoot() |
240 | 225 | |
241 | 226 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
242 | 227 | }) |
243 | 228 | |
244 | 229 | tape('response caps for errors', async t => { |
245 | 230 | t.plan(3) |
246 | 231 | let message |
247 | 232 | const expectedState = { |
248 | | - '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
| 233 | + '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex') |
249 | 234 | } |
250 | 235 | |
251 | 236 | const tree = new RadixTree({ |
252 | 237 | db: db |
283 | 268 | await hypervisor.createActor(testVMContainerA.typeId, new Message({ |
284 | 269 | caps: [capB] |
285 | 270 | })) |
286 | 271 | |
287 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
288 | | - |
| 272 | + const stateRoot = await hypervisor.createStateRoot() |
289 | 273 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
290 | 274 | }) |
291 | 275 | |
292 | 276 | tape('actor creation', async t => { |
293 | 277 | t.plan(2) |
294 | 278 | let message |
295 | 279 | const expectedState = { |
296 | | - '/': Buffer.from('8e809b10d473ef4592dc5c1683e89bc7001e5e3e', 'hex') |
| 280 | + '/': Buffer.from('b19c67aea0ff97e96df6e2aacbd45b1bd260af30', 'hex') |
297 | 281 | } |
298 | 282 | |
299 | 283 | const tree = new RadixTree({ |
300 | 284 | db: db |
329 | 313 | hypervisor.registerContainer(testVMContainerB) |
330 | 314 | |
331 | 315 | await hypervisor.createActor(testVMContainerA.typeId, new Message()) |
332 | 316 | |
333 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
334 | | - |
| 317 | + const stateRoot = await hypervisor.createStateRoot() |
335 | 318 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
336 | 319 | }) |
337 | 320 | |
338 | 321 | tape('simple message arbiter test', async t => { |
339 | 322 | t.plan(4) |
340 | 323 | const expectedState = { |
341 | | - '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
| 324 | + '/': Buffer.from('9e8d5671e2c7d167e03784e5d9ec36e15747ad95', 'hex') |
342 | 325 | } |
343 | 326 | |
344 | 327 | const tree = new RadixTree({ |
345 | 328 | db: db |
391 | 374 | await hypervisor.createActor(testVMContainerA.typeId, new Message({ |
392 | 375 | caps: [capB] |
393 | 376 | })) |
394 | 377 | |
395 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
396 | | - |
| 378 | + const stateRoot = await hypervisor.createStateRoot() |
397 | 379 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
398 | 380 | }) |
399 | 381 | |
400 | 382 | tape('arbiter test for id comparision', async t => { |
401 | 383 | t.plan(4) |
402 | 384 | let message |
403 | 385 | const expectedState = { |
404 | | - '/': Buffer.from('0866fe6a6adaf28c51ce99ddfddd49c492e9ce48', 'hex') |
| 386 | + '/': Buffer.from('840607eafe779858648d3311039f986e68f4752e', 'hex') |
405 | 387 | } |
406 | 388 | |
407 | 389 | const tree = new RadixTree({ |
408 | 390 | db: db |
454 | 436 | caps: [capB], |
455 | 437 | data: 'third' |
456 | 438 | })) |
457 | 439 | |
458 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
459 | | - |
| 440 | + const stateRoot = await hypervisor.createStateRoot() |
460 | 441 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
461 | 442 | }) |
462 | 443 | |
463 | 444 | tape('basic tagged caps', async t => { |
464 | 445 | t.plan(4) |
465 | 446 | const expectedState = { |
466 | | - '/': Buffer.from('ef403643f292108fe9edc1700d80a7bf2402e7a0', 'hex') |
| 447 | + '/': Buffer.from('d4291da4536544bf90aa473a1148cb29f913d078', 'hex') |
467 | 448 | } |
468 | 449 | |
469 | 450 | const tree = new RadixTree({ |
470 | 451 | db: db |
500 | 481 | let capB = await hypervisor.createActor(testVMContainerB.typeId, new Message()) |
501 | 482 | |
502 | 483 | await hypervisor.send(capA, new Message({caps: [capB]})) |
503 | 484 | |
504 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
505 | | - |
| 485 | + const stateRoot = await hypervisor.createStateRoot() |
506 | 486 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
507 | 487 | }) |
508 | 488 | |
509 | 489 | tape('trying to listen for caps more then once', async t => { |
510 | 490 | t.plan(4) |
511 | 491 | const expectedState = { |
512 | | - '/': Buffer.from('ef403643f292108fe9edc1700d80a7bf2402e7a0', 'hex') |
| 492 | + '/': Buffer.from('d4291da4536544bf90aa473a1148cb29f913d078', 'hex') |
513 | 493 | } |
514 | 494 | |
515 | 495 | const tree = new RadixTree({ |
516 | 496 | db: db |
551 | 531 | let capB = await hypervisor.createActor(testVMContainerB.typeId, new Message()) |
552 | 532 | |
553 | 533 | await hypervisor.send(capA, new Message({caps: [capB]})) |
554 | 534 | |
555 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
556 | | - |
| 535 | + const stateRoot = await hypervisor.createStateRoot() |
557 | 536 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
558 | 537 | }) |
559 | 538 | |
560 | 539 | tape('multple messages to restore on waiting for tags', async t => { |
561 | 540 | t.plan(6) |
562 | 541 | const expectedState = { |
563 | | - '/': Buffer.from('c2bbd78ee38ecf417f857451bdb06cdba1345b22', 'hex') |
| 542 | + '/': Buffer.from('b5c0822ccb21bbaa2ad8069c4dcd18add7d6e2d1', 'hex') |
564 | 543 | } |
565 | 544 | |
566 | 545 | const tree = new RadixTree({ |
567 | 546 | db: db |
611 | 590 | let capB2 = await hypervisor.createActor(testVMContainerB.typeId, new Message()) |
612 | 591 | |
613 | 592 | await hypervisor.send(capA, new Message({caps: [capB1, capB2]})) |
614 | 593 | |
615 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 594 | + const stateRoot = await hypervisor.createStateRoot() |
616 | 595 | |
617 | 596 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
618 | 597 | }) |
619 | 598 | |
620 | 599 | tape('multple messages to backup on waiting for tags', async t => { |
621 | 600 | t.plan(6) |
622 | 601 | const expectedState = { |
623 | | - '/': Buffer.from('c2bbd78ee38ecf417f857451bdb06cdba1345b22', 'hex') |
| 602 | + '/': Buffer.from('b5c0822ccb21bbaa2ad8069c4dcd18add7d6e2d1', 'hex') |
624 | 603 | } |
625 | 604 | |
626 | 605 | const tree = new RadixTree({ |
627 | 606 | db: db |
671 | 650 | let capB2 = await hypervisor.createActor(testVMContainerB.typeId, new Message()) |
672 | 651 | |
673 | 652 | await hypervisor.send(capA, new Message({caps: [capB1, capB2]})) |
674 | 653 | |
675 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
676 | | - |
| 654 | + const stateRoot = await hypervisor.createStateRoot() |
677 | 655 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
678 | 656 | }) |
679 | 657 | |
680 | 658 | tape('multple messages, but single tag', async t => { |
681 | 659 | t.plan(6) |
682 | 660 | const expectedState = { |
683 | | - '/': Buffer.from('c2bbd78ee38ecf417f857451bdb06cdba1345b22', 'hex') |
| 661 | + '/': Buffer.from('b5c0822ccb21bbaa2ad8069c4dcd18add7d6e2d1', 'hex') |
684 | 662 | } |
685 | 663 | |
686 | 664 | const tree = new RadixTree({ |
687 | 665 | db: db |
731 | 709 | let capB2 = await hypervisor.createActor(testVMContainerB.typeId, new Message()) |
732 | 710 | |
733 | 711 | await hypervisor.send(capA, new Message({caps: [capB1, capB2]})) |
734 | 712 | |
735 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
736 | | - |
| 713 | + const stateRoot = await hypervisor.createStateRoot() |
737 | 714 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
738 | 715 | }) |
739 | 716 | |
740 | 717 | tape('deadlock test', async t => { |
741 | 718 | t.plan(7) |
742 | 719 | const expectedState = { |
743 | | - '/': Buffer.from('2e8658dc2f616599b4fa622318b86ad6ed809db0', 'hex') |
| 720 | + '/': Buffer.from('f290945ad63dd06b9ada924fa5149df4a0a32f53', 'hex') |
744 | 721 | } |
745 | 722 | |
746 | 723 | const tree = new RadixTree({ |
747 | 724 | db: db |
794 | 771 | hypervisor.send(capA, new Message()), |
795 | 772 | hypervisor.send(capB, new Message()), |
796 | 773 | hypervisor.send(capC, new Message()) |
797 | 774 | ]) |
798 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 775 | + const stateRoot = await hypervisor.createStateRoot() |
799 | 776 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
800 | 777 | }) |