tests/index.jsView |
---|
57 | 57 | }) |
58 | 58 | |
59 | 59 | class testVMContainerA extends BaseContainer { |
60 | 60 | onCreation (m) { |
61 | | - const cap = this.kernel.mintCap() |
62 | 61 | message = new Message() |
63 | | - message.caps.push(cap) |
64 | 62 | return this.kernel.send(m.caps[0], message) |
65 | 63 | } |
66 | 64 | } |
67 | 65 | |
102 | 100 | }) |
103 | 101 | |
104 | 102 | class testVMContainerA extends BaseContainer { |
105 | 103 | onCreation (m) { |
106 | | - const cap = this.kernel.mintCap() |
107 | 104 | message = new Message() |
108 | | - message.caps.push(cap) |
109 | 105 | return this.kernel.send(m.caps[0], message) |
110 | 106 | } |
111 | 107 | } |
112 | 108 | |
191 | 187 | |
192 | 188 | t.deepEquals(stateRoot, expectedState, 'expected root!') |
193 | 189 | t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
194 | 190 | }) |
| 191 | + |
| 192 | +tape('response caps', async t => { |
| 193 | + t.plan(4) |
| 194 | + let message |
| 195 | + const expectedState = { |
| 196 | + '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
| 197 | + } |
| 198 | + |
| 199 | + const tree = new RadixTree({ |
| 200 | + db: db |
| 201 | + }) |
| 202 | + |
| 203 | + class testVMContainerA extends BaseContainer { |
| 204 | + onCreation (m) { |
| 205 | + message = new Message() |
| 206 | + message.responseCap = this.kernel.mintCap() |
| 207 | + return this.kernel.send(m.caps[0], message) |
| 208 | + } |
| 209 | + |
| 210 | + onMessage (m) { |
| 211 | + t.true(m, 'should recive a response message') |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + class testVMContainerB extends BaseContainer { |
| 216 | + onMessage (m) { |
| 217 | + t.true(m === message, 'should recive a message') |
| 218 | + } |
| 219 | + |
| 220 | + static get typeId () { |
| 221 | + return 8 |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + const hypervisor = new Hypervisor(tree) |
| 226 | + hypervisor.registerContainer(testVMContainerA) |
| 227 | + hypervisor.registerContainer(testVMContainerB) |
| 228 | + |
| 229 | + let capB = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 230 | + await hypervisor.createInstance(testVMContainerA.typeId, new Message({ |
| 231 | + caps: [capB] |
| 232 | + })) |
| 233 | + |
| 234 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 235 | + |
| 236 | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 237 | + t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
| 238 | +}) |
| 239 | + |
| 240 | +tape('response caps for errors', async t => { |
| 241 | + t.plan(4) |
| 242 | + let message |
| 243 | + const expectedState = { |
| 244 | + '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex') |
| 245 | + } |
| 246 | + |
| 247 | + const tree = new RadixTree({ |
| 248 | + db: db |
| 249 | + }) |
| 250 | + |
| 251 | + class testVMContainerA extends BaseContainer { |
| 252 | + onCreation (m) { |
| 253 | + message = new Message() |
| 254 | + message.responseCap = this.kernel.mintCap() |
| 255 | + return this.kernel.send(m.caps[0], message) |
| 256 | + } |
| 257 | + |
| 258 | + onMessage (m) { |
| 259 | + t.true(m.data.exceptionError instanceof Error, 'should recive a response message') |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + class testVMContainerB extends BaseContainer { |
| 264 | + onMessage (m) { |
| 265 | + t.true(m === message, 'should recive a message') |
| 266 | + throw new Error('test error') |
| 267 | + } |
| 268 | + |
| 269 | + static get typeId () { |
| 270 | + return 8 |
| 271 | + } |
| 272 | + } |
| 273 | + |
| 274 | + const hypervisor = new Hypervisor(tree) |
| 275 | + hypervisor.registerContainer(testVMContainerA) |
| 276 | + hypervisor.registerContainer(testVMContainerB) |
| 277 | + |
| 278 | + let capB = await hypervisor.createInstance(testVMContainerB.typeId, new Message()) |
| 279 | + await hypervisor.createInstance(testVMContainerA.typeId, new Message({ |
| 280 | + caps: [capB] |
| 281 | + })) |
| 282 | + |
| 283 | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 284 | + |
| 285 | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 286 | + t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0) |
| 287 | +}) |