tests/index.jsView |
---|
18 | 18 … | Object.getOwnPropertyNames(this.prototype).filter(name => name !== 'constructor').forEach(name => { |
19 | 19 … | exp[name] = {} |
20 | 20 … | }) |
21 | 21 … | return { |
22 | | - modRef: new ModuleRef(exp, id), |
| 22 … | + actor: new ModuleRef(exp, id), |
23 | 23 … | state: [] |
24 | 24 … | } |
25 | 25 … | } |
26 | 26 … | onMessage (message) { |
60 | 60 … | } |
61 | 61 … | } |
62 | 62 … | |
63 | 63 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainer]}) |
64 | | - const {module} = hypervisor.createActor(testVMContainer.typeId) |
| 64 … | + const actor = hypervisor.createActor(testVMContainer.typeId) |
65 | 65 … | const message = new Message({ |
66 | | - funcRef: module.getFuncRef('store') |
| 66 … | + funcRef: actor.getFuncRef('store') |
67 | 67 … | }) |
68 | 68 … | |
69 | 69 … | hypervisor.send(message) |
70 | 70 … | await hypervisor.createStateRoot() |
71 | 71 … | |
72 | 72 … | const message2 = new Message({ |
73 | | - funcRef: module.getFuncRef('load') |
| 73 … | + funcRef: actor.getFuncRef('load') |
74 | 74 … | }) |
75 | 75 … | hypervisor.send(message2) |
76 | 76 … | await hypervisor.createStateRoot() |
77 | 77 … | t.end() |
92 | 92 … | |
93 | 93 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainer]}) |
94 | 94 … | await hypervisor.createStateRoot() |
95 | 95 … | |
96 | | - const {module} = hypervisor.createActor(testVMContainer.typeId) |
| 96 … | + const actor = hypervisor.createActor(testVMContainer.typeId) |
97 | 97 … | |
98 | 98 … | const message = new Message({ |
99 | | - funcRef: module.getFuncRef('main'), |
| 99 … | + funcRef: actor.getFuncRef('main'), |
100 | 100 … | funcArguments: [1] |
101 | 101 … | }) |
102 | 102 … | hypervisor.send(message) |
103 | 103 … | |
134 | 134 … | } |
135 | 135 … | |
136 | 136 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]}) |
137 | 137 … | |
138 | | - const {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId) |
139 | | - const {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId) |
| 138 … | + const actorB = hypervisor.createActor(testVMContainerB.typeId) |
| 139 … | + const actorA = hypervisor.createActor(testVMContainerA.typeId) |
140 | 140 … | |
141 | 141 … | const message = new Message({ |
142 | | - funcRef: moduleA.getFuncRef('main'), |
143 | | - funcArguments: [moduleB.getFuncRef('main')] |
| 142 … | + funcRef: actorA.getFuncRef('main'), |
| 143 … | + funcArguments: [actorB.getFuncRef('main')] |
144 | 144 … | }) |
145 | 145 … | |
146 | 146 … | hypervisor.send(message) |
147 | 147 … | |
177 | 177 … | } |
178 | 178 … | |
179 | 179 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]}) |
180 | 180 … | |
181 | | - let {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId) |
182 | | - let {module: moduleA0} = hypervisor.createActor(testVMContainerA.typeId) |
183 | | - let {module: moduleA1} = hypervisor.createActor(testVMContainerA.typeId) |
| 181 … | + let actorB = hypervisor.createActor(testVMContainerB.typeId) |
| 182 … | + let actorA0 = hypervisor.createActor(testVMContainerA.typeId) |
| 183 … | + let actorA1 = hypervisor.createActor(testVMContainerA.typeId) |
184 | 184 … | |
185 | 185 … | const message0 = new Message({ |
186 | | - funcRef: moduleA0.getFuncRef('main'), |
187 | | - funcArguments: [moduleB.getFuncRef('main')] |
| 186 … | + funcRef: actorA0.getFuncRef('main'), |
| 187 … | + funcArguments: [actorB.getFuncRef('main')] |
188 | 188 … | }) |
189 | 189 … | |
190 | 190 … | const message1 = new Message({ |
191 | | - funcRef: moduleA1.getFuncRef('main'), |
192 | | - funcArguments: [moduleB.getFuncRef('main')] |
| 191 … | + funcRef: actorA1.getFuncRef('main'), |
| 192 … | + funcArguments: [actorB.getFuncRef('main')] |
193 | 193 … | }) |
194 | 194 … | |
195 | 195 … | await hypervisor.send(message0) |
196 | 196 … | await hypervisor.send(message1) |
202 | 202 … | tape('three communicating actors, with tick counting', async t => { |
203 | 203 … | t.plan(3) |
204 | 204 … | const expectedState = Buffer.from('ae2e8afa84748192064ddebab30d0e9852ceb722', 'hex') |
205 | 205 … | const tree = new RadixTree({ |
206 | | - db: db |
| 206 … | + db |
207 | 207 … | }) |
208 | 208 … | |
209 | 209 … | class testVMContainerA extends BaseContainer { |
210 | 210 … | main (funcRef) { |
|
232 | 232 … | let actorB = hypervisor.createActor(testVMContainerB.typeId) |
233 | 233 … | let actorA0 = hypervisor.createActor(testVMContainerA.typeId) |
234 | 234 … | let actorA1 = hypervisor.createActor(testVMContainerA.typeId) |
235 | 235 … | |
236 | | - const funcRef0 = actorA0.module.getFuncRef('main') |
| 236 … | + const funcRef0 = actorA0.getFuncRef('main') |
237 | 237 … | funcRef0.gas = 10000 |
238 | 238 … | |
239 | 239 … | const message0 = new Message({ |
240 | 240 … | funcRef: funcRef0, |
241 | | - funcArguments: [actorB.module.getFuncRef('main')] |
| 241 … | + funcArguments: [actorB.getFuncRef('main')] |
242 | 242 … | }) |
243 | | - const funcRef1 = actorA1.module.getFuncRef('main') |
| 243 … | + const funcRef1 = actorA1.getFuncRef('main') |
244 | 244 … | funcRef1.gas = 10000 |
245 | 245 … | const message1 = new Message({ |
246 | 246 … | funcRef: funcRef1, |
247 | | - funcArguments: [actorB.module.getFuncRef('main')] |
| 247 … | + funcArguments: [actorB.getFuncRef('main')] |
248 | 248 … | }) |
249 | 249 … | |
250 | 250 … | hypervisor.send(message0) |
251 | 251 … | hypervisor.send(message1) |
287 | 287 … | const hypervisor = new Hypervisor({tree}) |
288 | 288 … | hypervisor.registerContainer(testVMContainerA) |
289 | 289 … | hypervisor.registerContainer(testVMContainerB) |
290 | 290 … | |
291 | | - let {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId) |
292 | | - let {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId) |
| 291 … | + let actorB = hypervisor.createActor(testVMContainerB.typeId) |
| 292 … | + let actorA = hypervisor.createActor(testVMContainerA.typeId) |
293 | 293 … | const message = new Message({ |
294 | | - funcRef: moduleA.getFuncRef('main'), |
295 | | - funcArguments: [moduleB.getFuncRef('main')] |
| 294 … | + funcRef: actorA.getFuncRef('main'), |
| 295 … | + funcArguments: [actorB.getFuncRef('main')] |
296 | 296 … | }) |
297 | 297 … | hypervisor.send(message) |
298 | 298 … | const stateRoot = await hypervisor.createStateRoot() |
299 | 299 … | t.deepEquals(stateRoot, expectedState, 'expected root!') |
313 | 313 … | |
314 | 314 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainer]}) |
315 | 315 … | await hypervisor.createStateRoot() |
316 | 316 … | |
317 | | - const {module} = hypervisor.createActor(testVMContainer.typeId) |
| 317 … | + const actor = hypervisor.createActor(testVMContainer.typeId) |
318 | 318 … | |
319 | 319 … | const message = new Message({ |
320 | | - funcRef: module.getFuncRef('main'), |
| 320 … | + funcRef: actor.getFuncRef('main'), |
321 | 321 … | funcArguments: [1] |
322 | 322 … | }).on('execution:error', e => { |
323 | 323 … | t.equals(e.message, errors.OUT_OF_GAS) |
324 | 324 … | }) |
344 | 344 … | meter: false |
345 | 345 … | }) |
346 | 346 … | await hypervisor.createStateRoot() |
347 | 347 … | |
348 | | - const {module} = hypervisor.createActor(testVMContainer.typeId) |
| 348 … | + const actor = hypervisor.createActor(testVMContainer.typeId) |
349 | 349 … | |
350 | 350 … | const message = new Message({ |
351 | | - funcRef: module.getFuncRef('main'), |
| 351 … | + funcRef: actor.getFuncRef('main'), |
352 | 352 … | funcArguments: [1] |
353 | 353 … | }) |
354 | 354 … | hypervisor.send(message) |
355 | 355 … | }) |
363 | 363 … | }) |
364 | 364 … | |
365 | 365 … | class testVMContainerA extends BaseContainer { |
366 | 366 … | async start (funcRef) { |
367 | | - const {module} = this.actor.createActor(testVMContainerB.typeId) |
| 367 … | + const actor = this.actor.createActor(testVMContainerB.typeId) |
368 | 368 … | const message = new Message({ |
369 | | - funcRef: module.getFuncRef('main'), |
| 369 … | + funcRef: actor.getFuncRef('main'), |
370 | 370 … | funcArguments: [{ |
371 | 371 … | identifier: [0, 'main'], |
372 | 372 … | actorID: this.actor.id |
373 | 373 … | }] |
390 | 390 … | } |
391 | 391 … | |
392 | 392 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]}) |
393 | 393 … | |
394 | | - const {module} = hypervisor.createActor(testVMContainerA.typeId) |
395 | | - await hypervisor.send(new Message({funcRef: module.getFuncRef('start')})) |
| 394 … | + const actor = hypervisor.createActor(testVMContainerA.typeId) |
| 395 … | + await hypervisor.send(new Message({funcRef: actor.getFuncRef('start')})) |
396 | 396 … | |
397 | 397 … | const stateRoot = await hypervisor.createStateRoot() |
398 | 398 … | t.deepEquals(stateRoot, expectedState, 'expected root!') |
399 | 399 … | t.end() |
450 | 450 … | } |
451 | 451 … | |
452 | 452 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]}) |
453 | 453 … | |
454 | | - const {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId) |
455 | | - const {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId) |
456 | | - const funcRef = moduleA.getFuncRef('main') |
| 454 … | + const actorB = hypervisor.createActor(testVMContainerB.typeId) |
| 455 … | + const actorA = hypervisor.createActor(testVMContainerA.typeId) |
| 456 … | + const funcRef = actorA.getFuncRef('main') |
457 | 457 … | funcRef.gas = 4000 |
458 | 458 … | |
459 | 459 … | const message = new Message({ |
460 | 460 … | funcRef, |
461 | | - funcArguments: [moduleB.getFuncRef('main')] |
| 461 … | + funcArguments: [actorB.getFuncRef('main')] |
462 | 462 … | }) |
463 | 463 … | hypervisor.send(message) |
464 | 464 … | |
465 | 465 … | const stateRoot = await hypervisor.createStateRoot() |
505 | 505 … | } |
506 | 506 … | |
507 | 507 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]}) |
508 | 508 … | |
509 | | - let {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId) |
| 509 … | + let actorB = hypervisor.createActor(testVMContainerB.typeId) |
510 | 510 … | hypervisor.send(new Message({ |
511 | | - funcRef: moduleB.getFuncRef('main'), |
| 511 … | + funcRef: actorB.getFuncRef('main'), |
512 | 512 … | funcArguments: ['first'] |
513 | 513 … | })) |
514 | 514 … | |
515 | 515 … | const sr1 = await hypervisor.createStateRoot() |
516 | 516 … | |
517 | | - const {module: moduleA0} = hypervisor.createActor(testVMContainerA.typeId) |
| 517 … | + const actorA0 = hypervisor.createActor(testVMContainerA.typeId) |
518 | 518 … | |
519 | 519 … | hypervisor.send(new Message({ |
520 | | - funcRef: moduleA0.getFuncRef('main'), |
521 | | - funcArguments: [moduleB.getFuncRef('main'), 'second'] |
| 520 … | + funcRef: actorA0.getFuncRef('main'), |
| 521 … | + funcArguments: [actorB.getFuncRef('main'), 'second'] |
522 | 522 … | })) |
523 | 523 … | |
524 | | - const {module: moduleA1} = hypervisor.createActor(testVMContainerA.typeId) |
| 524 … | + const actorA1 = hypervisor.createActor(testVMContainerA.typeId) |
525 | 525 … | hypervisor.send(new Message({ |
526 | | - funcRef: moduleA1.getFuncRef('main'), |
527 | | - funcArguments: [moduleB.getFuncRef('main'), 'third'] |
| 526 … | + funcRef: actorA1.getFuncRef('main'), |
| 527 … | + funcArguments: [actorB.getFuncRef('main'), 'third'] |
528 | 528 … | })) |
529 | 529 … | |
530 | 530 … | const stateRoot = await hypervisor.createStateRoot() |
531 | 531 … | t.deepEquals(stateRoot, expectedState, 'expected root!') |
578 | 578 … | } |
579 | 579 … | |
580 | 580 … | const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]}) |
581 | 581 … | |
582 | | - const {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId) |
583 | | - const {module: moduleA} = hypervisor.createActor(testVMContainerA.typeId) |
584 | | - const funcRef = moduleA.getFuncRef('main') |
| 582 … | + const actorB = hypervisor.createActor(testVMContainerB.typeId) |
| 583 … | + const actorA = hypervisor.createActor(testVMContainerA.typeId) |
| 584 … | + const funcRef = actorA.getFuncRef('main') |
585 | 585 … | funcRef.gas = 200 |
586 | 586 … | |
587 | 587 … | const message = new Message({ |
588 | 588 … | funcRef, |
589 | | - funcArguments: [moduleB.getFuncRef('main')] |
| 589 … | + funcArguments: [actorB.getFuncRef('main')] |
590 | 590 … | }) |
591 | 591 … | |
592 | 592 … | hypervisor.send(message) |
593 | 593 … | |
620 | 620 … | tree, |
621 | 621 … | containers: [testVMContainer], |
622 | 622 … | drivers: [egress] |
623 | 623 … | }) |
624 | | - const {module} = hypervisor.createActor(testVMContainer.typeId) |
| 624 … | + const actor = hypervisor.createActor(testVMContainer.typeId) |
625 | 625 … | |
626 | 626 … | const message = new Message({ |
627 | | - funcRef: module.getFuncRef('main'), |
| 627 … | + funcRef: actor.getFuncRef('main'), |
628 | 628 … | funcArguments: [new FunctionRef({actorID: egress.id})] |
629 | 629 … | }) |
630 | 630 … | |
631 | 631 … | hypervisor.send(message) |
668 | 668 … | |
669 | 669 … | const references = [] |
670 | 670 … | let _numOfActors = numOfActors |
671 | 671 … | while (_numOfActors--) { |
672 | | - const {module} = hypervisor.createActor(BenchmarkContainer.typeId) |
673 | | - const funcRef = module.getFuncRef('main') |
| 672 … | + const actor = hypervisor.createActor(BenchmarkContainer.typeId) |
| 673 … | + const funcRef = actor.getFuncRef('main') |
674 | 674 … | references.push(funcRef) |
675 | 675 … | } |
676 | 676 … | _numOfActors = numOfActors |
677 | 677 … | const msgs = [] |