tests/index.jsView |
---|
178 | 178 | |
179 | 179 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
180 | 180 | }) |
181 | 181 | |
182 | | -tape('response caps', async t => { |
| 182 | +tape('errors', async t => { |
183 | 183 | t.plan(3) |
184 | 184 | let message |
185 | 185 | const expectedState = { |
186 | 186 | '/': Buffer.from('a4c7ceacd8c867ae1d0b472d8bffa3cb10048331', 'hex') |
192 | 192 | |
193 | 193 | class testVMContainerA extends BaseContainer { |
194 | 194 | onCreation (m) { |
195 | 195 | message = new Message() |
196 | | - message.responseCap = this.actor.mintCap() |
| 196 | + message.on('execution:error', () => { |
| 197 | + t.pass('should recive a exeption') |
| 198 | + }) |
197 | 199 | this.actor.send(m.caps[0], message) |
198 | 200 | } |
199 | | - |
200 | | - onMessage (m) { |
201 | | - t.true(m, 'should recive a response message') |
202 | | - } |
203 | 201 | } |
204 | 202 | |
205 | 203 | class testVMContainerB extends BaseContainer { |
206 | 204 | onMessage (m) { |
207 | 205 | t.true(m === message, 'should recive a message') |
208 | | - } |
209 | | - |
210 | | - static get typeId () { |
211 | | - return 8 |
212 | | - } |
213 | | - } |
214 | | - |
215 | | - const hypervisor = new Hypervisor(tree) |
216 | | - hypervisor.registerContainer(testVMContainerA) |
217 | | - hypervisor.registerContainer(testVMContainerB) |
218 | | - |
219 | | - let capB = await hypervisor.createActor(testVMContainerB.typeId, new Message()) |
220 | | - await hypervisor.createActor(testVMContainerA.typeId, new Message({ |
221 | | - caps: [capB] |
222 | | - })) |
223 | | - |
224 | | - const stateRoot = await hypervisor.createStateRoot() |
225 | | - |
226 | | - t.deepEquals(stateRoot, expectedState, 'expected root!') |
227 | | -}) |
228 | | - |
229 | | -tape('response caps for errors', async t => { |
230 | | - t.plan(3) |
231 | | - let message |
232 | | - const expectedState = { |
233 | | - '/': Buffer.from('a4c7ceacd8c867ae1d0b472d8bffa3cb10048331', 'hex') |
234 | | - } |
235 | | - |
236 | | - const tree = new RadixTree({ |
237 | | - db: db |
238 | | - }) |
239 | | - |
240 | | - class testVMContainerA extends BaseContainer { |
241 | | - onCreation (m) { |
242 | | - message = new Message() |
243 | | - message.responseCap = this.actor.mintCap() |
244 | | - this.actor.send(m.caps[0], message) |
245 | | - } |
246 | | - |
247 | | - onMessage (m) { |
248 | | - t.true(m.data.exceptionError instanceof Error, 'should recive a response message') |
249 | | - } |
250 | | - } |
251 | | - |
252 | | - class testVMContainerB extends BaseContainer { |
253 | | - onMessage (m) { |
254 | | - t.true(m === message, 'should recive a message') |
255 | 206 | throw new Error('test error') |
256 | 207 | } |
257 | 208 | |
258 | 209 | static get typeId () { |
454 | 405 | class testVMContainerA extends BaseContainer { |
455 | 406 | async onMessage (m) { |
456 | 407 | t.true(m, 'should recive first message') |
457 | 408 | const rCap = this.actor.mintCap(1) |
458 | | - const message = new Message() |
459 | | - message.responseCap = rCap |
| 409 | + const message = new Message({caps: [rCap]}) |
460 | 410 | this.actor.send(m.caps[0], message) |
461 | 411 | const rMessage = await this.actor.inbox.nextTaggedMessage([1], 44) |
462 | 412 | t.true(rMessage, 'should recive a response message') |
463 | 413 | } |
465 | 415 | |
466 | 416 | class testVMContainerB extends BaseContainer { |
467 | 417 | onMessage (m) { |
468 | 418 | t.true(m, 'should recive a message') |
| 419 | + this.actor.send(m.caps[0], new Message()) |
469 | 420 | } |
470 | 421 | |
471 | 422 | static get typeId () { |
472 | 423 | return 8 |
502 | 453 | t.true(m, 'should recive second message') |
503 | 454 | } else { |
504 | 455 | t.true(m, 'should recive first message') |
505 | 456 | const rCap = this.actor.mintCap(1) |
506 | | - const message = new Message() |
507 | | - message.responseCap = rCap |
| 457 | + const message = new Message({caps: [rCap]}) |
508 | 458 | this.actor.send(m.caps[0], message) |
509 | 459 | this.actor.inbox.nextTaggedMessage([1], 44) |
510 | 460 | } |
511 | 461 | } |
513 | 463 | |
514 | 464 | class testVMContainerB extends BaseContainer { |
515 | 465 | onMessage (m) { |
516 | 466 | t.true(m, 'should recive a message') |
| 467 | + this.actor.send(m.caps[0], new Message()) |
517 | 468 | } |
518 | 469 | |
519 | 470 | static get typeId () { |
520 | 471 | return 8 |
548 | 499 | async onMessage (m) { |
549 | 500 | t.true(m, 'should recive first message') |
550 | 501 | const rCap = this.actor.mintCap(1) |
551 | 502 | const message = new Message({data: 'first'}) |
552 | | - message.responseCap = rCap |
553 | 503 | this.actor.send(m.caps[0], message) |
554 | 504 | const promise = this.actor.inbox.nextTaggedMessage([1], 44) |
555 | 505 | try { |
556 | 506 | await this.actor.inbox.nextTaggedMessage([1], 44) |