Able to call all other functions in my token contract but only on calling sellBack () function it fails

contract LoanTokens{ 
    function _transfer(address _from, address _to, uint _value);
    mapping (address => uint256) public balanceOf;
    function sellBack(uint tokensSelling);
    uint256 public tokenPrice;

contract LoanForCFL{
// some code 

but when i call

function testEnd(uint amount) {

got no output (no specific error message in remix) .. in mist its showing that the transaction will fail. But when i create a new contract with only the sellBack() function in it,it's working fine. so confused with this ..can anyone help me out here . my sellback function in token code is

function sellBack(uint tokensSelling) external{
    require(balanceOf[msg.sender] >= tokensSelling);
    uint totalTokensPrice = tokensSelling * tokenPrice;
    balanceOf[msg.sender] -= tokensSelling;
    balanceOf[owner] += tokensSelling;
  • Are you are calling sellback from a truffle unit test? Make sure the balance of the sender is enough. – Ismael Sep 26 '17 at 8:01
  • I am calling it from the Mist .. i have over 10000eth in that account ( private network). – jaswanth Sep 26 '17 at 8:53
  • But this call function testEnd(uint amount) { m.sellBack(amount); } is inside a unit test and the sender is the test contract. – Ismael Sep 26 '17 at 15:05
  • i dint used truffel here. function testEnd(uint amount) { m.sellBack(amount); } is also part of LoanCfl contracts functions . it is also not working .. when i tested it in remix the controller stops at m.sellback() and it just stoped – jaswanth Sep 28 '17 at 4:33
  • The problem is when you call m.sellBack(amount) from testEnd the msg.sender will be LoanCfl contract and not the user. Remember that external calls change the msg.sender! – Ismael Sep 28 '17 at 15:49

Your Answer

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

Browse other questions tagged or ask your own question.