0

I have one contract and in it's constructor I have initialized properties of balances

contract TestChainCoin is RefundableCrowdsale
{
    function TestChainCoin() RefundableCrowdsale() {
            balances[msg.sender] = 100;                                                                   
        }
}

The balances is described in another contract and this contract have function balanceOf() to return balance.

contract StandardToken is Token {
    mapping (address => uint256) balances;

    function balanceOf(address _owner) constant returns (uint256) {
        return balances[_owner];
    }
  }

Now the problem arise here. I am trying to create test cases in Truffle using javascript and have following code. When I am trying to call balanceOf() then it hits but returns zero amount but I already initialized it to 100.

contract('TestChainCoin', function (accounts) {
  let owner = accounts[0];
      it("should TestChainCoin be deployed first", function() {
        return testChainCoin.deployed().then(function(instance) {
        testChainInstance=instance;
        });
      });

     it("should StandardToken be deployed first", function() {
        return standardToken.deployed().then(function(instance) {
            standTokenInstance=instance;
        });
      });

      it('should return balance of user', async () => {
      let userBal= await standTokenInstance.balanceOf.call(accounts[0]);
      console.log("the balance of user---"+userBal);
      assert(balanceFinal<= 100 && balanceFinal>0, 'balance should not be zero');
      });

So where I am doing wrong.

  • TestChainCoin is a crowdsale and StandardToken is a token, usually in OpenZeppelin they are separate contracts and they do not share storage. – Ismael Mar 18 '18 at 4:10
  • so what should be the solution Ismael? – Ritesh Gupta Mar 18 '18 at 8:15
  • I can't recommend anything without knowing more about the problem you want to solve. But most crowdsales have the token assignment inside the token contract, or in some class that inherits from StandardToken. – Ismael Mar 18 '18 at 20:39

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.