0

I'm doing testing of smart contract when I try to transfer token using https://remix.ethereum.org. That was working fine. But now I want to write its test case but that is not working fine and not transferring the tokens. Code:

 it('should properly [transfer] token', async function() {
    let recipient = "0xe0f5206bbd039e7b0592d8918820024e2a7437b9";
    let tokenWei = 1000000;
    let status = await contract.methods.transfer(recipient, tokenWei).call();
    console.log(status);

    let ownerBalance = await contract.methods.balanceOf(owner).call();
    let recipientBalance = await contract.methods.balanceOf("0xe0f5206bbd039e7b0592d8918820024e2a7437b9").call();
    console.log("Balance:"+ownerBalance +'----'+recipientBalance);
  });

Output is like this.

status = true
Balance:1705243055----100000000

These balaces are exactly same as before mean no deduction from owner account and no addition in recipient account.

Any guidance/help will be appreciated.

Thanks

2
  • Wie sendet man mit terminal? Not install senden wie? Apr 9 '18 at 9:05
  • Hi and welcome to Ethereum StackExchange. Please speak English so users could understand you. Apr 9 '18 at 10:38
1

You must to use send instead of call, since you're changing the status.

contract.methods.transfer(recipient, tokenWei).send({from: '0x123...'})
5
  • Thank you, balances are showing correctly as 1704243055-101000000 But when I tried another test case below of the test case that will show again starting assigned balance in owner account Code it('Owner balance', async function() { let Balance = await contract.methods.balanceOf(owner).call(); Balance = Balance.toString(); console.log(Balance); }) The output should be: 1704243055 But showing: 1705243055 So my question is there any scope issue why balance is again showing as assigned before in new test case or I need to write down one test case as I mentioned in question? Apr 9 '18 at 8:06
  • 1
    sounds strange. I don't have an answer on this it should work properly. are you using ganache-cli ?
    – mirg
    Apr 9 '18 at 8:59
  • Yes, I am using ganache-cli Apr 9 '18 at 10:13
  • Do you have an example of test cases with code? Please provide. Apr 9 '18 at 10:37
  • you can search on github something. es: github.com/gnosis/gnosis-contracts/tree/master/test/javascript
    – mirg
    Apr 9 '18 at 10:39

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.