You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.6 KiB
83 lines
2.6 KiB
7 years ago
|
import assertRevert from '../../helpers/assertRevert';
|
||
7 years ago
|
const BasicToken = artifacts.require('BasicTokenMock');
|
||
8 years ago
|
|
||
7 years ago
|
contract('StandardToken', function ([_, owner, recipient, anotherAccount]) {
|
||
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||
8 years ago
|
|
||
7 years ago
|
beforeEach(async function () {
|
||
|
this.token = await BasicToken.new(owner, 100);
|
||
|
});
|
||
|
|
||
|
describe('total supply', function () {
|
||
|
it('returns the total amount of tokens', async function () {
|
||
|
const totalSupply = await this.token.totalSupply();
|
||
8 years ago
|
|
||
7 years ago
|
assert.equal(totalSupply, 100);
|
||
|
});
|
||
7 years ago
|
});
|
||
8 years ago
|
|
||
7 years ago
|
describe('balanceOf', function () {
|
||
|
describe('when the requested account has no tokens', function () {
|
||
|
it('returns zero', async function () {
|
||
|
const balance = await this.token.balanceOf(anotherAccount);
|
||
8 years ago
|
|
||
7 years ago
|
assert.equal(balance, 0);
|
||
|
});
|
||
|
});
|
||
8 years ago
|
|
||
7 years ago
|
describe('when the requested account has some tokens', function () {
|
||
|
it('returns the total amount of tokens', async function () {
|
||
|
const balance = await this.token.balanceOf(owner);
|
||
8 years ago
|
|
||
7 years ago
|
assert.equal(balance, 100);
|
||
|
});
|
||
|
});
|
||
8 years ago
|
});
|
||
|
|
||
7 years ago
|
describe('transfer', function () {
|
||
|
describe('when the recipient is not the zero address', function () {
|
||
|
const to = recipient;
|
||
|
|
||
|
describe('when the sender does not have enough balance', function () {
|
||
|
const amount = 101;
|
||
|
|
||
|
it('reverts', async function () {
|
||
|
await assertRevert(this.token.transfer(to, amount, { from: owner }));
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('when the sender has enough balance', function () {
|
||
|
const amount = 100;
|
||
|
|
||
|
it('transfers the requested amount', async function () {
|
||
|
await this.token.transfer(to, amount, { from: owner });
|
||
|
|
||
|
const senderBalance = await this.token.balanceOf(owner);
|
||
|
assert.equal(senderBalance, 0);
|
||
|
|
||
|
const recipientBalance = await this.token.balanceOf(to);
|
||
|
assert.equal(recipientBalance, amount);
|
||
|
});
|
||
|
|
||
|
it('emits a transfer event', async function () {
|
||
|
const { logs } = await this.token.transfer(to, amount, { from: owner });
|
||
|
|
||
|
assert.equal(logs.length, 1);
|
||
|
assert.equal(logs[0].event, 'Transfer');
|
||
|
assert.equal(logs[0].args.from, owner);
|
||
|
assert.equal(logs[0].args.to, to);
|
||
|
assert(logs[0].args.value.eq(amount));
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('when the recipient is the zero address', function () {
|
||
|
const to = ZERO_ADDRESS;
|
||
|
|
||
|
it('reverts', async function () {
|
||
|
await assertRevert(this.token.transfer(to, 100, { from: owner }));
|
||
|
});
|
||
|
});
|
||
8 years ago
|
});
|
||
8 years ago
|
});
|