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

Add contractClass interpretation to address values #6130

Merged
merged 4 commits into from Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/codec/lib/basic/decode/index.ts
Expand Up @@ -222,7 +222,7 @@ export function* decodeBasic(
}
bytes = removePadding(bytes, dataType, paddingMode);
const address = Evm.Utils.toAddress(bytes);
let decoded = {
let decoded: Format.Values.AddressValue = {
type: dataType,
kind: "value" as const,
value: {
Expand All @@ -234,7 +234,12 @@ export function* decodeBasic(
//now: attach interpretations
const ensName = yield* reverseEnsResolve(address);
if (ensName !== null) {
decoded.interpretations = { ensName };
decoded.interpretations.ensName = ensName;
}
//yes, this makes the contract/address distinction a little silly
const contractValueInfo = yield* decodeContract(bytes, info);
if (contractValueInfo.kind === "known") {
decoded.interpretations.contractClass = contractValueInfo.class;
}
return decoded;
}
Expand Down
1 change: 1 addition & 0 deletions packages/codec/lib/format/elementary.ts
Expand Up @@ -137,6 +137,7 @@ export interface AddressValue {
};
interpretations: {
ensName?: StringValueInfo;
contractClass?: Types.ContractType;
};
}

Expand Down
37 changes: 21 additions & 16 deletions packages/codec/lib/format/utils/inspect.ts
Expand Up @@ -117,23 +117,28 @@ export class ResultInspector {
return options.stylize(`hex'${hex.slice(2)}'`, "string");
}
case "address": {
const coercedResult = this.result as Format.Values.AddressValue;
const addressString = options.stylize(
coercedResult.value.asAddress,
"number"
const coercedValue = this.result as Format.Values.AddressValue;
//the address/contract distinction has gotten pretty silly!
//so we're just going to convert to the contract case and
//use the existing code there.
const contractValueInfo = coercedValue.interpretations.contractClass
? {
kind: "known" as const,
address: coercedValue.value.asAddress,
class: coercedValue.interpretations.contractClass
}
: {
kind: "unknown" as const,
address: coercedValue.value.asAddress
};
return util.inspect(
new ContractInfoInspector(
contractValueInfo,
coercedValue.interpretations.ensName,
this.options
),
options
);
if (coercedResult.interpretations.ensName) {
const nameString = options.stylize(
stringValueInfoToStringLossy(
coercedResult.interpretations.ensName
),
"special"
);
return this.options.noHideAddress
? `${nameString} [${addressString}]`
: nameString;
}
return options.stylize(coercedResult.value.asAddress, "number");
}
case "string":
return util.inspect(
Expand Down
22 changes: 18 additions & 4 deletions packages/debugger/test/data/more-decoding.js
Expand Up @@ -446,9 +446,9 @@ describe("Further Decoding", function () {

await bugger.continueUntilBreakpoint();

const variables = Codec.Format.Utils.Inspect.unsafeNativizeVariables(
await bugger.variables()
);
const rawVariables = await bugger.variables();
const variables =
Codec.Format.Utils.Inspect.unsafeNativizeVariables(rawVariables);
debug("variables %O", variables);

const expectedResult = {
Expand All @@ -457,7 +457,11 @@ describe("Further Decoding", function () {
bytesMap: { "0x01": "0x01" },
uintMap: { 1: 1, 2: 2 },
intMap: { "-1": -1 },
stringMap: { "0xdeadbeef": "0xdeadbeef", 12345: "12345", hello: "hello" },
stringMap: {
"0xdeadbeef": "0xdeadbeef",
"12345": "12345",
"hello": "hello"
},
addressMap: { [address]: address },
contractMap: { [address]: address },
enumMap: { "ElementaryTest.Ternary.Blue": "ElementaryTest.Ternary.Blue" },
Expand All @@ -476,6 +480,16 @@ describe("Further Decoding", function () {
};

assert.deepInclude(variables, expectedResult);

//while we're at it, let's also test the interpretation on addressMap[address]
const value = rawVariables.addressMap.value[0].value;
assert.equal(value.kind, "value");
assert.equal(value.type.typeClass, "address");
assert.isDefined(value.interpretations.contractClass);
assert.equal(
value.interpretations.contractClass.typeName,
"ElementaryTest"
);
});

it("Splices locations correctly", async function () {
Expand Down