Merge pull request #185 from DavidKnott/create-token-with-owner-contract

Create and test MintableToken contract
pull/190/head
Manuel Aráoz 8 years ago committed by GitHub
commit d1f63f5c7e
  1. 41
      contracts/token/MintableToken.sol
  2. 35
      test/MintableToken.js

@ -0,0 +1,41 @@
pragma solidity ^0.4.8;
import './StandardToken.sol';
import '../ownership/Ownable.sol';
/**
* Mintable token
*
* Simple ERC20 Token example, with mintable token creation
* Issue:
* https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
* Based on code by TokenMarketNet:
* https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint value);
bool public mintingFinished = false;
uint public totalSupply = 0;
modifier canMint() {
if(mintingFinished) throw;
_;
}
function mint(address _to, uint _amount) onlyOwner canMint returns (bool) {
totalSupply = safeAdd(totalSupply, _amount);
balances[_to] = safeAdd(balances[_to], _amount);
Mint(_to, _amount);
return true;
}
function finishMinting() onlyOwner returns (bool) {
mintingFinished = true;
return true;
}
}

@ -0,0 +1,35 @@
'use strict';
const assertJump = require('./helpers/assertJump');
var MintableToken = artifacts.require('../contracts/Tokens/MintableToken.sol');
contract('Mintable', function(accounts) {
let token;
beforeEach(async function() {
token = await MintableToken.new();
});
it('should start with a totalSupply of 0', async function() {
let totalSupply = await token.totalSupply();
assert.equal(totalSupply, 0);
});
it('should return mintingFinished false after construction', async function() {
let mintingFinished = await token.mintingFinished();
assert.equal(mintingFinished, false);
});
it('should mint a given amount of tokens to a given address', async function() {
await token.mint(accounts[0], 100);
let balance0 = await token.balanceOf(accounts[0]);
assert(balance0, 100);
let totalSupply = await token.totalSupply();
assert(totalSupply, 100);
})
});
Loading…
Cancel
Save