mirror of https://github.com/vacp2p/minime.git
Fix race condition on approve
This commit is contained in:
parent
5bfd0b6429
commit
126a6a1dbf
|
@ -208,6 +208,12 @@ contract MiniMeToken is Controlled {
|
||||||
/// @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 (!transfersEnabled) throw;
|
if (!transfersEnabled) throw;
|
||||||
|
|
||||||
|
// To change the approve amount you first have to reduce the addresses´
|
||||||
|
// allowance to zero by calling `approve(_spender,0)` if it is not
|
||||||
|
// already 0 https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
|
||||||
|
if ((_amount!=0) && (allowed[msg.sender][_spender] !=0)) 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;
|
||||||
|
|
|
@ -101,7 +101,17 @@ describe('MiniMeToken test', function(){
|
||||||
it('Should transfer tokens from address 1 to address 2', function(done) {
|
it('Should transfer tokens from address 1 to address 2', function(done) {
|
||||||
this.timeout(2000);
|
this.timeout(2000);
|
||||||
async.series([
|
async.series([
|
||||||
|
function(cb) {
|
||||||
|
miniMeToken.transfer.estimateGas(ethConnector.accounts[2], ethConnector.web3.toWei(2), {
|
||||||
|
from: ethConnector.accounts[1],
|
||||||
|
gas: 200000},
|
||||||
|
function(err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
log("Gas for transfer: "+res);
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
function(cb) {
|
function(cb) {
|
||||||
miniMeToken.transfer(ethConnector.accounts[2], ethConnector.web3.toWei(2), {
|
miniMeToken.transfer(ethConnector.accounts[2], ethConnector.web3.toWei(2), {
|
||||||
from: ethConnector.accounts[1],
|
from: ethConnector.accounts[1],
|
||||||
|
@ -313,6 +323,24 @@ describe('MiniMeToken test', function(){
|
||||||
it('Should Create the clone token', function(done) {
|
it('Should Create the clone token', function(done) {
|
||||||
this.timeout(200000000);
|
this.timeout(200000000);
|
||||||
async.series([
|
async.series([
|
||||||
|
function(cb) {
|
||||||
|
miniMeToken.createCloneToken.estimateGas(
|
||||||
|
"Clone Token 1",
|
||||||
|
18,
|
||||||
|
"MMTc",
|
||||||
|
Number.MAX_SAFE_INTEGER,
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
from: ethConnector.accounts[3],
|
||||||
|
gas: 4700000
|
||||||
|
},
|
||||||
|
function(err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
log("Gas to create: " +res);
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
function(cb) {
|
function(cb) {
|
||||||
miniMeToken.createCloneToken(
|
miniMeToken.createCloneToken(
|
||||||
"Clone Token 1",
|
"Clone Token 1",
|
||||||
|
|
Loading…
Reference in New Issue