Add new test.

This commit is contained in:
Alexander Arlt 2020-05-12 20:52:33 -05:00 committed by chriseth
parent 52b9a92ff8
commit af44c05f1a
6 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,35 @@
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
1
]
},
"id": 2,
"license": "GPL-3.0",
"nodeType": "SourceUnit",
"nodes":
[
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 1,
"linearizedBaseContracts":
[
1
],
"name": "C",
"nodeType": "ContractDefinition",
"nodes": [],
"scope": 2,
"src": "36:13:1"
}
],
"src": "36:14:1"
}

View File

@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
contract C {}
// ----

View File

@ -0,0 +1,50 @@
{
"attributes":
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
1
]
},
"license": "GPL-3.0"
},
"children":
[
{
"attributes":
{
"abstract": false,
"baseContracts":
[
null
],
"contractDependencies":
[
null
],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"linearizedBaseContracts":
[
1
],
"name": "C",
"nodes":
[
null
],
"scope": 2
},
"id": 1,
"name": "ContractDefinition",
"src": "36:13:1"
}
],
"id": 2,
"name": "SourceUnit",
"src": "36:14:1"
}

View File

@ -1105,6 +1105,46 @@ BOOST_AUTO_TEST_CASE(metadata_without_compilation)
BOOST_CHECK(solidity::test::isValidMetadata(contract["metadata"].asString()));
}
BOOST_AUTO_TEST_CASE(license_in_metadata)
{
string const input = R"(
{
"language": "Solidity",
"sources": {
"fileA": { "content": "import \"fileB\"; contract A { } // SPDX-License-Identifier: GPL-3.0 \n" },
"fileB": { "content": "import \"fileC\"; /* SPDX-License-Identifier: MIT */ contract B { }" },
"fileC": { "content": "import \"fileD\"; /* SPDX-License-Identifier: MIT AND GPL-3.0 */ contract C { }" },
"fileD": { "content": "// SPDX-License-Identifier: (GPL-3.0+ OR MIT) AND MIT \n import \"fileE\"; contract D { }" },
"fileE": { "content": "import \"fileF\"; /// SPDX-License-Identifier: MIT \n contract E { }" },
"fileF": { "content": "/*\n * SPDX-License-Identifier: MIT\n */ contract F { }" }
},
"settings": {
"outputSelection": {
"fileA": {
"*": [ "metadata" ]
}
}
}
}
)";
Json::Value result = compile(input);
BOOST_CHECK(containsAtMostWarnings(result));
Json::Value contract = getContractResult(result, "fileA", "A");
BOOST_CHECK(contract.isObject());
BOOST_CHECK(contract["metadata"].isString());
Json::Value metadata;
BOOST_REQUIRE(util::jsonParseStrict(contract["metadata"].asString(), metadata));
BOOST_CHECK_EQUAL(metadata["sources"]["fileA"]["license"], "GPL-3.0");
BOOST_CHECK_EQUAL(metadata["sources"]["fileB"]["license"], "MIT");
BOOST_CHECK_EQUAL(metadata["sources"]["fileC"]["license"], "MIT AND GPL-3.0");
BOOST_CHECK_EQUAL(metadata["sources"]["fileD"]["license"], "(GPL-3.0+ OR MIT) AND MIT");
// This is actually part of the docstring, but still picked up
// because the source location of the contract does not cover the docstring.
BOOST_CHECK_EQUAL(metadata["sources"]["fileE"]["license"], "MIT");
BOOST_CHECK_EQUAL(metadata["sources"]["fileF"]["license"], "MIT");
}
BOOST_AUTO_TEST_CASE(common_pattern)
{
char const* input = R"(

View File

@ -0,0 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
contract C {}
// SPDX-License-Identifier: MIT
// ----
// ParserError: Multiple SPDX license identifiers found in source file. Use "AND" or "OR" to combine multiple licenses. Please see https://spdx.org for more information.

View File

@ -0,0 +1 @@
contract C {}