Truffle debug crashes when inspecting memory array
Games.sol
pragma solidity 0.5.4;
contract Games {
enum GameState {
Invalid,
odd,
even
}
struct Game {
GameState state;
bytes32 gameId;
}
mapping(bytes32 => Game) public games;
function recordMany(bytes32[] memory _games) public {
for (uint i=0; i<_games.length; i++) {
Game storage game = games[_games[i]];
game.state = GameState.odd;
}
}
}
games.test.js
const Games = artifacts.require("Games")
const {randomHex} = web3.utils
contract('Games', async (accounts) => {
let gameIds = []
let gamesInstance
before(async () => {
for(i=0; i < 2; i++) {
gameIds.push(randomHex(32))
}
gamesInstance = await Games.deployed()
})
describe.only('#recordMany', async () => {
it('get all games states', async () => {
await gamesInstance.recordMany(gameIds)
})
})
})
v) at line 19
v should show local variables
an exception thrown
TypeError: Cannot read property '10' of undefined
at Object.storageSize (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-decoder/dist/allocate/storage.js:162:1)
at storageSizeAndAllocate (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-decoder/dist/allocate/storage.js:245:1)
Bug submitted by peppersec.com
Thanks for raising this issue! We'll look into it and someone will get back to you.
OK, I've created PR #1788 to fix this bug. For what it's worth, the problem is not related to memory arrays; rather it was related to local variables of struct storage type, hence why it occurred on line 19, where the local Game storage game was declared.
(Edit: For what it's worth, a local storage variable that was a statically-sized array of structs would also have triggered the bug.)
It was discovered during one of the security audits we have been performing with truffle suite. Thanks again to Truffle team for building amazing tools for auditors.
Just released Truffle v5.0.7 containing the fix for this. Could you try it out and let us know if it's not fixed? Thanks again!