Files: 3820100dc50eb86a7f6f941410dc7e8dd2c7aaa7 / tests / index.js
2136 bytesRaw
1 | const tape = require('tape') |
2 | const IPFS = require('ipfs') |
3 | const Hypervisor = require('../') |
4 | const Message = require('primea-message') |
5 | |
6 | const node = new IPFS() |
7 | |
8 | class BaseContainer { |
9 | static createState (code) { |
10 | return { |
11 | nonce: Buffer.from([0]), |
12 | ports: {} |
13 | } |
14 | } |
15 | } |
16 | |
17 | node.on('error', err => { |
18 | console.log(err) |
19 | }) |
20 | |
21 | node.on('start', () => { |
22 | tape.only('basic', async t => { |
23 | const message = new Message() |
24 | const expectedState = { '/': 'zdpuB2hzCvqE34W71CFtqqzHLP8kyuwGZm1bz8Cy2kAVCh1fP' } |
25 | |
26 | class testVMContainer extends BaseContainer { |
27 | run (m) { |
28 | t.true(m === message, 'should recive a message') |
29 | } |
30 | } |
31 | |
32 | const hypervisor = new Hypervisor({dag: node.dag}) |
33 | hypervisor.addVM('test', testVMContainer) |
34 | const port = hypervisor.createPort('test') |
35 | |
36 | await hypervisor.send(port, message) |
37 | await hypervisor.createStateRoot(port, Infinity) |
38 | t.deepEquals(port, expectedState, 'expected') |
39 | // await hypervisor.graph.tree(port, Infinity) |
40 | // console.log(JSON.stringify(port, null, 2)) |
41 | t.end() |
42 | }) |
43 | |
44 | tape('one child contract', async t => { |
45 | t.end() |
46 | const message = new Message() |
47 | const expectedState = { '/': 'zdpuAwqyF4X1hAHMBcsn7eDJXcLfcyoyEWWR73eeqXXmFkBe3' } |
48 | |
49 | class testVMContainer2 extends BaseContainer { |
50 | run (m) { |
51 | console.log('here!') |
52 | t.true(m === message, 'should recive a message') |
53 | } |
54 | } |
55 | |
56 | class testVMContainer extends BaseContainer { |
57 | constructor (kernel) { |
58 | super() |
59 | this.kernel = kernel |
60 | } |
61 | |
62 | async run (m) { |
63 | console.log('first') |
64 | const port = await this.kernel.createPort(this.kernel.ports, 'test2', 'child') |
65 | return this.kernel.send(port, m) |
66 | } |
67 | } |
68 | |
69 | const hypervisor = new Hypervisor({dag: node.dag}) |
70 | hypervisor.addVM('test', testVMContainer) |
71 | hypervisor.addVM('test2', testVMContainer2) |
72 | const port = hypervisor.createPort('test') |
73 | |
74 | await hypervisor.send(port, message) |
75 | await hypervisor.createStateRoot(port, Infinity) |
76 | t.deepEquals(port, expectedState, 'expected') |
77 | |
78 | node.stop(() => { |
79 | process.exit() |
80 | }) |
81 | }) |
82 | }) |
83 |
Built with git-ssb-web