From e9365e93fcef5298ab960aac9d71d2fa0dd64303 Mon Sep 17 00:00:00 2001 From: ssi91 Date: Fri, 25 Aug 2023 21:41:24 -0400 Subject: [PATCH] add some test-cases for unverified library addresses --- .../input.json | 33 +++++++++ .../output.json | 12 ++++ .../input.json | 33 +++++++++ .../output.json | 12 ++++ .../input.json | 33 +++++++++ .../output.json | 12 ++++ test/solc/CommandLineParser.cpp | 70 +++++++++++++++++++ 7 files changed, 205 insertions(+) create mode 100644 test/cmdlineTests/linking_standard_solidity_empty_address/input.json create mode 100644 test/cmdlineTests/linking_standard_solidity_empty_address/output.json create mode 100644 test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/input.json create mode 100644 test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/output.json create mode 100644 test/cmdlineTests/linking_standard_solidity_invalid_length_address/input.json create mode 100644 test/cmdlineTests/linking_standard_solidity_invalid_length_address/output.json diff --git a/test/cmdlineTests/linking_standard_solidity_empty_address/input.json b/test/cmdlineTests/linking_standard_solidity_empty_address/input.json new file mode 100644 index 000000000..4afdf77e5 --- /dev/null +++ b/test/cmdlineTests/linking_standard_solidity_empty_address/input.json @@ -0,0 +1,33 @@ +{ + "language": "Solidity", + "sources": { + "A": { + "content": " + // SPDX-License-Identifier: GPL-3.0 + pragma solidity >=0.0; + + library L { + function f() external {} + } + + contract C { + function foo() public { + L.f(); + } + } + " + } + }, + "settings": { + "libraries": { + "A": { + "L": "" + } + }, + "outputSelection": { + "*": { + "C": ["evm.bytecode.object", "evm.bytecode.linkReferences"] + } + } + } +} diff --git a/test/cmdlineTests/linking_standard_solidity_empty_address/output.json b/test/cmdlineTests/linking_standard_solidity_empty_address/output.json new file mode 100644 index 000000000..f8cc5ed1f --- /dev/null +++ b/test/cmdlineTests/linking_standard_solidity_empty_address/output.json @@ -0,0 +1,12 @@ +{ + "errors": + [ + { + "component": "general", + "formattedMessage": "Library address is not prefixed with \"0x\".", + "message": "Library address is not prefixed with \"0x\".", + "severity": "error", + "type": "JSONError" + } + ] +} diff --git a/test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/input.json b/test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/input.json new file mode 100644 index 000000000..88447c993 --- /dev/null +++ b/test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/input.json @@ -0,0 +1,33 @@ +{ + "language": "Solidity", + "sources": { + "A": { + "content": " + // SPDX-License-Identifier: GPL-3.0 + pragma solidity >=0.0; + + library L { + function f() external {} + } + + contract C { + function foo() public { + L.f(); + } + } + " + } + }, + "settings": { + "libraries": { + "A": { + "L": "0x123456789012345678901234567890123456789T" + } + }, + "outputSelection": { + "*": { + "C": ["evm.bytecode.object", "evm.bytecode.linkReferences"] + } + } + } +} diff --git a/test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/output.json b/test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/output.json new file mode 100644 index 000000000..da02e58c7 --- /dev/null +++ b/test/cmdlineTests/linking_standard_solidity_invalid_address_supplied/output.json @@ -0,0 +1,12 @@ +{ + "errors": + [ + { + "component": "general", + "formattedMessage": "Invalid library address (\"0x123456789012345678901234567890123456789T\") supplied.", + "message": "Invalid library address (\"0x123456789012345678901234567890123456789T\") supplied.", + "severity": "error", + "type": "JSONError" + } + ] +} diff --git a/test/cmdlineTests/linking_standard_solidity_invalid_length_address/input.json b/test/cmdlineTests/linking_standard_solidity_invalid_length_address/input.json new file mode 100644 index 000000000..9aa91a07c --- /dev/null +++ b/test/cmdlineTests/linking_standard_solidity_invalid_length_address/input.json @@ -0,0 +1,33 @@ +{ + "language": "Solidity", + "sources": { + "A": { + "content": " + // SPDX-License-Identifier: GPL-3.0 + pragma solidity >=0.0; + + library L { + function f() external {} + } + + contract C { + function foo() public { + L.f(); + } + } + " + } + }, + "settings": { + "libraries": { + "A": { + "L": "0x2323232232323" + } + }, + "outputSelection": { + "*": { + "C": ["evm.bytecode.object", "evm.bytecode.linkReferences"] + } + } + } +} diff --git a/test/cmdlineTests/linking_standard_solidity_invalid_length_address/output.json b/test/cmdlineTests/linking_standard_solidity_invalid_length_address/output.json new file mode 100644 index 000000000..b3fd6d6cf --- /dev/null +++ b/test/cmdlineTests/linking_standard_solidity_invalid_length_address/output.json @@ -0,0 +1,12 @@ +{ + "errors": + [ + { + "component": "general", + "formattedMessage": "Library address is of invalid length.", + "message": "Library address is of invalid length.", + "severity": "error", + "type": "JSONError" + } + ] +} diff --git a/test/solc/CommandLineParser.cpp b/test/solc/CommandLineParser.cpp index 43cef9d27..b85bd26de 100644 --- a/test/solc/CommandLineParser.cpp +++ b/test/solc/CommandLineParser.cpp @@ -399,6 +399,76 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options) BOOST_TEST(parsedOptions == expectedOptions); } +BOOST_AUTO_TEST_CASE(invalid_library_address_length) +{ + vector commandLine = { + "solc", + "contract.sol", + "--libraries=" + "dir1/file1.sol:L=0x" + }; + + string expectedMessage = "Invalid length for address for library \"dir1/file1.sol:L\": 0 instead of 40 characters."; + auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { + return _exception.what() == expectedMessage; + }; + + BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage); +} + +BOOST_AUTO_TEST_CASE(invalid_library_address_empty) +{ + vector commandLine = { + "solc", + "contract.sol", + "--libraries=" + "dir1/file1.sol:L=" + }; + + string expectedMessage = "Empty address provided for library \"dir1/file1.sol:L\".\n" + "Note that there should not be any whitespace after the equal sign." ; + auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { + return _exception.what() == expectedMessage; + }; + + BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage); +} + +BOOST_AUTO_TEST_CASE(invalid_library_address_prefix) +{ + vector commandLine = { + "solc", + "contract.sol", + "--libraries=" + "dir1/file1.sol:L=1111122222333334444455555666667777788888" + }; + + string expectedMessage = "The address 1111122222333334444455555666667777788888 is not prefixed with \"0x\".\n" + "Note that the address must be prefixed with \"0x\"." ; + auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { + return _exception.what() == expectedMessage; + }; + + BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage); +} + +BOOST_AUTO_TEST_CASE(invalid_library_address_checksum) +{ + vector commandLine = { + "solc", + "contract.sol", + "--libraries=" + "dir1/file1.sol:L=0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaaa" + }; + + string expectedMessage = "Invalid checksum on address for library \"dir1/file1.sol:L\": aAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaaa\n" + "The correct checksum is 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"; + auto hasCorrectMessage + = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedMessage; }; + + BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage); +} + BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations) { map> invalidOptionInputModeCombinations = {