Some tests.

This commit is contained in:
chriseth 2018-02-22 14:47:36 +01:00
parent f75a411325
commit 60f7be5d4c
2 changed files with 35 additions and 1 deletions

View File

@ -60,7 +60,8 @@ bool isValidMetadata(string const& _metadata)
!metadata.isMember("compiler") || !metadata.isMember("compiler") ||
!metadata.isMember("settings") || !metadata.isMember("settings") ||
!metadata.isMember("sources") || !metadata.isMember("sources") ||
!metadata.isMember("output") !metadata.isMember("output") ||
!metadata["settings"].isMember("evmVersion")
) )
return false; return false;

View File

@ -724,6 +724,39 @@ BOOST_AUTO_TEST_CASE(library_linking)
BOOST_CHECK(contract["evm"]["bytecode"]["linkReferences"]["library2.sol"]["L2"][0].isObject()); BOOST_CHECK(contract["evm"]["bytecode"]["linkReferences"]["library2.sol"]["L2"][0].isObject());
} }
BOOST_AUTO_TEST_CASE(evm_version)
{
auto inputForVersion = [](string const& _version)
{
return R"(
{
"language": "Solidity",
"sources": { "fileA": { "content": "contract A { }" } },
"settings": {
)" + _version + R"(
"outputSelection": {
"fileA": {
"A": [ "metadata" ]
}
}
}
}
)";
};
Json::Value result;
result = compile(inputForVersion("\"evmVersion\": \"homestead\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"homestead\"") != string::npos);
result = compile(inputForVersion("\"evmVersion\": \"byzantium\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"byzantium\"") != string::npos);
// test default
result = compile(inputForVersion(""));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"byzantium\"") != string::npos);
// test invalid
result = compile(inputForVersion("\"evmVersion\": \"invalid\","));
BOOST_CHECK(result["errors"][0]["message"].asString() == "Invalid EVM version requested.");
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }