0

I have very basic contract like this:

pragma solidity ^0.4.0;

contract Playground {
    uint public tokenPrice = 1;

    function setTokenPrice(uint newTokenPrice) public returns (uint) {
        tokenPrice = newTokenPrice;

        return tokenPrice;
    }
}

and correspondig test:

  it("should have token price changeable and publicly visible", () => {
    let instance;

    return Playground.deployed().then(inst => {
      instance = inst;
      return instance.tokenPrice.call();
    }).then(price => {
      console.log('Initial price:' + formatNumber(price));
      return instance.setTokenPrice.call(2);
    }).then(price => {
      console.log('Price immediately after change:' + formatNumber(price));
      return instance.tokenPrice.call();
    }).then(price => {
      console.log('Price after get:' + formatNumber(price));
      assert.equal(price, 2, format(price, 2, "Token Price"));
    });
  });

This test checks initial value of token price then change it and check again. But it seems that setter does not work! Here is the output:

Initial price:1
Price immediately after change:2
Price after get:1

I.e. value that updated in setter returned correctly but when I am getting it again - it returns old, not updated value. What is wrong here?

Tests are running in local testrpc instance. In Remix data updated as expected.

2

You are calling setTokenPrice func with a .call() on a function that intends to write on the Blockchain. call() methods are used when you want to read data from the contract.

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.