diff --git a/contracts/token/MintableToken.sol b/contracts/token/MintableToken.sol new file mode 100644 index 000000000..e3a5f8291 --- /dev/null +++ b/contracts/token/MintableToken.sol @@ -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; + } +} \ No newline at end of file diff --git a/test/MintableToken.js b/test/MintableToken.js new file mode 100644 index 000000000..4f574d51d --- /dev/null +++ b/test/MintableToken.js @@ -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); + }) + +});