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
323d1fa9
Commit
323d1fa9
authored
Dec 28, 2017
by
Facundo Spagnuolo
Committed by
Federico Bond
Dec 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor assert revert helper to encapsulate promises (#628)
parent
4ce0e211
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
44 additions
and
159 deletions
+44
-159
BasicToken.test.js
test/BasicToken.test.js
+3
-13
Claimable.test.js
test/Claimable.test.js
+4
-13
DayLimit.test.js
test/DayLimit.test.js
+5
-26
LimitBalance.test.js
test/LimitBalance.test.js
+3
-15
Ownable.test.js
test/Ownable.test.js
+3
-13
Pausable.test.js
test/Pausable.test.js
+5
-19
PausableToken.test.js
test/PausableToken.test.js
+4
-14
SafeMath.test.js
test/SafeMath.test.js
+3
-13
StandardToken.test.js
test/StandardToken.test.js
+6
-31
assertRevert.js
test/helpers/assertRevert.js
+8
-2
No files found.
test/BasicToken.test.js
View file @
323d1fa9
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
var
BasicTokenMock
=
artifacts
.
require
(
'mocks/BasicTokenMock.sol'
);
var
BasicTokenMock
=
artifacts
.
require
(
'mocks/BasicTokenMock.sol'
);
...
@@ -23,21 +23,11 @@ contract('BasicToken', function (accounts) {
...
@@ -23,21 +23,11 @@ contract('BasicToken', function (accounts) {
it
(
'should throw an error when trying to transfer more than balance'
,
async
function
()
{
it
(
'should throw an error when trying to transfer more than balance'
,
async
function
()
{
let
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
let
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
try
{
await
assertRevert
(
token
.
transfer
(
accounts
[
1
],
101
));
await
token
.
transfer
(
accounts
[
1
],
101
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should throw an error when trying to transfer to 0x0'
,
async
function
()
{
it
(
'should throw an error when trying to transfer to 0x0'
,
async
function
()
{
let
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
let
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
try
{
await
assertRevert
(
token
.
transfer
(
0x0
,
100
));
await
token
.
transfer
(
0x0
,
100
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
});
});
test/Claimable.test.js
View file @
323d1fa9
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
var
Claimable
=
artifacts
.
require
(
'../contracts/ownership/Claimable.sol'
);
var
Claimable
=
artifacts
.
require
(
'../contracts/ownership/Claimable.sol'
);
...
@@ -24,24 +24,15 @@ contract('Claimable', function (accounts) {
...
@@ -24,24 +24,15 @@ contract('Claimable', function (accounts) {
});
});
it
(
'should prevent to claimOwnership from no pendingOwner'
,
async
function
()
{
it
(
'should prevent to claimOwnership from no pendingOwner'
,
async
function
()
{
try
{
await
assertRevert
(
claimable
.
claimOwnership
({
from
:
accounts
[
2
]
}));
await
claimable
.
claimOwnership
({
from
:
accounts
[
2
]
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
const
other
=
accounts
[
2
];
const
other
=
accounts
[
2
];
const
owner
=
await
claimable
.
owner
.
call
();
const
owner
=
await
claimable
.
owner
.
call
();
assert
.
isTrue
(
owner
!==
other
);
assert
.
isTrue
(
owner
!==
other
);
try
{
await
assertRevert
(
claimable
.
transferOwnership
(
other
,
{
from
:
other
}));
await
claimable
.
transferOwnership
(
other
,
{
from
:
other
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
describe
(
'after initiating a transfer'
,
function
()
{
describe
(
'after initiating a transfer'
,
function
()
{
...
...
test/DayLimit.test.js
View file @
323d1fa9
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
latestTime
from
'./helpers/latestTime'
;
import
latestTime
from
'./helpers/latestTime'
;
import
{
increaseTimeTo
,
duration
}
from
'./helpers/increaseTime'
;
import
{
increaseTimeTo
,
duration
}
from
'./helpers/increaseTime'
;
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
const
DayLimitMock
=
artifacts
.
require
(
'mocks/DayLimitMock.sol'
);
const
DayLimitMock
=
artifacts
.
require
(
'mocks/DayLimitMock.sol'
);
...
@@ -34,13 +34,7 @@ contract('DayLimit', function (accounts) {
...
@@ -34,13 +34,7 @@ contract('DayLimit', function (accounts) {
await
dayLimit
.
attemptSpend
(
8
);
await
dayLimit
.
attemptSpend
(
8
);
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
await
assertRevert
(
dayLimit
.
attemptSpend
(
3
));
try
{
await
dayLimit
.
attemptSpend
(
3
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should allow spending if daily limit is reached and then set higher'
,
async
function
()
{
it
(
'should allow spending if daily limit is reached and then set higher'
,
async
function
()
{
...
@@ -48,12 +42,7 @@ contract('DayLimit', function (accounts) {
...
@@ -48,12 +42,7 @@ contract('DayLimit', function (accounts) {
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
try
{
await
assertRevert
(
dayLimit
.
attemptSpend
(
3
));
await
dayLimit
.
attemptSpend
(
3
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
spentToday
=
await
dayLimit
.
spentToday
();
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
...
@@ -68,12 +57,7 @@ contract('DayLimit', function (accounts) {
...
@@ -68,12 +57,7 @@ contract('DayLimit', function (accounts) {
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
try
{
await
assertRevert
(
dayLimit
.
attemptSpend
(
3
));
await
dayLimit
.
attemptSpend
(
3
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
spentToday
=
await
dayLimit
.
spentToday
();
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
...
@@ -91,12 +75,7 @@ contract('DayLimit', function (accounts) {
...
@@ -91,12 +75,7 @@ contract('DayLimit', function (accounts) {
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
try
{
await
assertRevert
(
dayLimit
.
attemptSpend
(
3
));
await
dayLimit
.
attemptSpend
(
3
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
spentToday
=
await
dayLimit
.
spentToday
();
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
...
...
test/LimitBalance.test.js
View file @
323d1fa9
import
assertRevert
from
'./helpers/assertRevert'
;
var
LimitBalanceMock
=
artifacts
.
require
(
'mocks/LimitBalanceMock.sol'
);
var
LimitBalanceMock
=
artifacts
.
require
(
'mocks/LimitBalanceMock.sol'
);
const
assertRevert
=
require
(
'./helpers/assertRevert'
);
contract
(
'LimitBalance'
,
function
(
accounts
)
{
contract
(
'LimitBalance'
,
function
(
accounts
)
{
let
lb
;
let
lb
;
...
@@ -25,12 +24,7 @@ contract('LimitBalance', function (accounts) {
...
@@ -25,12 +24,7 @@ contract('LimitBalance', function (accounts) {
it
(
'shouldnt allow sending above limit'
,
async
function
()
{
it
(
'shouldnt allow sending above limit'
,
async
function
()
{
let
amount
=
1110
;
let
amount
=
1110
;
try
{
await
assertRevert
(
lb
.
limitedDeposit
({
value
:
amount
}));
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should allow multiple sends below limit'
,
async
function
()
{
it
(
'should allow multiple sends below limit'
,
async
function
()
{
...
@@ -48,12 +42,6 @@ contract('LimitBalance', function (accounts) {
...
@@ -48,12 +42,6 @@ contract('LimitBalance', function (accounts) {
await
lb
.
limitedDeposit
({
value
:
amount
});
await
lb
.
limitedDeposit
({
value
:
amount
});
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
assert
.
equal
(
web3
.
eth
.
getBalance
(
lb
.
address
),
amount
);
await
assertRevert
(
lb
.
limitedDeposit
({
value
:
amount
+
1
}));
try
{
await
lb
.
limitedDeposit
({
value
:
amount
+
1
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
});
});
test/Ownable.test.js
View file @
323d1fa9
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
var
Ownable
=
artifacts
.
require
(
'../contracts/ownership/Ownable.sol'
);
var
Ownable
=
artifacts
.
require
(
'../contracts/ownership/Ownable.sol'
);
...
@@ -27,21 +27,11 @@ contract('Ownable', function (accounts) {
...
@@ -27,21 +27,11 @@ contract('Ownable', function (accounts) {
const
other
=
accounts
[
2
];
const
other
=
accounts
[
2
];
const
owner
=
await
ownable
.
owner
.
call
();
const
owner
=
await
ownable
.
owner
.
call
();
assert
.
isTrue
(
owner
!==
other
);
assert
.
isTrue
(
owner
!==
other
);
try
{
await
assertRevert
(
ownable
.
transferOwnership
(
other
,
{
from
:
other
}));
await
ownable
.
transferOwnership
(
other
,
{
from
:
other
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should guard ownership against stuck state'
,
async
function
()
{
it
(
'should guard ownership against stuck state'
,
async
function
()
{
let
originalOwner
=
await
ownable
.
owner
();
let
originalOwner
=
await
ownable
.
owner
();
try
{
await
assertRevert
(
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
}));
await
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
});
assert
.
fail
();
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
});
});
test/Pausable.test.js
View file @
323d1fa9
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
const
PausableMock
=
artifacts
.
require
(
'mocks/PausableMock.sol'
);
const
PausableMock
=
artifacts
.
require
(
'mocks/PausableMock.sol'
);
contract
(
'Pausable'
,
function
(
accounts
)
{
contract
(
'Pausable'
,
function
(
accounts
)
{
...
@@ -19,24 +19,14 @@ contract('Pausable', function (accounts) {
...
@@ -19,24 +19,14 @@ contract('Pausable', function (accounts) {
let
count0
=
await
Pausable
.
count
();
let
count0
=
await
Pausable
.
count
();
assert
.
equal
(
count0
,
0
);
assert
.
equal
(
count0
,
0
);
try
{
await
assertRevert
(
Pausable
.
normalProcess
());
await
Pausable
.
normalProcess
();
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
let
count1
=
await
Pausable
.
count
();
let
count1
=
await
Pausable
.
count
();
assert
.
equal
(
count1
,
0
);
assert
.
equal
(
count1
,
0
);
});
});
it
(
'can not take drastic measure in non-pause'
,
async
function
()
{
it
(
'can not take drastic measure in non-pause'
,
async
function
()
{
let
Pausable
=
await
PausableMock
.
new
();
let
Pausable
=
await
PausableMock
.
new
();
try
{
await
assertRevert
(
Pausable
.
drasticMeasure
());
await
Pausable
.
drasticMeasure
();
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
const
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
const
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
assert
.
isFalse
(
drasticMeasureTaken
);
assert
.
isFalse
(
drasticMeasureTaken
);
});
});
...
@@ -64,12 +54,8 @@ contract('Pausable', function (accounts) {
...
@@ -64,12 +54,8 @@ contract('Pausable', function (accounts) {
let
Pausable
=
await
PausableMock
.
new
();
let
Pausable
=
await
PausableMock
.
new
();
await
Pausable
.
pause
();
await
Pausable
.
pause
();
await
Pausable
.
unpause
();
await
Pausable
.
unpause
();
try
{
await
Pausable
.
drasticMeasure
();
await
assertRevert
(
Pausable
.
drasticMeasure
());
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
const
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
const
drasticMeasureTaken
=
await
Pausable
.
drasticMeasureTaken
();
assert
.
isFalse
(
drasticMeasureTaken
);
assert
.
isFalse
(
drasticMeasureTaken
);
...
...
test/PausableToken.test.js
View file @
323d1fa9
'user strict'
;
'user strict'
;
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
var
PausableTokenMock
=
artifacts
.
require
(
'mocks/PausableTokenMock.sol'
);
var
PausableTokenMock
=
artifacts
.
require
(
'
./
mocks/PausableTokenMock.sol'
);
contract
(
'PausableToken'
,
function
(
accounts
)
{
contract
(
'PausableToken'
,
function
(
accounts
)
{
let
token
;
let
token
;
...
@@ -53,21 +53,11 @@ contract('PausableToken', function (accounts) {
...
@@ -53,21 +53,11 @@ contract('PausableToken', function (accounts) {
it
(
'should throw an error trying to transfer while transactions are paused'
,
async
function
()
{
it
(
'should throw an error trying to transfer while transactions are paused'
,
async
function
()
{
await
token
.
pause
();
await
token
.
pause
();
try
{
await
assertRevert
(
token
.
transfer
(
accounts
[
1
],
100
));
await
token
.
transfer
(
accounts
[
1
],
100
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should throw an error trying to transfer from another account while transactions are paused'
,
async
function
()
{
it
(
'should throw an error trying to transfer from another account while transactions are paused'
,
async
function
()
{
await
token
.
pause
();
await
token
.
pause
();
try
{
await
assertRevert
(
token
.
transferFrom
(
accounts
[
0
],
accounts
[
1
],
100
));
await
token
.
transferFrom
(
accounts
[
0
],
accounts
[
1
],
100
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
});
});
test/SafeMath.test.js
View file @
323d1fa9
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
const
assertJump
=
require
(
'./helpers/assertJump'
);
const
assertJump
=
require
(
'./helpers/assertJump'
);
var
SafeMathMock
=
artifacts
.
require
(
'mocks/SafeMathMock.sol'
);
var
SafeMathMock
=
artifacts
.
require
(
'mocks/SafeMathMock.sol'
);
...
@@ -49,22 +49,12 @@ contract('SafeMath', function (accounts) {
...
@@ -49,22 +49,12 @@ contract('SafeMath', function (accounts) {
it
(
'should throw an error on addition overflow'
,
async
function
()
{
it
(
'should throw an error on addition overflow'
,
async
function
()
{
let
a
=
115792089237316195423570985008687907853269984665640564039457584007913129639935
;
let
a
=
115792089237316195423570985008687907853269984665640564039457584007913129639935
;
let
b
=
1
;
let
b
=
1
;
try
{
await
assertRevert
(
safeMath
.
add
(
a
,
b
));
await
safeMath
.
add
(
a
,
b
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should throw an error on multiplication overflow'
,
async
function
()
{
it
(
'should throw an error on multiplication overflow'
,
async
function
()
{
let
a
=
115792089237316195423570985008687907853269984665640564039457584007913129639933
;
let
a
=
115792089237316195423570985008687907853269984665640564039457584007913129639933
;
let
b
=
2
;
let
b
=
2
;
try
{
await
assertRevert
(
safeMath
.
multiply
(
a
,
b
));
await
safeMath
.
multiply
(
a
,
b
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
});
});
test/StandardToken.test.js
View file @
323d1fa9
const
assertRevert
=
require
(
'./helpers/assertRevert'
)
;
import
assertRevert
from
'./helpers/assertRevert'
;
var
StandardTokenMock
=
artifacts
.
require
(
'mocks/StandardTokenMock.sol'
);
var
StandardTokenMock
=
artifacts
.
require
(
'mocks/StandardTokenMock.sol'
);
...
@@ -36,12 +36,7 @@ contract('StandardToken', function (accounts) {
...
@@ -36,12 +36,7 @@ contract('StandardToken', function (accounts) {
it
(
'should throw an error when trying to transfer more than balance'
,
async
function
()
{
it
(
'should throw an error when trying to transfer more than balance'
,
async
function
()
{
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
try
{
await
assertRevert
(
token
.
transfer
(
accounts
[
1
],
101
));
await
token
.
transfer
(
accounts
[
1
],
101
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should return correct balances after transfering from another account'
,
async
function
()
{
it
(
'should return correct balances after transfering from another account'
,
async
function
()
{
...
@@ -61,23 +56,13 @@ contract('StandardToken', function (accounts) {
...
@@ -61,23 +56,13 @@ contract('StandardToken', function (accounts) {
it
(
'should throw an error when trying to transfer more than allowed'
,
async
function
()
{
it
(
'should throw an error when trying to transfer more than allowed'
,
async
function
()
{
await
token
.
approve
(
accounts
[
1
],
99
);
await
token
.
approve
(
accounts
[
1
],
99
);
try
{
await
assertRevert
(
token
.
transferFrom
(
accounts
[
0
],
accounts
[
2
],
100
,
{
from
:
accounts
[
1
]
}));
await
token
.
transferFrom
(
accounts
[
0
],
accounts
[
2
],
100
,
{
from
:
accounts
[
1
]
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should throw an error when trying to transferFrom more than _from has'
,
async
function
()
{
it
(
'should throw an error when trying to transferFrom more than _from has'
,
async
function
()
{
let
balance0
=
await
token
.
balanceOf
(
accounts
[
0
]);
let
balance0
=
await
token
.
balanceOf
(
accounts
[
0
]);
await
token
.
approve
(
accounts
[
1
],
99
);
await
token
.
approve
(
accounts
[
1
],
99
);
try
{
await
assertRevert
(
token
.
transferFrom
(
accounts
[
0
],
accounts
[
2
],
balance0
+
1
,
{
from
:
accounts
[
1
]
}));
await
token
.
transferFrom
(
accounts
[
0
],
accounts
[
2
],
balance0
+
1
,
{
from
:
accounts
[
1
]
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
describe
(
'validating allowance updates to spender'
,
function
()
{
describe
(
'validating allowance updates to spender'
,
function
()
{
...
@@ -107,22 +92,12 @@ contract('StandardToken', function (accounts) {
...
@@ -107,22 +92,12 @@ contract('StandardToken', function (accounts) {
it
(
'should throw an error when trying to transfer to 0x0'
,
async
function
()
{
it
(
'should throw an error when trying to transfer to 0x0'
,
async
function
()
{
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
try
{
await
assertRevert
(
token
.
transfer
(
0x0
,
100
));
await
token
.
transfer
(
0x0
,
100
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
it
(
'should throw an error when trying to transferFrom to 0x0'
,
async
function
()
{
it
(
'should throw an error when trying to transferFrom to 0x0'
,
async
function
()
{
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
await
token
.
approve
(
accounts
[
1
],
100
);
await
token
.
approve
(
accounts
[
1
],
100
);
try
{
await
assertRevert
(
token
.
transferFrom
(
accounts
[
0
],
0x0
,
100
,
{
from
:
accounts
[
1
]
}));
await
token
.
transferFrom
(
accounts
[
0
],
0x0
,
100
,
{
from
:
accounts
[
1
]
});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertRevert
(
error
);
}
});
});
});
});
test/helpers/assertRevert.js
View file @
323d1fa9
module
.
exports
=
function
(
error
)
{
export
default
async
promise
=>
{
assert
.
isAbove
(
error
.
message
.
search
(
'revert'
),
-
1
,
'Error containing "revert" must be returned'
);
try
{
await
promise
;
assert
.
fail
(
'Expected revert not received'
);
}
catch
(
error
)
{
const
revertFound
=
error
.
message
.
search
(
'revert'
)
>=
0
;
assert
(
revertFound
,
`Expected "revert", got
${
error
}
instead`
);
}
};
};
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