An error appears stating that the equal member is an invalid type (library Assistant).

Asked 2 years ago, Updated 2 years ago, 93 views

If you try to test if the string value is correct, an error occurs. When you do numbers, there are no errors and compiles well. However, the string keeps getting 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.
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];
    }
}
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 this error appear? And how can we solve it?

Source: https://stackoverflow.com/questions/42783106/member-equal-is-not-available-in-typelibrary-assert This question is authorized to change the same condition (Available under the https://creativecommons.org/licenses/by-sa/3.0/deed.ko ) license.

ethereum truffle

2022-09-22 20:42

1 Answers

Solidity now does not support returning Contract-to-Contract strings because the length of the string is not known exactly when calling. So it only supports fixed-size arrays like byte32.

If you save a string using multiple bytes32, you will be able to correct the error.


2022-09-22 20:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.