aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-21 22:59:34 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-03-21 22:53:29 +0800
commitcc0f70263f41ea288391ef1ad416d70aff4b031e (patch)
treed1811a7ca9c57226c23700bc120dc9fdb6fe0e0c /test/libsolidity
parentc2709a2d8e53155513fa8002a564e434fce68c68 (diff)
downloaddexon-solidity-cc0f70263f41ea288391ef1ad416d70aff4b031e.tar.gz
dexon-solidity-cc0f70263f41ea288391ef1ad416d70aff4b031e.tar.zst
dexon-solidity-cc0f70263f41ea288391ef1ad416d70aff4b031e.zip
Tests for returning dynamic data.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/ABIDecoderTests.cpp83
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp27
2 files changed, 104 insertions, 6 deletions
diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp
index 15c04b37..beb7b5af 100644
--- a/test/libsolidity/ABIDecoderTests.cpp
+++ b/test/libsolidity/ABIDecoderTests.cpp
@@ -786,6 +786,89 @@ BOOST_AUTO_TEST_CASE(complex_struct)
}
+BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_simple)
+{
+ if (m_evmVersion == EVMVersion::homestead())
+ return;
+
+ string sourceCode = R"(
+ contract C {
+ function dyn() public returns (bytes) {
+ return "1234567890123456789012345678901234567890";
+ }
+ function f() public returns (bytes) {
+ return this.dyn();
+ }
+ }
+ )";
+ BOTH_ENCODERS(
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(0x20, 40, string("1234567890123456789012345678901234567890")));
+ )
+}
+
+BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_advanced)
+{
+ if (m_evmVersion == EVMVersion::homestead())
+ return;
+
+ string sourceCode = R"(
+ contract C {
+ function dyn() public returns (bytes a, uint b, bytes20[] c, uint d) {
+ a = "1234567890123456789012345678901234567890";
+ b = uint(-1);
+ c = new bytes20[](4);
+ c[0] = bytes20(1234);
+ c[3] = bytes20(6789);
+ d = 0x1234;
+ }
+ function f() public returns (bytes, uint, bytes20[], uint) {
+ return this.dyn();
+ }
+ }
+ )";
+ BOTH_ENCODERS(
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(
+ 0x80, u256(-1), 0xe0, 0x1234,
+ 40, string("1234567890123456789012345678901234567890"),
+ 4, u256(1234) << (8 * (32 - 20)), 0, 0, u256(6789) << (8 * (32 - 20))
+ ));
+ )
+}
+
+BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_out_of_range)
+{
+ string sourceCode = R"(
+ contract C {
+ function dyn(uint x) public returns (bytes a) {
+ assembly {
+ mstore(0, 0x20)
+ mstore(0x20, 0x21)
+ return(0, x)
+ }
+ }
+ function f(uint x) public returns (bool) {
+ this.dyn(x);
+ return true;
+ }
+ }
+ )";
+ BOTH_ENCODERS(
+ compileAndRun(sourceCode, 0, "C");
+ if (m_evmVersion == EVMVersion::homestead())
+ {
+ ABI_CHECK(callContractFunction("f(uint256)", 0x60), encodeArgs(true));
+ ABI_CHECK(callContractFunction("f(uint256)", 0x7f), encodeArgs(true));
+ }
+ else
+ {
+ ABI_CHECK(callContractFunction("f(uint256)", 0x60), encodeArgs());
+ ABI_CHECK(callContractFunction("f(uint256)", 0x61), encodeArgs(true));
+ }
+ ABI_CHECK(callContractFunction("f(uint256)", 0x80), encodeArgs(true));
+ )
+}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 8a020ca6..50ee2b2e 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -3372,12 +3372,10 @@ BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible)
}
}
)";
- m_compiler.setEVMVersion(EVMVersion{});
- CHECK_WARNING(sourceCode, "Use of the \"var\" keyword is deprecated");
- m_compiler.setEVMVersion(*EVMVersion::fromString("byzantium"));
- CHECK_WARNING(sourceCode, "Use of the \"var\" keyword is deprecated");
- m_compiler.setEVMVersion(*EVMVersion::fromString("homestead"));
- CHECK_ERROR(sourceCode, TypeError, "Explicit type conversion not allowed from \"inaccessible dynamic type\" to \"bytes storage pointer\".");
+ if (dev::test::Options::get().evmVersion() == EVMVersion::homestead())
+ CHECK_ERROR(sourceCode, TypeError, "Explicit type conversion not allowed from \"inaccessible dynamic type\" to \"bytes storage pointer\".");
+ else
+ CHECK_WARNING(sourceCode, "Use of the \"var\" keyword is deprecated");
}
BOOST_AUTO_TEST_CASE(memory_arrays_not_resizeable)
@@ -6392,6 +6390,23 @@ BOOST_AUTO_TEST_CASE(return_structs)
CHECK_SUCCESS(text);
}
+BOOST_AUTO_TEST_CASE(read_returned_struct)
+{
+ char const* text = R"(
+ pragma experimental ABIEncoderV2;
+ contract A {
+ struct T {
+ int x;
+ int y;
+ }
+ function g() public returns (T) {
+ return this.g();
+ }
+ }
+ )";
+ CHECK_WARNING(text, "Experimental features");
+}
+
BOOST_AUTO_TEST_CASE(return_recursive_structs)
{
char const* text = R"(