Skip to content

Commit

Permalink
Fix #5: tests fails with decimal 0
Browse files Browse the repository at this point in the history
  • Loading branch information
lorien committed Nov 9, 2017
1 parent 013231d commit 42a62af
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
10 changes: 8 additions & 2 deletions contracts/TestToken.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
pragma solidity 0.4.18;

import "zeppelin-solidity/contracts/token/StandardToken.sol";
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "./Treasury.sol";


contract TestToken is StandardToken, Ownable {
using SafeMath for uint256;

Treasury public treasury = Treasury(0x0);
uint256 public decimals = 0;

function TestToken(uint _hardCap, uint _decimals) public {
totalSupply = _hardCap * (10**_decimals);
function TestToken(uint256 _totalSupplyItems, uint256 _decimals) public {
decimals = _decimals;
totalSupply = _totalSupplyItems.mul(10**_decimals);
balances[msg.sender] = totalSupply;
}

Expand Down
7 changes: 5 additions & 2 deletions test/data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
let big = require('./util/bigNum.js').big;

const ETHER = big(10**18);
const DECIMALS = big(18);
const TOTAL_SUPPLY_ITEMS = big(252460800)

module.exports = {
DECIMALS: 18,
ETHER: ETHER,
DECIMALS,
TOTAL_SUPPLY_ITEMS,
ETHER,
}
20 changes: 18 additions & 2 deletions test/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ require('chai')
.should();
let data = require('./data.js');
let big = require('./util/bigNum.js').big;

let TestToken = artifacts.require('TestToken');
let {deployTestContracts} = require('./util/deploy.js');

contract('Treasury [all features]', function(accounts) {
contract('TestToken [all features]', function(accounts) {
let {tokenContract} = {};

beforeEach(async () => {
({tokenContract, treasuryContract} = await deployTestContracts(accounts));
});

it('constructor arguments set totalSupply', async () => {
let token = await TestToken.new(100, 2);
10000..should.be.bignumber.equal(await token.totalSupply());
});

it('decimals constructor argument', async () => {
let token = await TestToken.new(100, 2);
2..should.be.bignumber.equal(await token.decimals());
});

it('totalSupply', async() => {
data.TOTAL_SUPPLY_ITEMS.mul(10**data.DECIMALS).should.be.bignumber.equal(
await tokenContract.totalSupply()
);
});

it('setTreasury fails for non-owner', async () => {
await tokenContract.setTreasury(treasuryContract.address, {from: accounts[1]})
.should.be.rejectedWith('invalid opcode');
Expand Down
5 changes: 4 additions & 1 deletion test/util/deploy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
let Treasury = artifacts.require('Treasury');
let TestToken = artifacts.require('TestToken');
let data = require('./../data.js');


async function deployTestContracts(accounts) {
let treasuryContract = await Treasury.new();
let tokenContract = await TestToken.new(252460800, 0);
let tokenContract = await TestToken.new(
data.TOTAL_SUPPLY_ITEMS, data.DECIMALS
);
return {
treasuryContract: treasuryContract,
tokenContract: tokenContract,
Expand Down

0 comments on commit 42a62af

Please sign in to comment.