git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit cc5033335b1996f393363b44254f957946b87199

createActor returns actor

wanderer committed on 4/27/2018, 7:03:24 PM
Parent: dcd4e757706b7946eff933674387a29bc6270077

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -75,9 +75,9 @@
7575 */
7676 createActor (type, code, id = {nonce: this.nonce++, parent: null}) {
7777 const Container = this._containerTypes[type]
7878 const actorId = generateActorId(id)
79- const {modRef: module, state} = Container.onCreation(code, actorId)
79 + const {actor, state} = Container.onCreation(code, actorId)
8080 const metaData = [type, 0]
8181
8282 // save the container in the state
8383 this.tree.set(actorId.id, metaData).then(node => {
@@ -90,12 +90,9 @@
9090 '/': state
9191 }
9292 })
9393
94- return {
95- id: actorId,
96- module
97- }
94 + return actor
9895 }
9996
10097 /**
10198 * creates a state root starting from a given container and a given number of
tests/index.jsView
@@ -18,9 +18,9 @@
1818 Object.getOwnPropertyNames(this.prototype).filter(name => name !== 'constructor').forEach(name => {
1919 exp[name] = {}
2020 })
2121 return {
22- modRef: new ModuleRef(exp, id),
22 + actor: new ModuleRef(exp, id),
2323 state: []
2424 }
2525 }
2626 onMessage (message) {
@@ -60,18 +60,18 @@
6060 }
6161 }
6262
6363 const hypervisor = new Hypervisor({tree, containers: [testVMContainer]})
64- const {module} = hypervisor.createActor(testVMContainer.typeId)
64 + const actor = hypervisor.createActor(testVMContainer.typeId)
6565 const message = new Message({
66- funcRef: module.getFuncRef('store')
66 + funcRef: actor.getFuncRef('store')
6767 })
6868
6969 hypervisor.send(message)
7070 await hypervisor.createStateRoot()
7171
7272 const message2 = new Message({
73- funcRef: module.getFuncRef('load')
73 + funcRef: actor.getFuncRef('load')
7474 })
7575 hypervisor.send(message2)
7676 await hypervisor.createStateRoot()
7777 t.end()
@@ -92,12 +92,12 @@
9292
9393 const hypervisor = new Hypervisor({tree, containers: [testVMContainer]})
9494 await hypervisor.createStateRoot()
9595
96- const {module} = hypervisor.createActor(testVMContainer.typeId)
96 + const actor = hypervisor.createActor(testVMContainer.typeId)
9797
9898 const message = new Message({
99- funcRef: module.getFuncRef('main'),
99 + funcRef: actor.getFuncRef('main'),
100100 funcArguments: [1]
101101 })
102102 hypervisor.send(message)
103103
@@ -134,14 +134,14 @@
134134 }
135135
136136 const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]})
137137
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)
140140
141141 const message = new Message({
142- funcRef: moduleA.getFuncRef('main'),
143- funcArguments: [moduleB.getFuncRef('main')]
142 + funcRef: actorA.getFuncRef('main'),
143 + funcArguments: [actorB.getFuncRef('main')]
144144 })
145145
146146 hypervisor.send(message)
147147
@@ -177,20 +177,20 @@
177177 }
178178
179179 const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]})
180180
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)
184184
185185 const message0 = new Message({
186- funcRef: moduleA0.getFuncRef('main'),
187- funcArguments: [moduleB.getFuncRef('main')]
186 + funcRef: actorA0.getFuncRef('main'),
187 + funcArguments: [actorB.getFuncRef('main')]
188188 })
189189
190190 const message1 = new Message({
191- funcRef: moduleA1.getFuncRef('main'),
192- funcArguments: [moduleB.getFuncRef('main')]
191 + funcRef: actorA1.getFuncRef('main'),
192 + funcArguments: [actorB.getFuncRef('main')]
193193 })
194194
195195 await hypervisor.send(message0)
196196 await hypervisor.send(message1)
@@ -202,9 +202,9 @@
202202 tape('three communicating actors, with tick counting', async t => {
203203 t.plan(3)
204204 const expectedState = Buffer.from('ae2e8afa84748192064ddebab30d0e9852ceb722', 'hex')
205205 const tree = new RadixTree({
206- db: db
206 + db
207207 })
208208
209209 class testVMContainerA extends BaseContainer {
210210 main (funcRef) {
@@ -232,20 +232,20 @@
232232 let actorB = hypervisor.createActor(testVMContainerB.typeId)
233233 let actorA0 = hypervisor.createActor(testVMContainerA.typeId)
234234 let actorA1 = hypervisor.createActor(testVMContainerA.typeId)
235235
236- const funcRef0 = actorA0.module.getFuncRef('main')
236 + const funcRef0 = actorA0.getFuncRef('main')
237237 funcRef0.gas = 10000
238238
239239 const message0 = new Message({
240240 funcRef: funcRef0,
241- funcArguments: [actorB.module.getFuncRef('main')]
241 + funcArguments: [actorB.getFuncRef('main')]
242242 })
243- const funcRef1 = actorA1.module.getFuncRef('main')
243 + const funcRef1 = actorA1.getFuncRef('main')
244244 funcRef1.gas = 10000
245245 const message1 = new Message({
246246 funcRef: funcRef1,
247- funcArguments: [actorB.module.getFuncRef('main')]
247 + funcArguments: [actorB.getFuncRef('main')]
248248 })
249249
250250 hypervisor.send(message0)
251251 hypervisor.send(message1)
@@ -287,13 +287,13 @@
287287 const hypervisor = new Hypervisor({tree})
288288 hypervisor.registerContainer(testVMContainerA)
289289 hypervisor.registerContainer(testVMContainerB)
290290
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)
293293 const message = new Message({
294- funcRef: moduleA.getFuncRef('main'),
295- funcArguments: [moduleB.getFuncRef('main')]
294 + funcRef: actorA.getFuncRef('main'),
295 + funcArguments: [actorB.getFuncRef('main')]
296296 })
297297 hypervisor.send(message)
298298 const stateRoot = await hypervisor.createStateRoot()
299299 t.deepEquals(stateRoot, expectedState, 'expected root!')
@@ -313,12 +313,12 @@
313313
314314 const hypervisor = new Hypervisor({tree, containers: [testVMContainer]})
315315 await hypervisor.createStateRoot()
316316
317- const {module} = hypervisor.createActor(testVMContainer.typeId)
317 + const actor = hypervisor.createActor(testVMContainer.typeId)
318318
319319 const message = new Message({
320- funcRef: module.getFuncRef('main'),
320 + funcRef: actor.getFuncRef('main'),
321321 funcArguments: [1]
322322 }).on('execution:error', e => {
323323 t.equals(e.message, errors.OUT_OF_GAS)
324324 })
@@ -344,12 +344,12 @@
344344 meter: false
345345 })
346346 await hypervisor.createStateRoot()
347347
348- const {module} = hypervisor.createActor(testVMContainer.typeId)
348 + const actor = hypervisor.createActor(testVMContainer.typeId)
349349
350350 const message = new Message({
351- funcRef: module.getFuncRef('main'),
351 + funcRef: actor.getFuncRef('main'),
352352 funcArguments: [1]
353353 })
354354 hypervisor.send(message)
355355 })
@@ -363,11 +363,11 @@
363363 })
364364
365365 class testVMContainerA extends BaseContainer {
366366 async start (funcRef) {
367- const {module} = this.actor.createActor(testVMContainerB.typeId)
367 + const actor = this.actor.createActor(testVMContainerB.typeId)
368368 const message = new Message({
369- funcRef: module.getFuncRef('main'),
369 + funcRef: actor.getFuncRef('main'),
370370 funcArguments: [{
371371 identifier: [0, 'main'],
372372 actorID: this.actor.id
373373 }]
@@ -390,10 +390,10 @@
390390 }
391391
392392 const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]})
393393
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')}))
396396
397397 const stateRoot = await hypervisor.createStateRoot()
398398 t.deepEquals(stateRoot, expectedState, 'expected root!')
399399 t.end()
@@ -450,16 +450,16 @@
450450 }
451451
452452 const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]})
453453
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')
457457 funcRef.gas = 4000
458458
459459 const message = new Message({
460460 funcRef,
461- funcArguments: [moduleB.getFuncRef('main')]
461 + funcArguments: [actorB.getFuncRef('main')]
462462 })
463463 hypervisor.send(message)
464464
465465 const stateRoot = await hypervisor.createStateRoot()
@@ -505,27 +505,27 @@
505505 }
506506
507507 const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]})
508508
509- let {module: moduleB} = hypervisor.createActor(testVMContainerB.typeId)
509 + let actorB = hypervisor.createActor(testVMContainerB.typeId)
510510 hypervisor.send(new Message({
511- funcRef: moduleB.getFuncRef('main'),
511 + funcRef: actorB.getFuncRef('main'),
512512 funcArguments: ['first']
513513 }))
514514
515515 const sr1 = await hypervisor.createStateRoot()
516516
517- const {module: moduleA0} = hypervisor.createActor(testVMContainerA.typeId)
517 + const actorA0 = hypervisor.createActor(testVMContainerA.typeId)
518518
519519 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']
522522 }))
523523
524- const {module: moduleA1} = hypervisor.createActor(testVMContainerA.typeId)
524 + const actorA1 = hypervisor.createActor(testVMContainerA.typeId)
525525 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']
528528 }))
529529
530530 const stateRoot = await hypervisor.createStateRoot()
531531 t.deepEquals(stateRoot, expectedState, 'expected root!')
@@ -578,16 +578,16 @@
578578 }
579579
580580 const hypervisor = new Hypervisor({tree, containers: [testVMContainerA, testVMContainerB]})
581581
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')
585585 funcRef.gas = 200
586586
587587 const message = new Message({
588588 funcRef,
589- funcArguments: [moduleB.getFuncRef('main')]
589 + funcArguments: [actorB.getFuncRef('main')]
590590 })
591591
592592 hypervisor.send(message)
593593
@@ -620,12 +620,12 @@
620620 tree,
621621 containers: [testVMContainer],
622622 drivers: [egress]
623623 })
624- const {module} = hypervisor.createActor(testVMContainer.typeId)
624 + const actor = hypervisor.createActor(testVMContainer.typeId)
625625
626626 const message = new Message({
627- funcRef: module.getFuncRef('main'),
627 + funcRef: actor.getFuncRef('main'),
628628 funcArguments: [new FunctionRef({actorID: egress.id})]
629629 })
630630
631631 hypervisor.send(message)
@@ -668,10 +668,10 @@
668668
669669 const references = []
670670 let _numOfActors = numOfActors
671671 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')
674674 references.push(funcRef)
675675 }
676676 _numOfActors = numOfActors
677677 const msgs = []

Built with git-ssb-web