UNPKG

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