Fix various decoding errors with reference types #1677
Conversation
…or mappings in memory structs, remove the now-unused baseDefinition().
…storage.ts, adjusting references appropriately. (Also, fix an incorrect invocation of storageSize in mapping decoding.)
…ndex.ts so that it dispatches purely based on the pointer type (adding a new stack.ts for the stack), and add extra dispatcher functions in memory.ts and storage.ts to make this work.
…own the timeout on the ID tests from 30 seconds (!) to 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an initial round of comments while we're waiting on Travis. they're mostly devoid of usefulness.
}; | ||
|
||
export interface Slot { | ||
key?: any; // TODO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's preexisting -- I assume @seesemichaelj put that there. I assume it's about the fact that key
is of type any
, which should be narrowed down to something more specific (I figure I'll get to that when I get to going over mapping keys more generally). You're seeing it anew due to it having moved to a different file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe I'll wait until the new decoder output format, actually. In any case the point is I'll handle it eventually.
import BN from "bn.js"; | ||
import Web3 from "web3"; | ||
import { EvmStruct, EvmMapping } from "../interface/contract-decoder"; | ||
import clonedeep from "lodash.clonedeep"; | ||
|
||
export default async function decodeStorageReference(definition: DecodeUtils.AstDefinition, pointer: StoragePointer, info: EvmInfo, web3?: Web3, contractAddress?: string): Promise<any> { | ||
export default async function decodeStorage(definition: DecodeUtils.AstDefinition, pointer: StoragePointer, info: EvmInfo, web3?: Web3, contractAddress?: string): Promise <any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gosh this line is long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then turn on prettier :P
@@ -269,7 +351,7 @@ export default async function decodeStorageReference(definition: DecodeUtils.Ast | |||
} | |||
|
|||
result.members[memberName] = | |||
await decode(definition.typeName.valueType, valuePointer, info, web3, contractAddress); | |||
await decode(valueDefinition, valuePointer, info, web3, contractAddress); | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gosh, changes to this file are sure getting difficult to read about. it all seems reasonable though. we should think about getting this more organized so it doesn't require as large a brain-cache size to look at PRs.
… typo and remove a needless empty line.
…. Also, fix an error in decodeStorageByAddress where it didn't pass enough arguments to read.
Let me add a comment on this most recent commit, because it changes the structure somewhat. Literal pointers are now no longer passed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting effort! Looks good @haltman-at
This PR fixes a number of decoding errors with reference types. Specifically:
Also, the file
truffle-decode-utils/allocation.ts
has now been deleted; its contents have been moved intotruffle-decoder/allocate/storage.ts
, except fornormalizeSlot
, which is gone. (Turns out it was already unused, and I could have deleted it in my last PR like I wanted to, but I didn't notice that then.)Note that in order to add support for local variables, I ended up rewriting
decode/index.ts
to change how the dispatching works there, and added a new filedecode/stack.ts
, along with some new entry points to storage and memory decoding (decodeStorage
,decodeMemory
,decodeStorageByAddress
).I also added a test for these fixes; it doesn't fit in well with the other decoding tests, but I figured it was better than not including it. Also incidentally I turned down the timeout on the variable ID tests from 30 seconds (!) to just 4 seconds. Hopefully that's not too short and this PR passes Travis without me having to turn that back up!