tests/index.jsView |
---|
26 | 26 … | tape('basic', async t => { |
27 | 27 … | t.plan(3) |
28 | 28 … | let message |
29 | 29 … | const expectedState = { |
30 | | - '/': 'zdpuAmN9VSrvNbArWkAEhEYaKhhCT3rk8xMhUam6eUfQmr6aZ' |
| 30 … | + '/': 'zdpuAsvLUNKxnxpKxuipCJz7sH4kmHuu3gVEUEmJ1QuWnikht' |
31 | 31 … | } |
32 | 32 … | |
33 | 33 … | class testVMContainer extends BaseContainer { |
34 | 34 … | onMessage (m) { |
35 | 35 … | t.true(m === message, 'should recive a message') |
36 | 36 … | } |
37 | 37 … | } |
38 | 38 … | |
39 | | - const hypervisor = new Hypervisor(node.dag) |
40 | | - hypervisor.registerContainer(testVMContainer) |
| 39 … | + try { |
| 40 … | + const hypervisor = new Hypervisor(node.dag) |
| 41 … | + hypervisor.registerContainer(testVMContainer) |
41 | 42 … | |
42 | | - const rootContainer = await hypervisor.createInstance(testVMContainer.typeId) |
| 43 … | + const rootContainer = await hypervisor.createInstance(testVMContainer.typeId) |
43 | 44 … | |
44 | | - const [portRef1, portRef2] = rootContainer.ports.createChannel() |
45 | | - const initMessage = rootContainer.createMessage({ |
46 | | - data: Buffer.from('test code'), |
47 | | - ports: [portRef2] |
48 | | - }) |
| 45 … | + const [portRef1, portRef2] = rootContainer.ports.createChannel() |
| 46 … | + const initMessage = rootContainer.createMessage({ |
| 47 … | + data: Buffer.from('test code'), |
| 48 … | + ports: [portRef2] |
| 49 … | + }) |
49 | 50 … | |
50 | | - rootContainer.createInstance(testVMContainer.typeId, initMessage) |
| 51 … | + rootContainer.createInstance(testVMContainer.typeId, initMessage) |
51 | 52 … | |
52 | | - rootContainer.ports.bind('first', portRef1) |
53 | | - message = rootContainer.createMessage() |
54 | | - rootContainer.send(portRef1, message) |
| 53 … | + rootContainer.ports.bind('first', portRef1) |
| 54 … | + message = rootContainer.createMessage() |
| 55 … | + rootContainer.send(portRef1, message) |
55 | 56 … | |
56 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
57 | | - t.deepEquals(stateRoot, expectedState, 'expected root!') |
58 | | - t.equals(hypervisor.scheduler.oldest(), 0) |
| 57 … | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 58 … | + |
| 59 … | + |
| 60 … | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 61 … | + t.equals(hypervisor.scheduler.oldest(), 0) |
| 62 … | + } catch (e) { |
| 63 … | + console.log(e) |
| 64 … | + } |
59 | 65 … | }) |
60 | 66 … | |
61 | 67 … | tape('basic - do not store containers with no ports bound', async t => { |
62 | 68 … | t.plan(1) |
63 | 69 … | const expectedState = { |
64 | | - '/': 'zdpuAxGvPHM4DRbq7GeyGjwuPA8NT7DZLszcDDX9R5iwHWnTo' |
| 70 … | + '/': 'zdpuAop4nt8pqzg7duciSYbZmWfDaBiz87RCtGCbb35ewUrbW' |
65 | 71 … | } |
66 | 72 … | |
67 | 73 … | class testVMContainer extends BaseContainer { |
68 | 74 … | onCreation () {} |
69 | 75 … | } |
70 | 76 … | |
71 | | - const hypervisor = new Hypervisor(node.dag) |
72 | | - hypervisor.registerContainer(testVMContainer) |
| 77 … | + try { |
| 78 … | + const hypervisor = new Hypervisor(node.dag) |
| 79 … | + hypervisor.registerContainer(testVMContainer) |
73 | 80 … | |
74 | | - const root = await hypervisor.createInstance(testVMContainer.typeId) |
75 | | - const [portRef1, portRef2] = root.ports.createChannel() |
| 81 … | + const root = await hypervisor.createInstance(testVMContainer.typeId) |
| 82 … | + const [portRef1, portRef2] = root.ports.createChannel() |
76 | 83 … | |
77 | | - root.ports.bind('one', portRef1) |
78 | | - root.createInstance(testVMContainer.typeId, root.createMessage({ |
79 | | - ports: [portRef2] |
80 | | - })) |
| 84 … | + root.ports.bind('one', portRef1) |
| 85 … | + root.createInstance(testVMContainer.typeId, root.createMessage({ |
| 86 … | + ports: [portRef2] |
| 87 … | + })) |
81 | 88 … | |
82 | | - const stateRoot = await hypervisor.createStateRoot(Infinity) |
83 | | - t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 89 … | + const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 90 … | + |
| 91 … | + |
| 92 … | + |
| 93 … | + t.deepEquals(stateRoot, expectedState, 'expected root!') |
| 94 … | + } catch (e) { |
| 95 … | + console.log(e) |
| 96 … | + } |
84 | 97 … | }) |
85 | 98 … | |
86 | 99 … | tape('one child contract with saturated ports', async t => { |
87 | 100 … | t.plan(2) |
88 | 101 … | let message |
89 | 102 … | const expectedState = { |
90 | | - '/': 'zdpuAvWT2E1Hg6cvFNLTDbmjGRLSDbMnRtrA6s17oSdBX5EWs' |
| 103 … | + '/': 'zdpuAnfZ1fGUSzNwAovfArzcTfEVbXjVYABprgtjUKMtGb8k5' |
91 | 104 … | } |
92 | 105 … | |
93 | 106 … | class testVMContainer2 extends BaseContainer { |
94 | 107 … | onMessage (m) { |
127 | 140 … | }) |
128 | 141 … | |
129 | 142 … | root.send(portRef1, message) |
130 | 143 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
| 144 … | + |
| 145 … | + |
| 146 … | + |
131 | 147 … | t.deepEquals(stateRoot, expectedState, 'expected state') |
132 | 148 … | }) |
133 | 149 … | |
134 | 150 … | tape('one child contract', async t => { |
135 | 151 … | t.plan(4) |
136 | 152 … | let message |
137 | 153 … | const expectedState = { |
138 | | - '/': 'zdpuAvWT2E1Hg6cvFNLTDbmjGRLSDbMnRtrA6s17oSdBX5EWs' |
| 154 … | + '/': 'zdpuArCqpDZtEqjrXrRhMiYLE7QQ1szVr1qLVkiwtDLincGWU' |
139 | 155 … | } |
140 | 156 … | let hasResolved = false |
141 | 157 … | |
142 | 158 … | class testVMContainer2 extends BaseContainer { |
184 | 200 … | |
185 | 201 … | root.send(portRef1, message) |
186 | 202 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
187 | 203 … | t.true(hasResolved, 'should resolve before generating the state root') |
| 204 … | + |
| 205 … | + |
| 206 … | + |
188 | 207 … | t.deepEquals(stateRoot, expectedState, 'expected state') |
189 | 208 … | |
190 | 209 … | |
191 | 210 … | class testVMContainer3 extends BaseContainer { |
239 | 258 … | await root.message(root.createMessage()) |
240 | 259 … | const stateRoot = await hypervisor.createStateRoot() |
241 | 260 … | |
242 | 261 … | t.deepEquals(stateRoot, { |
243 | | - '/': 'zdpuAwxK8kAM3SkxSyALurpFHTobp6sFJef9gZJ8ZDQRww1LN' |
| 262 … | + '/': 'zdpuAtChoDT1Er7c9Ndv6ov4m46wibCNY1HKthoVLUn5n4Rg5' |
244 | 263 … | }, 'should revert the state') |
245 | 264 … | }) |
246 | 265 … | |
247 | 266 … | tape('message should arrive in the correct oder if sent in order', async t => { |
845 | 864 … | }) |
846 | 865 … | |
847 | 866 … | tape('port deletion', async t => { |
848 | 867 … | const expectedSr = { |
849 | | - '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh' |
| 868 … | + '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
850 | 869 … | } |
851 | 870 … | class Root extends BaseContainer { |
852 | 871 … | onMessage (m) { |
853 | 872 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
888 | 907 … | root.send(portRef1, message) |
889 | 908 … | |
890 | 909 … | const sr = await hypervisor.createStateRoot() |
891 | 910 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
| 911 … | + await hypervisor.graph.tree(sr, Infinity, true) |
892 | 912 … | |
893 | 913 … | t.end() |
894 | 914 … | }) |
895 | 915 … | |
896 | 916 … | tape('clear unbounded ports', async t => { |
897 | 917 … | const expectedSr = { |
898 | | - '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh' |
| 918 … | + '/': 'zdpuAxVzUQRWaAeFWXq5TgDpZqPaNgNp1ZuEfxbxg7h4qnXmC' |
899 | 919 … | } |
900 | 920 … | class Root extends BaseContainer { |
901 | 921 … | onMessage (m) { |
902 | 922 … | this.kernel.createInstance(Root.typeId) |
923 | 943 … | }) |
924 | 944 … | |
925 | 945 … | tape('should remove subgraphs', async t => { |
926 | 946 … | const expectedSr = { |
927 | | - '/': 'zdpuAqFMWKsATaU1gJwMTegcw18GFQ7szZix3QNgMN2sYm2vh' |
| 947 … | + '/': 'zdpuAopMy53q2uvL2a4fhVEAvwXjSDW28fh8zhQUj598tb5md' |
928 | 948 … | } |
929 | 949 … | class Root extends BaseContainer { |
930 | 950 … | onMessage (m) { |
931 | 951 … | const [, portRef2] = this.kernel.ports.createChannel() |
969 | 989 … | }) |
970 | 990 … | |
971 | 991 … | tape('should not remove connected nodes', async t => { |
972 | 992 … | const expectedSr = { |
973 | | - '/': 'zdpuAppPTaXwHnfU2yjtTyT9XsY7SJAkDwQWUZnkHU7myRzaj' |
| 993 … | + '/': 'zdpuApKrsvsWknDML2Mme9FyZfRnVZ1hTCoKzkooYAWT3dUDV' |
974 | 994 … | } |
975 | 995 … | class Root extends BaseContainer { |
976 | 996 … | onMessage (m) { |
977 | 997 … | if (m.ports.length) { |
1036 | 1056 … | }) |
1037 | 1057 … | |
1038 | 1058 … | tape('should remove multiple subgraphs', async t => { |
1039 | 1059 … | const expectedSr = { |
1040 | | - '/': 'zdpuAvQqoEnojZHaw6dMDy8ACRVqfarfD2RCKTwFBYsj8suRC' |
| 1060 … | + '/': 'zdpuAo1qZHhS6obxbGbtvnUxkbAxA6VSbcjYiiTVNWTm37xQv' |
1041 | 1061 … | } |
1042 | 1062 … | class Root extends BaseContainer { |
1043 | 1063 … | onMessage (m) { |
|
1044 | 1064 … | if (m.ports.length) { |