UNPKG

8.53 kBJavaScriptView Raw
1'use strict'
2var TraceManager = require('../src/trace/traceManager')
3var tape = require('tape')
4var remixLib = require('remix-lib')
5var Web3Providers = remixLib.vm.Web3Providers
6var global = remixLib.global
7var web3Test = require('./resources/testWeb3')
8
9tape('TraceManager', function (t) {
10 var traceManager
11
12 t.test('TraceManager.init', function (st) {
13 var web3Providers = new Web3Providers()
14 web3Providers.addProvider('TEST', web3Test)
15 web3Providers.get('TEST', function (error, obj) {
16 if (error) {
17 var mes = 'provider TEST not defined'
18 console.log(mes)
19 st.fail(mes)
20 } else {
21 global.web3 = obj
22 traceManager = new TraceManager()
23 st.end()
24 }
25 })
26 })
27
28 t.test('TraceManager.resolveTrace', function (st) {
29 var tx = global.web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
30 traceManager.resolveTrace(tx, function (error, result) {
31 if (error) {
32 st.fail(' - traceManager.resolveTrace - failed ' + result)
33 } else {
34 st.end()
35 }
36 })
37 })
38
39 t.test('TraceManager.getLength ', function (st) {
40 traceManager.getLength(function (error, result) {
41 if (error) {
42 st.fail(error)
43 } else {
44 st.end()
45 }
46 })
47 })
48
49 t.test('TraceManager.inRange ', function (st) {
50 st.notOk(traceManager.inRange(-1))
51 st.ok(traceManager.inRange(10))
52 st.notOk(traceManager.inRange(142))
53 st.ok(traceManager.inRange(141))
54 st.end()
55 })
56
57 t.test('TraceManager.accumulateStorageChanges', function (st) {
58 traceManager.accumulateStorageChanges(110, '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', {}, function (error, result) {
59 if (error) {
60 st.fail(error)
61 } else {
62 st.ok(result['0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563'].value === '0x38')
63 st.end()
64 }
65 })
66 })
67
68 t.test('TraceManager.getCallData', function (st) {
69 traceManager.getCallDataAt(0, function (error, result) {
70 if (error) {
71 st.fail(error)
72 } else {
73 st.ok(result[0] === '0x60fe47b10000000000000000000000000000000000000000000000000000000000000038')
74 st.end()
75 }
76 })
77 })
78
79 t.test('TraceManager.getCallStackAt', function (st) {
80 st.plan(3)
81 traceManager.getCallStackAt(0, function (error, result) {
82 if (error) {
83 st.fail(error)
84 } else {
85 st.ok(result[0] === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
86 }
87 })
88
89 traceManager.getCallStackAt(64, function (error, result) {
90 if (error) {
91 st.fail(error)
92 } else {
93 st.ok(result.length === 2)
94 st.ok(result[1] === '(Contract Creation - Step 63)')
95 }
96 })
97 })
98
99 t.test('TraceManager.getStackAt', function (st) {
100 st.plan(3)
101 traceManager.getStackAt(0, function (error, result) {
102 console.log(result)
103 if (error) {
104 st.fail(error)
105 } else {
106 st.ok(result.length === 0)
107 }
108 })
109
110 traceManager.getStackAt(28, function (error, result) {
111 console.log(result)
112 if (error) {
113 st.fail(error)
114 } else {
115 st.ok(result.length === 4)
116 st.ok(result[3] === '0x60fe47b1')
117 }
118 })
119 })
120
121 t.test('TraceManager.getLastCallChangeSince', function (st) {
122 st.plan(3)
123 traceManager.getLastCallChangeSince(10, function (error, result) {
124 console.log(result)
125 if (error) {
126 st.fail(error)
127 } else {
128 st.ok(result.start === 0)
129 }
130 })
131
132 traceManager.getLastCallChangeSince(70, function (error, result) {
133 console.log(result)
134 if (error) {
135 st.fail(error)
136 } else {
137 st.ok(result.start === 64)
138 }
139 })
140
141 traceManager.getLastCallChangeSince(111, function (error, result) {
142 console.log(result)
143 if (error) {
144 st.fail(error)
145 } else {
146 st.ok(result.start === 0)
147 // this was 109 before: 111 is targeting the root call (starting index 0)
148 // this test make more sense as it is now (109 is the index of RETURN).
149 }
150 })
151 })
152
153 t.test('TraceManager.getCurrentCalledAddressAt', function (st) {
154 st.plan(3)
155 traceManager.getCurrentCalledAddressAt(10, function (error, result) {
156 console.log(result)
157 if (error) {
158 st.fail(error)
159 } else {
160 st.ok(result === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
161 }
162 })
163
164 traceManager.getCurrentCalledAddressAt(70, function (error, result) {
165 console.log(result)
166 if (error) {
167 st.fail(error)
168 } else {
169 st.ok(result === '(Contract Creation - Step 63)')
170 }
171 })
172
173 traceManager.getCurrentCalledAddressAt(111, function (error, result) {
174 console.log(result)
175 if (error) {
176 st.fail(error)
177 } else {
178 st.ok(result === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
179 }
180 })
181 })
182
183 t.test('TraceManager.getContractCreationCode', function (st) { // contract code has been retrieved from the memory
184 traceManager.getContractCreationCode('(Contract Creation - Step 63)', function (error, result) {
185 console.log(result)
186 if (error) {
187 st.fail(error)
188 } else {
189 st.ok(result === '0x60606040526040516020806045833981016040528080519060200190919050505b806001016000600050819055505b50600a80603b6000396000f360606040526008565b00000000000000000000000000000000000000000000000000000000000000002d')
190 st.end()
191 }
192 })
193 })
194
195 t.test('TraceManager.getMemoryAt', function (st) {
196 st.plan(3)
197 traceManager.getMemoryAt(0, function (error, result) {
198 console.log(result)
199 if (error) {
200 st.fail(error)
201 } else {
202 st.ok(result.length === 0)
203 }
204 })
205
206 traceManager.getMemoryAt(34, function (error, result) {
207 console.log(result)
208 if (error) {
209 st.fail(error)
210 } else {
211 st.ok(result.length === 3)
212 st.ok(result[2] === '0000000000000000000000000000000000000000000000000000000000000060')
213 }
214 })
215 })
216
217 t.test('TraceManager.getCurrentPC', function (st) {
218 traceManager.getCurrentPC(13, function (error, result) {
219 console.log(result)
220 if (error) {
221 st.fail(error)
222 } else {
223 st.ok(result === '65')
224 st.end()
225 }
226 })
227 })
228
229 t.test('TraceManager.getCurrentStep', function (st) {
230 traceManager.getCurrentStep(66, function (error, result) {
231 console.log(result)
232 if (error) {
233 st.fail(error)
234 } else {
235 st.ok(result === 2)
236 st.end()
237 }
238 })
239 })
240
241 t.test('TraceManager.getMemExpand', function (st) {
242 traceManager.getMemExpand(2, function (error, result) {
243 console.log(result)
244 if (error) {
245 st.fail(error)
246 } else {
247 st.ok(result === '3')
248 st.end()
249 }
250 })
251 })
252
253 t.test('TraceManager.getStepCost', function (st) {
254 traceManager.getStepCost(34, function (error, result) {
255 console.log(result)
256 if (error) {
257 st.fail(error)
258 } else {
259 st.ok(result === '3')
260 st.end()
261 }
262 })
263 })
264
265 t.test('TraceManager.getRemainingGas', function (st) {
266 traceManager.getRemainingGas(55, function (error, result) {
267 console.log(result)
268 if (error) {
269 st.fail(error)
270 } else {
271 st.ok(result === '79306')
272 st.end()
273 }
274 })
275 })
276
277 t.test('TraceManager.findStepOverBack', function (st) {
278 var result = traceManager.findStepOverBack(116)
279 console.log(result)
280 st.ok(result === 115)
281 st.end()
282 })
283
284 t.test('TraceManager.findStepOverForward', function (st) {
285 var result = traceManager.findStepOverForward(66)
286 console.log(result)
287 st.ok(result === 67)
288 st.end()
289 })
290
291 t.test('TraceManager.findNextCall', function (st) {
292 var result = traceManager.findNextCall(10)
293 console.log(result)
294 st.ok(result === 63)
295 st.end()
296 })
297
298 t.test('TraceManager.getAddresses', function (st) {
299 traceManager.getAddresses(function (error, result) {
300 if (error) {
301 st.fail(error)
302 } else {
303 st.ok(result[0] === '0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
304 st.ok(result[1] === '(Contract Creation - Step 63)')
305 st.end()
306 }
307 })
308 })
309
310 t.test('TraceManager.getReturnValue', function (st) {
311 traceManager.getReturnValue(108, function (error, result) {
312 if (error) {
313 st.fail(error)
314 } else {
315 st.ok(result === '0x60606040526008565b00')
316 st.end()
317 }
318 })
319 })
320})