From 1e8c26421be9c577ece43c2d1602afe70288c674 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 22 Jun 2015 20:50:29 +0200 Subject: Decoding for constructor. --- libsolidity/SolidityEndToEndTest.cpp | 40 ++++++++++++++++++++++----- libsolidity/SolidityNameAndTypeResolution.cpp | 13 +++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index b0275b1b..d397dc59 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4457,26 +4457,52 @@ BOOST_AUTO_TEST_CASE(bytes_index_access_memory) ); } -BOOST_AUTO_TEST_CASE(bytes_in_constructors) +BOOST_AUTO_TEST_CASE(bytes_in_constructors_unpacker) { char const* sourceCode = R"( - contract Base { + contract Test { uint public m_x; bytes public m_s; + function Test(uint x, bytes s) { + m_x = x; + m_s = s; + } + } + )"; + string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); + bytes dyn1 = encodeArgs(u256(s1.length()), s1); + u256 x = 7; + bytes args1 = encodeArgs(x, u256(0x40)) + dyn1; + compileAndRun(sourceCode, 0, "Test", args1); + BOOST_REQUIRE(callContractFunction("m_x()") == encodeArgs(x)); + BOOST_REQUIRE(callContractFunction("m_s()") == encodeArgs(u256(0x20)) + dyn1); +} + +BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer) +{ + char const* sourceCode = R"( + contract Base { + uint public m_x; + bytes m_s; function Base(uint x, bytes s) { m_x = x; m_s = s; } + function part(uint i) returns (byte) { + return m_s[i]; + } } contract Main is Base { - function Main(bytes s, uint x) Base(x, f(s)) {} - function f(bytes s) returns (bytes) { return s; } + function Main(bytes s, uint x) Base(x, s){}//f(s)) {} + function f(bytes s) returns (bytes) { + return s; + } } contract Creator { - function f(uint x, bytes s) returns (uint r, bytes b) { + function f(uint x, bytes s) returns (uint r, byte ch) { var c = new Main(s, x); r = c.m_x(); - b = c.m_s(); + ch = c.part(x); } } )"; @@ -4487,7 +4513,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors) bytes args1 = encodeArgs(x, u256(0x40)) + dyn1; BOOST_REQUIRE( callContractFunction("f(uint256,bytes)", asString(args1)) == - encodeArgs(x, u256(0x40), dyn1) + encodeArgs(x, string{s1[unsigned(x)]}) ); } diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index afa8b727..765593c5 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1987,6 +1987,19 @@ BOOST_AUTO_TEST_CASE(mem_array_assignment_changes_base_type) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible) +{ + char const* sourceCode = R"( + contract C { + function f(uint) returns (string); + function g() { + var x = this.f(2); + } + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3