The error message "Member "equal" is not available in the library assistant" appears

Asked 1 years ago, Updated 1 years ago, 112 views

A problem occurs when you try to test if it is a valid string value. The numbers are also correct and no error messages are displayed when trying to compile. However, if you try to check the string, this error appears.

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 this error appear? How can we solve this?

ethereum truffle

2022-09-21 14:55

1 Answers

Currently, solidity does not support string return during the contract. This is because the length of the string is unknown when calling. Therefore, they only support fixed size arrays, such as bytes32.

You can store different parts of a string with multiple bytes32.


2022-09-21 14:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.