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;
// Flag that determines if the token is transferable or not.
bool public isConstant;
bool public transfersEnabled;
// The factory used to create new clone tokens
MiniMeTokenFactory public tokenFactory;
@ -106,7 +106,7 @@ contract MiniMeToken is Controlled {
/// @param _tokenName Name of the new token
/// @param _decimalUnits Number of decimals of 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(
address _tokenFactory,
address _parentToken,
@ -114,7 +114,7 @@ contract MiniMeToken is Controlled {
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol,
bool _isConstant
bool _transfersEnabled
) {
tokenFactory = MiniMeTokenFactory(_tokenFactory);
name = _tokenName; // Set the name
@ -122,7 +122,7 @@ contract MiniMeToken is Controlled {
symbol = _tokenSymbol; // Set the symbol
parentToken = MiniMeToken(_parentToken);
parentSnapShotBlock = _parentSnapShotBlock;
isConstant = _isConstant;
transfersEnabled = _transfersEnabled;
creationBlock = block.number;
}
@ -136,7 +136,7 @@ contract MiniMeToken is Controlled {
/// @param _amount The amount of tokens to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _amount) returns (bool success) {
if (isConstant) throw;
if (!transfersEnabled) throw;
return doTransfer(msg.sender, _to, _amount);
}
@ -154,7 +154,7 @@ contract MiniMeToken is Controlled {
// this contract, which in most situations should be another open
// source smart contract or 0x0
if (msg.sender != controller) {
if (isConstant) throw;
if (!transfersEnabled) throw;
// The standard ERC 20 transferFrom functionality
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
/// @return True if the approval was successful
function approve(address _spender, uint256 _amount) returns (bool success) {
if (isConstant) throw;
if (!transfersEnabled) throw;
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
return true;
@ -230,7 +230,6 @@ contract MiniMeToken is Controlled {
/// @return True if the function call was successful
function approveAndCall(address _spender, uint256 _amount, bytes _extraData
) returns (bool success) {
if (isConstant) throw;
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
@ -276,7 +275,7 @@ contract MiniMeToken is Controlled {
// These next few lines are used when the balance of the token is
// requested before a check point was ever created for this token, it
// requires that the `parentToken.balanceOfAt` be queried at the
// genesis block for that token as this contains initial balance of
// genesis block for that token as this contains initial balance of
// this token
} else if ((balances[_owner].length == 0)
|| (balances[_owner][0].fromBlock > _blockNumber)) {
@ -335,7 +334,7 @@ contract MiniMeToken is Controlled {
/// @param _snapshotBlock Block when the distribution of the parent token is
/// 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
/// @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
/// @return The address of the new MiniMeToken Contract
function createCloneToken(
@ -343,7 +342,7 @@ contract MiniMeToken is Controlled {
uint8 _cloneDecimalUnits,
string _cloneTokenSymbol,
uint _snapshotBlock,
bool _isConstant
bool _transfersEnabled
) returns(address) {
if (_snapshotBlock > block.number) _snapshotBlock = block.number;
MiniMeToken cloneToken = tokenFactory.createCloneToken(
@ -352,7 +351,7 @@ contract MiniMeToken is Controlled {
_cloneTokenName,
_cloneDecimalUnits,
_cloneTokenSymbol,
_isConstant
_transfersEnabled
);
// 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
/// @param _isConstant true to don't allow transfers false to allow transfer
function setConstant(bool _isConstant) onlyController {
isConstant = _isConstant;
/// @notice Sets if the contract allows transfers or not
/// @param _transfersEnabled true to don't allow transfers false to allow transfer
function enableTransfers(bool _transfersEnabled) onlyController {
transfersEnabled = _transfersEnabled;
}
////////////////
@ -484,7 +483,7 @@ contract MiniMeTokenFactory {
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol,
bool _isConstant
bool _transfersEnabled
) returns (MiniMeToken) {
MiniMeToken newToken = new MiniMeToken(
this,
@ -493,7 +492,7 @@ contract MiniMeTokenFactory {
_tokenName,
_decimalUnits,
_tokenSymbol,
_isConstant
_transfersEnabled
);
return newToken;
}

View File

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

View File

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