diff --git a/packages/truffle-debugger/test/data/calldata.js b/packages/truffle-debugger/test/data/calldata.js index acf8b945113..b4f407b1c48 100644 --- a/packages/truffle-debugger/test/data/calldata.js +++ b/packages/truffle-debugger/test/data/calldata.js @@ -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 { @@ -25,6 +25,10 @@ contract CalldataTest { uint y; } + struct StringBox { + string it; + } + function simpleTest(string calldata hello) external { emit Done(); //break simple } @@ -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 { @@ -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(); diff --git a/packages/truffle-debugger/test/helpers.js b/packages/truffle-debugger/test/helpers.js index 17aa58a3f4e..fbf21ceb1d8 100644 --- a/packages/truffle-debugger/test/helpers.js +++ b/packages/truffle-debugger/test/helpers.js @@ -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" diff --git a/packages/truffle-decoder/lib/decode/calldata.ts b/packages/truffle-decoder/lib/decode/calldata.ts index 4e9b01013ff..d94bbe15e50 100644 --- a/packages/truffle-decoder/lib/decode/calldata.ts +++ b/packages/truffle-decoder/lib/decode/calldata.ts @@ -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; }