git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e0e219228a47a0ba7de5d933251a480f1bacf2ae

store nonce in state

wanderer committed on 3/28/2018, 11:57:27 PM
Parent: 3f06f72bb36d2b3efb72366b6b5db8a966a3273a

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -19,8 +19,9 @@
1919 containers.forEach(container => this.registerContainer(container))
2020 drivers.forEach(driver => this.registerDriver(driver))
2121 }
2222
23+
2324 /**
2425 * sends a message
2526 * @param {Object} message - the [message](https://github.com/primea/js-primea-message) to send
2627 * @returns {Promise} a promise that resolves once the receiving container is loaded
@@ -107,14 +108,18 @@
107108 await new Promise((resolve, reject) => {
108109 this.scheduler.once('idle', resolve)
109110 })
110111 }
111- return this.tree.flush().then(sr => {
112- console.log(sr.toString('hex'))
113- return sr
114- })
112+ await this.tree.set(Buffer.from([0]), this.nonce)
113+ return this.tree.flush()
115114 }
116115
116+ async setStateRoot (stateRoot) {
117+ this.tree.root = stateRoot
118+ const node = await this.tree.get(Buffer.from([0]))
119+ this.nonce = node.value
120+ }
121+
117122 /**
118123 * regirsters a container with the hypervisor
119124 * @param {Class} Constructor - a Class for instantiating the container
120125 * @param {*} args - any args that the contructor takes
tests/index.jsView
@@ -74,9 +74,9 @@
7474 })
7575
7676 tape('basic', async t => {
7777 t.plan(2)
78- const expectedState = Buffer.from('e3669fbd4ee56f958d9090f60617f3a50cd8062b', 'hex')
78+ const expectedState = Buffer.from('32b919149345b74e431c42a1b7dd65c30c625284', 'hex')
7979 const tree = new RadixTree({
8080 db
8181 })
8282
@@ -102,9 +102,9 @@
102102 })
103103
104104 tape('two communicating actors', async t => {
105105 t.plan(2)
106- const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', 'hex')
106+ const expectedState = Buffer.from('7f638e41261bc0238c3e9b34fce11827b6a3cb61', 'hex')
107107
108108 const tree = new RadixTree({
109109 db
110110 })
@@ -146,9 +146,9 @@
146146 })
147147
148148 tape('three communicating actors', async t => {
149149 t.plan(3)
150- const expectedState = Buffer.from('622078699d4688e09c4930b49c6e465c9fbbcc07', 'hex')
150+ const expectedState = Buffer.from('ae2e8afa84748192064ddebab30d0e9852ceb722', 'hex')
151151 const tree = new RadixTree({
152152 db: db
153153 })
154154
@@ -196,9 +196,9 @@
196196 })
197197
198198 tape('three communicating actors, with tick counting', async t => {
199199 t.plan(3)
200- const expectedState = Buffer.from('622078699d4688e09c4930b49c6e465c9fbbcc07', 'hex')
200+ const expectedState = Buffer.from('ae2e8afa84748192064ddebab30d0e9852ceb722', 'hex')
201201 const tree = new RadixTree({
202202 db: db
203203 })
204204
@@ -246,9 +246,9 @@
246246 })
247247
248248 tape('errors', async t => {
249249 t.plan(3)
250- const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', 'hex')
250+ const expectedState = Buffer.from('7f638e41261bc0238c3e9b34fce11827b6a3cb61', 'hex')
251251 const tree = new RadixTree({
252252 db
253253 })
254254
@@ -291,9 +291,9 @@
291291 })
292292
293293 tape('actor creation', async t => {
294294 t.plan(2)
295- const expectedState = Buffer.from('09ada4d5ccb874b5767ea4aaf6081437eb36b3e0', 'hex')
295+ const expectedState = Buffer.from('0e6d32f2fe8b5b99f0203eb46bfc7e319a07f700', 'hex')
296296
297297 const tree = new RadixTree({
298298 db
299299 })
@@ -338,9 +338,9 @@
338338 })
339339
340340 tape('simple message arbiter test', async t => {
341341 t.plan(4)
342- const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', 'hex')
342+ const expectedState = Buffer.from('7f638e41261bc0238c3e9b34fce11827b6a3cb61', 'hex')
343343 const tree = new RadixTree({
344344 db
345345 })
346346
@@ -402,11 +402,11 @@
402402 t.deepEquals(stateRoot, expectedState, 'expected root!')
403403 })
404404
405405 tape('arbiter test for id comparision', async t => {
406- t.plan(4)
406+ // t.plan(4)
407407 let message
408- const expectedState = Buffer.from('622078699d4688e09c4930b49c6e465c9fbbcc07', 'hex')
408+ const expectedState = Buffer.from('ae2e8afa84748192064ddebab30d0e9852ceb722', 'hex')
409409
410410 const tree = new RadixTree({
411411 db: db
412412 })
@@ -450,8 +450,10 @@
450450 funcRef: moduleB.getFuncRef('main'),
451451 funcArguments: ['first']
452452 }))
453453
454+ const sr1 = await hypervisor.createStateRoot()
455+
454456 const {module: moduleA0} = hypervisor.createActor(testVMContainerA.typeId)
455457
456458 hypervisor.send(new Message({
457459 funcRef: moduleA0.getFuncRef('main'),
@@ -465,13 +467,17 @@
465467 }))
466468
467469 const stateRoot = await hypervisor.createStateRoot()
468470 t.deepEquals(stateRoot, expectedState, 'expected root!')
471+
472+ await hypervisor.setStateRoot(sr1)
473+ t.equals(hypervisor.nonce, 1, 'should get the correct nonce')
474+ t.end()
469475 })
470476
471477 tape('async work', async t => {
472478 t.plan(3)
473- const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', 'hex')
479+ const expectedState = Buffer.from('7f638e41261bc0238c3e9b34fce11827b6a3cb61', 'hex')
474480
475481 const tree = new RadixTree({
476482 db
477483 })

Built with git-ssb-web