diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/cmdlineTests.sh | 2 | ||||
-rw-r--r-- | test/contracts/AuctionRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/FixedFeeRegistrar.cpp | 2 | ||||
-rw-r--r-- | test/contracts/Wallet.cpp | 2 | ||||
-rwxr-xr-x | test/externalTests.sh | 4 | ||||
-rw-r--r-- | test/libjulia/Inliner.cpp | 35 | ||||
-rw-r--r-- | test/liblll/Compiler.cpp | 10 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 19 | ||||
-rw-r--r-- | test/libsolidity/StandardCompiler.cpp | 65 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/array/length/fixed_size_multidim_zero_length.sol | 15 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/array/length/fixed_size_zero_length.sol | 15 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/array/length/parentheses.sol | 2 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol | 2 |
13 files changed, 164 insertions, 11 deletions
diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 6e57ce0f..d7b95e8a 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -183,6 +183,8 @@ do then echo " - $dir" cd "$dir" + # Replace version pragmas + find . -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity [\^0-9\.]*/pragma solidity >=0.0/' compileFull -w *.sol */*.sol cd .. fi diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index 70503605..eb274c09 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -40,7 +40,7 @@ namespace { static char const* registrarCode = R"DELIMITER( -pragma solidity ^0.4.0; +pragma solidity >=0.4.0 <0.6.0; contract NameRegister { function addr(string memory _name) public view returns (address o_owner); diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index ae921a96..e82f389f 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -53,7 +53,7 @@ static char const* registrarCode = R"DELIMITER( // @authors: // Gav Wood <g@ethdev.com> -pragma solidity ^0.4.0; +pragma solidity >=0.4.0 <0.6.0; contract Registrar { event Changed(string indexed name); diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index e0e3045c..9fe02e46 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -56,7 +56,7 @@ static char const* walletCode = R"DELIMITER( // some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the // interior is executed. -pragma solidity ^0.4.0; +pragma solidity >=0.4.0 <0.6.0; contract multiowned { diff --git a/test/externalTests.sh b/test/externalTests.sh index f2839083..0168fb03 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -56,10 +56,10 @@ function test_truffle echo "Current commit hash: `git rev-parse HEAD`" npm install find . -name soljson.js -exec cp "$SOLJSON" {} \; - if [ "$name" == "Gnosis" ]; then + if [ "$name" == "Zeppelin" -o "$name" == "Gnosis" ]; then echo "Replaced fixed-version pragmas..." # Replace fixed-version pragmas in Gnosis (part of Consensys best practice) - find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity 0/pragma solidity ^0/' + find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity [\^0-9\.]*/pragma solidity >=0.0/' fi assertsol="node_modules/truffle/build/Assert.sol" if [ -f "$assertsol" ] diff --git a/test/libjulia/Inliner.cpp b/test/libjulia/Inliner.cpp index 43a7d757..d0ecd42f 100644 --- a/test/libjulia/Inliner.cpp +++ b/test/libjulia/Inliner.cpp @@ -342,5 +342,40 @@ BOOST_AUTO_TEST_CASE(pop_result) ); } +BOOST_AUTO_TEST_CASE(inside_condition) +{ + // This tests that breaking the expression inside the condition works properly. + BOOST_CHECK_EQUAL( + fullInline("{" + "if gt(f(mload(1)), mload(0)) {" + "sstore(0, 2)" + "}" + "function f(a) -> r {" + "a := mload(a)" + "r := add(a, calldatasize())" + "}" + "}", false), + format("{" + "{" + "let _1 := mload(0)" + "let f_a := mload(1)" + "let f_r" + "{" + "f_a := mload(f_a)" + "f_r := add(f_a, calldatasize())" + "}" + "if gt(f_r, _1)" + "{" + "sstore(0, 2)" + "}" + "}" + "function f(a) -> r" + "{" + "a := mload(a)" + "r := add(a, calldatasize())" + "}" + "}", false) + ); +} BOOST_AUTO_TEST_SUITE_END() diff --git a/test/liblll/Compiler.cpp b/test/liblll/Compiler.cpp index 39f5e620..a4394f54 100644 --- a/test/liblll/Compiler.cpp +++ b/test/liblll/Compiler.cpp @@ -186,6 +186,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_functional) "60006000600060003c", "3d", "6000600060003e", + "60003f", "600040", "41", "42", @@ -291,6 +292,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_functional) "{ (EXTCODECOPY 0 0 0 0) }", "{ (RETURNDATASIZE) }", "{ (RETURNDATACOPY 0 0 0) }", + "{ (EXTCODEHASH 0) }", "{ (BLOCKHASH 0) }", "{ (COINBASE) }", "{ (TIMESTAMP) }", @@ -356,7 +358,8 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_functional) "{ (SELFDESTRUCT 0) }" }; - for (size_t i = 0; i < opcodes_bytecode.size(); i++) { + for (size_t i = 0; i < opcodes_bytecode.size(); i++) + { vector<string> errors; bytes code = lll::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors); @@ -408,6 +411,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_asm) "3c", "3d", "3e", + "3f", "40", "41", "42", @@ -546,6 +550,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_asm) "{ (asm EXTCODECOPY) }", "{ (asm RETURNDATASIZE) }", "{ (asm RETURNDATACOPY) }", + "{ (asm EXTCODEHASH) }", "{ (asm BLOCKHASH) }", "{ (asm COINBASE) }", "{ (asm TIMESTAMP) }", @@ -644,7 +649,8 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_asm) "{ (asm SELFDESTRUCT) }" }; - for (size_t i = 0; i < opcodes_bytecode.size(); i++) { + for (size_t i = 0; i < opcodes_bytecode.size(); i++) + { vector<string> errors; bytes code = lll::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors); diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index af8465fc..640bf4d0 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -396,7 +396,7 @@ BOOST_AUTO_TEST_CASE(returndatasize_as_variable) {Error::Type::Warning, "Variable is shadowed in inline assembly by an instruction of the same name"} }); if (!dev::test::Options::get().evmVersion().supportsReturndata()) - expectations.emplace_back(make_pair(Error::Type::Warning, std::string("\"returndatasize\" instruction is only available for Byzantium-compatible"))); + expectations.emplace_back(make_pair(Error::Type::Warning, std::string("\"returndatasize\" instruction is only available for Byzantium-compatible VMs."))); CHECK_ALLOW_MULTI(text, expectations); } @@ -407,9 +407,24 @@ BOOST_AUTO_TEST_CASE(create2_as_variable) )"; // This needs special treatment, because the message mentions the EVM version, // so cannot be run via isoltest. + vector<pair<Error::Type, std::string>> expectations(vector<pair<Error::Type, std::string>>{ + {Error::Type::Warning, "Variable is shadowed in inline assembly by an instruction of the same name"} + }); + if (!dev::test::Options::get().evmVersion().hasCreate2()) + expectations.emplace_back(make_pair(Error::Type::Warning, std::string("\"create2\" instruction is only available for Constantinople-compatible VMs."))); + CHECK_ALLOW_MULTI(text, expectations); +} + +BOOST_AUTO_TEST_CASE(extcodehash_as_variable) +{ + char const* text = R"( + contract c { function f() public view { uint extcodehash; extcodehash; assembly { pop(extcodehash(0)) } }} + )"; + // This needs special treatment, because the message mentions the EVM version, + // so cannot be run via isoltest. CHECK_ALLOW_MULTI(text, (std::vector<std::pair<Error::Type, std::string>>{ {Error::Type::Warning, "Variable is shadowed in inline assembly by an instruction of the same name"}, - {Error::Type::Warning, "The \"create2\" instruction is not supported by the VM version"}, + {Error::Type::Warning, "The \"extcodehash\" instruction is not supported by the VM version"}, })); } diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index d34bacda..1570a9d2 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -225,6 +225,71 @@ BOOST_AUTO_TEST_CASE(smoke_test) BOOST_CHECK(containsAtMostWarnings(result)); } +BOOST_AUTO_TEST_CASE(optimizer_enabled_not_boolean) +{ + char const* input = R"( + { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": "wrong" + } + }, + "sources": { + "empty": { + "content": "" + } + } + } + )"; + Json::Value result = compile(input); + BOOST_CHECK(containsError(result, "JSONError", "The \"enabled\" setting must be a boolean.")); +} + +BOOST_AUTO_TEST_CASE(optimizer_runs_not_a_number) +{ + char const* input = R"( + { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": "not a number" + } + }, + "sources": { + "empty": { + "content": "" + } + } + } + )"; + Json::Value result = compile(input); + BOOST_CHECK(containsError(result, "JSONError", "The \"runs\" setting must be an unsigned number.")); +} + +BOOST_AUTO_TEST_CASE(optimizer_runs_not_an_unsigned_number) +{ + char const* input = R"( + { + "language": "Solidity", + "settings": { + "optimizer": { + "enabled": true, + "runs": -1 + } + }, + "sources": { + "empty": { + "content": "" + } + } + } + )"; + Json::Value result = compile(input); + BOOST_CHECK(containsError(result, "JSONError", "The \"runs\" setting must be an unsigned number.")); +} + BOOST_AUTO_TEST_CASE(basic_compilation) { char const* input = R"( diff --git a/test/libsolidity/syntaxTests/array/length/fixed_size_multidim_zero_length.sol b/test/libsolidity/syntaxTests/array/length/fixed_size_multidim_zero_length.sol new file mode 100644 index 00000000..fd8f3078 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/fixed_size_multidim_zero_length.sol @@ -0,0 +1,15 @@ +contract C { + function a() public pure returns(int[0][500] memory) {} + function b() public pure returns(uint[0][500] memory) {} + function c() public pure returns(byte[0][500] memory) {} + function d() public pure returns(bytes32[0][500] memory) {} + function e() public pure returns(bytes[0][500] memory) {} + function e() public pure returns(string[0][500] memory) {} +} +// ---- +// TypeError: (52-53): Array with zero length specified. +// TypeError: (111-112): Array with zero length specified. +// TypeError: (170-171): Array with zero length specified. +// TypeError: (232-233): Array with zero length specified. +// TypeError: (292-293): Array with zero length specified. +// TypeError: (353-354): Array with zero length specified. diff --git a/test/libsolidity/syntaxTests/array/length/fixed_size_zero_length.sol b/test/libsolidity/syntaxTests/array/length/fixed_size_zero_length.sol new file mode 100644 index 00000000..b38939e3 --- /dev/null +++ b/test/libsolidity/syntaxTests/array/length/fixed_size_zero_length.sol @@ -0,0 +1,15 @@ +contract C { + int[0] a; + uint[0] b; + byte[0] c; + bytes32[0] d; + bytes[0] e; + string[0] f; +} +// ---- +// TypeError: (19-20): Array with zero length specified. +// TypeError: (32-33): Array with zero length specified. +// TypeError: (45-46): Array with zero length specified. +// TypeError: (61-62): Array with zero length specified. +// TypeError: (75-76): Array with zero length specified. +// TypeError: (90-91): Array with zero length specified. diff --git a/test/libsolidity/syntaxTests/array/length/parentheses.sol b/test/libsolidity/syntaxTests/array/length/parentheses.sol index 40f55ad6..8dbcc0a4 100644 --- a/test/libsolidity/syntaxTests/array/length/parentheses.sol +++ b/test/libsolidity/syntaxTests/array/length/parentheses.sol @@ -21,5 +21,5 @@ contract C { uint[((2) + 1) + 1] a12; uint[(2 + 1) + ((1))] a13; uint[(((2) + 1)) + (((1)))] a14; - uint[((((2) + 1)) + (((1))))%1] a15; + uint[((((3) + 1)) + (((1))))%2] a15; } diff --git a/test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol b/test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol index 9181222e..9adf6f12 100644 --- a/test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol +++ b/test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol @@ -1,6 +1,6 @@ contract c { uint[10] a; uint[] a2; - struct x { uint[2**20] b; y[0] c; } + struct x { uint[2**20] b; y[1] c; } struct y { uint d; mapping(uint=>x)[] e; } } |