Compute canonical names of types for function signatures.

This commit is contained in:
chriseth
2015-10-06 14:20:06 +02:00
parent ce25ddfa6a
commit bc609c55c0
16 changed files with 195 additions and 70 deletions
+30
View File
@@ -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()
}
-26
View File
@@ -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
+15
View File
@@ -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()
}
@@ -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());
}