Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/behaviors/erc20/burn.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ module.exports = (tokenOwner) => {
initialBalance = new BigNumber(await this.contract.balanceOf(tokenOwner));
});

describe("Behavior / ERC20 / Burn", () => {
describe("Behavior / ERC20 / Burn", function () {
it("sanity check: balance >= 100", async function () {
const actual = new BigNumber(await this.contract.balanceOf(tokenOwner));
assert(actual.isGreaterThanOrEqualTo("100"));
});

describe("when the given amount is not greater than balance of the sender", () => {
describe("when the given amount is not greater than balance of the sender", function () {
context("for a zero amount", function () {
shouldBurn("0");
});
Expand Down Expand Up @@ -59,7 +59,7 @@ module.exports = (tokenOwner) => {
}
});

describe("when the given amount is greater than the balance of the sender", () => {
describe("when the given amount is greater than the balance of the sender", function () {
it("reverts", async function () {
const amount = initialBalance.plus(1);
await expectRevert(
Expand Down
39 changes: 39 additions & 0 deletions test/behaviors/erc20/burnFrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { reverts } = require("truffle-assertions");
const { constants } = require("hardlydifficult-eth");

/**
* Requires `this.contract`
*/
module.exports = function (tokenOwner, operator) {
describe("Behavior / ERC20 / BurnFrom", function () {
const burnAmount = 20;

it("should fail to burnFrom without approval", async function () {
await reverts(
this.contract.burnFrom(tokenOwner, burnAmount, { from: operator }),
"ERC20: burn amount exceeds allowance"
);
});

describe("can burn", function () {
let accountBalanceBefore;

beforeEach(async function () {
accountBalanceBefore = await this.contract.balanceOf(tokenOwner);
await this.contract.approve(operator, constants.MAX_UINT, {
from: tokenOwner,
});
await this.contract.burnFrom(tokenOwner, burnAmount, {
from: operator,
});
});

it("account balance went down", async function () {
assert.equal(
(await this.contract.balanceOf(tokenOwner)).toString(),
accountBalanceBefore.subn(burnAmount).toString()
);
});
});
});
};
10 changes: 10 additions & 0 deletions test/behaviors/erc20/decimals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Requires `this.contract`
*/
module.exports = function () {
describe("Behavior / ERC20 / Decimals", function () {
it("should have 18 decimals", async function () {
assert.equal(await this.contract.decimals(), 18);
});
});
};
20 changes: 20 additions & 0 deletions test/behaviors/erc20/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
const burn = require("./burn");
const burnFrom = require("./burnFrom");
const decimals = require("./decimals");
const totalSupply = require("./totalSupply");
const transfer = require("./transfer");
const transferFrom = require("./transferFrom");

function all(tokenOwner, nonTokenHolder, operator) {
burn(tokenOwner);
burnFrom(tokenOwner, operator);
decimals();
totalSupply(tokenOwner);
transfer(tokenOwner, nonTokenHolder);
transferFrom(tokenOwner, nonTokenHolder, operator);
}

module.exports = {
all,
burn,
burnFrom,
decimals,
totalSupply,
transfer,
transferFrom,
};
21 changes: 21 additions & 0 deletions test/behaviors/erc20/totalSupply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const BigNumber = require("bignumber.js");

/**
* Requires `this.contract`
*/
module.exports = function (tokenOwner) {
describe("Behavior / ERC20 / TotalSupply", function () {
let initialBalance;

beforeEach(async function () {
initialBalance = new BigNumber(await this.contract.balanceOf(tokenOwner));
});

it("defaults to token holder's balance", async function () {
assert.equal(
(await this.contract.totalSupply()).toString(),
initialBalance.toFixed()
);
});
});
};
43 changes: 43 additions & 0 deletions test/behaviors/erc20/transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const BigNumber = require("bignumber.js");

/**
* Requires `this.contract`
*/
module.exports = function (tokenOwner, nonTokenHolder) {
describe("Behavior / ERC20 / Transfer", function () {
let initialBalance;

beforeEach(async function () {
initialBalance = new BigNumber(await this.contract.balanceOf(tokenOwner));
});

it("has expected balance before transfer", async function () {
assert.equal(
(await this.contract.balanceOf(tokenOwner)).toString(),
initialBalance.toFixed()
);
assert.equal(await this.contract.balanceOf(nonTokenHolder), 0);
});

describe("can transfer funds", function () {
const transferAmount = 42;

beforeEach(async function () {
await this.contract.transfer(nonTokenHolder, transferAmount, {
from: tokenOwner,
});
});

it("has expected after after transfer", async function () {
assert.equal(
(await this.contract.balanceOf(tokenOwner)).toString(),
initialBalance.minus(transferAmount).toFixed()
);
assert.equal(
(await this.contract.balanceOf(nonTokenHolder)).toString(),
transferAmount
);
});
});
});
};
49 changes: 49 additions & 0 deletions test/behaviors/erc20/transferFrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const BigNumber = require("bignumber.js");

/**
* Requires `this.contract`
*/
module.exports = function (tokenOwner, nonTokenHolder, operator) {
describe("Behavior / ERC20 / TransferFrom", function () {
let initialBalance;

beforeEach(async function () {
initialBalance = new BigNumber(await this.contract.balanceOf(tokenOwner));
});

it("has expected balance before transfer", async function () {
assert.equal(
(await this.contract.balanceOf(tokenOwner)).toString(),
initialBalance.toFixed()
);
assert.equal(await this.contract.balanceOf(nonTokenHolder), 0);
});

describe("can transfer funds", function () {
const transferAmount = 42;

beforeEach(async function () {
await this.contract.approve(operator, -1, { from: tokenOwner });
await this.contract.transferFrom(
tokenOwner,
nonTokenHolder,
transferAmount,
{
from: operator,
}
);
});

it("has expected after after transfer", async function () {
assert.equal(
(await this.contract.balanceOf(tokenOwner)).toString(),
initialBalance.minus(transferAmount).toFixed()
);
assert.equal(
(await this.contract.balanceOf(nonTokenHolder)).toString(),
transferAmount
);
});
});
});
};
49 changes: 0 additions & 49 deletions test/fair/burnFrom.js

This file was deleted.

9 changes: 5 additions & 4 deletions test/fair/burn.js → test/fair/erc20.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const { deployDat } = require("../datHelpers");
const { approveAll } = require("../helpers");
const behaviors = require("../behaviors");

contract("fair / burn", (accounts) => {
contract("fair / ERC20", (accounts) => {
let contracts;
const tokenOwner = accounts[1];
const [beneficiary, tokenOwner, nonTokenHolder, operator] = accounts;

beforeEach(async function () {
contracts = await deployDat(accounts, {
initGoal: 0,
initReserve: 0,
beneficiary,
});
await approveAll(contracts, accounts);

Expand All @@ -20,5 +21,5 @@ contract("fair / burn", (accounts) => {
this.contract = contracts.dat;
});

behaviors.erc20.burn(tokenOwner);
behaviors.erc20.all(tokenOwner, nonTokenHolder, operator);
});
13 changes: 0 additions & 13 deletions test/fair/erc20/decimals.js

This file was deleted.

13 changes: 0 additions & 13 deletions test/fair/erc20/totalSupply.js

This file was deleted.

42 changes: 0 additions & 42 deletions test/fair/erc20/transfer.js

This file was deleted.

Loading