"멤버 "equal"은 타입(library Assert)에서 가능하지 않습니다." 라는 오류 메시지가 뜹니다

조회수 643회

제대로 된 문자열 값인지 테스트하려고 할 때 문제가 발생합니다. 숫자도 올바르게 나오고 컴파일하려고 할 때에도 오류 메시지가 뜨지 않습니다. 그런데 문자열을 확인하려고 하면 이런 오류가 뜹니다.

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

왜 이 에러가 뜰까요? 어떻게 해결할 수 있을까요?

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

1 답변

  • 현재 solidity는 계약 중에 문자열 반환을 지원하지 않습니다. 호출할 떄 문자열의 길이를 알 수 없기 때문입니다. 따라서 이들은 bytes32와 같은 고정된 크기 배열만 지원합니다.

    여러 개의 bytes32로 문자열의 다른 부분을 저장할 수 있습니다.

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

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

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

(ಠ_ಠ)
(ಠ‿ಠ)