change SmartToken test to work with new linter rules
This commit is contained in:
@ -1,18 +1,16 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const assertJump = require('./helpers/assertJump');
|
import EVMRevert from './helpers/EVMRevert';
|
||||||
const expectThrow = require('./helpers/expectThrow');
|
var Message = artifacts.require('./mock/MessageHelper.sol');
|
||||||
var Message = artifacts.require('./helpers/Message.sol');
|
var SmartTokenMock = artifacts.require('./mock/SmartTokenMock.sol');
|
||||||
var SmartTokenMock = artifacts.require('./helpers/SmartTokenMock.sol');
|
|
||||||
|
|
||||||
var BigNumber = web3.BigNumber;
|
var BigNumber = web3.BigNumber;
|
||||||
|
|
||||||
require('chai')
|
require('chai')
|
||||||
|
.use(require('chai-as-promised'))
|
||||||
.use(require('chai-bignumber')(BigNumber))
|
.use(require('chai-bignumber')(BigNumber))
|
||||||
.should();
|
.should();
|
||||||
|
|
||||||
contract('SmartToken', function (accounts) {
|
contract('SmartToken', function (accounts) {
|
||||||
|
|
||||||
let token;
|
let token;
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
@ -43,12 +41,7 @@ contract('SmartToken', 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 () {
|
||||||
try {
|
await token.transfer(accounts[1], 101).should.be.rejectedWith(EVMRevert);
|
||||||
await token.transfer(accounts[1], 101);
|
|
||||||
assert.fail('should have thrown before');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(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 () {
|
||||||
@ -67,23 +60,19 @@ contract('SmartToken', 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 token.transferFrom(
|
||||||
await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
|
accounts[0], accounts[2], 100,
|
||||||
assert.fail('should have thrown before');
|
{ from: accounts[1] }
|
||||||
} catch (error) {
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assertJump(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 token.transferFrom(
|
||||||
await token.transferFrom(accounts[0], accounts[2], balance0+1, {from: accounts[1]});
|
accounts[0], accounts[2], balance0 + 1,
|
||||||
assert.fail('should have thrown before');
|
{ from: accounts[1] }
|
||||||
} catch (error) {
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validating allowance updates to spender', function () {
|
describe('validating allowance updates to spender', function () {
|
||||||
@ -92,7 +81,7 @@ contract('SmartToken', function(accounts) {
|
|||||||
it('should start with zero', async function () {
|
it('should start with zero', async function () {
|
||||||
preApproved = await token.allowance(accounts[0], accounts[1]);
|
preApproved = await token.allowance(accounts[0], accounts[1]);
|
||||||
assert.equal(preApproved, 0);
|
assert.equal(preApproved, 0);
|
||||||
})
|
});
|
||||||
|
|
||||||
it('should increase by 50 then decrease by 10', async function () {
|
it('should increase by 50 then decrease by 10', async function () {
|
||||||
await token.increaseApproval(accounts[1], 50);
|
await token.increaseApproval(accounts[1], 50);
|
||||||
@ -101,7 +90,7 @@ contract('SmartToken', function(accounts) {
|
|||||||
await token.decreaseApproval(accounts[1], 10);
|
await token.decreaseApproval(accounts[1], 10);
|
||||||
let postDecrease = await token.allowance(accounts[0], accounts[1]);
|
let postDecrease = await token.allowance(accounts[0], accounts[1]);
|
||||||
postIncrease.minus(10).should.be.bignumber.equal(postDecrease);
|
postIncrease.minus(10).should.be.bignumber.equal(postDecrease);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should increase by 50 then set to 0 when decreasing by more than 50', async function () {
|
it('should increase by 50 then set to 0 when decreasing by more than 50', async function () {
|
||||||
@ -112,22 +101,13 @@ contract('SmartToken', 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 () {
|
||||||
try {
|
await token.transfer(0x0, 100).should.be.rejectedWith(EVMRevert);
|
||||||
let transfer = await token.transfer(0x0, 100);
|
|
||||||
assert.fail('should have thrown before');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(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 () {
|
||||||
await token.approve(accounts[1], 100);
|
await token.approve(accounts[1], 100);
|
||||||
try {
|
await token.transferFrom(accounts[0], 0x0, 100, { from: accounts[1] })
|
||||||
let transfer = await token.transferFrom(accounts[0], 0x0, 100, {from: accounts[1]});
|
.should.be.rejectedWith(EVMRevert);
|
||||||
assert.fail('should have thrown before');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return correct balances after approve and show the event on receiver contract', async function () {
|
it('should return correct balances after approve and show the event on receiver contract', async function () {
|
||||||
@ -146,7 +126,6 @@ contract('SmartToken', function(accounts) {
|
|||||||
new BigNumber(100).should.be.bignumber.equal(
|
new BigNumber(100).should.be.bignumber.equal(
|
||||||
await token.allowance(accounts[0], message.contract.address)
|
await token.allowance(accounts[0], message.contract.address)
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return correct balances after transferData and show the event on receiver contract', async function () {
|
it('should return correct balances after transferData and show the event on receiver contract', async function () {
|
||||||
@ -165,7 +144,6 @@ contract('SmartToken', function(accounts) {
|
|||||||
new BigNumber(100).should.be.bignumber.equal(
|
new BigNumber(100).should.be.bignumber.equal(
|
||||||
await token.balanceOf(message.contract.address)
|
await token.balanceOf(message.contract.address)
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return correct allowance after approveData and show the event on receiver contract', async function () {
|
it('should return correct allowance after approveData and show the event on receiver contract', async function () {
|
||||||
@ -184,7 +162,6 @@ contract('SmartToken', function(accounts) {
|
|||||||
new BigNumber(100).should.be.bignumber.equal(
|
new BigNumber(100).should.be.bignumber.equal(
|
||||||
await token.allowance(accounts[0], message.contract.address)
|
await token.allowance(accounts[0], message.contract.address)
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return correct balances after transferFrom and show the event on receiver contract', async function () {
|
it('should return correct balances after transferFrom and show the event on receiver contract', async function () {
|
||||||
@ -209,7 +186,6 @@ contract('SmartToken', function(accounts) {
|
|||||||
new BigNumber(100).should.be.bignumber.equal(
|
new BigNumber(100).should.be.bignumber.equal(
|
||||||
await token.balanceOf(message.contract.address)
|
await token.balanceOf(message.contract.address)
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail inside approveData', async function () {
|
it('should fail inside approveData', async function () {
|
||||||
@ -217,20 +193,14 @@ contract('SmartToken', function(accounts) {
|
|||||||
|
|
||||||
let data = message.contract.fail.getData();
|
let data = message.contract.fail.getData();
|
||||||
|
|
||||||
try {
|
|
||||||
await token.approveData(
|
await token.approveData(
|
||||||
message.contract.address, 10, data,
|
message.contract.address, 10, data,
|
||||||
{ from: accounts[1] }
|
{ from: accounts[1] }
|
||||||
);
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assert(false, 'approveData should have raised');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// approval should not have gone through so allowance is still 0
|
// approval should not have gone through so allowance is still 0
|
||||||
new BigNumber(0).should.be.bignumber
|
new BigNumber(0).should.be.bignumber
|
||||||
.equal(await token.allowance(accounts[1], message.contract.address));
|
.equal(await token.allowance(accounts[1], message.contract.address));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail inside transferData', async function () {
|
it('should fail inside transferData', async function () {
|
||||||
@ -238,20 +208,14 @@ contract('SmartToken', function(accounts) {
|
|||||||
|
|
||||||
let data = message.contract.fail.getData();
|
let data = message.contract.fail.getData();
|
||||||
|
|
||||||
try {
|
|
||||||
await token.transferData(
|
await token.transferData(
|
||||||
message.contract.address, 10, data,
|
message.contract.address, 10, data,
|
||||||
{ from: accounts[0] }
|
{ from: accounts[0] }
|
||||||
);
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assert(false, 'transferData should have failed');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// transfer should not have gone through, so balance is still 0
|
// transfer should not have gone through, so balance is still 0
|
||||||
new BigNumber(0).should.be.bignumber
|
new BigNumber(0).should.be.bignumber
|
||||||
.equal(await token.balanceOf(message.contract.address));
|
.equal(await token.balanceOf(message.contract.address));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail inside transferDataFrom', async function () {
|
it('should fail inside transferDataFrom', async function () {
|
||||||
@ -261,62 +225,37 @@ contract('SmartToken', function(accounts) {
|
|||||||
|
|
||||||
await token.approve(accounts[1], 10, { from: accounts[2] });
|
await token.approve(accounts[1], 10, { from: accounts[2] });
|
||||||
|
|
||||||
try {
|
|
||||||
await token.transferDataFrom(
|
await token.transferDataFrom(
|
||||||
accounts[2], message.contract.address, 10, data,
|
accounts[2], message.contract.address, 10, data,
|
||||||
{ from: accounts[1] }
|
{ from: accounts[1] }
|
||||||
);
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assert(false, 'transferDataFrom should have thrown');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// transferDataFrom should have failed so balance is still 0 but allowance is 10
|
// transferDataFrom should have failed so balance is still 0 but allowance is 10
|
||||||
new BigNumber(10).should.be.bignumber
|
new BigNumber(10).should.be.bignumber
|
||||||
.equal(await token.allowance(accounts[2], accounts[1]));
|
.equal(await token.allowance(accounts[2], accounts[1]));
|
||||||
new BigNumber(0).should.be.bignumber
|
new BigNumber(0).should.be.bignumber
|
||||||
.equal(await token.balanceOf(message.contract.address));
|
.equal(await token.balanceOf(message.contract.address));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail approveData when using token contract address as receiver', async function () {
|
it('should fail approveData when using token contract address as receiver', async function () {
|
||||||
let data = token.contract.approve.getData(accounts[5], 66);
|
let data = token.contract.approve.getData(accounts[5], 66);
|
||||||
|
|
||||||
try {
|
await token.approveData(
|
||||||
await token.approveData(token.contract.address, 100, data, {from: accounts[0]});
|
token.contract.address, 100, data,
|
||||||
assert(false, 'approveData should have thrown because the spender cannot be the token itself');
|
{ from: accounts[0] }
|
||||||
} catch(error) {
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail transferData when using token contract address as receiver', async function () {
|
it('should fail transferData when using token contract address as receiver', async function () {
|
||||||
|
|
||||||
try {
|
|
||||||
await token.transferData(
|
await token.transferData(
|
||||||
token.contract.address, 100, web3.toHex(0), { from: accounts[0] }
|
token.contract.address, 100, web3.toHex(0), { from: accounts[0] }
|
||||||
);
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assert(false, 'transferData should have thrown because the spender cannot be the token itself');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail transferDataFrom when using token contract address as receiver', async function () {
|
it('should fail transferDataFrom when using token contract address as receiver', async function () {
|
||||||
|
|
||||||
await token.approve(accounts[1], 1, { from: accounts[0] });
|
await token.approve(accounts[1], 1, { from: accounts[0] });
|
||||||
|
|
||||||
try {
|
|
||||||
await token.transferDataFrom(
|
await token.transferDataFrom(
|
||||||
accounts[0], token.contract.address, 1, web3.toHex(0), { from: accounts[1] }
|
accounts[0], token.contract.address, 1, web3.toHex(0), { from: accounts[1] }
|
||||||
);
|
).should.be.rejectedWith(EVMRevert);
|
||||||
assert(false, 'transferDataFrom should have thrown because the spender cannot be the token itself');
|
|
||||||
} catch(error) {
|
|
||||||
assertJump(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user