Tests corrected and ->

This commit is contained in:
Jordi Baylina 2016-11-13 06:49:15 +01:00
parent ca15656954
commit 5e8a0fdfa2
3 changed files with 46 additions and 47 deletions

View File

@ -86,7 +86,7 @@ contract MiniMeToken is Controlled {
Checkpoint[] totalSupplyHistory; Checkpoint[] totalSupplyHistory;
// Flag that determines if the token is transferable or not. // Flag that determines if the token is transferable or not.
bool public isConstant; bool public transfersEnabled;
// The factory used to create new clone tokens // The factory used to create new clone tokens
MiniMeTokenFactory public tokenFactory; MiniMeTokenFactory public tokenFactory;
@ -106,7 +106,7 @@ contract MiniMeToken is Controlled {
/// @param _tokenName Name of the new token /// @param _tokenName Name of the new token
/// @param _decimalUnits Number of decimals of the new token /// @param _decimalUnits Number of decimals of the new token
/// @param _tokenSymbol Token Symbol for the new token /// @param _tokenSymbol Token Symbol for the new token
/// @param _isConstant If true, tokens will not be able to be transferred /// @param _transfersEnabled If true, tokens will not be able to be transferred
function MiniMeToken( function MiniMeToken(
address _tokenFactory, address _tokenFactory,
address _parentToken, address _parentToken,
@ -114,7 +114,7 @@ contract MiniMeToken is Controlled {
string _tokenName, string _tokenName,
uint8 _decimalUnits, uint8 _decimalUnits,
string _tokenSymbol, string _tokenSymbol,
bool _isConstant bool _transfersEnabled
) { ) {
tokenFactory = MiniMeTokenFactory(_tokenFactory); tokenFactory = MiniMeTokenFactory(_tokenFactory);
name = _tokenName; // Set the name name = _tokenName; // Set the name
@ -122,7 +122,7 @@ contract MiniMeToken is Controlled {
symbol = _tokenSymbol; // Set the symbol symbol = _tokenSymbol; // Set the symbol
parentToken = MiniMeToken(_parentToken); parentToken = MiniMeToken(_parentToken);
parentSnapShotBlock = _parentSnapShotBlock; parentSnapShotBlock = _parentSnapShotBlock;
isConstant = _isConstant; transfersEnabled = _transfersEnabled;
creationBlock = block.number; creationBlock = block.number;
} }
@ -136,7 +136,7 @@ contract MiniMeToken is Controlled {
/// @param _amount The amount of tokens to be transferred /// @param _amount The amount of tokens to be transferred
/// @return Whether the transfer was successful or not /// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _amount) returns (bool success) { function transfer(address _to, uint256 _amount) returns (bool success) {
if (isConstant) throw; if (!transfersEnabled) throw;
return doTransfer(msg.sender, _to, _amount); return doTransfer(msg.sender, _to, _amount);
} }
@ -154,7 +154,7 @@ contract MiniMeToken is Controlled {
// this contract, which in most situations should be another open // this contract, which in most situations should be another open
// source smart contract or 0x0 // source smart contract or 0x0
if (msg.sender != controller) { if (msg.sender != controller) {
if (isConstant) throw; if (!transfersEnabled) throw;
// The standard ERC 20 transferFrom functionality // The standard ERC 20 transferFrom functionality
if (allowed[_from][msg.sender] < _amount) return false; if (allowed[_from][msg.sender] < _amount) return false;
@ -207,7 +207,7 @@ contract MiniMeToken is Controlled {
/// @param _amount The amount of tokens to be approved for transfer /// @param _amount The amount of tokens to be approved for transfer
/// @return True if the approval was successful /// @return True if the approval was successful
function approve(address _spender, uint256 _amount) returns (bool success) { function approve(address _spender, uint256 _amount) returns (bool success) {
if (isConstant) throw; if (!transfersEnabled) throw;
allowed[msg.sender][_spender] = _amount; allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount); Approval(msg.sender, _spender, _amount);
return true; return true;
@ -230,7 +230,6 @@ contract MiniMeToken is Controlled {
/// @return True if the function call was successful /// @return True if the function call was successful
function approveAndCall(address _spender, uint256 _amount, bytes _extraData function approveAndCall(address _spender, uint256 _amount, bytes _extraData
) returns (bool success) { ) returns (bool success) {
if (isConstant) throw;
allowed[msg.sender][_spender] = _amount; allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount); Approval(msg.sender, _spender, _amount);
@ -335,7 +334,7 @@ contract MiniMeToken is Controlled {
/// @param _snapshotBlock Block when the distribution of the parent token is /// @param _snapshotBlock Block when the distribution of the parent token is
/// copied to set the initial distribution of the new clone token; /// copied to set the initial distribution of the new clone token;
/// if the block is higher than the actual block, the current block is used /// if the block is higher than the actual block, the current block is used
/// @param _isConstant True if transfers are not allowed in the clone token /// @param _transfersEnabled True if transfers are not allowed in the clone token
/// if the block is higher than the actual block, the current block is used /// if the block is higher than the actual block, the current block is used
/// @return The address of the new MiniMeToken Contract /// @return The address of the new MiniMeToken Contract
function createCloneToken( function createCloneToken(
@ -343,7 +342,7 @@ contract MiniMeToken is Controlled {
uint8 _cloneDecimalUnits, uint8 _cloneDecimalUnits,
string _cloneTokenSymbol, string _cloneTokenSymbol,
uint _snapshotBlock, uint _snapshotBlock,
bool _isConstant bool _transfersEnabled
) returns(address) { ) returns(address) {
if (_snapshotBlock > block.number) _snapshotBlock = block.number; if (_snapshotBlock > block.number) _snapshotBlock = block.number;
MiniMeToken cloneToken = tokenFactory.createCloneToken( MiniMeToken cloneToken = tokenFactory.createCloneToken(
@ -352,7 +351,7 @@ contract MiniMeToken is Controlled {
_cloneTokenName, _cloneTokenName,
_cloneDecimalUnits, _cloneDecimalUnits,
_cloneTokenSymbol, _cloneTokenSymbol,
_isConstant _transfersEnabled
); );
// An event to make the token easy to find on the blockchain // An event to make the token easy to find on the blockchain
@ -396,14 +395,14 @@ contract MiniMeToken is Controlled {
} }
//////////////// ////////////////
// Constant tokens // Enable tokens transfers
//////////////// ////////////////
/// @notice Sets if the contract is constant or not /// @notice Sets if the contract allows transfers or not
/// @param _isConstant true to don't allow transfers false to allow transfer /// @param _transfersEnabled true to don't allow transfers false to allow transfer
function setConstant(bool _isConstant) onlyController { function enableTransfers(bool _transfersEnabled) onlyController {
isConstant = _isConstant; transfersEnabled = _transfersEnabled;
} }
//////////////// ////////////////
@ -484,7 +483,7 @@ contract MiniMeTokenFactory {
string _tokenName, string _tokenName,
uint8 _decimalUnits, uint8 _decimalUnits,
string _tokenSymbol, string _tokenSymbol,
bool _isConstant bool _transfersEnabled
) returns (MiniMeToken) { ) returns (MiniMeToken) {
MiniMeToken newToken = new MiniMeToken( MiniMeToken newToken = new MiniMeToken(
this, this,
@ -493,7 +492,7 @@ contract MiniMeTokenFactory {
_tokenName, _tokenName,
_decimalUnits, _decimalUnits,
_tokenSymbol, _tokenSymbol,
_isConstant _transfersEnabled
); );
return newToken; return newToken;
} }

View File

@ -63,7 +63,7 @@ exports.deploy = function(opts, cb) {
opts.tokenName, opts.tokenName,
opts.decimalUnits, opts.decimalUnits,
opts.tokenSymbol, opts.tokenSymbol,
opts.isConstant || false, (opts.transfersEnabled === false) ? false : true,
function(err, _minimeToken) { function(err, _minimeToken) {
if (err) return cb(err); if (err) return cb(err);
minimeToken = _minimeToken; minimeToken = _minimeToken;

View File

@ -21,7 +21,7 @@ var verbose = false;
// b[2] -> 0, 8, 2, 0 // b[2] -> 0, 8, 2, 0
// b[3] -> 0, 9, 1, 0 // b[3] -> 0, 9, 1, 0
// b[4] -> 0, 6, 1, 0 // b[4] -> 0, 6, 1, 0
// Cloned token // Clone token
// b[5] -> 0, 6, 1, 0 // b[5] -> 0, 6, 1, 0
// b[6] -> 0, 2, 5. 0 // b[6] -> 0, 2, 5. 0
@ -29,7 +29,7 @@ var verbose = false;
describe('MiniMeToken test', function(){ describe('MiniMeToken test', function(){
var miniMeToken; var miniMeToken;
var miniMeTokenCloned; var miniMeTokenClone;
var b = []; var b = [];
before(function(done) { before(function(done) {
@ -310,16 +310,16 @@ describe('MiniMeToken test', function(){
}); });
}); });
it('Should Create the cloned token', function(done) { it('Should Create the clone token', function(done) {
this.timeout(200000000); this.timeout(200000000);
async.series([ async.series([
function(cb) { function(cb) {
miniMeToken.createClonedToken( miniMeToken.createCloneToken(
"Cloned Token 1", "Clone Token 1",
18, 18,
"MMTc", "MMTc",
Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER,
false, true,
{ {
from: ethConnector.accounts[3], from: ethConnector.accounts[3],
gas: 4700000 gas: 4700000
@ -327,10 +327,10 @@ describe('MiniMeToken test', function(){
function(err, txHash) { function(err, txHash) {
assert.ifError(err); assert.ifError(err);
ethConnector.web3.eth.getTransactionReceipt(txHash, function(err, res) { ethConnector.web3.eth.getTransactionReceipt(txHash, function(err, res) {
var clonedTokenAddr = ethConnector.web3.toBigNumber(res.logs[0].topics[1]).toString(16); var cloneTokenAddr = ethConnector.web3.toBigNumber(res.logs[0].topics[1]).toString(16);
while (clonedTokenAddr.length < 40) clonedTokenAddr = '0' + clonedTokenAddr; while (cloneTokenAddr.length < 40) cloneTokenAddr = '0' + cloneTokenAddr;
clonedTokenAddr = '0x' + clonedTokenAddr; cloneTokenAddr = '0x' + cloneTokenAddr;
miniMeTokenCloned = ethConnector.web3.eth.contract( miniMeTokenHelper.miniMeTokenAbi).at(clonedTokenAddr); miniMeTokenClone = ethConnector.web3.eth.contract( miniMeTokenHelper.miniMeTokenAbi).at(cloneTokenAddr);
cb(); cb();
}); });
}); });
@ -344,42 +344,42 @@ describe('MiniMeToken test', function(){
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.parentToken(function(err, _parentAddress) { miniMeTokenClone.parentToken(function(err, _parentAddress) {
assert.ifError(err); assert.ifError(err);
assert.equal(_parentAddress, miniMeToken.address); assert.equal(_parentAddress, miniMeToken.address);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.parentSnapShotBlock(function(err, _parentSnapshotBlock) { miniMeTokenClone.parentSnapShotBlock(function(err, _parentSnapshotBlock) {
assert.ifError(err); assert.ifError(err);
assert.equal(_parentSnapshotBlock, b[5]); assert.equal(_parentSnapshotBlock, b[5]);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.totalSupply(function(err, _balance) { miniMeTokenClone.totalSupply(function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 7); assert.equal(ethConnector.web3.fromWei(_balance), 7);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOf(ethConnector.accounts[1], function(err, _balance) { miniMeTokenClone.balanceOf(ethConnector.accounts[1], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 6); assert.equal(ethConnector.web3.fromWei(_balance), 6);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.totalSupplyAt(b[4], function(err, _balance) { miniMeTokenClone.totalSupplyAt(b[4], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0); assert.equal(ethConnector.web3.fromWei(_balance), 0);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOfAt(ethConnector.accounts[2], b[4], function(err, _balance) { miniMeTokenClone.balanceOfAt(ethConnector.accounts[2], b[4], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0); assert.equal(ethConnector.web3.fromWei(_balance), 0);
cb(); cb();
@ -389,10 +389,10 @@ describe('MiniMeToken test', function(){
done(); done();
}); });
}); });
it('Should move tokens in the cloned token from 2 to 3', function(done) { it('Should move tokens in the clone token from 2 to 3', function(done) {
async.series([ async.series([
function(cb) { function(cb) {
miniMeTokenCloned.transfer(ethConnector.accounts[2], ethConnector.web3.toWei(4), { miniMeTokenClone.transfer(ethConnector.accounts[2], ethConnector.web3.toWei(4), {
from: ethConnector.accounts[1], from: ethConnector.accounts[1],
gas: 200000}, gas: 200000},
function(err) { function(err) {
@ -410,14 +410,14 @@ describe('MiniMeToken test', function(){
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOf(ethConnector.accounts[1], function(err, _balance) { miniMeTokenClone.balanceOf(ethConnector.accounts[1], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 2); assert.equal(ethConnector.web3.fromWei(_balance), 2);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOf(ethConnector.accounts[2], function(err, _balance) { miniMeTokenClone.balanceOf(ethConnector.accounts[2], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 5); assert.equal(ethConnector.web3.fromWei(_balance), 5);
cb(); cb();
@ -438,49 +438,49 @@ describe('MiniMeToken test', function(){
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOfAt(ethConnector.accounts[1], b[5], function(err, _balance) { miniMeTokenClone.balanceOfAt(ethConnector.accounts[1], b[5], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 6); assert.equal(ethConnector.web3.fromWei(_balance), 6);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOfAt(ethConnector.accounts[2], b[5], function(err, _balance) { miniMeTokenClone.balanceOfAt(ethConnector.accounts[2], b[5], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 1); assert.equal(ethConnector.web3.fromWei(_balance), 1);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOfAt(ethConnector.accounts[1], b[4], function(err, _balance) { miniMeTokenClone.balanceOfAt(ethConnector.accounts[1], b[4], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0); assert.equal(ethConnector.web3.fromWei(_balance), 0);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.balanceOfAt(ethConnector.accounts[2], b[4], function(err, _balance) { miniMeTokenClone.balanceOfAt(ethConnector.accounts[2], b[4], function(err, _balance) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_balance), 0); assert.equal(ethConnector.web3.fromWei(_balance), 0);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.totalSupply(function(err, _totalSupply) { miniMeTokenClone.totalSupply(function(err, _totalSupply) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_totalSupply), 7); assert.equal(ethConnector.web3.fromWei(_totalSupply), 7);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.totalSupplyAt(b[5], function(err, _totalSupply) { miniMeTokenClone.totalSupplyAt(b[5], function(err, _totalSupply) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_totalSupply), 7); assert.equal(ethConnector.web3.fromWei(_totalSupply), 7);
cb(); cb();
}); });
}, },
function(cb) { function(cb) {
miniMeTokenCloned.totalSupplyAt(b[4], function(err, _totalSupply) { miniMeTokenClone.totalSupplyAt(b[4], function(err, _totalSupply) {
assert.ifError(err); assert.ifError(err);
assert.equal(ethConnector.web3.fromWei(_totalSupply), 0); assert.equal(ethConnector.web3.fromWei(_totalSupply), 0);
cb(); cb();