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.js | changed |
tests/index.js | ||
---|---|---|
@@ -128,104 +128,108 @@ | ||
128 | 128 … | |
129 | 129 … | tape('one child contract', async t => { |
130 | 130 … | t.plan(4) |
131 | 131 … | |
132 | - const tree = new RadixTree({ | |
133 | - db: db | |
134 | - }) | |
132 … | + try { | |
133 … | + const tree = new RadixTree({ | |
134 … | + db: db | |
135 … | + }) | |
135 | 136 … | |
136 | - let message | |
137 | - const expectedState = { | |
138 | - '/': Buffer.from('c91821c303cd07adde06c0d46c40aafe4542dea1', 'hex') | |
139 | - } | |
137 … | + let message | |
138 … | + const expectedState = { | |
139 … | + '/': Buffer.from('c91821c303cd07adde06c0d46c40aafe4542dea1', 'hex') | |
140 … | + } | |
140 | 141 … | |
141 | - let hasResolved = false | |
142 … | + let hasResolved = false | |
142 | 143 … | |
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 … | + } | |
154 | 155 … | |
155 | - static get typeId () { | |
156 | - return 99 | |
156 … | + static get typeId () { | |
157 … | + return 99 | |
158 … | + } | |
157 | 159 … | } |
158 | - } | |
159 | 160 … | |
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() | |
164 | 165 … | |
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 … | + ]) | |
174 | 175 … | |
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 … | + } | |
177 | 179 … | } |
178 | - } | |
179 | 180 … | |
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) | |
183 | 184 … | |
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 … | + })) | |
190 | 191 … | |
191 | - hypervisor.pin(root) | |
192 … | + hypervisor.pin(root) | |
192 | 193 … | |
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() | |
196 | 197 … | |
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 … | + ]) | |
208 | 209 … | |
209 | - root.shutdown() | |
210 … | + root.shutdown() | |
210 | 211 … | |
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') | |
214 | 215 … | |
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 … | + } | |
221 | 223 … | } |
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) | |
222 | 231 … | } |
223 | - | |
224 | - hypervisor.registerContainer(testVMContainer3) | |
225 | - root = await hypervisor.getInstance(rootId) | |
226 | - const port = root.ports.get('first') | |
227 | - root.send(port, message) | |
228 | 232 … | }) |
229 | 233 … | |
230 | 234 … | tape('traps', async t => { |
231 | 235 … | t.plan(1) |
Built with git-ssb-web