mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add new test.
This commit is contained in:
parent
52b9a92ff8
commit
af44c05f1a
35
test/libsolidity/ASTJSON/license.json
Normal file
35
test/libsolidity/ASTJSON/license.json
Normal 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"
|
||||||
|
}
|
4
test/libsolidity/ASTJSON/license.sol
Normal file
4
test/libsolidity/ASTJSON/license.sol
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
contract C {}
|
||||||
|
|
||||||
|
// ----
|
50
test/libsolidity/ASTJSON/license_legacy.json
Normal file
50
test/libsolidity/ASTJSON/license_legacy.json
Normal 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"
|
||||||
|
}
|
@ -1105,6 +1105,46 @@ BOOST_AUTO_TEST_CASE(metadata_without_compilation)
|
|||||||
BOOST_CHECK(solidity::test::isValidMetadata(contract["metadata"].asString()));
|
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)
|
BOOST_AUTO_TEST_CASE(common_pattern)
|
||||||
{
|
{
|
||||||
char const* input = R"(
|
char const* input = R"(
|
||||||
|
5
test/libsolidity/syntaxTests/license/license_double.sol
Normal file
5
test/libsolidity/syntaxTests/license/license_double.sol
Normal 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.
|
1
test/libsolidity/syntaxTests/license/license_missing.sol
Normal file
1
test/libsolidity/syntaxTests/license/license_missing.sol
Normal file
@ -0,0 +1 @@
|
|||||||
|
contract C {}
|
Loading…
Reference in New Issue
Block a user