Skip to content

Commit

Permalink
Update abiParser.ts to work with foundry / forge output + Tests (#624)
Browse files Browse the repository at this point in the history
Co-authored-by: Kris Kaczor <[email protected]>
  • Loading branch information
alvrs and krzkaczor authored Mar 6, 2022
1 parent db551b5 commit 7e7bbed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-carrots-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"typechain": patch
---

Add support for foundry / forge style artifacts
5 changes: 5 additions & 0 deletions packages/typechain/src/parser/abiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/typechain/test/parser/abiParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 7e7bbed

Please sign in to comment.