mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Most EndToEndTests are now compliant with the Bytes renaming
This commit is contained in:
parent
2bddebc3d5
commit
73ce24ae75
@ -41,14 +41,14 @@ namespace solidity
|
||||
{
|
||||
|
||||
const map<string, string> StandardSources = map<string, string>{
|
||||
{"coin", R"(import "CoinReg";import "Config";import "configUser";contract coin is configUser{function coin(string3 name, uint denom) {CoinReg(Config(configAddr()).lookup(3)).register(name, denom);}})"},
|
||||
{"coin", R"(import "CoinReg";import "Config";import "configUser";contract coin is configUser{function coin(bytes3 name, uint denom) {CoinReg(Config(configAddr()).lookup(3)).register(name, denom);}})"},
|
||||
{"Coin", R"(contract Coin{function isApprovedFor(address _target,address _proxy)constant returns(bool _r){}function isApproved(address _proxy)constant returns(bool _r){}function sendCoinFrom(address _from,uint256 _val,address _to){}function coinBalanceOf(address _a)constant returns(uint256 _r){}function sendCoin(uint256 _val,address _to){}function coinBalance()constant returns(uint256 _r){}function approve(address _a){}})"},
|
||||
{"CoinReg", R"(contract CoinReg{function count()constant returns(uint256 r){}function info(uint256 i)constant returns(address addr,string3 name,uint256 denom){}function register(string3 name,uint256 denom){}function unregister(){}})"},
|
||||
{"CoinReg", R"(contract CoinReg{function count()constant returns(uint256 r){}function info(uint256 i)constant returns(address addr,bytes3 name,uint256 denom){}function register(bytes3 name,uint256 denom){}function unregister(){}})"},
|
||||
{"configUser", R"(contract configUser{function configAddr()constant returns(address a){ return 0xc6d9d2cd449a754c494264e1809c50e34d64562b;}})"},
|
||||
{"Config", R"(contract Config{function lookup(uint256 service)constant returns(address a){}function kill(){}function unregister(uint256 id){}function register(uint256 id,address service){}})"},
|
||||
{"mortal", R"(import "owned";contract mortal is owned {function kill() { if (msg.sender == owner) suicide(owner); }})"},
|
||||
{"named", R"(import "Config";import "NameReg";import "configUser";contract named is configUser {function named(string32 name) {NameReg(Config(configAddr()).lookup(1)).register(name);}})"},
|
||||
{"NameReg", R"(contract NameReg{function register(string32 name){}function addressOf(string32 name)constant returns(address addr){}function unregister(){}function nameOf(address addr)constant returns(string32 name){}})"},
|
||||
{"named", R"(import "Config";import "NameReg";import "configUser";contract named is configUser {function named(bytes32 name) {NameReg(Config(configAddr()).lookup(1)).register(name);}})"},
|
||||
{"NameReg", R"(contract NameReg{function register(bytes32 name){}function addressOf(bytes32 name)constant returns(address addr){}function unregister(){}function nameOf(address addr)constant returns(bytes32 name){}})"},
|
||||
{"owned", R"(contract owned{function owned(){owner = msg.sender;}modifier onlyowner(){if(msg.sender==owner)_}address owner;})"},
|
||||
{"service", R"(import "Config";import "configUser";contract service is configUser{function service(uint _n){Config(configAddr()).register(_n, this);}})"},
|
||||
{"std", R"(import "owned";import "mortal";import "Config";import "configUser";import "NameReg";import "named";)"}
|
||||
|
@ -131,7 +131,6 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
|
||||
// conversion from string to bytes. no need to clean the high bit
|
||||
// only to shift right because of opposite alignment
|
||||
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
|
||||
solAssert(targetIntegerType.isAddress(), "Only conversion between Address and FixedBytes is allowed.");
|
||||
solAssert(targetIntegerType.getNumBits() == typeOnStack.getNumBytes() * 8, "The size should be the same.");
|
||||
m_context << (u256(1) << (256 - typeOnStack.getNumBytes() * 8)) << eth::Instruction::SWAP1 << eth::Instruction::DIV;
|
||||
}
|
||||
@ -164,7 +163,6 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
|
||||
// only to shift left because of opposite alignment
|
||||
FixedBytesType const& targetBytesType = dynamic_cast<FixedBytesType const&>(_targetType);
|
||||
IntegerType const& typeOnStack = dynamic_cast<IntegerType const&>(_typeOnStack);
|
||||
solAssert(typeOnStack.isAddress(), "Only conversion between Address and Bytes is allowed.");
|
||||
solAssert(typeOnStack.getNumBits() == targetBytesType.getNumBytes() * 8, "The size should be the same.");
|
||||
m_context << (u256(1) << (256 - typeOnStack.getNumBits())) << eth::Instruction::MUL;
|
||||
}
|
||||
|
@ -41,23 +41,23 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
|
||||
make_shared<MagicVariableDeclaration>("suicide",
|
||||
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Suicide)),
|
||||
make_shared<MagicVariableDeclaration>("sha3",
|
||||
make_shared<FunctionType>(strings(), strings{"hash"}, FunctionType::Location::SHA3, true)),
|
||||
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Location::SHA3, true)),
|
||||
make_shared<MagicVariableDeclaration>("log0",
|
||||
make_shared<FunctionType>(strings{"hash"},strings{}, FunctionType::Location::Log0)),
|
||||
make_shared<FunctionType>(strings{"bytes32"}, strings{}, FunctionType::Location::Log0)),
|
||||
make_shared<MagicVariableDeclaration>("log1",
|
||||
make_shared<FunctionType>(strings{"hash", "hash"},strings{}, FunctionType::Location::Log1)),
|
||||
make_shared<FunctionType>(strings{"bytes32", "bytes32"}, strings{}, FunctionType::Location::Log1)),
|
||||
make_shared<MagicVariableDeclaration>("log2",
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash"},strings{}, FunctionType::Location::Log2)),
|
||||
make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Location::Log2)),
|
||||
make_shared<MagicVariableDeclaration>("log3",
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::Log3)),
|
||||
make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Location::Log3)),
|
||||
make_shared<MagicVariableDeclaration>("log4",
|
||||
make_shared<FunctionType>(strings{"hash", "hash", "hash", "hash", "hash"},strings{}, FunctionType::Location::Log4)),
|
||||
make_shared<FunctionType>(strings{"bytes32", "bytes32", "bytes32", "bytes32", "bytes32"}, strings{}, FunctionType::Location::Log4)),
|
||||
make_shared<MagicVariableDeclaration>("sha256",
|
||||
make_shared<FunctionType>(strings(), strings{"hash"}, FunctionType::Location::SHA256, true)),
|
||||
make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Location::SHA256, true)),
|
||||
make_shared<MagicVariableDeclaration>("ecrecover",
|
||||
make_shared<FunctionType>(strings{"hash", "hash8", "hash", "hash"}, strings{"address"}, FunctionType::Location::ECRecover)),
|
||||
make_shared<FunctionType>(strings{"bytes32", "bytes1", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Location::ECRecover)),
|
||||
make_shared<MagicVariableDeclaration>("ripemd160",
|
||||
make_shared<FunctionType>(strings(), strings{"hash160"}, FunctionType::Location::RIPEMD160, true))})
|
||||
make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true))})
|
||||
{
|
||||
}
|
||||
|
||||
|
3
Token.h
3
Token.h
@ -252,7 +252,7 @@ namespace solidity
|
||||
K(UInt240, "uint240", 0) \
|
||||
K(UInt248, "uint248", 0) \
|
||||
K(UInt256, "uint256", 0) \
|
||||
K(Bytes, "bytes", 0) \
|
||||
K(Bytes0, "bytes0", 0) \
|
||||
K(Bytes1, "bytes1", 0) \
|
||||
K(Bytes2, "bytes2", 0) \
|
||||
K(Bytes3, "bytes3", 0) \
|
||||
@ -285,6 +285,7 @@ namespace solidity
|
||||
K(Bytes30, "bytes30", 0) \
|
||||
K(Bytes31, "bytes31", 0) \
|
||||
K(Bytes32, "bytes32", 0) \
|
||||
K(Bytes, "bytes", 0) \
|
||||
K(Address, "address", 0) \
|
||||
K(Bool, "bool", 0) \
|
||||
K(StringType, "string", 0) \
|
||||
|
13
Types.cpp
13
Types.cpp
@ -37,13 +37,15 @@ namespace solidity
|
||||
|
||||
TypePointer Type::fromElementaryTypeName(Token::Value _typeToken)
|
||||
{
|
||||
solAssert(Token::isElementaryTypeName(_typeToken), "Elementary type name expected.");
|
||||
char const* tokenCstr = Token::toString(_typeToken);
|
||||
solAssert(Token::isElementaryTypeName(_typeToken),
|
||||
"Expected an elementary type name but got " + ((tokenCstr) ? std::string(Token::toString(_typeToken)) : ""));
|
||||
|
||||
if (Token::Int <= _typeToken && _typeToken <= Token::Bytes32)
|
||||
{
|
||||
int offset = _typeToken - Token::Int;
|
||||
int bytes = offset % 33;
|
||||
if (bytes == 0)
|
||||
if (bytes == 0 && _typeToken != Token::Bytes0)
|
||||
bytes = 32;
|
||||
int modifier = offset / 33;
|
||||
switch(modifier)
|
||||
@ -173,6 +175,11 @@ bool IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
|
||||
bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
{
|
||||
if (_convertTo.getCategory() == Category::FixedBytes)
|
||||
{
|
||||
FixedBytesType const& convertTo = dynamic_cast<FixedBytesType const&>(_convertTo);
|
||||
return (m_bits == convertTo.getNumBytes() * 8);
|
||||
}
|
||||
return _convertTo.getCategory() == getCategory() ||
|
||||
_convertTo.getCategory() == Category::Contract ||
|
||||
_convertTo.getCategory() == Category::Enum;
|
||||
@ -436,7 +443,7 @@ shared_ptr<FixedBytesType> FixedBytesType::smallestTypeForLiteral(string const&
|
||||
FixedBytesType::FixedBytesType(int _bytes): m_bytes(_bytes)
|
||||
{
|
||||
solAssert(m_bytes >= 0 && m_bytes <= 32,
|
||||
"Invalid byte number for static string type: " + dev::toString(m_bytes));
|
||||
"Invalid byte number for fixed bytes type: " + dev::toString(m_bytes));
|
||||
}
|
||||
|
||||
bool FixedBytesType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
|
Loading…
Reference in New Issue
Block a user