From febefc1358b2f4ba61f8bcabdc27b5ac8d5512fa Mon Sep 17 00:00:00 2001 From: Clouds Date: Fri, 5 Aug 2022 21:03:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=A0=20Fix=20error=20when=20address=20l?= =?UTF-8?q?ength=20less=20than=2020=20(#782)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/red-rats-jump.md | 5 +++++ waffle-provider/src/CallHistory.ts | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/red-rats-jump.md diff --git a/.changeset/red-rats-jump.md b/.changeset/red-rats-jump.md new file mode 100644 index 000000000..0be8c9370 --- /dev/null +++ b/.changeset/red-rats-jump.md @@ -0,0 +1,5 @@ +--- +"@ethereum-waffle/provider": patch +--- + +🧠 Fix error when address length less than 20 diff --git a/waffle-provider/src/CallHistory.ts b/waffle-provider/src/CallHistory.ts index c83654c58..3d272c8d3 100644 --- a/waffle-provider/src/CallHistory.ts +++ b/waffle-provider/src/CallHistory.ts @@ -96,7 +96,7 @@ export class CallHistory { function toRecordedCall(message: any): RecordedCall { return { - address: message.to ? utils.getAddress(utils.hexlify(message.to)) : undefined, + address: message.to ? decodeAddress(message.to) : undefined, data: message.data ? utils.hexlify(message.data) : '0x' }; } @@ -132,3 +132,14 @@ function decodeNumber(data: Buffer): number { const newData = Buffer.concat([data, Buffer.alloc(32, 0)]); return newData.readUInt32LE(); } + +/** + * Decodes a address taken from EVM execution step + * into a checksumAddress. + */ +function decodeAddress(data: Buffer): string { + if (data.length < 20) { + data = Buffer.concat([Buffer.alloc(20 - data.length, 0), data]); + } + return utils.getAddress(utils.hexlify(data)); +}