2017-03-14 8 views
12

문자열 값이 올바른지 테스트 할 때 문제가 발생합니다. 숫자는 올바르게 어설트되며 컴파일하려고 할 때 오류 메시지를 반환하지 않습니다.구성원 동등 형을 사용할 수 없습니다 (라이브러리 Assert)

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

이유는 무엇입니까

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]; 
    } 
} 

: 나는 문자열을 주장 할 때 그러나, 다음과 같은 오류 메시지를 반환 그것은 어떻게되고 어떻게 해결합니까?

+0

아마도 도움이 될 수 있습니까? http://ethereum.stackexchange.com/q/1701 – default

+2

이 주제에 관한 뉴스? –

답변

-3

유형을 string에서 다른 유형으로 변경하십시오 (예 : bytes32). 그것은 작동합니다.

모두 최고입니다.

1

지금부터 solidity는 계약서간에 문자열을 반환하는 것을 지원하지 않습니다. 호출 할 때 문자열의 길이를 알 수 없기 때문입니다. 따라서 이들은 bytes32와 같은 고정 크기 arryas 만 지원합니다.

문자열의 다른 부분을 저장하기 위해 여러 개의 bytes32를 가질 수 있습니다.