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

Commit

Permalink
Add test of using Yul sources in debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed Jul 26, 2023
1 parent 3a0a190 commit 1b1fac3
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions packages/debugger/test/data/yul-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import debugModule from "debug";
const debug = debugModule("debugger:test:data:yul");

import { assert } from "chai";

import Ganache from "ganache";

import { prepareContracts, lineOf, testBlockGasLimit } from "../helpers";
import Debugger from "lib/debugger";

import sourcemapping from "lib/sourcemapping/selectors";

import * as Codec from "@truffle/codec";

const __YUL = `
object "YulTest" {
code {
let size := datasize("runtime")
datacopy(0, dataoffset("runtime"), size)
return(0, size)
}
object "runtime" {
code {
let a := 1
let b := 2 //BREAK #1
mstore(0, add(b, a)) //BREAK #2
return(0, 0x20)
}
}
}
`;

let sources = {
"YulTest.yul": __YUL
};

describe("Assembly decoding (Yul source)", function () {
let provider;
let abstractions;
let compilations;

before("Create Provider", async function () {
provider = Ganache.provider({
seed: "debugger",
miner: {
instamine: "strict",
blockGasLimit: testBlockGasLimit
},
logging: {
quiet: true
}
});
});

before("Prepare contracts and artifacts", async function () {
this.timeout(30000);

let prepared = await prepareContracts(provider, sources);
abstractions = prepared.abstractions;
compilations = prepared.compilations;
});

it("Decodes variables in Yul files", async function () {
this.timeout(12000);

let instance = await abstractions.YulTest.deployed();
let receipt = await instance.sendTransaction({});
let txHash = receipt.tx;

let bugger = await Debugger.forTx(txHash, { provider, compilations });

let sourceId = bugger.view(sourcemapping.current.source).id;
let source = bugger.view(sourcemapping.current.source).source;
await bugger.addBreakpoint({
sourceId,
line: lineOf("BREAK #1", source)
});
await bugger.addBreakpoint({
sourceId,
line: lineOf("BREAK #2", source)
});
await bugger.addBreakpoint({
sourceId,
line: lineOf("BREAK #3", source)
});

await bugger.continueUntilBreakpoint();

const numberize = obj =>
Object.assign(
{},
...Object.entries(obj).map(([key, value]) => ({ [key]: Number(value) }))
);

let variables = numberize(
Codec.Format.Utils.Inspect.unsafeNativizeVariables(
await bugger.variables()
)
);

let expectedResult = {
a: 1
};

assert.deepEqual(variables, expectedResult);

await bugger.continueUntilBreakpoint();

variables = numberize(
Codec.Format.Utils.Inspect.unsafeNativizeVariables(
await bugger.variables()
)
);

expectedResult = {
a: 1,
b: 2
};

assert.deepEqual(variables, expectedResult);
});
});

0 comments on commit 1b1fac3

Please sign in to comment.