diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 8f25c4c6b20..45439db666e 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -235,3 +235,7 @@ Documentation: - `_sendPendingRequests` will catch unhandled errors from `_sendToSocket` (#6968) ## [Unreleased] + +### Fixed + +- fix `padRight` validation failure on large `uint` (#7265) diff --git a/packages/web3-utils/src/string_manipulation.ts b/packages/web3-utils/src/string_manipulation.ts index 88a0a9a5534..37e82b04b3a 100644 --- a/packages/web3-utils/src/string_manipulation.ts +++ b/packages/web3-utils/src/string_manipulation.ts @@ -75,11 +75,11 @@ export const padRight = (value: Numbers, characterAmount: number, sign = '0'): s return value.padEnd(characterAmount, sign); } - validator.validate(['int'], [value]); - const hexString = typeof value === 'string' && isHexStrict(value) ? value : numberToHex(value); - const prefixLength = hexString.startsWith('-') ? 3 : 2; + + validator.validate([hexString.startsWith('-') ? 'int' : 'uint'], [value]); + return hexString.padEnd(characterAmount + prefixLength, sign); }; diff --git a/packages/web3-utils/test/fixtures/string_manipulation.ts b/packages/web3-utils/test/fixtures/string_manipulation.ts index dde49247677..77cbdfac8e9 100644 --- a/packages/web3-utils/test/fixtures/string_manipulation.ts +++ b/packages/web3-utils/test/fixtures/string_manipulation.ts @@ -56,6 +56,14 @@ export const padRightData: [[Numbers, number, string], HexString][] = [ [[BigInt(10000), 8, '0'], '0x27100000'], [[BigInt(-14), 8, '0'], '-0xe0000000'], [['15.5', 8, '0'], '15.50000'], + [ + ['0x05e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2', 64, '0'], + '0x05e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2', + ], + [ + ['0xb5e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2', 64, '0'], + '0xb5e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2', + ], ]; export const toTwosComplementData: [[Numbers, number | undefined], HexString][] = [