Skip to content

Commit

Permalink
🧠 Fix error when address length less than 20 (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
clouds56 committed Aug 5, 2022
1 parent 2199c8d commit febefc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/red-rats-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ethereum-waffle/provider": patch
---

🧠 Fix error when address length less than 20
13 changes: 12 additions & 1 deletion waffle-provider/src/CallHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
}
Expand Down Expand Up @@ -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));
}

0 comments on commit febefc1

Please sign in to comment.