git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 3f06f72bb36d2b3efb72366b6b5db8a966a3273a

fix nonce encodeing

wanderer committed on 3/28/2018, 12:02:42 AM
Parent: b9ba5b15445f78c8ddf04e0c79f6e5d9caead624

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -1,8 +1,9 @@
11 const crypto = require('crypto')
22 const Actor = require('./actor.js')
33 const Scheduler = require('./scheduler.js')
44 const {ID, decoder} = require('primea-objects')
5+const cbor = require('borc')
56
67 module.exports = class Hypervisor {
78 /**
89 * The Hypervisor manages the container instances by instantiating them and
@@ -106,9 +107,12 @@
106107 await new Promise((resolve, reject) => {
107108 this.scheduler.once('idle', resolve)
108109 })
109110 }
110- return this.tree.flush()
111+ return this.tree.flush().then(sr => {
112+ console.log(sr.toString('hex'))
113+ return sr
114+ })
111115 }
112116
113117 /**
114118 * regirsters a container with the hypervisor
@@ -125,11 +129,10 @@
125129 }
126130 }
127131
128132 function encodedID (id) {
129- const nonce = Buffer.from([id.nonce])
130133 if (id.parent) {
131- return Buffer.concat([nonce, id.parent.id])
134+ return cbor.encode([id.nonce, id.parent.id])
132135 } else {
133- return nonce
136+ return cbor.encode([id.nonce, null])
134137 }
135138 }
tests/index.jsView
@@ -74,9 +74,9 @@
7474 })
7575
7676 tape('basic', async t => {
7777 t.plan(2)
78- const expectedState = Buffer.from('1602fe14ee1e95c9d5cf10e809d0615cb21927a2', 'hex')
78+ const expectedState = Buffer.from('e3669fbd4ee56f958d9090f60617f3a50cd8062b', '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('3cdad3b1024074e7edafadbb98ee162cc8cfe565', 'hex')
106+ const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', '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('7b659c263363b0b9c461a432aac8d8bf0d351788', 'hex')
150+ const expectedState = Buffer.from('622078699d4688e09c4930b49c6e465c9fbbcc07', '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('7b659c263363b0b9c461a432aac8d8bf0d351788', 'hex')
200+ const expectedState = Buffer.from('622078699d4688e09c4930b49c6e465c9fbbcc07', '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('3cdad3b1024074e7edafadbb98ee162cc8cfe565', 'hex')
250+ const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', '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('f1803a4188890e205e2e6480159d504d149d8910', 'hex')
295+ const expectedState = Buffer.from('09ada4d5ccb874b5767ea4aaf6081437eb36b3e0', '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('3cdad3b1024074e7edafadbb98ee162cc8cfe565', 'hex')
342+ const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', 'hex')
343343 const tree = new RadixTree({
344344 db
345345 })
346346
@@ -404,9 +404,9 @@
404404
405405 tape('arbiter test for id comparision', async t => {
406406 t.plan(4)
407407 let message
408- const expectedState = Buffer.from('7b659c263363b0b9c461a432aac8d8bf0d351788', 'hex')
408+ const expectedState = Buffer.from('622078699d4688e09c4930b49c6e465c9fbbcc07', 'hex')
409409
410410 const tree = new RadixTree({
411411 db: db
412412 })
@@ -469,9 +469,9 @@
469469 })
470470
471471 tape('async work', async t => {
472472 t.plan(3)
473- const expectedState = Buffer.from('3cdad3b1024074e7edafadbb98ee162cc8cfe565', 'hex')
473+ const expectedState = Buffer.from('d2ab2c32f5eca6706d72a70d08ba7711ef8dde03', 'hex')
474474
475475 const tree = new RadixTree({
476476 db
477477 })

Built with git-ssb-web