diff options
-rw-r--r-- | solidityCompiler.cpp | 2 | ||||
-rw-r--r-- | solidityEndToEndTest.cpp | 29 | ||||
-rw-r--r-- | solidityExpressionCompiler.cpp | 2 | ||||
-rw-r--r-- | solidityNameAndTypeResolution.cpp | 2 | ||||
-rw-r--r-- | solidityParser.cpp | 20 |
5 files changed, 43 insertions, 12 deletions
diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index e0635b6a..1767a0f3 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -48,7 +48,7 @@ bytes compileContract(const string& _sourceCode) Parser parser; ASTPointer<ContractDefinition> contract; BOOST_REQUIRE_NO_THROW(contract = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); - NameAndTypeResolver resolver; + NameAndTypeResolver resolver({}); BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); Compiler compiler; diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 4e68103a..a7c6357b 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -45,17 +45,17 @@ class ExecutionFramework public: ExecutionFramework() { g_logVerbosity = 0; } - bytes const& compileAndRun(string const& _sourceCode) + bytes const& compileAndRun(string const& _sourceCode, u256 const& _value = 0) { bytes code = dev::solidity::CompilerStack::staticCompile(_sourceCode); - sendMessage(code, true); + sendMessage(code, true, _value); BOOST_REQUIRE(!m_output.empty()); return m_output; } - bytes const& callContractFunction(byte _index, bytes const& _data = bytes()) + bytes const& callContractFunction(byte _index, bytes const& _data = bytes(), u256 const& _value = 0) { - sendMessage(bytes(1, _index) + _data, false); + sendMessage(bytes(1, _index) + _data, false, _value); return m_output; } @@ -111,11 +111,11 @@ private: return toBigEndian(_cppFunction(_arguments...)); } - void sendMessage(bytes const& _data, bool _isCreation) + void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0) { eth::Executive executive(m_state); - eth::Transaction t = _isCreation ? eth::Transaction(0, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) - : eth::Transaction(0, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); + eth::Transaction t = _isCreation ? eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) + : eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec()); bytes transactionRLP = t.rlp(); try { @@ -125,7 +125,7 @@ private: catch (...) {} if (_isCreation) { - BOOST_REQUIRE(!executive.create(Address(), 0, m_gasPrice, m_gas, &_data, Address())); + BOOST_REQUIRE(!executive.create(Address(), _value, m_gasPrice, m_gas, &_data, Address())); m_contractAddress = executive.newAddress(); BOOST_REQUIRE(m_contractAddress); BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); @@ -133,7 +133,7 @@ private: else { BOOST_REQUIRE(m_state.addressHasCode(m_contractAddress)); - BOOST_REQUIRE(!executive.call(m_contractAddress, Address(), 0, m_gasPrice, &_data, m_gas, Address())); + BOOST_REQUIRE(!executive.call(m_contractAddress, Address(), _value, m_gasPrice, &_data, m_gas, Address())); } BOOST_REQUIRE(executive.go()); executive.finalize(); @@ -722,6 +722,17 @@ BOOST_AUTO_TEST_CASE(constructor) testSolidityAgainstCpp(0, get, u256(7)); } +BOOST_AUTO_TEST_CASE(balance) +{ + char const* sourceCode = "contract test {\n" + " function getBalance() returns (u256 balance) {\n" + " return address(this).balance;\n" + " }\n" + "}\n"; + compileAndRun(sourceCode, 23); + BOOST_CHECK(callContractFunction(0) == toBigEndian(u256(23))); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/solidityExpressionCompiler.cpp b/solidityExpressionCompiler.cpp index 59a9e933..6ea66bad 100644 --- a/solidityExpressionCompiler.cpp +++ b/solidityExpressionCompiler.cpp @@ -88,7 +88,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _ Parser parser; ASTPointer<ContractDefinition> contract; BOOST_REQUIRE_NO_THROW(contract = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); - NameAndTypeResolver resolver; + NameAndTypeResolver resolver({}); BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); FirstExpressionExtractor extractor(*contract); BOOST_REQUIRE(extractor.getExpression() != nullptr); diff --git a/solidityNameAndTypeResolution.cpp b/solidityNameAndTypeResolution.cpp index 930bba0e..61aabb34 100644 --- a/solidityNameAndTypeResolution.cpp +++ b/solidityNameAndTypeResolution.cpp @@ -43,7 +43,7 @@ void parseTextAndResolveNames(std::string const& _source) Parser parser; ASTPointer<ContractDefinition> contract = parser.parse( std::make_shared<Scanner>(CharStream(_source))); - NameAndTypeResolver resolver; + NameAndTypeResolver resolver({}); resolver.resolveNamesAndTypes(*contract); } } diff --git a/solidityParser.cpp b/solidityParser.cpp index 9319a02c..0ee88b26 100644 --- a/solidityParser.cpp +++ b/solidityParser.cpp @@ -221,6 +221,26 @@ BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(blockchain_access) +{ + char const* text = "contract test {\n" + " function fun() {\n" + " u256 x = address(0).balance;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(blockchain_access_invalid) +{ + char const* text = "contract test {\n" + " function fun() {\n" + " address(0).balance = 7;\n" + " }\n" + "}\n"; + BOOST_CHECK_THROW(parseText(text), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } |