Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
d3be6829
Commit
d3be6829
authored
Jan 05, 2021
by
aniket-engg
Committed by
Aniket
Jan 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
safemath tests enabled and updated
parent
3225071a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
+41
-5
SafeMath_test.sol
libs/remix-tests/tests/examples_4/SafeMath_test.sol
+21
-5
testRunner.spec.ts
libs/remix-tests/tests/testRunner.spec.ts
+20
-0
No files found.
libs/remix-tests/tests/examples_4/SafeMath_test.sol
View file @
d3be6829
...
@@ -23,7 +23,7 @@ contract SafeMathTest {
...
@@ -23,7 +23,7 @@ contract SafeMathTest {
function safeMultiplicationShouldRevert() public returns (bool) {
function safeMultiplicationShouldRevert() public returns (bool) {
uint256 a = 4;
uint256 a = 4;
uint256 b = 2 ** 256 - 1;
uint256 b = 2 ** 256 - 1;
(bool success, bytes memory data) = address(safemathproxy).call
.gas(40000).value(0)
(abi.encode("mulProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call
{gas:40000, value:0}
(abi.encode("mulProxy, [a, b]"));
return Assert.equal(
return Assert.equal(
success,
success,
false,
false,
...
@@ -34,7 +34,7 @@ contract SafeMathTest {
...
@@ -34,7 +34,7 @@ contract SafeMathTest {
function safeDivisionByZeroShouldRevert() public returns (bool) {
function safeDivisionByZeroShouldRevert() public returns (bool) {
uint256 a = 4;
uint256 a = 4;
uint256 b = 0;
uint256 b = 0;
(bool success, bytes memory data) = address(safemathproxy).call
.gas(40000).value(0)
(abi.encode("divProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call
{gas:40000, value:0}
(abi.encode("divProxy, [a, b]"));
return Assert.equal(
return Assert.equal(
success,
success,
false,
false,
...
@@ -53,7 +53,7 @@ contract SafeMathTest {
...
@@ -53,7 +53,7 @@ contract SafeMathTest {
}
}
function safeSubtractShouldRevert() public returns (bool) {
function safeSubtractShouldRevert() public returns (bool) {
(bool success, bytes memory data) = address(safemathproxy).call
.gas(40000).value(0)
(abi.encode("subProxy, [0, 1]"));
(bool success, bytes memory data) = address(safemathproxy).call
{gas:40000, value:0}
(abi.encode("subProxy, [0, 1]"));
return Assert.equal(
return Assert.equal(
success,
success,
false,
false,
...
@@ -61,6 +61,22 @@ contract SafeMathTest {
...
@@ -61,6 +61,22 @@ contract SafeMathTest {
);
);
}
}
function safeSubtractShouldRevertUsingTryCatch() public returns (bool) {
try safemathproxy.subProxy(0, 1) returns ( uint256 res) {
Assert.ok(false, "Should revert");
} catch (bytes memory /*lowLevelData*/) {
Assert.ok(true, "safe subtract should revert");
}
}
function safeSubtractShouldNotRevert() public returns (bool) {
try safemathproxy.subProxy(3, 2) returns ( uint256 res) {
Assert.equal(res, 1, "should be equal to 1");
} catch (bytes memory /*lowLevelData*/) {
Assert.ok(false, "safe subtract should not revert");
}
}
function unsafeAdditionShouldOverflow() public returns (bool) {
function unsafeAdditionShouldOverflow() public returns (bool) {
uint256 a = 1;
uint256 a = 1;
uint256 b = 2 ** 256 - 1;
uint256 b = 2 ** 256 - 1;
...
@@ -70,7 +86,7 @@ contract SafeMathTest {
...
@@ -70,7 +86,7 @@ contract SafeMathTest {
function safeAdditionShouldRevert() public returns (bool) {
function safeAdditionShouldRevert() public returns (bool) {
uint256 a = 1;
uint256 a = 1;
uint256 b = 2 ** 256 - 1;
uint256 b = 2 ** 256 - 1;
(bool success, bytes memory data) = address(safemathproxy).call
.gas(40000).value(0)
(abi.encode("addProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call
{gas:40000, value:0}
(abi.encode("addProxy, [a, b]"));
return Assert.equal(
return Assert.equal(
success,
success,
false,
false,
...
@@ -81,7 +97,7 @@ contract SafeMathTest {
...
@@ -81,7 +97,7 @@ contract SafeMathTest {
function safeModulusShouldRevert() public returns (bool) {
function safeModulusShouldRevert() public returns (bool) {
uint256 a = 1;
uint256 a = 1;
uint256 b = 0;
uint256 b = 0;
(bool success, bytes memory data) = address(safemathproxy).call
.gas(40000).value(0)
(abi.encode("modProxy, [a, b]"));
(bool success, bytes memory data) = address(safemathproxy).call
{gas:40000, value:0}
(abi.encode("modProxy, [a, b]"));
return Assert.equal(
return Assert.equal(
success,
success,
false,
false,
...
...
libs/remix-tests/tests/testRunner.spec.ts
View file @
d3be6829
...
@@ -393,6 +393,26 @@ describe('testRunner', () => {
...
@@ -393,6 +393,26 @@ describe('testRunner', () => {
})
})
//Test signed/unsigned integer weight
//Test signed/unsigned integer weight
describe
(
'test SafeMath library'
,
()
=>
{
const
filename
:
string
=
__dirname
+
'/examples_4/SafeMath_test.sol'
beforeAll
(
done
=>
{
compileAndDeploy
(
filename
,
function
(
_err
:
Error
|
null
|
undefined
,
compilationData
:
object
,
contracts
:
any
,
asts
:
any
,
accounts
:
string
[])
{
runTest
(
'SafeMathTest'
,
contracts
.
SafeMathTest
,
compilationData
[
filename
][
'SafeMathTest'
],
asts
[
filename
],
{
accounts
},
testCallback
,
resultsCallback
(
done
))
})
})
afterAll
(()
=>
{
tests
=
[]
})
it
(
'should have 10 passing tests'
,
()
=>
{
assert
.
equal
(
results
.
passingNum
,
10
)
})
it
(
'should have 0 failing tests'
,
()
=>
{
assert
.
equal
(
results
.
failureNum
,
0
)
})
})
//Test signed/unsigned integer weight
describe
(
'test number weight'
,
()
=>
{
describe
(
'test number weight'
,
()
=>
{
const
filename
:
string
=
__dirname
+
'/number/number_test.sol'
const
filename
:
string
=
__dirname
+
'/number/number_test.sol'
...
...
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