1

DappToken.sol

   function transfer(address _to, uint256 _value) public  returns (bool success){

    require(balanceOf[msg.sender] >= _value); 

    balanceOf[msg.sender] -= _value;
    balanceOf[_to] += _value;

    emit Transfer(msg.sender, _to, _value);
    return (true);

DappToken.js file

it('transfer token ownership', function() {
    return DappToken.deployed().then(function(instance) {
        tokenInstance = instance;

    something larger than the sender's balance
    return tokenInstance.transfer.call(accounts[1], 999999);
    }).then(assert.fail).catch(function(error) {
        assert(error.message.indexOf('revert') >= 0, 'error message must contain revert');

        return tokenInstance.transfer(accounts[1], 2500, { from: accounts[0] });
    }).then(function(success) {
        assert.equal(success, true, 'it returns true');



    return tokenInstance.transfer(accounts[1], 2500, {from: accounts[0] });     
    }).then(function(receipt) {


        assert.equal(receipt.logs.length, 1, 'triggers one event');
        assert.equal(receipt.logs[0].event, 'Transfer', 'should be the "Transfer" event');
        assert.equal(receipt.logs[0].args._from, accounts[0], 'logs the account the tokens are transferred from');
        assert.equal(receipt.logs[0].args._to, accounts[1], 'logs the account the tokens are transferred to');
        assert.equal(receipt.logs[0].args._value, 2500, 'logs the transfer amount');


    return tokenInstance.balanceOf(accounts[1]);
    }).then(function(balance) {
        assert.equal(balance.toNumber(), 2500, 'adds the amount to the receiving account');
    return tokenInstance.balanceOf(accounts[0]);    
    }).then(function(balance) {
        assert.equal(balance.toNumber(), 7500, 'deducts the amount from the sending account');
    });
0

I'd guess the problem is in the assert

    return tokenInstance.transfer(accounts[1], 2500, { from: accounts[0] });
}).then(function(success) {
    assert.equal(success, true, 'it returns true');

You are comparing the return of a transaction against true. Transactions do not return anything, calls return the value. See here for an explanation about the difference What is the difference between a transaction and a call?.

A possible solution is to check the status of the transaction in the receipt:

    return tokenInstance.transfer(accounts[1], 2500, { from: accounts[0] });
}).then(function(result) {
    assert.ok(result.receipt.status, 'it returns true');

A better solution for token is to verify the emission of the event.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.