Skip to content
New issue

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

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

Already on GitHub? # to your account

Rename toString to toStringSigned #4330

17 changes: 17 additions & 0 deletions .changeset/tasty-tomatoes-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'openzeppelin-solidity': major
---

Replaces `toString(int256)` with `toStringSigned(int256)`

# WHAT the breaking change is?

- The toString(int256) is now replaced with toStringSigned(int256)

# WHY the change was made?

- The change was made as invoking `toString(int256)` with an integer literal from another contract was failing with the error `Member "toString" not unique` since `toString(1)` qualifies for both int256 & uint256, hence replaced `toString(int256)` with `toStringSigned(int256)`.

# HOW a consumer should update their code?

- Replace the instances of `toString(int256)` with `toStringSigned(int256)`.
2 changes: 1 addition & 1 deletion contracts/utils/Strings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ library Strings {
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}

Expand Down
8 changes: 4 additions & 4 deletions test/utils/Strings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ contract('Strings', function () {
describe('int256', function () {
it('converts MAX_INT256', async function () {
const value = constants.MAX_INT256;
expect(await this.strings.methods['$toString(int256)'](value)).to.equal(value.toString(10));
expect(await this.strings.methods['$toStringSigned(int256)'](value)).to.equal(value.toString(10));
});

it('converts MIN_INT256', async function () {
const value = constants.MIN_INT256;
expect(await this.strings.methods['$toString(int256)'](value)).to.equal(value.toString(10));
expect(await this.strings.methods['$toStringSigned(int256)'](value)).to.equal(value.toString(10));
});

for (const value of values) {
it(`convert ${value}`, async function () {
expect(await this.strings.methods['$toString(int256)'](value)).to.equal(value);
expect(await this.strings.methods['$toStringSigned(int256)'](value)).to.equal(value);
});

it(`convert negative ${value}`, async function () {
const negated = new BN(value).neg();
expect(await this.strings.methods['$toString(int256)'](negated)).to.equal(negated.toString(10));
expect(await this.strings.methods['$toStringSigned(int256)'](negated)).to.equal(negated.toString(10));
});
}
});
Expand Down