diff options
-rw-r--r-- | .travis.yml | 62 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | docs/contracts.rst | 79 | ||||
-rw-r--r-- | docs/solidity-by-example.rst | 44 | ||||
-rw-r--r-- | docs/utils/SolidityLexer.py | 6 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 2 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 33 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.h | 5 | ||||
-rw-r--r-- | solc/CommandLineInterface.cpp | 2 | ||||
-rw-r--r-- | solc/jsonCompiler.cpp | 2 | ||||
-rw-r--r-- | std/StandardToken.sol | 43 | ||||
-rw-r--r-- | std/Token.sol | 11 | ||||
-rw-r--r-- | std/mortal.sol | 8 | ||||
-rw-r--r-- | std/owned.sol | 13 | ||||
-rw-r--r-- | std/std.sol | 4 | ||||
-rw-r--r-- | test/contracts/AuctionRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/FixedFeeRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/Wallet.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityABIJSON.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 33 | ||||
-rw-r--r-- | test/libsolidity/SolidityExecutionFramework.h | 3 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 | ||||
-rw-r--r-- | test/libsolidity/SolidityNatspecJSON.cpp | 2 |
23 files changed, 253 insertions, 121 deletions
diff --git a/.travis.yml b/.travis.yml index d787c795..1b0ff15d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,13 @@ matrix: env: - ZIP_SUFFIX=ubuntu-trusty + - os: linux + dist: trusty + sudo: required + compiler: clang + env: + - ZIP_SUFFIX=ubuntu-trusty-clang + # Documentation target, which generates documentation using Phoenix / ReadTheDocs. - os: linux dist: trusty @@ -85,41 +92,42 @@ matrix: # OS X Yosemite (10.10) # https://en.wikipedia.org/wiki/OS_X_Yosemite # - - os: osx - osx_image: xcode7.1 - env: - # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" - # https://github.com/ethereum/solidity/issues/894 - - TRAVIS_TESTS=Off - - ZIP_SUFFIX=osx-yosemite +# - os: osx +# osx_image: xcode7.1 +# env: +# # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" +# # https://github.com/ethereum/solidity/issues/894 +# - TRAVIS_TESTS=Off +# - ZIP_SUFFIX=osx-yosemite # OS X El Capitan (10.11) # https://en.wikipedia.org/wiki/OS_X_El_Capitan # - - os: osx - osx_image: xcode7.3 - env: - # The use of Debug config here ONLY for El Capitan is a workaround for "The Heisenbug" - # See https://github.com/ethereum/webthree-umbrella/issues/565 - - TRAVIS_BUILD_TYPE=Debug - # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" - # https://github.com/ethereum/solidity/issues/894 - - TRAVIS_TESTS=Off - - ZIP_SUFFIX=osx-elcapitan +# - os: osx +# osx_image: xcode7.3 +# env: +# # The use of Debug config here ONLY for El Capitan is a workaround for "The Heisenbug" +# # See https://github.com/ethereum/webthree-umbrella/issues/565 +# - TRAVIS_BUILD_TYPE=Debug +# # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" +# # https://github.com/ethereum/solidity/issues/894 +# - TRAVIS_TESTS=Off +# - ZIP_SUFFIX=osx-elcapitan # macOS Sierra (10.12) # https://en.wikipedia.org/wiki/MacOS_Sierra # - - os: osx - osx_image: xcode8 - env: - # Look like "The Heisenbug" is occurring here too, so we'll do the same workaround. - # See https://travis-ci.org/ethereum/solidity/jobs/150240930 - - TRAVIS_BUILD_TYPE=Debug - # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" - # https://github.com/ethereum/solidity/issues/894 - - TRAVIS_TESTS=Off - - ZIP_SUFFIX=macos-sierra +# - os: osx +# osx_image: xcode8 +# env: +# # Look like "The Heisenbug" is occurring here too, so we'll do the same workaround. +# # See https://travis-ci.org/ethereum/solidity/jobs/150240930 +# - TRAVIS_BUILD_TYPE=Debug +# # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" +# # https://github.com/ethereum/solidity/issues/894 +# - TRAVIS_TESTS=Off +# - ZIP_SUFFIX=macos-sierra + git: depth: 2 @@ -14,7 +14,7 @@ Solidity is still under development. So please do not hesitate and open an [issu See the [Solidity documentation](http://solidity.readthedocs.io/en/latest/installing-solidity.html#building-from-source) for build instructions. ## How to Contribute -This repository uses the same [coding style](https://github.com/ethereum/webthree-umbrella/blob/develop/CodingStandards.txt) as -all of the cpp-ethereum projects. Please try to align with us in the gitter channel before making larger changes. +This repository uses the same [coding style](https://github.com/ethereum/cpp-ethereum/blob/develop/CodingStandards.txt) as +all of the cpp-ethereum projects. Please try to align with us in the Gitter channel before making larger changes. Any contributions are welcome! diff --git a/docs/contracts.rst b/docs/contracts.rst index 911bfc0d..dfdcaf18 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -179,7 +179,7 @@ and the default is ``internal``. .. note:: Everything that is inside a contract is visible to all external observers. Making something ``private`` - only prevents other contract from accessing and modifying + only prevents other contracts from accessing and modifying the information, but it will still be visible to the whole world outside of the blockchain. @@ -195,9 +195,37 @@ return parameter list for functions. uint public data; } -Other contracts can call ``c.data()`` to retrieve the value of data in state -storage, but are not able to call ``f``. Contracts derived from ``c`` can call -``setData`` to alter the value of ``data`` (but only in their own state). +An other contract ``D`` can call ``c.getData()`` to retrieve the value of data in state +storage and is not able to call ``f``. Contract ``E`` is derived from ``C`` and can call +``compute``. + +:: + + contract C { + function f(uint a) private returns(uint b) { return a + 1; } + function setData(uint a) { data = a; } + function getData() public returns(uint) {return data;} + function compute(uint a, uint b) internal returns (uint) { return a+b;} + uint private data; + } + + contract D { + function readData() { + C c = new C(); + local = c.f(7); // error: member "f" is not visible + c.setData(3); + uint local = c.getData(); + local = c.compute(3,5); // error: member "compute" is not visible + } + } + + contract E is C { + function g() { + C c = new C(); + uint val = compute(3,5); // acces to internal member (from derivated to parent contract) + } + } + .. index:: ! accessor;function, ! function;accessor @@ -205,21 +233,38 @@ Accessor Functions ================== The compiler automatically creates accessor functions for -all public state variables. The contract given below will -have a function called ``data`` that does not take any -arguments and returns a uint, the value of the state +all public state variables. For the contract given below the compiler will +generate a function called ``data`` that does not take any +arguments and returns a ``uint``, the value of the state variable ``data``. The initialization of state variables can be done at declaration. +:: + + contract C { + uint public data = 42; + } + + contract Caller { + C c = new C(); + function f() { + uint local = c.data(); + } + } + The accessor functions have external visibility. If the symbol is accessed internally (i.e. without ``this.``), -it is a state variable and if it is accessed externally -(i.e. with ``this.``), it is a function. +it is evaluated as state variable and if it is accessed externally +(i.e. with ``this.``), it is evaluated as function. :: - contract Test { - uint public data = 42; + contract C { + uint public data; + function x() { + data = 3; // internal access + uint val = this.data(); // external access + } } The next example is a bit more complex: @@ -380,7 +425,8 @@ Fallback Function ***************** A contract can have exactly one unnamed function. This function cannot have -arguments and is executed on a call to the contract if none of the other +arguments and cannot return anything. +It is executed on a call to the contract if none of the other functions matches the given function identifier (or if no data was supplied at all). @@ -389,6 +435,15 @@ Ether (without data). In such a context, there is very little gas available to the function call (to be precise, 2300 gas), so it is important to make fallback functions as cheap as possible. +In particular, the following operations will consume more gas than the stipend provided to a fallback function: + +- Writing to storage +- Creating a contract +- Calling an external function which consumes a large amount of gas +- Sending Ether + +Please ensure you test your fallback function thoroughly to ensure the execution cost is less than 2300 gas before deploying a contract. + :: contract Test { diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst index 86d6f72b..61589b2e 100644 --- a/docs/solidity-by-example.rst +++ b/docs/solidity-by-example.rst @@ -280,14 +280,21 @@ activate themselves. } /// Withdraw a bid that was overbid. - function withdraw() { + function withdraw() returns (bool) { var amount = pendingReturns[msg.sender]; - // It is important to set this to zero because the recipient - // can call this function again as part of the receiving call - // before `send` returns. - pendingReturns[msg.sender] = 0; - if (!msg.sender.send(amount)) - throw; // If anything fails, this will revert the changes above + if (amount > 0) { + // It is important to set this to zero because the recipient + // can call this function again as part of the receiving call + // before `send` returns. + pendingReturns[msg.sender] = 0; + + if (!msg.sender.send(amount)) { + // No need to call throw here, just reset the amount owing + pendingReturns[msg.sender] = amount; + return false; + } + } + return true; } /// End the auction and send the highest bid @@ -491,15 +498,22 @@ high or low invalid bids. } /// Withdraw a bid that was overbid. - function withdraw() { + function withdraw() returns (bool) { var amount = pendingReturns[msg.sender]; - // It is important to set this to zero because the recipient - // can call this function again as part of the receiving call - // before `send` returns (see the remark above about - // conditions -> effects -> interaction). - pendingReturns[msg.sender] = 0; - if (!msg.sender.send(amount)) - throw; // If anything fails, this will revert the changes above + if (amount > 0) { + // It is important to set this to zero because the recipient + // can call this function again as part of the receiving call + // before `send` returns (see the remark above about + // conditions -> effects -> interaction). + pendingReturns[msg.sender] = 0; + + if (!msg.sender.send(amount)){ + // No need to call throw here, just reset the amount owing + pendingReturns[msg.sender] = amount; + return false; + } + } + return true; } /// End the auction and send the highest bid diff --git a/docs/utils/SolidityLexer.py b/docs/utils/SolidityLexer.py index d05c7b0c..779147f4 100644 --- a/docs/utils/SolidityLexer.py +++ b/docs/utils/SolidityLexer.py @@ -58,12 +58,14 @@ class SolidityLexer(RegexLexer): r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' r'this|import|mapping|returns|private|public|external|internal|' r'constant|memory|storage)\b', Keyword, 'slashstartsregex'), - (r'(var|let|with|function|event|modifier|struct|enum|contract)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(var|let|with|function|event|modifier|struct|enum|contract|library)\b', Keyword.Declaration, 'slashstartsregex'), (r'(bytes|string|address|uint|int|bool|byte|' + '|'.join( ['uint%d' % (i + 8) for i in range(0, 256, 8)] + ['int%d' % (i + 8) for i in range(0, 256, 8)] + - ['bytes%d' % (i + 1) for i in range(0, 32)] + ['bytes%d' % (i + 1) for i in range(0, 32)] + + ['ufixed%dx%d' % ((i), (j + 8)) for i in range(0, 256, 8) for j in range(0, 256 - i, 8)] + + ['fixed%dx%d' % ((i), (j + 8)) for i in range(0, 256, 8) for j in range(0, 256 - i, 8)] ) + r')\b', Keyword.Type, 'slashstartsregex'), (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' r'extends|final|float|goto|implements|int|interface|long|native|' diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 6b2c1cb8..235fcabd 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -94,6 +94,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract) fallbackFunction = function; if (!fallbackFunction->parameters().empty()) typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters."); + if (!fallbackFunction->returnParameters().empty()) + typeError(fallbackFunction->returnParameterList()->location(), "Fallback function cannot return values."); } } if (!function->isImplemented()) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 0e5ead2b..bd79bb73 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -42,26 +42,8 @@ using namespace std; using namespace dev; using namespace dev::solidity; -const map<string, string> StandardSources = map<string, string>{ - {"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,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(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";)"} -}; - -CompilerStack::CompilerStack(bool _addStandardSources, ReadFileCallback const& _readFile): - m_readFile(_readFile), m_parseSuccessful(false) -{ - if (_addStandardSources) - addSources(StandardSources, true); // add them as libraries -} +CompilerStack::CompilerStack(ReadFileCallback const& _readFile): + m_readFile(_readFile), m_parseSuccessful(false) {} void CompilerStack::setRemappings(vector<string> const& _remappings) { @@ -81,7 +63,7 @@ void CompilerStack::setRemappings(vector<string> const& _remappings) swap(m_remappings, remappings); } -void CompilerStack::reset(bool _keepSources, bool _addStandardSources) +void CompilerStack::reset(bool _keepSources) { m_parseSuccessful = false; if (_keepSources) @@ -90,8 +72,6 @@ void CompilerStack::reset(bool _keepSources, bool _addStandardSources) else { m_sources.clear(); - if (_addStandardSources) - addSources(StandardSources, true); } m_globalContext.reset(); m_sourceOrder.clear(); @@ -616,10 +596,9 @@ CompilerStack::Contract const& CompilerStack::contract(string const& _contractNa if (_contractName.empty()) // try to find some user-supplied contract for (auto const& it: m_sources) - if (!StandardSources.count(it.first)) - for (ASTPointer<ASTNode> const& node: it.second.ast->nodes()) - if (auto contract = dynamic_cast<ContractDefinition const*>(node.get())) - contractName = contract->name(); + for (ASTPointer<ASTNode> const& node: it.second.ast->nodes()) + if (auto contract = dynamic_cast<ContractDefinition const*>(node.get())) + contractName = contract->name(); auto it = m_contracts.find(contractName); if (it == m_contracts.end()) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract " + _contractName + " not found.")); diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index b3c4450c..da479638 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -85,14 +85,13 @@ public: /// Creates a new compiler stack. /// @param _readFile callback to used to read files for import statements. Should return - /// @param _addStandardSources Adds standard sources if @a _addStandardSources. - explicit CompilerStack(bool _addStandardSources = true, ReadFileCallback const& _readFile = ReadFileCallback()); + explicit CompilerStack(ReadFileCallback const& _readFile = ReadFileCallback()); /// Sets path remappings in the format "context:prefix=target" void setRemappings(std::vector<std::string> const& _remappings); /// Resets the compiler to a state where the sources are not parsed or even removed. - void reset(bool _keepSources = false, bool _addStandardSources = true); + void reset(bool _keepSources = false); /// Adds a source object (e.g. file) to the parser. After this, parse has to be called again. /// @returns true if a source object by the name already existed and was replaced. diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 08c08797..fbef56f0 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -560,7 +560,7 @@ bool CommandLineInterface::processInput() } }; - m_compiler.reset(new CompilerStack(m_args.count(g_argAddStandard) > 0, fileReader)); + m_compiler.reset(new CompilerStack(fileReader)); auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); }; try { diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index 896a5922..5cdee2e2 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -159,7 +159,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback return result; }; } - CompilerStack compiler(true, readCallback); + CompilerStack compiler(readCallback); auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return compiler.scanner(_sourceName); }; bool success = false; try diff --git a/std/StandardToken.sol b/std/StandardToken.sol new file mode 100644 index 00000000..db453492 --- /dev/null +++ b/std/StandardToken.sol @@ -0,0 +1,43 @@ +import "./Token.sol"; + +contract StandardToken is Token { + uint256 public totalSupply; + mapping (address => uint256) public balanceOf; + mapping (address => + mapping (address => uint256)) public allowance; + + function StandardToken(address _initialOwner, uint256 _supply) { + totalSupply = _supply; + balanceOf[_initialOwner] = _supply; + } + + function transfer(address _to, uint256 _value) returns (bool success) { + if (balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) { + balanceOf[msg.sender] -= _value; + balanceOf[_to] += _value; + Transfer(msg.sender, _to, _value); + return true; + } + else { + return false; + } + } + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + if (allowance[_from][msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) { + allowance[_from][msg.sender] -= _value; + balanceOf[_to] += _value; + Transfer(_from, _to, _value); + return true; + } + else { + return false; + } + } + + function approve(address _spender, uint256 _value) returns (bool success) { + allowance[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } +} diff --git a/std/Token.sol b/std/Token.sol new file mode 100644 index 00000000..50d9ab7a --- /dev/null +++ b/std/Token.sol @@ -0,0 +1,11 @@ +contract Token { + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + function totalSupply() constant returns (uint256 supply) {} + function balanceOf(address _owner) constant returns (uint256 balance) {} + function transfer(address _to, uint256 _value) returns (bool success) {} + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} + function approve(address _spender, uint256 _value) returns (bool success) {} + function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} +} diff --git a/std/mortal.sol b/std/mortal.sol new file mode 100644 index 00000000..8de019ab --- /dev/null +++ b/std/mortal.sol @@ -0,0 +1,8 @@ +import "./owned.sol"; + +contract mortal is owned { + function kill() { + if (msg.sender == owner) + selfdestruct(owner); + } +} diff --git a/std/owned.sol b/std/owned.sol new file mode 100644 index 00000000..37f0ecb9 --- /dev/null +++ b/std/owned.sol @@ -0,0 +1,13 @@ +contract owned { + address owner; + + modifier onlyowner() { + if (msg.sender == owner) { + _ + } + } + + function owned() { + owner = msg.sender; + } +} diff --git a/std/std.sol b/std/std.sol new file mode 100644 index 00000000..c3f66b1b --- /dev/null +++ b/std/std.sol @@ -0,0 +1,4 @@ +import "./owned.sol"; +import "./mortal.sol"; +import "./Token.sol"; +import "./StandardToken.sol"; diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index bb2e5663..3b1d1165 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -230,7 +230,7 @@ protected: if (!s_compiledRegistrar) { m_optimize = true; - m_compiler.reset(false, m_addStandardSources); + m_compiler.reset(false); m_compiler.addSource("", registrarCode); ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed"); s_compiledRegistrar.reset(new bytes(m_compiler.object("GlobalRegistrar").bytecode)); diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index 6d79bec6..3acfba62 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -131,7 +131,7 @@ protected: if (!s_compiledRegistrar) { m_optimize = true; - m_compiler.reset(false, m_addStandardSources); + m_compiler.reset(false); m_compiler.addSource("", registrarCode); ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed"); s_compiledRegistrar.reset(new bytes(m_compiler.object("FixedFeeRegistrar").bytecode)); diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index 7a9b0b17..9e797af4 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -445,7 +445,7 @@ protected: if (!s_compiledWallet) { m_optimize = true; - m_compiler.reset(false, m_addStandardSources); + m_compiler.reset(false); m_compiler.addSource("", walletCode); ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed"); s_compiledWallet.reset(new bytes(m_compiler.object("Wallet").bytecode)); diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index 77b39978..b21e03eb 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -35,7 +35,7 @@ namespace test class JSONInterfaceChecker { public: - JSONInterfaceChecker(): m_compilerStack(false) {} + JSONInterfaceChecker(): m_compilerStack() {} void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString) { diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 45f6aec5..8a61907a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2469,21 +2469,6 @@ BOOST_AUTO_TEST_CASE(function_modifier_for_constructor) BOOST_CHECK(callContractFunction("getData()") == encodeArgs(4 | 2)); } -BOOST_AUTO_TEST_CASE(use_std_lib) -{ - char const* sourceCode = R"( - import "mortal"; - contract Icarus is mortal { } - )"; - m_addStandardSources = true; - u256 amount(130 * ether); - compileAndRun(sourceCode, amount, "Icarus"); - u256 balanceBefore = balanceAt(m_sender); - BOOST_CHECK(callContractFunction("kill()") == bytes()); - BOOST_CHECK(!addressHasCode(m_contractAddress)); - BOOST_CHECK(balanceAt(m_sender) > balanceBefore); -} - BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack) { char const* sourceCode = R"( @@ -2529,13 +2514,13 @@ BOOST_AUTO_TEST_CASE(fallback_function) char const* sourceCode = R"( contract A { uint data; - function() returns (uint r) { data = 1; return 2; } + function() { data = 1; } function getData() returns (uint r) { return data; } } )"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(0)); - BOOST_CHECK(callContractFunction("") == encodeArgs(2)); + BOOST_CHECK(callContractFunction("") == encodeArgs()); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(1)); } @@ -2544,14 +2529,14 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) char const* sourceCode = R"( contract A { uint data; - function() returns (uint r) { data = 1; return 2; } + function() { data = 1; } function getData() returns (uint r) { return data; } } contract B is A {} )"; compileAndRun(sourceCode, 0, "B"); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(0)); - BOOST_CHECK(callContractFunction("") == encodeArgs(2)); + BOOST_CHECK(callContractFunction("") == encodeArgs()); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(1)); } @@ -3002,13 +2987,13 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) { char const* sourceCode = R"( contract C { - function() returns (bytes32) { + function f() returns (bytes32) { return sha3("abc", msg.data); } } )"; compileAndRun(sourceCode); - bytes calldata1 = bytes(61, 0x22) + bytes(12, 0x12); + bytes calldata1 = FixedHash<4>(dev::sha3("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12); sendMessage(calldata1, false); BOOST_CHECK(m_output == encodeArgs(dev::sha3(bytes{'a', 'b', 'c'} + calldata1))); } @@ -3024,7 +3009,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) contract sender { function sender() { rec = new receiver(); } function() { savedData = msg.data; } - function forward() returns (bool) { rec.call(savedData); return true; } + function forward() returns (bool) { !rec.call(savedData); return true; } function clear() returns (bool) { delete savedData; return true; } function val() returns (uint) { return rec.received(); } receiver rec; @@ -4342,12 +4327,12 @@ BOOST_AUTO_TEST_CASE(external_types_in_calls) y = this.t1(C1(7)); } function t1(C1 a) returns (C1) { return a; } - function() returns (C1) { return C1(9); } + function t2() returns (C1) { return C1(9); } } )"; compileAndRun(sourceCode, 0, "C"); BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(9), u256(7))); - BOOST_CHECK(callContractFunction("nonexisting") == encodeArgs(u256(9))); + BOOST_CHECK(callContractFunction("t2()") == encodeArgs(u256(9))); } BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes) diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index c34b00ec..f4bdc657 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -67,7 +67,7 @@ public: std::map<std::string, Address> const& _libraryAddresses = std::map<std::string, Address>() ) { - m_compiler.reset(false, m_addStandardSources); + m_compiler.reset(false); m_compiler.addSource("", _sourceCode); if (!m_compiler.compile(m_optimize, m_optimizeRuns)) { @@ -290,7 +290,6 @@ protected: size_t m_optimizeRuns = 200; bool m_optimize = false; - bool m_addStandardSources = false; dev::solidity::CompilerStack m_compiler; Address m_sender; Address m_contractAddress; diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index e9da390c..f0ab07c5 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1102,6 +1102,16 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_arguments) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters) +{ + char const* text = R"( + contract C { + function() returns (uint) { } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + BOOST_AUTO_TEST_CASE(fallback_function_twice) { char const* text = R"( diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp index 8c0c2098..56572b43 100644 --- a/test/libsolidity/SolidityNatspecJSON.cpp +++ b/test/libsolidity/SolidityNatspecJSON.cpp @@ -37,7 +37,7 @@ namespace test class DocumentationChecker { public: - DocumentationChecker(): m_compilerStack(false) {} + DocumentationChecker(): m_compilerStack() {} void checkNatspec( std::string const& _code, |