tests/wasmContainer.jsView |
---|
47 | 47 | const hypervisor = new Hypervisor(tree) |
48 | 48 | hypervisor.registerContainer(TestWasmContainer) |
49 | 49 | |
50 | 50 | const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) |
| 51 | + const funcRef = module.getFuncRef('receive') |
| 52 | + funcRef.gas = 300 |
51 | 53 | |
52 | 54 | const message = new Message({ |
53 | | - funcRef: module.getFuncRef('receive'), |
| 55 | + funcRef, |
54 | 56 | funcArguments: [5] |
55 | 57 | }) |
56 | 58 | hypervisor.send(message) |
57 | 59 | const stateRoot = await hypervisor.createStateRoot() |
74 | 76 | hypervisor.registerContainer(TestWasmContainer) |
75 | 77 | |
76 | 78 | const {module: receiverMod} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) |
77 | 79 | const {module: callerMod} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) |
| 80 | + const callFuncRef = callerMod.getFuncRef('call') |
| 81 | + const recvFuncRef = receiverMod.getFuncRef('receive') |
| 82 | + callFuncRef.gas = 100000 |
| 83 | + recvFuncRef.gas = 1000 |
78 | 84 | const message = new Message({ |
79 | | - funcRef: callerMod.getFuncRef('call'), |
80 | | - funcArguments: [receiverMod.getFuncRef('receive')] |
| 85 | + funcRef: callFuncRef, |
| 86 | + funcArguments: [recvFuncRef] |
81 | 87 | }) |
82 | 88 | |
83 | 89 | hypervisor.send(message) |
84 | 90 | const stateRoot = await hypervisor.createStateRoot() |
104 | 110 | |
105 | 111 | const {module: callerMod} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) |
106 | 112 | const {module: receiverMod} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) |
107 | 113 | |
| 114 | + const callFuncRef = callerMod.getFuncRef('call') |
| 115 | + const recvFuncRef = receiverMod.getFuncRef('receive') |
| 116 | + callFuncRef.gas = 100000 |
| 117 | + recvFuncRef.gas = 100000 |
| 118 | + |
108 | 119 | const message = new Message({ |
109 | | - funcRef: callerMod.getFuncRef('call'), |
110 | | - funcArguments: [receiverMod.getFuncRef('receive')] |
| 120 | + funcRef: callFuncRef, |
| 121 | + funcArguments: [recvFuncRef] |
111 | 122 | }) |
112 | 123 | |
113 | 124 | hypervisor.send(message) |
114 | 125 | const stateRoot = await hypervisor.createStateRoot() |
115 | 126 | |
116 | 127 | }) |
117 | 128 | |
118 | | -tape('two communicating actors with callback', async t => { |
| 129 | +tape('two communicating actors with private callback', async t => { |
119 | 130 | t.plan(1) |
120 | 131 | tester = t |
121 | 132 | const expectedState = { |
122 | 133 | '/': Buffer.from('9bf27cf07b75a90e0af530e2df73e3102482b24a', 'hex') |
134 | 145 | |
135 | 146 | const {module: callerMod} = await hypervisor.createActor(TestWasmContainer.typeId, callerWasm) |
136 | 147 | const {module: receiverMod} = await hypervisor.createActor(TestWasmContainer.typeId, recieverWasm) |
137 | 148 | |
| 149 | + const callFuncRef = callerMod.getFuncRef('call') |
| 150 | + const recvFuncRef = receiverMod.getFuncRef('receive') |
| 151 | + callFuncRef.gas = 100000 |
| 152 | + recvFuncRef.gas = 100000 |
| 153 | + |
138 | 154 | const message = new Message({ |
139 | | - funcRef: callerMod.getFuncRef('call'), |
140 | | - funcArguments: [receiverMod.getFuncRef('receive')] |
141 | | - }).on('execution:error', (e) => {console.log(e)}) |
| 155 | + funcRef: callFuncRef, |
| 156 | + funcArguments: [recvFuncRef] |
| 157 | + }) |
142 | 158 | |
143 | 159 | hypervisor.send(message) |
144 | 160 | const stateRoot = await hypervisor.createStateRoot() |
145 | 161 | |
157 | 173 | const hypervisor = new Hypervisor(tree) |
158 | 174 | hypervisor.registerContainer(TestWasmContainer) |
159 | 175 | |
160 | 176 | const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) |
| 177 | + const funcRef = module.getFuncRef('test') |
| 178 | + funcRef.gas = 10000 |
161 | 179 | |
162 | | - const message = new Message({ |
163 | | - funcRef: module.getFuncRef('test') |
164 | | - }).on('done', actor => { |
| 180 | + const message = new Message({funcRef}).on('done', actor => { |
165 | 181 | const a = actor.container.getMemory(0, 5) |
166 | 182 | const b = actor.container.getMemory(5, 5) |
167 | 183 | t.deepEquals(a, b, 'should copy memory correctly') |
168 | 184 | }) |
181 | 197 | hypervisor.registerContainer(TestWasmContainer) |
182 | 198 | |
183 | 199 | const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) |
184 | 200 | |
185 | | - const message = new Message({ |
186 | | - funcRef: module.getFuncRef('test') |
187 | | - }).on('done', actor => { |
| 201 | + const funcRef = module.getFuncRef('test') |
| 202 | + funcRef.gas = 10000 |
| 203 | + |
| 204 | + const message = new Message({funcRef}).on('done', actor => { |
188 | 205 | const a = actor.container.getMemory(0, 8) |
189 | 206 | const b = actor.container.getMemory(8, 8) |
190 | 207 | t.deepEquals(a, b, 'should copy memory correctly') |
191 | 208 | }) |
206 | 223 | |
207 | 224 | const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm) |
208 | 225 | |
209 | 226 | await new Promise((resolve, reject) => { |
| 227 | + const funcRef = module.getFuncRef('store') |
| 228 | + funcRef.gas = 400 |
210 | 229 | const message = new Message({ |
211 | | - funcRef: module.getFuncRef('store') |
| 230 | + funcRef |
212 | 231 | }).on('done', actor => { |
213 | 232 | resolve() |
214 | 233 | }) |
215 | 234 | hypervisor.send(message) |
216 | 235 | }) |
217 | 236 | |
218 | 237 | await new Promise((resolve, reject) => { |
| 238 | + const funcRef = module.getFuncRef('load') |
| 239 | + funcRef.gas = 400 |
219 | 240 | const message = new Message({ |
220 | | - funcRef: module.getFuncRef('load') |
| 241 | + funcRef |
221 | 242 | }).on('done', actor => { |
222 | 243 | resolve() |
223 | 244 | const b = actor.container.getMemory(5, 4) |
224 | 245 | const result = Buffer.from(b).toString() |