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
b6feefae
Commit
b6feefae
authored
Nov 23, 2016
by
Arseniy Klempner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create tests for SafeMath
parent
1548e38d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
0 deletions
+100
-0
SafeMathMock.sol
contracts/test-helpers/SafeMathMock.sol
+18
-0
SafeMath.js
test/SafeMath.js
+82
-0
No files found.
contracts/test-helpers/SafeMathMock.sol
0 → 100644
View file @
b6feefae
pragma solidity ^0.4.4;
import '../SafeMath.sol';
contract SafeMathMock is SafeMath {
uint public result;
function multiply(uint a, uint b) {
result = safeMul(a, b);
}
function subtract(uint a, uint b) {
result = safeSub(a, b);
}
function add(uint a, uint b) {
result = safeAdd(a, b);
}
}
test/SafeMath.js
0 → 100644
View file @
b6feefae
contract
(
'SafeMath'
,
function
(
accounts
)
{
var
safeMath
;
before
(
function
()
{
return
SafeMathMock
.
new
()
.
then
(
function
(
_safeMath
)
{
safeMath
=
_safeMath
;
});
});
it
(
"multiplies correctly"
,
function
(
done
)
{
var
a
=
5678
;
var
b
=
1234
;
return
safeMath
.
multiply
(
a
,
b
)
.
then
(
function
()
{
return
safeMath
.
result
();
})
.
then
(
function
(
result
)
{
assert
.
equal
(
result
,
a
*
b
);
})
.
then
(
done
);
});
it
(
"adds correctly"
,
function
(
done
)
{
var
a
=
5678
;
var
b
=
1234
;
return
safeMath
.
add
(
a
,
b
)
.
then
(
function
()
{
return
safeMath
.
result
();
})
.
then
(
function
(
result
)
{
assert
.
equal
(
result
,
a
+
b
);
})
.
then
(
done
);
});
it
(
"subtracts correctly"
,
function
(
done
)
{
var
a
=
5678
;
var
b
=
1234
;
return
safeMath
.
subtract
(
a
,
b
)
.
then
(
function
()
{
return
safeMath
.
result
();
})
.
then
(
function
(
result
)
{
assert
.
equal
(
result
,
a
-
b
);
})
.
then
(
done
);
});
it
(
"should throw an error if subtraction result would be negative"
,
function
(
done
)
{
var
a
=
1234
;
var
b
=
5678
;
return
safeMath
.
subtract
(
a
,
b
)
.
catch
(
function
(
error
)
{
if
(
error
.
message
.
search
(
'invalid JUMP'
)
==
-
1
)
throw
error
})
.
then
(
done
);
});
it
(
"should throw an error on addition overflow"
,
function
(
done
)
{
var
a
=
115792089237316195423570985008687907853269984665640564039457584007913129639935
;
var
b
=
1
;
return
safeMath
.
add
(
a
,
b
)
.
catch
(
function
(
error
)
{
if
(
error
.
message
.
search
(
'invalid JUMP'
)
==
-
1
)
throw
error
})
.
then
(
done
);
});
it
(
"should throw an error on multiplication overflow"
,
function
(
done
)
{
var
a
=
115792089237316195423570985008687907853269984665640564039457584007913129639933
;
var
b
=
2
;
return
safeMath
.
multiply
(
a
,
b
)
.
catch
(
function
(
error
)
{
if
(
error
.
message
.
search
(
'invalid JUMP'
)
==
-
1
)
throw
error
})
.
then
(
done
);
});
});
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