equal 멤버가 적절하지 않은 타입(library Assert)이라고 오류가 뜹니다.

조회수 691회

문자열 값이 맞는지 테스트하려고 하면 오류가 납니다. 숫자로 할 때에는 오류가 안뜨고 컴파일도 잘 됩니다. 하지만 문자열은 자꾸 아래와 같은 오류 메세지가 뜹니다.

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 $");
    }
}

왜 이런 오류가 뜨는 것일까요? 그리고 어떻게 해결할 수 있을까요?

출처: https://stackoverflow.com/questions/42783106/member-equal-is-not-available-in-typelibrary-assert 이 질문은 저작자표시-동일조건변경허락(https://creativecommons.org/licenses/by-sa/3.0/deed.ko) 라이센스로 이용할 수 있습니다.

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • 지금 솔리디티는 호출할 때에 문자열의 길이를 정확히 알 수 없으므로 Contract 끼리 문자열을 반환하는 것을 지원하지 않습니다. 그래서 byte32 같이 고정된 크기의 배열만지원합니다.

    문자열을 저장할 때에 여러개의 byte32를 이용해 저장한다면 오류를 해결할 수 있을 것입니다.

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)