Skip to content

Commit 7e7bbed

Browse files
alvrskrzkaczor
andauthoredMar 6, 2022
Update abiParser.ts to work with foundry / forge output + Tests (#624)
Co-authored-by: Kris Kaczor <chris@kaczor.io>
1 parent db551b5 commit 7e7bbed

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed
 

Diff for: ‎.changeset/four-carrots-collect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"typechain": patch
3+
---
4+
5+
Add support for foundry / forge style artifacts

Diff for: ‎packages/typechain/src/parser/abiParser.ts

+5
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ export function extractBytecode(rawContents: string): BytecodeWithLinkReferences
396396
)
397397
}
398398

399+
// handle json schema of @foundry/forge
400+
if (json.bytecode?.object?.match(bytecodeRegex)) {
401+
return extractLinkReferences(json.bytecode.object, json.bytecode.linkReferences)
402+
}
403+
399404
if (json.bytecode?.match(bytecodeRegex)) {
400405
return extractLinkReferences(json.bytecode, json.linkReferences)
401406
}

Diff for: ‎packages/typechain/test/parser/abiParser.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ describe('extractBytecode', () => {
140140
).toEqual(resultBytecode)
141141
})
142142

143+
it('should return bytecode from nested abi (@foundry/forge style)', () => {
144+
expect(extractBytecode(`{ "bytecode": { "object": "${sampleBytecode}" } }`)).toEqual(resultBytecode)
145+
})
146+
143147
it('should return undefined when nested abi bytecode is malformed', () => {
144148
expect(extractBytecode(`{ "bytecode": "surely-not-bytecode" }`)).toEqual(undefined)
145149
})

0 commit comments

Comments
 (0)
Please sign in to comment.