diff options
author | chriseth <chris@ethereum.org> | 2018-11-13 23:13:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-13 23:13:14 +0800 |
commit | 8ed2e02407cd9ad483d1645ffb67df83b339af3d (patch) | |
tree | 4d020d7fa482528b98759b755a8a725e6acda295 /test | |
parent | c21c7e74fee74c6201f14eaa664784aae79a52a2 (diff) | |
parent | 6ed3765941c4418881a6842f58ea1123a9c54738 (diff) | |
download | dexon-solidity-8ed2e02407cd9ad483d1645ffb67df83b339af3d.tar dexon-solidity-8ed2e02407cd9ad483d1645ffb67df83b339af3d.tar.gz dexon-solidity-8ed2e02407cd9ad483d1645ffb67df83b339af3d.tar.bz2 dexon-solidity-8ed2e02407cd9ad483d1645ffb67df83b339af3d.tar.lz dexon-solidity-8ed2e02407cd9ad483d1645ffb67df83b339af3d.tar.xz dexon-solidity-8ed2e02407cd9ad483d1645ffb67df83b339af3d.tar.zst dexon-solidity-8ed2e02407cd9ad483d1645ffb67df83b339af3d.zip |
Merge pull request #5105 from ethereum/libsolc-api
Remove old libsolc API (compileJSON, compileJSONMulti, compileJSONCallback)
Diffstat (limited to 'test')
-rwxr-xr-x | test/externalTests.sh | 13 | ||||
-rw-r--r-- | test/libsolidity/LibSolc.cpp | 143 | ||||
-rw-r--r-- | test/tools/fuzzer.cpp | 2 |
3 files changed, 16 insertions, 142 deletions
diff --git a/test/externalTests.sh b/test/externalTests.sh index 0168fb03..93581925 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -55,7 +55,16 @@ function test_truffle cd "$DIR" echo "Current commit hash: `git rev-parse HEAD`" npm install - find . -name soljson.js -exec cp "$SOLJSON" {} \; + # Replace solc package by master + for d in node_modules node_modules/truffle/node_modules + do + ( + cd $d + rm -rf solc + git clone --depth 1 https://github.com/ethereum/solc-js.git solc + cp "$SOLJSON" solc/ + ) + done if [ "$name" == "Zeppelin" -o "$name" == "Gnosis" ]; then echo "Replaced fixed-version pragmas..." # Replace fixed-version pragmas in Gnosis (part of Consensys best practice) @@ -68,6 +77,8 @@ function test_truffle rm "$assertsol" wget https://raw.githubusercontent.com/trufflesuite/truffle-core/ef31bcaa15dbd9bd0f6a0070a5c63f271cde2dbc/lib/testing/Assert.sol -o "$assertsol" fi + # Change "compileStandard" to "compile" + sed -i s/solc.compileStandard/solc.compile/ "node_modules/truffle/build/cli.bundled.js" npm run test ) rm -rf "$DIR" diff --git a/test/libsolidity/LibSolc.cpp b/test/libsolidity/LibSolc.cpp index 94fed7e8..09c08700 100644 --- a/test/libsolidity/LibSolc.cpp +++ b/test/libsolidity/LibSolc.cpp @@ -40,29 +40,9 @@ namespace test namespace { -Json::Value compileSingle(string const& _input) -{ - string output(compileJSON(_input.c_str(), dev::test::Options::get().optimize)); - Json::Value ret; - BOOST_REQUIRE(jsonParseStrict(output, ret)); - return ret; -} - -Json::Value compileMulti(string const& _input, bool _callback) -{ - string output( - _callback ? - compileJSONCallback(_input.c_str(), dev::test::Options::get().optimize, nullptr) : - compileJSONMulti(_input.c_str(), dev::test::Options::get().optimize) - ); - Json::Value ret; - BOOST_REQUIRE(jsonParseStrict(output, ret)); - return ret; -} - Json::Value compile(string const& _input) { - string output(compileStandard(_input.c_str(), nullptr)); + string output(solidity_compile(_input.c_str(), nullptr)); Json::Value ret; BOOST_REQUIRE(jsonParseStrict(output, ret)); return ret; @@ -74,113 +54,16 @@ BOOST_AUTO_TEST_SUITE(LibSolc) BOOST_AUTO_TEST_CASE(read_version) { - string output(version()); + string output(solidity_version()); BOOST_CHECK(output.find(VersionString) == 0); } BOOST_AUTO_TEST_CASE(read_license) { - string output(license()); + string output(solidity_license()); BOOST_CHECK(output.find("GNU GENERAL PUBLIC LICENSE") != string::npos); } -BOOST_AUTO_TEST_CASE(basic_compilation) -{ - char const* input = R"( - { - "sources": { - "fileA": "contract A { }" - } - } - )"; - Json::Value result = compileMulti(input, false); - BOOST_CHECK(result.isObject()); - - // Compare with compileJSONCallback - BOOST_CHECK_EQUAL( - dev::jsonCompactPrint(result), - dev::jsonCompactPrint(compileMulti(input, true)) - ); - - BOOST_CHECK(result["contracts"].isObject()); - BOOST_CHECK(result["contracts"]["fileA:A"].isObject()); - Json::Value contract = result["contracts"]["fileA:A"]; - BOOST_CHECK(contract.isObject()); - BOOST_CHECK(contract["interface"].isString()); - BOOST_CHECK_EQUAL(contract["interface"].asString(), "[]"); - BOOST_CHECK(contract["bytecode"].isString()); - BOOST_CHECK_EQUAL( - dev::test::bytecodeSansMetadata(contract["bytecode"].asString()), - "6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfe" - ); - BOOST_CHECK(contract["runtimeBytecode"].isString()); - BOOST_CHECK_EQUAL( - dev::test::bytecodeSansMetadata(contract["runtimeBytecode"].asString()), - "6080604052600080fdfe" - ); - BOOST_CHECK(contract["functionHashes"].isObject()); - BOOST_CHECK(contract["gasEstimates"].isObject()); - BOOST_CHECK_EQUAL( - dev::jsonCompactPrint(contract["gasEstimates"]), - "{\"creation\":[66,10600],\"external\":{},\"internal\":{}}" - ); - BOOST_CHECK(contract["metadata"].isString()); - BOOST_CHECK(dev::test::isValidMetadata(contract["metadata"].asString())); - BOOST_CHECK(result["sources"].isObject()); - BOOST_CHECK(result["sources"]["fileA"].isObject()); - BOOST_CHECK(result["sources"]["fileA"]["AST"].isObject()); - BOOST_CHECK_EQUAL( - dev::jsonCompactPrint(result["sources"]["fileA"]["AST"]), - "{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}}," - "\"children\":[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null]," - "\"contractKind\":\"contract\",\"documentation\":null,\"fullyImplemented\":true,\"linearizedBaseContracts\":[1]," - "\"name\":\"A\",\"nodes\":[null],\"scope\":2},\"id\":1,\"name\":\"ContractDefinition\"," - "\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}" - ); -} - -BOOST_AUTO_TEST_CASE(single_compilation) -{ - Json::Value result = compileSingle("contract A { }"); - BOOST_CHECK(result.isObject()); - - BOOST_CHECK(result["contracts"].isObject()); - BOOST_CHECK(result["contracts"][":A"].isObject()); - Json::Value contract = result["contracts"][":A"]; - BOOST_CHECK(contract.isObject()); - BOOST_CHECK(contract["interface"].isString()); - BOOST_CHECK_EQUAL(contract["interface"].asString(), "[]"); - BOOST_CHECK(contract["bytecode"].isString()); - BOOST_CHECK_EQUAL( - dev::test::bytecodeSansMetadata(contract["bytecode"].asString()), - "6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfe" - ); - BOOST_CHECK(contract["runtimeBytecode"].isString()); - BOOST_CHECK_EQUAL( - dev::test::bytecodeSansMetadata(contract["runtimeBytecode"].asString()), - "6080604052600080fdfe" - ); - BOOST_CHECK(contract["functionHashes"].isObject()); - BOOST_CHECK(contract["gasEstimates"].isObject()); - BOOST_CHECK_EQUAL( - dev::jsonCompactPrint(contract["gasEstimates"]), - "{\"creation\":[66,10600],\"external\":{},\"internal\":{}}" - ); - BOOST_CHECK(contract["metadata"].isString()); - BOOST_CHECK(dev::test::isValidMetadata(contract["metadata"].asString())); - BOOST_CHECK(result["sources"].isObject()); - BOOST_CHECK(result["sources"][""].isObject()); - BOOST_CHECK(result["sources"][""]["AST"].isObject()); - BOOST_CHECK_EQUAL( - dev::jsonCompactPrint(result["sources"][""]["AST"]), - "{\"attributes\":{\"absolutePath\":\"\",\"exportedSymbols\":{\"A\":[1]}}," - "\"children\":[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null]," - "\"contractKind\":\"contract\",\"documentation\":null,\"fullyImplemented\":true,\"linearizedBaseContracts\":[1]," - "\"name\":\"A\",\"nodes\":[null],\"scope\":2},\"id\":1,\"name\":\"ContractDefinition\"," - "\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}" - ); -} - BOOST_AUTO_TEST_CASE(standard_compilation) { char const* input = R"( @@ -201,26 +84,6 @@ BOOST_AUTO_TEST_CASE(standard_compilation) BOOST_CHECK(result.isMember("contracts")); } -BOOST_AUTO_TEST_CASE(new_api) -{ - char const* input = R"( - { - "language": "Solidity", - "sources": { - "fileA": { - "content": "contract A { }" - } - } - } - )"; - BOOST_CHECK_EQUAL(string(version()), string(solidity_version())); - BOOST_CHECK_EQUAL(string(license()), string(solidity_license())); - BOOST_CHECK_EQUAL( - string(compileStandard(input, nullptr)), - string(solidity_compile(input, nullptr)) - ); -} - BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/tools/fuzzer.cpp b/test/tools/fuzzer.cpp index bb020f8c..8633454c 100644 --- a/test/tools/fuzzer.cpp +++ b/test/tools/fuzzer.cpp @@ -89,7 +89,7 @@ void testConstantOptimizer(string const& input) void runCompiler(string input) { - string outputString(compileStandard(input.c_str(), nullptr)); + string outputString(solidity_compile(input.c_str(), nullptr)); Json::Value output; if (!jsonParseStrict(outputString, output)) { |