git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 92d7c78382c4c1263d34dc2eced70feb25a04d85

log

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 10/10/2017, 2:03:57 AM
Parent: 87a2a18856fe92f22372903f2ad5e17b57cb9959

Files changed

tests/index.jschanged
tests/index.jsView
@@ -128,104 +128,108 @@
128128
129129 tape('one child contract', async t => {
130130 t.plan(4)
131131
132- const tree = new RadixTree({
133- db: db
134- })
132 + try {
133 + const tree = new RadixTree({
134 + db: db
135 + })
135136
136- let message
137- const expectedState = {
138- '/': Buffer.from('c91821c303cd07adde06c0d46c40aafe4542dea1', 'hex')
139- }
137 + let message
138 + const expectedState = {
139 + '/': Buffer.from('c91821c303cd07adde06c0d46c40aafe4542dea1', 'hex')
140 + }
140141
141- let hasResolved = false
142 + let hasResolved = false
142143
143- class testVMContainer2 extends BaseContainer {
144- onMessage (m) {
145- t.true(m === message, 'should recive a message')
146- return new Promise((resolve, reject) => {
147- setTimeout(() => {
148- this.kernel.incrementTicks(1)
149- hasResolved = true
150- resolve()
151- }, 200)
152- })
153- }
144 + class testVMContainer2 extends BaseContainer {
145 + onMessage (m) {
146 + t.true(m === message, 'should recive a message')
147 + return new Promise((resolve, reject) => {
148 + setTimeout(() => {
149 + this.kernel.incrementTicks(1)
150 + hasResolved = true
151 + resolve()
152 + }, 200)
153 + })
154 + }
154155
155- static get typeId () {
156- return 99
156 + static get typeId () {
157 + return 99
158 + }
157159 }
158- }
159160
160- class testVMContainer extends BaseContainer {
161- async onMessage (m) {
162- const [portRef1, portRef2] = this.kernel.ports.createChannel()
163- const port = this.kernel.hypervisor.creationService.getPort()
161 + class testVMContainer extends BaseContainer {
162 + async onMessage (m) {
163 + const [portRef1, portRef2] = this.kernel.ports.createChannel()
164 + const port = this.kernel.hypervisor.creationService.getPort()
164165
165- await Promise.all([
166- this.kernel.send(port, this.kernel.createMessage({
167- data: {
168- type: testVMContainer2.typeId
169- },
170- ports: [portRef2]
171- })),
172- this.kernel.send(portRef1, m)
173- ])
166 + await Promise.all([
167 + this.kernel.send(port, this.kernel.createMessage({
168 + data: {
169 + type: testVMContainer2.typeId
170 + },
171 + ports: [portRef2]
172 + })),
173 + this.kernel.send(portRef1, m)
174 + ])
174175
175- this.kernel.incrementTicks(1)
176- return this.kernel.ports.bind('child', portRef1)
176 + this.kernel.incrementTicks(1)
177 + return this.kernel.ports.bind('child', portRef1)
178 + }
177179 }
178- }
179180
180- const hypervisor = new Hypervisor(tree)
181- hypervisor.registerContainer(testVMContainer)
182- hypervisor.registerContainer(testVMContainer2)
181 + const hypervisor = new Hypervisor(tree)
182 + hypervisor.registerContainer(testVMContainer)
183 + hypervisor.registerContainer(testVMContainer2)
183184
184- let creationPort = hypervisor.creationService.getPort()
185- let root = await hypervisor.send(creationPort, new Message({
186- data: {
187- type: testVMContainer.typeId
188- }
189- }))
185 + let creationPort = hypervisor.creationService.getPort()
186 + let root = await hypervisor.send(creationPort, new Message({
187 + data: {
188 + type: testVMContainer.typeId
189 + }
190 + }))
190191
191- hypervisor.pin(root)
192 + hypervisor.pin(root)
192193
193- const rootId = root.id
194- root = await hypervisor.getInstance(rootId)
195- const [portRef1, portRef2] = root.ports.createChannel()
194 + const rootId = root.id
195 + root = await hypervisor.getInstance(rootId)
196 + const [portRef1, portRef2] = root.ports.createChannel()
196197
197- message = root.createMessage()
198- await Promise.all([
199- root.send(creationPort, root.createMessage({
200- data: {
201- type: testVMContainer.typeId
202- },
203- ports: [portRef2]
204- })),
205- root.ports.bind('first', portRef1),
206- root.send(portRef1, message)
207- ])
198 + message = root.createMessage()
199 + await Promise.all([
200 + root.send(creationPort, root.createMessage({
201 + data: {
202 + type: testVMContainer.typeId
203 + },
204 + ports: [portRef2]
205 + })),
206 + root.ports.bind('first', portRef1),
207 + root.send(portRef1, message)
208 + ])
208209
209- root.shutdown()
210 + root.shutdown()
210211
211- const stateRoot = await hypervisor.createStateRoot(Infinity)
212- t.true(hasResolved, 'should resolve before generating the state root')
213- t.deepEquals(stateRoot, expectedState, 'expected state')
212 + const stateRoot = await hypervisor.createStateRoot(Infinity)
213 + t.true(hasResolved, 'should resolve before generating the state root')
214 + t.deepEquals(stateRoot, expectedState, 'expected state')
214215
215- // test reviving the state
216- class testVMContainer3 extends BaseContainer {
217- onMessage (m) {
218- const port = this.kernel.ports.get('child')
219- this.kernel.send(port, m)
220- this.kernel.incrementTicks(1)
216 + // test reviving the state
217 + class testVMContainer3 extends BaseContainer {
218 + onMessage (m) {
219 + const port = this.kernel.ports.get('child')
220 + this.kernel.send(port, m)
221 + this.kernel.incrementTicks(1)
222 + }
221223 }
224 +
225 + hypervisor.registerContainer(testVMContainer3)
226 + root = await hypervisor.getInstance(rootId)
227 + const port = root.ports.get('first')
228 + root.send(port, message)
229 + } catch (e) {
230 + console.log(e)
222231 }
223-
224- hypervisor.registerContainer(testVMContainer3)
225- root = await hypervisor.getInstance(rootId)
226- const port = root.ports.get('first')
227- root.send(port, message)
228232 })
229233
230234 tape('traps', async t => {
231235 t.plan(1)

Built with git-ssb-web