aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-23 02:50:29 +0800
committerchriseth <c@ethdev.com>2015-06-23 02:55:46 +0800
commit1e8c26421be9c577ece43c2d1602afe70288c674 (patch)
tree36b1083959df867c392163dfbfa8e827a3dfc8e3 /libsolidity
parent90ee186044bfa881d944836be9c6f396e610e219 (diff)
downloaddexon-solidity-1e8c26421be9c577ece43c2d1602afe70288c674.tar.gz
dexon-solidity-1e8c26421be9c577ece43c2d1602afe70288c674.tar.zst
dexon-solidity-1e8c26421be9c577ece43c2d1602afe70288c674.zip
Decoding for constructor.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/SolidityEndToEndTest.cpp40
-rw-r--r--libsolidity/SolidityNameAndTypeResolution.cpp13
2 files changed, 46 insertions, 7 deletions
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()
}