Skip to content

Commit 1f4e33f

Browse files
balajipachaifrangioAmxx
authored
Add toStringSigned to Strings.sol (#4330)
Co-authored-by: Francisco <[email protected]> Co-authored-by: Hadrien Croubois <[email protected]>
1 parent fc19a79 commit 1f4e33f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.changeset/tasty-tomatoes-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': major
3+
---
4+
5+
`Strings`: Rename `toString(int256)` to `toStringSigned(int256)`.

contracts/utils/Strings.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ library Strings {
4646
/**
4747
* @dev Converts a `int256` to its ASCII `string` decimal representation.
4848
*/
49-
function toString(int256 value) internal pure returns (string memory) {
49+
function toStringSigned(int256 value) internal pure returns (string memory) {
5050
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
5151
}
5252

test/utils/Strings.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ contract('Strings', function () {
4848
describe('int256', function () {
4949
it('converts MAX_INT256', async function () {
5050
const value = constants.MAX_INT256;
51-
expect(await this.strings.methods['$toString(int256)'](value)).to.equal(value.toString(10));
51+
expect(await this.strings.methods['$toStringSigned(int256)'](value)).to.equal(value.toString(10));
5252
});
5353

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

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

6464
it(`convert negative ${value}`, async function () {
6565
const negated = new BN(value).neg();
66-
expect(await this.strings.methods['$toString(int256)'](negated)).to.equal(negated.toString(10));
66+
expect(await this.strings.methods['$toStringSigned(int256)'](negated)).to.equal(negated.toString(10));
6767
});
6868
}
6969
});

0 commit comments

Comments
 (0)