Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix padRight validation failure on large uint #7265

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/web3-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,7 @@ Documentation:
- `_sendPendingRequests` will catch unhandled errors from `_sendToSocket` (#6968)

## [Unreleased]

### Fixed

- fix `padRight` validation failure on large `uint` (#7265)
6 changes: 3 additions & 3 deletions packages/web3-utils/src/string_manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
8 changes: 8 additions & 0 deletions packages/web3-utils/test/fixtures/string_manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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][] = [
Expand Down
Loading