From 7e7bbed11ca097c8645020f44d398fa4e0512900 Mon Sep 17 00:00:00 2001 From: alvarius <89248902+alvrs@users.noreply.github.com> Date: Sun, 6 Mar 2022 11:48:30 +0100 Subject: [PATCH] Update abiParser.ts to work with foundry / forge output + Tests (#624) Co-authored-by: Kris Kaczor --- .changeset/four-carrots-collect.md | 5 +++++ packages/typechain/src/parser/abiParser.ts | 5 +++++ packages/typechain/test/parser/abiParser.test.ts | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 .changeset/four-carrots-collect.md diff --git a/.changeset/four-carrots-collect.md b/.changeset/four-carrots-collect.md new file mode 100644 index 000000000..08f009781 --- /dev/null +++ b/.changeset/four-carrots-collect.md @@ -0,0 +1,5 @@ +--- +"typechain": patch +--- + +Add support for foundry / forge style artifacts diff --git a/packages/typechain/src/parser/abiParser.ts b/packages/typechain/src/parser/abiParser.ts index 82ffdba55..a33ccce78 100644 --- a/packages/typechain/src/parser/abiParser.ts +++ b/packages/typechain/src/parser/abiParser.ts @@ -396,6 +396,11 @@ export function extractBytecode(rawContents: string): BytecodeWithLinkReferences ) } + // handle json schema of @foundry/forge + if (json.bytecode?.object?.match(bytecodeRegex)) { + return extractLinkReferences(json.bytecode.object, json.bytecode.linkReferences) + } + if (json.bytecode?.match(bytecodeRegex)) { return extractLinkReferences(json.bytecode, json.linkReferences) } diff --git a/packages/typechain/test/parser/abiParser.test.ts b/packages/typechain/test/parser/abiParser.test.ts index 1fbff63bb..da3f41f45 100644 --- a/packages/typechain/test/parser/abiParser.test.ts +++ b/packages/typechain/test/parser/abiParser.test.ts @@ -140,6 +140,10 @@ describe('extractBytecode', () => { ).toEqual(resultBytecode) }) + it('should return bytecode from nested abi (@foundry/forge style)', () => { + expect(extractBytecode(`{ "bytecode": { "object": "${sampleBytecode}" } }`)).toEqual(resultBytecode) + }) + it('should return undefined when nested abi bytecode is malformed', () => { expect(extractBytecode(`{ "bytecode": "surely-not-bytecode" }`)).toEqual(undefined) })