Refactor assert revert helper to encapsulate promises (#628)
This commit is contained in:
committed by
Federico Bond
parent
4ce0e211c5
commit
323d1fa941
@ -1,5 +1,5 @@
|
||||
|
||||
const assertRevert = require('./helpers/assertRevert');
|
||||
import assertRevert from './helpers/assertRevert';
|
||||
|
||||
var StandardTokenMock = artifacts.require('mocks/StandardTokenMock.sol');
|
||||
|
||||
@ -36,12 +36,7 @@ contract('StandardToken', function (accounts) {
|
||||
|
||||
it('should throw an error when trying to transfer more than balance', async function () {
|
||||
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||
try {
|
||||
await token.transfer(accounts[1], 101);
|
||||
assert.fail('should have thrown before');
|
||||
} catch (error) {
|
||||
assertRevert(error);
|
||||
}
|
||||
await assertRevert(token.transfer(accounts[1], 101));
|
||||
});
|
||||
|
||||
it('should return correct balances after transfering from another account', async function () {
|
||||
@ -61,23 +56,13 @@ contract('StandardToken', function (accounts) {
|
||||
|
||||
it('should throw an error when trying to transfer more than allowed', async function () {
|
||||
await token.approve(accounts[1], 99);
|
||||
try {
|
||||
await token.transferFrom(accounts[0], accounts[2], 100, { from: accounts[1] });
|
||||
assert.fail('should have thrown before');
|
||||
} catch (error) {
|
||||
assertRevert(error);
|
||||
}
|
||||
await assertRevert(token.transferFrom(accounts[0], accounts[2], 100, { from: accounts[1] }));
|
||||
});
|
||||
|
||||
it('should throw an error when trying to transferFrom more than _from has', async function () {
|
||||
let balance0 = await token.balanceOf(accounts[0]);
|
||||
await token.approve(accounts[1], 99);
|
||||
try {
|
||||
await token.transferFrom(accounts[0], accounts[2], balance0 + 1, { from: accounts[1] });
|
||||
assert.fail('should have thrown before');
|
||||
} catch (error) {
|
||||
assertRevert(error);
|
||||
}
|
||||
await assertRevert(token.transferFrom(accounts[0], accounts[2], balance0 + 1, { from: accounts[1] }));
|
||||
});
|
||||
|
||||
describe('validating allowance updates to spender', function () {
|
||||
@ -107,22 +92,12 @@ contract('StandardToken', function (accounts) {
|
||||
|
||||
it('should throw an error when trying to transfer to 0x0', async function () {
|
||||
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||
try {
|
||||
await token.transfer(0x0, 100);
|
||||
assert.fail('should have thrown before');
|
||||
} catch (error) {
|
||||
assertRevert(error);
|
||||
}
|
||||
await assertRevert(token.transfer(0x0, 100));
|
||||
});
|
||||
|
||||
it('should throw an error when trying to transferFrom to 0x0', async function () {
|
||||
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||
await token.approve(accounts[1], 100);
|
||||
try {
|
||||
await token.transferFrom(accounts[0], 0x0, 100, { from: accounts[1] });
|
||||
assert.fail('should have thrown before');
|
||||
} catch (error) {
|
||||
assertRevert(error);
|
||||
}
|
||||
await assertRevert(token.transferFrom(accounts[0], 0x0, 100, { from: accounts[1] }));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user