diff options
author | chriseth <c@ethdev.com> | 2014-12-17 02:47:36 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2014-12-17 02:47:36 +0800 |
commit | 350953e598c26b4e403d11c927f6c74452d59a69 (patch) | |
tree | 4771fb33fb6e755c8a1b6335f09753663f583152 | |
parent | 4b907092e63e8957ba43cc6b6d5e03f4afc56469 (diff) | |
parent | a1f61684b0bf687d15eb95d9d235876cdfa3c6e2 (diff) | |
download | dexon-solidity-350953e598c26b4e403d11c927f6c74452d59a69.tar.gz dexon-solidity-350953e598c26b4e403d11c927f6c74452d59a69.tar.zst dexon-solidity-350953e598c26b4e403d11c927f6c74452d59a69.zip |
Merge pull request #621 from chriseth/sol_createContracts
Contract creation ("new" operator).
-rw-r--r-- | solidityCompiler.cpp | 2 | ||||
-rw-r--r-- | solidityEndToEndTest.cpp | 26 | ||||
-rw-r--r-- | solidityNameAndTypeResolution.cpp | 9 |
3 files changed, 36 insertions, 1 deletions
diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index eae8f314..29f61454 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -56,7 +56,7 @@ bytes compileContract(const string& _sourceCode) BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); Compiler compiler; - compiler.compileContract(*contract, {}); + compiler.compileContract(*contract, {}, {}); // debug //compiler.streamAssembly(cout); return compiler.getAssembledBytecode(); diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 15722abe..b6f63aa7 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -1012,6 +1012,32 @@ BOOST_AUTO_TEST_CASE(strings_in_calls) BOOST_CHECK(callContractFunction(0, bytes({0, 'a', 1})) == bytes({0, 'a', 0, 0, 0})); } +BOOST_AUTO_TEST_CASE(constructor_arguments) +{ + char const* sourceCode = R"( + contract Helper { + string3 name; + bool flag; + function Helper(string3 x, bool f) { + name = x; + flag = f; + } + function getName() returns (string3 ret) { return name; } + function getFlag() returns (bool ret) { return flag; } + } + contract Main { + Helper h; + function Main() { + h = new Helper("abc", true); + } + function getFlag() returns (bool ret) { return h.getFlag(); } + function getName() returns (string3 ret) { return h.getName(); } + })"; + compileAndRun(sourceCode, 0, "Main"); + BOOST_REQUIRE(callContractFunction(0) == bytes({0x01})); + BOOST_REQUIRE(callContractFunction(1) == bytes({'a', 'b', 'c'})); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/solidityNameAndTypeResolution.cpp b/solidityNameAndTypeResolution.cpp index 03eaebb3..0ea6e51b 100644 --- a/solidityNameAndTypeResolution.cpp +++ b/solidityNameAndTypeResolution.cpp @@ -284,6 +284,15 @@ BOOST_AUTO_TEST_CASE(assignment_to_struct) BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } +BOOST_AUTO_TEST_CASE(returns_in_constructor) +{ + char const* text = "contract test {\n" + " function test() returns (uint a) {\n" + " }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } |