aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-10-05 23:19:23 +0800
committerchriseth <c@ethdev.com>2015-10-06 20:20:06 +0800
commitbc609c55c0fa622a68fa9718c55046416c201b1d (patch)
tree0757a485f2e6c0e0c70bb924c4b4acfac53aec5c /test
parentce25ddfa6a9b8cfff08b4a05591dcc3b4a8b63cc (diff)
downloaddexon-solidity-bc609c55c0fa622a68fa9718c55046416c201b1d.tar.gz
dexon-solidity-bc609c55c0fa622a68fa9718c55046416c201b1d.tar.zst
dexon-solidity-bc609c55c0fa622a68fa9718c55046416c201b1d.zip
Compute canonical names of types for function signatures.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityABIJSON.cpp30
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp26
-rw-r--r--test/libsolidity/SolidityInterface.cpp15
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp10
4 files changed, 50 insertions, 31 deletions
diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp
index 69504e3d..f3004b5f 100644
--- a/test/libsolidity/SolidityABIJSON.cpp
+++ b/test/libsolidity/SolidityABIJSON.cpp
@@ -595,6 +595,36 @@ BOOST_AUTO_TEST_CASE(strings_and_arrays)
checkInterface(sourceCode, interface);
}
+BOOST_AUTO_TEST_CASE(library_function)
+{
+ char const* sourceCode = R"(
+ library test {
+ struct StructType { uint a; }
+ function f(StructType storage b, uint[] storage c, test d) returns (uint[] e, StructType storage f){}
+ }
+ )";
+
+ char const* interface = R"(
+ [
+ {
+ "constant" : false,
+ "name": "f",
+ "inputs": [
+ { "name": "b", "type": "test.StructType storage" },
+ { "name": "c", "type": "uint256[] storage" },
+ { "name": "d", "type": "test" }
+ ],
+ "outputs": [
+ { "name": "e", "type": "uint256[]" },
+ { "name": "f", "type": "test.StructType storage" }
+ ],
+ "type" : "function"
+ }
+ ]
+ )";
+ checkInterface(sourceCode, interface);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 26185b41..c40a027a 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5383,32 +5383,6 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17)));
}
-BOOST_AUTO_TEST_CASE(differentiate_storage_and_memory_in_libraries)
-{
- char const* sourceCode = R"(
- library Lib {
- function f(uint[] storage x) returns (uint) { return 1; }
- function f(uint[] memory x) returns (uint) { return 2; }
- }
- contract Test {
- uint[] data;
- function f() returns (uint a,)
- {
- uint[] memory d = data;
- Lib.f(d)
- data["abc"].length = 20;
- data["abc"][4] = 9;
- data["abc"][17] = 3;
- a = Lib.find(data["abc"], 9);
- b = Lib.find(data["abc"], 3);
- }
- }
- )";
- compileAndRun(sourceCode, 0, "Lib");
- compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4), u256(17)));
-}
-
BOOST_AUTO_TEST_CASE(short_strings)
{
// This test verifies that the byte array encoding that combines length and data works
diff --git a/test/libsolidity/SolidityInterface.cpp b/test/libsolidity/SolidityInterface.cpp
index d77bccbd..4006968a 100644
--- a/test/libsolidity/SolidityInterface.cpp
+++ b/test/libsolidity/SolidityInterface.cpp
@@ -142,6 +142,21 @@ BOOST_AUTO_TEST_CASE(inheritance)
sourcePart(*contract.definedFunctions().at(1))}));
}
+BOOST_AUTO_TEST_CASE(libraries)
+{
+ char const* sourceCode = R"(
+ library Lib {
+ struct Str { uint a; }
+ enum E { E1, E2 }
+ function f(uint[] x,Str storage y,E z) external;
+ }
+ )";
+ ContractDefinition const& contract = checkInterface(sourceCode);
+ set<string> expectedFunctions({"function f(uint256[] x,Lib.Str y,Lib.E z);"});
+ BOOST_REQUIRE_EQUAL(1, contract.definedFunctions().size());
+ BOOST_CHECK(expectedFunctions == set<string>({sourcePart(*contract.definedFunctions().at(0))}));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index c386e2b4..b4f16913 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -933,24 +933,24 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors)
BOOST_REQUIRE((contract = retrieveContract(source, 0)) != nullptr);
FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()");
BOOST_REQUIRE(function && function->hasDeclaration());
- auto returnParams = function->returnParameterTypeNames();
+ auto returnParams = function->returnParameterTypeNames(false);
BOOST_CHECK_EQUAL(returnParams.at(0), "uint256");
BOOST_CHECK(function->isConstant());
function = retrieveFunctionBySignature(contract, "map(uint256)");
BOOST_REQUIRE(function && function->hasDeclaration());
- auto params = function->parameterTypeNames();
+ auto params = function->parameterTypeNames(false);
BOOST_CHECK_EQUAL(params.at(0), "uint256");
- returnParams = function->returnParameterTypeNames();
+ returnParams = function->returnParameterTypeNames(false);
BOOST_CHECK_EQUAL(returnParams.at(0), "bytes4");
BOOST_CHECK(function->isConstant());
function = retrieveFunctionBySignature(contract, "multiple_map(uint256,uint256)");
BOOST_REQUIRE(function && function->hasDeclaration());
- params = function->parameterTypeNames();
+ params = function->parameterTypeNames(false);
BOOST_CHECK_EQUAL(params.at(0), "uint256");
BOOST_CHECK_EQUAL(params.at(1), "uint256");
- returnParams = function->returnParameterTypeNames();
+ returnParams = function->returnParameterTypeNames(false);
BOOST_CHECK_EQUAL(returnParams.at(0), "bytes4");
BOOST_CHECK(function->isConstant());
}