0

My contract is

contract SimpleContract {
    uint storedData;
    function set(uint x) public { storedData = x; }
    function get() public returns (uint) { return storedData; }
}

This test doesn't work:

var SimpleContract = artifacts.require("SimpleContract");

contract('SimpleContract', function(accounts) {
  let contract;
  let owner;
  let web3Contract;

  before(async () => {
    contract = await SimpleContract.deployed();
    web3Contract = web3.eth.contract(contract.abi).at(contract.address);
    owner = web3Contract._eth.coinbase;        
  });

  it("test", async function() {    
    await contract.set.call(10);    
    let result = await contract.get.call();
    assert.equal(result.toNumber(), 10, "updates the field");
  });  
});

I'm getting

AssertionError: fail: expected 0 to equal 10

Any idea?

  • 1
    Usevally call() is for get the value from state variable. It will not change state variable. If you want to change the state. Use contract.set.sendTransaction(args...,); – Jitendra Kumar. Balla Feb 20 '18 at 9:04
  • Cool @Jitendra, this solves the problem – Robert Feb 20 '18 at 9:07
1

@Jitendra Kumar. Balla's reply is the correct one. I was calling set.call(10) instead of set.sendTransaction(10).

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.