Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
f4e57fd5
Unverified
Commit
f4e57fd5
authored
Feb 02, 2021
by
Francisco Giordano
Committed by
GitHub
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove SafeMathMock compilation warnings (#2497)
parent
63a0343d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
21 deletions
+23
-21
SafeMathMock.sol
contracts/mocks/SafeMathMock.sol
+7
-5
SafeMath.test.js
test/math/SafeMath.test.js
+16
-16
No files found.
contracts/mocks/SafeMathMock.sol
View file @
f4e57fd5
...
...
@@ -25,23 +25,25 @@ contract SafeMathMock {
return SafeMath.tryMod(a, b);
}
function add(uint256 a, uint256 b) public pure returns (uint256) {
// using the do* naming convention to avoid warnings due to clashing opcode names
function doAdd(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.add(a, b);
}
function
s
ub(uint256 a, uint256 b) public pure returns (uint256) {
function
doS
ub(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.sub(a, b);
}
function
m
ul(uint256 a, uint256 b) public pure returns (uint256) {
function
doM
ul(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.mul(a, b);
}
function div(uint256 a, uint256 b) public pure returns (uint256) {
function d
oD
iv(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.div(a, b);
}
function
m
od(uint256 a, uint256 b) public pure returns (uint256) {
function
doM
od(uint256 a, uint256 b) public pure returns (uint256) {
return SafeMath.mod(a, b);
}
...
...
test/math/SafeMath.test.js
View file @
f4e57fd5
...
...
@@ -167,14 +167,14 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'1234'
);
await
testCommutative
(
this
.
safeMath
.
a
dd
,
a
,
b
,
a
.
add
(
b
));
await
testCommutative
(
this
.
safeMath
.
doA
dd
,
a
,
b
,
a
.
add
(
b
));
});
it
(
'reverts on addition overflow'
,
async
function
()
{
const
a
=
MAX_UINT256
;
const
b
=
new
BN
(
'1'
);
await
testFailsCommutative
(
this
.
safeMath
.
a
dd
,
a
,
b
,
'SafeMath: addition overflow'
);
await
testFailsCommutative
(
this
.
safeMath
.
doA
dd
,
a
,
b
,
'SafeMath: addition overflow'
);
});
});
...
...
@@ -183,14 +183,14 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'1234'
);
expect
(
await
this
.
safeMath
.
s
ub
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
sub
(
b
));
expect
(
await
this
.
safeMath
.
doS
ub
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
sub
(
b
));
});
it
(
'reverts if subtraction result would be negative'
,
async
function
()
{
const
a
=
new
BN
(
'1234'
);
const
b
=
new
BN
(
'5678'
);
await
expectRevert
(
this
.
safeMath
.
s
ub
(
a
,
b
),
'SafeMath: subtraction overflow'
);
await
expectRevert
(
this
.
safeMath
.
doS
ub
(
a
,
b
),
'SafeMath: subtraction overflow'
);
});
});
...
...
@@ -199,21 +199,21 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'1234'
);
const
b
=
new
BN
(
'5678'
);
await
testCommutative
(
this
.
safeMath
.
m
ul
,
a
,
b
,
a
.
mul
(
b
));
await
testCommutative
(
this
.
safeMath
.
doM
ul
,
a
,
b
,
a
.
mul
(
b
));
});
it
(
'multiplies by zero correctly'
,
async
function
()
{
const
a
=
new
BN
(
'0'
);
const
b
=
new
BN
(
'5678'
);
await
testCommutative
(
this
.
safeMath
.
m
ul
,
a
,
b
,
'0'
);
await
testCommutative
(
this
.
safeMath
.
doM
ul
,
a
,
b
,
'0'
);
});
it
(
'reverts on multiplication overflow'
,
async
function
()
{
const
a
=
MAX_UINT256
;
const
b
=
new
BN
(
'2'
);
await
testFailsCommutative
(
this
.
safeMath
.
m
ul
,
a
,
b
,
'SafeMath: multiplication overflow'
);
await
testFailsCommutative
(
this
.
safeMath
.
doM
ul
,
a
,
b
,
'SafeMath: multiplication overflow'
);
});
});
...
...
@@ -222,28 +222,28 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
div
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
div
(
b
));
expect
(
await
this
.
safeMath
.
d
oD
iv
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
div
(
b
));
});
it
(
'divides zero correctly'
,
async
function
()
{
const
a
=
new
BN
(
'0'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
div
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'0'
);
expect
(
await
this
.
safeMath
.
d
oD
iv
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'0'
);
});
it
(
'returns complete number result on non-even division'
,
async
function
()
{
const
a
=
new
BN
(
'7000'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
div
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'1'
);
expect
(
await
this
.
safeMath
.
d
oD
iv
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
'1'
);
});
it
(
'reverts on division by zero'
,
async
function
()
{
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'0'
);
await
expectRevert
(
this
.
safeMath
.
div
(
a
,
b
),
'SafeMath: division by zero'
);
await
expectRevert
(
this
.
safeMath
.
d
oD
iv
(
a
,
b
),
'SafeMath: division by zero'
);
});
});
...
...
@@ -253,28 +253,28 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'284'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
it
(
'when the dividend is equal to the divisor'
,
async
function
()
{
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
it
(
'when the dividend is larger than the divisor'
,
async
function
()
{
const
a
=
new
BN
(
'7000'
);
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
it
(
'when the dividend is a multiple of the divisor'
,
async
function
()
{
const
a
=
new
BN
(
'17034'
);
// 17034 == 5678 * 3
const
b
=
new
BN
(
'5678'
);
expect
(
await
this
.
safeMath
.
m
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
expect
(
await
this
.
safeMath
.
doM
od
(
a
,
b
)).
to
.
be
.
bignumber
.
equal
(
a
.
mod
(
b
));
});
});
...
...
@@ -282,7 +282,7 @@ contract('SafeMath', function (accounts) {
const
a
=
new
BN
(
'5678'
);
const
b
=
new
BN
(
'0'
);
await
expectRevert
(
this
.
safeMath
.
m
od
(
a
,
b
),
'SafeMath: modulo by zero'
);
await
expectRevert
(
this
.
safeMath
.
doM
od
(
a
,
b
),
'SafeMath: modulo by zero'
);
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment