question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accounts balances not update after transactions are performed

See original GitHub issue

I’m making a test in truffle with this solidity contract:

contract Cashbox{


    address public owner;

    uint public limit;
    address public beneficiary;

    function Cashbox( address _beneficiary , uint _limit  ){

        owner = msg.sender;
        beneficiary = _beneficiary;
        limit = _limit;

    }

    function withdraw() returns (bool){



        if(msg.sender != beneficiary )
            return false;


        if(this.balance > limit){

            var sent = beneficiary.send(this.balance);

        }
        else
            return false;


        if(sent)
            return true;
        else
            return false;
    }




}

Being the test file as follows:



contract("Cashbox" , function(accounts){

    var cashbox = null;


    it("constructor is OK" , function(done){

        var aLimit = null;
        var aBenef = null;


        Cashbox.at(Cashbox.deployed_address);


        Cashbox.new(  accounts[1] , 1000   )

        .then(function(c){
            cashbox = c;

            return cashbox.limit.call();

        })

        .then(function(lim){
            aLimit = lim;
            return cashbox.beneficiary.call();
        })


        .then(function(benef){

            aBenef = benef;


            return cashbox.owner.call();

        })


        .then(function(owner){

            assert.equal(aLimit.toNumber() , 1000 , "limit should be 1000");
            assert.equal(aBenef , accounts[1] , "beneficiary should be the second account");
            assert.equal(owner , accounts[0] , "The owner should be the default account");

        })

        .then(done).catch(done);
    });


    it("contract is persistent over tests" , function(done){


        cashbox.limit.call()

        .then(function(value){
            assert.equal(value.toNumber(), 1000 , "limit should have persisted form the first test");
        })

        .then(done).catch(done);

    });


    it("accounts work OK" , function(done){

        var balanceBeforeSend;
        var balanceAfterSend;
        var balanceAfterWithdraw;

        new Promise( function(resolve , error ){

                return web3.eth.getBalance(accounts[1], function(err, hashValue ){

                        if(err)
                            return error(err);
                        else {
                            return resolve(hashValue);
                        }
                }) ;
        } )

        .then(function(balance_beneficiary_before_send){


            balanceBeforeSend = balance_beneficiary_before_send;

            console.log("The beneficiary balance before sending funds is : " + balance_beneficiary_before_send.toNumber() );

            return new Promise( function(resolve , error ){

                    return web3.eth.getBalance(cashbox.address, function(err, hashValue ){

                            if(err)
                                return error(err);
                            else {
                                return resolve(hashValue);
                            }
                    }) ;
            } )
        })


        .then(function(balance_cashbox_before_send){

            console.log("Balance of cashbox contract before send is : " + balance_cashbox_before_send.toNumber() );


            return new Promise( function(resolve , reject){

                web3.eth.sendTransaction({  to : cashbox.address , value : "2000000000000000000" , from : accounts[1] }  , function(err , success ){

                    if (err)
                        return reject(err);
                    else
                        return resolve(success);

                });

            } );//end promise

        })

        .then(function(txResult){

            return new Promise( function(resolve , error ){

                    return web3.eth.getBalance(cashbox.address, function(err, hashValue ){

                            if(err)
                                return error(err);
                            else {
                                return resolve(hashValue);
                            }
                    }) ;
            } )
        })

        .then(function(balance_cashbox_after_send ){

            console.log("balance of contract cashbox after ether send : " + balance_cashbox_after_send.toNumber() );

            return new Promise( function(resolve , error ){

                    return web3.eth.getBalance(accounts[1], function(err, hashValue ){

                            if(err)
                                return error(err);
                            else {
                                return resolve(hashValue);
                            }
                    }) ;
            } )

        })

        .then(function(balance_beneficiary_after_send){

            balanceAfterSend = balance_beneficiary_after_send;
            console.log("balance of beneficiary after the send transaction : " + balance_beneficiary_after_send.toNumber() );

            return cashbox.withdraw({from : accounts[1] });
        })

        .then(function(withdrawResult){

            return new Promise( function(resolve , error ){

                    return web3.eth.getBalance(accounts[1], function(err, hashValue ){

                            if(err)
                                return error(err);
                            else {
                                return resolve(hashValue);
                            }
                    }) ;
            } )
        })


        .then(function( balance_beneficiary_after_withdraw){
            balanceAfterWithdraw = balance_beneficiary_after_withdraw;
            console.log("balance of beneficiary after witdraw : " + balance_beneficiary_after_withdraw.toNumber() );

            return new Promise( function(resolve , error ){

                    return web3.eth.getBalance(cashbox.address, function(err, hashValue ){

                            if(err)
                                return error(err);
                            else {
                                return resolve(hashValue);
                            }
                    }) ;
            } )
        })

        .then(function(balance_cashbox_after_withdraw){

            console.log("balance of cashbox after witdraw : " + balance_cashbox_after_withdraw.toNumber() );

            assert.equal(balance_cashbox_after_withdraw.toNumber() , 0 , "Contract balance should be 0 after a withdraw");
            assert.notEqual(balanceBeforeSend.toNumber() , balanceAfterSend.toNumber() , "beneficiary address balance should not remain equal after a deposit" );
        }).then(done).catch(done);



    })

});

Basically is just to send some ether from an account to a contract and then send that same ether back to the same account.

The second assertion of the third test is failing, stating that the balance of the account is not changed between transactions (but the contract balance does change as it would). It can also be viewed in the console logs.

I’m not sureif I’m doing the things right with all the Promises, I’m not used to them, but the fact that the test is working right with the contract balance but failing with the accounts balance could suggest that all the issue can be a testrpc problem.

Hope this is useful, thanks in advance.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
redsquirrelcommented, Jun 18, 2016

I believe I just ran into this issue. I’m using send to transfer money from one account to another. The send succeeds (returns true), but the balances don’t change.

0reactions
cds-amalcommented, Nov 3, 2021

Closing for issue maintenance

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bank is updating balance but not showing transactions to ...
Go to the Banking menu. Select the blue tile at the top for the bank account you want to update. Select Update.
Read more >
Online balance not updating in one step update but does ...
Not sure about investment accounts. One way to get the account balance to update is to download transactions directly from your bank's website....
Read more >
Account balance not updating? - Tiller Community
Has anybody else run into an issue where their balances aren't updating after running Tiller Money Feeds? I have a number of accounts...
Read more >
Waiting for your balance to update after a payment
If you don't see your account balance update within the typical timeframe for your payment type, contact your local Google Ads collections team...
Read more >
All Chase Accounts do not balance after update - Reddit
If you don't know your opening balance you could check a backup of your data file that was done prior to the Chase...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found