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

Commit c5d5b7d

Browse files
authored
Merge pull request #2120 from trufflesuite/fix-constant-keys
Fix bugs relating to constant mapping keys
2 parents 83ac203 + cd25ce6 commit c5d5b7d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/truffle-debugger/lib/data/sagas/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function* variablesAndMappingsSaga() {
403403
indexValue = yield* decode(splicedDefinition, indexReference);
404404
} else if (
405405
indexDefinition.referencedDeclaration &&
406-
scopes[indexDefinition.referenceDeclaration]
406+
scopes[indexDefinition.referencedDeclaration]
407407
) {
408408
//there's one more reason we might have failed to decode it: it might be a
409409
//constant state variable. Unfortunately, we don't know how to decode all
@@ -426,7 +426,11 @@ function* variablesAndMappingsSaga() {
426426
indexValue = yield* decode(keyDefinition, {
427427
definition: indexConstantDeclaration.value
428428
});
429+
} else {
430+
indexValue = null; //can't decode; see below for more explanation
429431
}
432+
} else {
433+
indexValue = null; //can't decode; see below for more explanation
430434
}
431435
}
432436
//there's still one more reason we might have failed to decode it:

packages/truffle-debugger/test/data/more-decoding.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ contract ElementaryTest {
9797
mapping(string => string) stringMap;
9898
mapping(address => address) addressMap;
9999
100+
//constant state variables to try as mapping keys
101+
uint constant two = 2;
102+
100103
function run() public {
101104
//local variables to be tested
102105
byte oneByte;
@@ -114,6 +117,7 @@ contract ElementaryTest {
114117
bytesMap[hex"01"] = hex"01";
115118
116119
uintMap[1] = 1;
120+
uintMap[two] = two;
117121
118122
intMap[-1] = -1;
119123
@@ -340,7 +344,7 @@ describe("Further Decoding", function() {
340344
boolMap: new Map([[true, true]]),
341345
byteMap: new Map([["0x01", "0x01"]]),
342346
bytesMap: new Map([["0x01", "0x01"]]),
343-
uintMap: new Map([[1, 1]]),
347+
uintMap: new Map([[1, 1], [2, 2]]),
344348
intMap: new Map([[-1, -1]]),
345349
stringMap: new Map([["0xdeadbeef", "0xdeadbeef"], ["12345", "12345"]]),
346350
addressMap: new Map([[address, address]]),

0 commit comments

Comments
 (0)