Member equal is not available in type(library Assert)
Asked Answered
W

2

17

The problem arises when I want to test whether a string value is correct. Numbers are asserted correctly and don't return an error message when they are trying to be compiled. However, when I try to assert a string, it returns the following error message:

Error: Member "equal" is not available in type(library Assert) outside of storage.
        Assert.equal(token.symbol(), "$", "The symbol of the token should be $");
        ^----------^
Compiliation failed. See above.

Token.sol

pragma solidity ^0.4.8;

contract Token {
    /* The amount of tokens a person will get for 1 ETH */
    uint256 public exchangeRate;

    /* The name of the token */
    string public name;

    /* The address which controls the token */
    address public owner;

    /* The symbol of the token */
    string public symbol;

    /* The balances of all registered addresses */
    mapping (address => uint256) balances;

    /* Token constructor */
    function Token(uint256 _exchangeRate, string _name, string _symbol) {
        exchangeRate = _exchangeRate;
        name = _name;
        owner = msg.sender;
        symbol = _symbol;
    }

    function getBalance(address account) returns (uint256 balance) {
        return balances[account];
    }
}

TestToken.sol

pragma solidity ^0.4.8;

// Framework libraries
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";

// Custom libraries and contracts
import "../contracts/Token.sol";

contract TestToken {
    function testExchangeRate() {
        Token token = new Token(500, "Dollar", "$");

        uint256 expected = 500;

        Assert.equal(token.exchangeRate(), expected, "The exchange rate should be 500 tokens for 1 ETH");
    }

    function testSymbol() {
        Token token = new Token(500, "Dollar", "$");

        Assert.equal(token.symbol(), "$", "The symbol of the token should be $");
    }
}

Why does it happen and how do you solve it?

Whidah answered 14/3, 2017 at 10:12 Comment(2)
Maybe this could help? ethereum.stackexchange.com/q/1701Vann
Any news about this topic ?Lineberry
L
2

As of now solidity doesn't support returning strings between contracts. Because length of a string is not known at the time of call. So they only support fixed size arryas like bytes32.

You can have multiple bytes32 to store different parts of your string.

Langford answered 13/9, 2017 at 17:9 Comment(0)
B
-3

Try changing the type from string to another, say, bytes32. It works.

All the best.

Beggarweed answered 28/6, 2017 at 14:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.