diff options
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 68 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 41 | ||||
-rw-r--r-- | test/libsolidity/SolidityOptimizer.cpp | 16 |
3 files changed, 105 insertions, 20 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 700201aa..20fef48d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2484,6 +2484,41 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data_from_storage) BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(uint256,bytes,uint256)"))); } +BOOST_AUTO_TEST_CASE(event_indexed_string) +{ + char const* sourceCode = R"( + contract C { + string x; + uint[4] y; + event E(string indexed r, uint[4] indexed t); + function deposit() { + bytes(x).length = 90; + for (uint i = 0; i < 90; i++) + bytes(x)[i] = byte(i); + y[0] = 4; + y[1] = 5; + y[2] = 6; + y[3] = 7; + E(x, y); + } + } + )"; + compileAndRun(sourceCode); + callContractFunction("deposit()"); + BOOST_REQUIRE_EQUAL(m_logs.size(), 1); + BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); + string dynx(90, 0); + for (size_t i = 0; i < dynx.size(); ++i) + dynx[i] = i; + BOOST_CHECK(m_logs[0].data == bytes()); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 3); + BOOST_CHECK_EQUAL(m_logs[0].topics[1], dev::sha3(dynx)); + BOOST_CHECK_EQUAL(m_logs[0].topics[2], dev::sha3( + encodeArgs(u256(4), u256(5), u256(6), u256(7)) + )); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("E(string,uint256[4])"))); +} + BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) { char const* sourceCode = R"( @@ -5781,6 +5816,39 @@ BOOST_AUTO_TEST_CASE(lone_struct_array_type) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(3))); } +BOOST_AUTO_TEST_CASE(memory_overwrite) +{ + char const* sourceCode = R"( + contract C { + function f() returns (bytes x) { + x = "12345"; + x[3] = 0x61; + x[0] = 0x62; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("f()") == encodeDyn(string("b23a5"))); +} + +BOOST_AUTO_TEST_CASE(addmod_mulmod) +{ + char const* sourceCode = R"( + contract C { + function test() returns (uint) { + // Note that this only works because computation on literals is done using + // unbounded integers. + if ((2**255 + 2**255) % 7 != addmod(2**255, 2**255, 7)) + return 1; + if ((2**255 + 2**255) % 7 != addmod(2**255, 2**255, 7)) + return 2; + return 0; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(0))); +} BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 6b36f4cc..e87e47a8 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -62,35 +62,38 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false) solAssert(Error::containsOnlyWarnings(errors), ""); resolver.registerDeclarations(*sourceUnit); + bool success = true; for (ASTPointer<ASTNode> const& node: sourceUnit->nodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) { globalContext->setCurrentContract(*contract); resolver.updateDeclaration(*globalContext->currentThis()); resolver.updateDeclaration(*globalContext->currentSuper()); - resolver.resolveNamesAndTypes(*contract); + if (!resolver.resolveNamesAndTypes(*contract)) + success = false; } - for (ASTPointer<ASTNode> const& node: sourceUnit->nodes()) - if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) - { - globalContext->setCurrentContract(*contract); - resolver.updateDeclaration(*globalContext->currentThis()); + if (success) + for (ASTPointer<ASTNode> const& node: sourceUnit->nodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + globalContext->setCurrentContract(*contract); + resolver.updateDeclaration(*globalContext->currentThis()); - TypeChecker typeChecker(errors); - bool success = typeChecker.checkTypeRequirements(*contract); - BOOST_CHECK(success || !errors.empty()); + TypeChecker typeChecker(errors); + bool success = typeChecker.checkTypeRequirements(*contract); + BOOST_CHECK(success || !errors.empty()); - for (auto const& currentError: errors) - { - if ( - (_reportWarnings && currentError->type() == Error::Type::Warning) || - (!_reportWarnings && currentError->type() != Error::Type::Warning) - ) - return make_pair(sourceUnit, std::make_shared<Error::Type const>(currentError->type())); } - } + for (auto const& currentError: errors) + { + if ( + (_reportWarnings && currentError->type() == Error::Type::Warning) || + (!_reportWarnings && currentError->type() != Error::Type::Warning) + ) + return make_pair(sourceUnit, std::make_shared<Error::Type const>(currentError->type())); + } } - catch(Error const& _e) + catch (Error const& _e) { return make_pair(sourceUnit, std::make_shared<Error::Type const>(_e.type())); } @@ -133,7 +136,7 @@ static ContractDefinition const* retrieveContract(ASTPointer<SourceUnit> _source return nullptr; } -static FunctionTypePointer const& retrieveFunctionBySignature( +static FunctionTypePointer retrieveFunctionBySignature( ContractDefinition const* _contract, std::string const& _signature ) diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index 20d59a04..732f599f 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -359,6 +359,16 @@ BOOST_AUTO_TEST_CASE(store_tags_as_unions) // BOOST_CHECK_EQUAL(2, numSHA3s); } +BOOST_AUTO_TEST_CASE(successor_not_found_bug) +{ + // This bug was caused because MSVC chose to use the u256->bool conversion + // instead of u256->unsigned + char const* sourceCode = R"( + contract greeter { function greeter() {} } + )"; + compileBothVersions(sourceCode); +} + BOOST_AUTO_TEST_CASE(cse_intermediate_swap) { eth::KnownState state; @@ -1113,7 +1123,11 @@ BOOST_AUTO_TEST_CASE(computing_constants) bytes complicatedConstant = toBigEndian(u256("0x817416927846239487123469187231298734162934871263941234127518276")); unsigned occurrences = 0; for (auto iter = optimizedBytecode.cbegin(); iter < optimizedBytecode.cend(); ++occurrences) - iter = search(iter, optimizedBytecode.cend(), complicatedConstant.cbegin(), complicatedConstant.cend()) + 1; + { + iter = search(iter, optimizedBytecode.cend(), complicatedConstant.cbegin(), complicatedConstant.cend()); + if (iter < optimizedBytecode.cend()) + ++iter; + } BOOST_CHECK_EQUAL(2, occurrences); bytes constantWithZeros = toBigEndian(u256("0x77abc0000000000000000000000000000000000000000000000000000000001")); |