5

Good day,

I have a contract General and a library GenLib.

library GenLib{
    event MoneyIn (address _from, uint256 _amount);
    function moneyIn() {
       MoneyIn(msg.sender, msg.value); <- Only call the event MoneyIn()
   } 
}

contract General{
    function getMoney () payable{
        GenLib.moneyIn();
   }
}

Now the weird part, when I'm trying to send money to the General contract using the getMoney function, the amount that is actually transferred is TWICE the amount that is specified.

That's the JS file I'm using to check my contract:

var Gen   = artifacts.require("General");

contract('Gen', function(accounts) {

  var user = accounts[0];

  var valueP2C      = web3.toWei(2, "ether");

  it("Deploy Gen contract", function(){
    return Gen.deployed().then(function(instance){
      gen = instance;
    });
  });

  it("Gen account is empty", function(done){
    web3.eth.getBalance(gen.address, function(err, res){
      done(assert.equal(res.valueOf(), 0, ""));
    });
  });

  it("Use account is full", function(done){
    web3.eth.getBalance(user, function(err, res){
      userAmount = res.valueOf(); 
      done(assert.equal(res.valueOf(), 0, ""));
    });
  });  

  it ("Send money from user to gen", function(done){ 
    gen.getMoney({from: user, value: valueP2C}).then(function(res){
        done(assert.notEqual(res, null, ""));
      });
  });


  it("Gen recieved money", function(done){
    web3.eth.getBalance(gen.address, function(err, res){
      done(assert.equal(res.valueOf(), valueP2C, ""));
    });
  });

  it("User account is P2C lower", function(done){
    web3.eth.getBalance(user, function(err, res){
      done(assert.equal(res.valueOf(), userAmount - valueP2C, ""));
    });
  });  
}); 

And the final results:

✓ Deploy Gen contract
✓ Gen account is empty
✓ User account is full
✓ Send money from user to gen
1) Gen received money
> No events were emitted
2) User account is P2C lower
> No events were emitted


expected '4000000000000000000' to equal '2000000000000000000' <-TWICE THE AMOUNT
expected '87641250800000000000' to equal 89643554700000000000

Another piece of information that might be useful is that whenever I remove the call to the external library, everything works just fine.

I'm baffled by this weird behavior and would appreciate any help or insight you might have.

  • This bug is still there for me with testRPC 4.0.1 Has anyone found a workaround? – szerte Aug 18 '17 at 13:02
2

You're quite right to be baffled - the behaviour you observe is wrong.

This is an open issue with testrpc, and as you say it is related to the calling of a library function: https://github.com/ethereumjs/testrpc/issues/122

Sorry I couldn't be of more help - you can keep an eye out on the issue for when it is fixed officially!

1

It has been fixed in latest 4.1.0 release

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.