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

Commit

Permalink
Merge pull request #2131 from trufflesuite/fix-dynamic-struct-regression
Browse files Browse the repository at this point in the history
Fix a regression in decoding of dynamic structs!
  • Loading branch information
haltman-at committed Jun 26, 2019
2 parents ddc5216 + 1700933 commit 247e2ff
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
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;
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);
//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

0 comments on commit 247e2ff

Please sign in to comment.