2017-03-14 9 views
12

文字列の値が正しいかどうかをテストするときに問題が発生します。数値は正しくアサートされ、コンパイルしようとするとエラーメッセージが返されません。メンバーequalは型では使用できません(ライブラリ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を持つことができます。

関連する問題