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

Fix a regression in decoding of dynamic structs! #2131

Merged
merged 1 commit into from Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 43 additions & 1 deletion packages/truffle-debugger/test/data/calldata.js
Expand Up @@ -13,7 +13,7 @@ import * as TruffleDecodeUtils from "truffle-decode-utils";
import solidity from "lib/solidity/selectors";

const __CALLDATA = `
pragma solidity ^0.5.4;
pragma solidity ^0.5.6;
pragma experimental ABIEncoderV2;

contract CalldataTest {
Expand All @@ -25,6 +25,10 @@ contract CalldataTest {
uint y;
}

struct StringBox {
string it;
}

function simpleTest(string calldata hello) external {
emit Done(); //break simple
}
Expand Down Expand Up @@ -61,6 +65,10 @@ contract CalldataTest {
this.multiTest("hello", someInts, pair);
}

function stringBoxTest(StringBox calldata stringBox) external returns (string memory) {
return stringBox.it; //break stringBox
}

}

library CalldataLibrary {
Expand Down Expand Up @@ -180,6 +188,40 @@ describe("Calldata Decoding", function() {
assert.include(variables, expectedResult);
});

it("Decodes dynamic structs correctly", async function() {
this.timeout(6000);
let instance = await abstractions.CalldataTest.deployed();
let receipt = await instance.stringBoxTest({ it: "hello world" });
let txHash = receipt.tx;

let bugger = await Debugger.forTx(txHash, {
provider,
files,
contracts: artifacts
});

let session = bugger.connect();

let sourceId = session.view(solidity.current.source).id;
let source = session.view(solidity.current.source).source;
haltman-at marked this conversation as resolved.
Show resolved Hide resolved
await session.addBreakpoint({
sourceId,
line: lineOf("break stringBox", source)
});

await session.continueUntilBreakpoint();

const variables = await session.variables();

const expectedResult = {
stringBox: {
it: "hello world"
}
};

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

it("Decodes correctly in a pure call", async function() {
this.timeout(6000);
let instance = await abstractions.CalldataTest.deployed();
Expand Down
2 changes: 1 addition & 1 deletion packages/truffle-debugger/test/helpers.js
Expand Up @@ -25,7 +25,7 @@ export async function prepareContracts(provider, sources = {}, migrations) {

config.compilers = {
solc: {
version: "0.5.4",
version: "0.5.10",
settings: {
optimizer: { enabled: false, runs: 200 },
evmVersion: "constantinople"
Expand Down
3 changes: 2 additions & 1 deletion packages/truffle-decoder/lib/decode/calldata.ts
Expand Up @@ -177,7 +177,8 @@ function* decodeCalldataStructByPosition(definition: DecodeUtils.AstDefinition,
//there also used to be code here to add on the "_ptr" ending when absent, but we
//presently ignore that ending, so we'll skip that

let decoded = yield* decodeCalldata(memberDefinition, childPointer, info);
let decoded = yield* decodeCalldata(memberDefinition, childPointer, info, startPosition);
haltman-at marked this conversation as resolved.
Show resolved Hide resolved
//note that startPosition is only needed in the dynamic case, but we don't know which case we're in

decodedMembers[memberDefinition.name] = decoded;
}
Expand Down