Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 17ed93c

Browse files
committed
Add tests of steps in txlog
1 parent 5b3b7bc commit 17ed93c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

packages/debugger/test/txlog.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as Codec from "@truffle/codec";
1515
import Web3 from "web3";
1616

1717
import txlog from "lib/txlog/selectors";
18+
import trace from "lib/trace/selectors";
1819

1920
const __TXLOG = `
2021
//SPDX-License-Identifier: MIT
@@ -220,6 +221,7 @@ describe("Transaction log (visualizer)", function () {
220221
verifyNoIntermediates(untied);
221222

222223
const root = bugger.view(txlog.views.transactionLog);
224+
const steps = bugger.view(trace.steps).length;
223225
assert.equal(root.type, "transaction");
224226
assert.lengthOf(root.actions, 1);
225227
let call = root.actions[0];
@@ -229,6 +231,8 @@ describe("Transaction log (visualizer)", function () {
229231
assert.equal(call.functionName, "testCall");
230232
assert.equal(call.contractName, "VizTest");
231233
assert.equal(call.returnKind, "return");
234+
assert.equal(call.beginStep, -1); //initial call considered to begin on step -1
235+
assert.equal(call.endStep, steps - 1);
232236
const expectedSelector = Web3.utils
233237
.soliditySha3("testCall(uint256)")
234238
.slice(0, 2 + 2 * Codec.Evm.Utils.SELECTOR_SIZE);
@@ -256,6 +260,11 @@ describe("Transaction log (visualizer)", function () {
256260
assert.equal(call.functionName, "called");
257261
assert.equal(call.contractName, "VizTest");
258262
assert.equal(call.returnKind, "return");
263+
assert.isAbove(
264+
call.endStep,
265+
call.beginStep,
266+
"beginStep should precede endStep for non-instant calls"
267+
);
259268
inputs = Codec.Export.unsafeNativizeVariables(byName(call.arguments));
260269
assert.deepEqual(inputs, {
261270
x: 108
@@ -282,6 +291,7 @@ describe("Transaction log (visualizer)", function () {
282291
verifyNoIntermediates(untied);
283292

284293
const root = bugger.view(txlog.views.transactionLog);
294+
const steps = bugger.view(trace.steps).length;
285295
assert.equal(root.type, "transaction");
286296
assert.lengthOf(root.actions, 1);
287297
let call = root.actions[0];
@@ -291,6 +301,8 @@ describe("Transaction log (visualizer)", function () {
291301
assert.isUndefined(call.functionName);
292302
assert.equal(call.contractName, "Secondary");
293303
assert.equal(call.returnKind, "return");
304+
assert.equal(call.beginStep, -1); //initial call considered to begin on step -1
305+
assert.equal(call.endStep, steps - 1);
294306
const expectedBytecode = abstractions.Secondary.binary;
295307
const expectedArgument = Codec.Conversion.toHexString(
296308
108,
@@ -316,6 +328,11 @@ describe("Transaction log (visualizer)", function () {
316328
assert.equal(call.functionName, "another");
317329
assert.equal(call.contractName, "Secondary");
318330
assert.equal(call.returnKind, "return");
331+
assert.isAbove(
332+
call.endStep,
333+
call.beginStep,
334+
"beginStep should precede endStep for non-instant calls"
335+
);
319336
assert.lengthOf(call.arguments, 0);
320337
outputs = Codec.Export.unsafeNativizeVariables(byName(call.returnValues));
321338
assert.include(outputs, {
@@ -341,6 +358,7 @@ describe("Transaction log (visualizer)", function () {
341358
verifyNoIntermediates(untied);
342359

343360
const root = bugger.view(txlog.views.transactionLog);
361+
const steps = bugger.view(trace.steps).length;
344362
assert.equal(root.type, "transaction");
345363
assert.lengthOf(root.actions, 1);
346364
let call = root.actions[0];
@@ -352,6 +370,8 @@ describe("Transaction log (visualizer)", function () {
352370
assert.equal(call.returnKind, "return");
353371
assert.lengthOf(call.arguments, 0);
354372
assert.lengthOf(call.returnValues, 0);
373+
assert.equal(call.beginStep, -1); //initial call considered to begin on step -1
374+
assert.equal(call.endStep, steps - 1);
355375
assert.lengthOf(call.actions, 1);
356376
call = call.actions[0];
357377
assert.equal(call.type, "callexternal");
@@ -361,6 +381,11 @@ describe("Transaction log (visualizer)", function () {
361381
assert.equal(call.functionName, "loudIncrement");
362382
assert.equal(call.contractName, "VizLibrary");
363383
assert.equal(call.returnKind, "return");
384+
assert.isAbove(
385+
call.endStep,
386+
call.beginStep,
387+
"beginStep should precede endStep for non-instant calls"
388+
);
364389
let inputs = Codec.Export.unsafeNativizeVariables(byName(call.arguments));
365390
assert.deepEqual(inputs, {
366391
x: 1
@@ -390,6 +415,7 @@ describe("Transaction log (visualizer)", function () {
390415
verifyNoIntermediates(untied);
391416

392417
const root = bugger.view(txlog.views.transactionLog);
418+
const steps = bugger.view(trace.steps).length;
393419
assert.equal(root.type, "transaction");
394420
let origin = root.origin;
395421
assert.lengthOf(root.actions, 1);
@@ -403,12 +429,19 @@ describe("Transaction log (visualizer)", function () {
403429
assert.lengthOf(call.arguments, 0);
404430
assert.lengthOf(call.returnValues, 0);
405431
assert.lengthOf(call.actions, 1);
432+
assert.equal(call.beginStep, -1); //initial call considered to begin on step -1
433+
assert.equal(call.endStep, steps - 1);
406434
call = call.actions[0];
407435
assert.equal(call.type, "callexternal");
408436
assert.equal(call.kind, "message");
409437
assert.equal(call.address, origin);
410438
assert.equal(call.value.toNumber(), 1);
411439
assert.equal(call.returnKind, "return");
440+
assert.equal(
441+
call.endStep,
442+
call.beginStep,
443+
"beginStep should equal endStep for instant calls"
444+
);
412445
});
413446

414447
it("Correctly logs a fallback call", async function () {
@@ -428,6 +461,7 @@ describe("Transaction log (visualizer)", function () {
428461
verifyNoIntermediates(untied);
429462

430463
const root = bugger.view(txlog.views.transactionLog);
464+
const steps = bugger.view(trace.steps).length;
431465
assert.equal(root.type, "transaction");
432466
assert.lengthOf(root.actions, 1);
433467
let call = root.actions[0];
@@ -439,11 +473,18 @@ describe("Transaction log (visualizer)", function () {
439473
assert.equal(call.returnKind, "return");
440474
assert.equal(call.returnData, "0xbeefdead");
441475
assert.lengthOf(call.actions, 1);
476+
assert.equal(call.beginStep, -1); //initial call considered to begin on step -1
477+
assert.equal(call.endStep, steps - 1);
442478
call = call.actions[0];
443479
assert.equal(call.type, "callinternal");
444480
assert.equal(call.functionName, "called");
445481
assert.equal(call.contractName, "VizTest");
446482
assert.equal(call.returnKind, "return");
483+
assert.isAbove(
484+
call.endStep,
485+
call.beginStep,
486+
"beginStep should precede endStep for non-instant calls"
487+
);
447488
let inputs = Codec.Export.unsafeNativizeVariables(byName(call.arguments));
448489
assert.deepEqual(inputs, {
449490
x: 4
@@ -481,6 +522,7 @@ describe("Transaction log (visualizer)", function () {
481522
verifyNoIntermediates(untied);
482523

483524
const root = bugger.view(txlog.views.transactionLog);
525+
const steps = bugger.view(trace.steps).length;
484526
assert.equal(root.type, "transaction");
485527
assert.lengthOf(root.actions, 1);
486528
let call = root.actions[0];
@@ -492,13 +534,16 @@ describe("Transaction log (visualizer)", function () {
492534
assert.equal(call.returnKind, "unwind");
493535
assert.lengthOf(call.arguments, 0);
494536
assert.lengthOf(call.actions, 1);
537+
assert.equal(call.beginStep, -1); //initial call considered to begin on step -1
538+
assert.equal(call.endStep, steps - 1);
495539
call = call.actions[0];
496540
assert.equal(call.type, "callinternal");
497541
assert.equal(call.functionName, "callReverter");
498542
assert.equal(call.contractName, "VizTest");
499543
assert.equal(call.returnKind, "revert");
500544
assert.lengthOf(call.arguments, 0);
501545
assert.equal(call.error.kind, "revert");
546+
assert.equal(call.endStep, steps - 1); //the internal and external call should end simultaneously
502547
assert.lengthOf(call.error.arguments, 1);
503548
assert.equal(
504549
Codec.Export.unsafeNativize(call.error.arguments[0].value),
@@ -536,7 +581,9 @@ describe("Transaction log (visualizer)", function () {
536581
x: 108
537582
});
538583
assert.notProperty(call, "returnValues");
584+
assert.notProperty(call, "endStep");
539585
assert.lengthOf(call.actions, 0);
586+
assert.equal(call.beginStep, -1);
540587
assert.isTrue(call.waitingForFunctionDefinition);
541588
assert.isTrue(call.absorbNextInternalCall);
542589
});
@@ -708,6 +755,18 @@ describe("Transaction log (visualizer)", function () {
708755
assert.strictEqual(event.address, instance.address);
709756
assert.strictEqual(event.codeAddress, instance.address);
710757
assert.isTrue(event.status);
758+
759+
//now: check that they all have steps and are in increasing order
760+
let previousStep = -1;
761+
for (const event of flattedEvents) {
762+
assert.isFinite(event.step);
763+
assert.isAbove(
764+
event.step,
765+
previousStep,
766+
"steps should be in increasing order"
767+
);
768+
previousStep = event.step;
769+
}
711770
});
712771

713772
it("Correctly logs an event inside a library", async function () {

0 commit comments

Comments
 (0)