Browse Source

removed exception when function is not found

cl-refactor
Liana Husikyan 10 years ago
parent
commit
0d55798adf
  1. 2
      libsolidity/Compiler.cpp
  2. 18
      libsolidity/ExpressionCompiler.cpp
  3. 6
      libsolidity/ExpressionCompiler.h
  4. 32
      test/libsolidity/SolidityEndToEndTest.cpp

2
libsolidity/Compiler.cpp

@ -193,7 +193,7 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract)
appendReturnValuePacker(FunctionType(*fallback).getReturnParameterTypes()); appendReturnValuePacker(FunctionType(*fallback).getReturnParameterTypes());
} }
else else
m_context.appendConditionalJumpTo(m_context.errorTag()); // function not found m_context << eth::Instruction::STOP; // function not found
for (auto const& it: interfaceFunctions) for (auto const& it: interfaceFunctions)
{ {
FunctionTypePointer const& functionType = it.second; FunctionTypePointer const& functionType = it.second;

18
libsolidity/ExpressionCompiler.cpp

@ -534,8 +534,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
true, true,
true true
), ),
{}, {}
true
); );
break; break;
case Location::Suicide: case Location::Suicide:
@ -1035,8 +1034,8 @@ void ExpressionCompiler::appendHighBitsCleanup(IntegerType const& _typeOnStack)
void ExpressionCompiler::appendExternalFunctionCall( void ExpressionCompiler::appendExternalFunctionCall(
FunctionType const& _functionType, FunctionType const& _functionType,
vector<ASTPointer<Expression const>> const& _arguments, vector<ASTPointer<Expression const>> const& _arguments
bool isSend) )
{ {
solAssert(_functionType.takesArbitraryParameters() || solAssert(_functionType.takesArbitraryParameters() ||
_arguments.size() == _functionType.getParameterTypes().size(), ""); _arguments.size() == _functionType.getParameterTypes().size(), "");
@ -1106,15 +1105,8 @@ void ExpressionCompiler::appendExternalFunctionCall(
m_context << eth::Instruction::CALL; m_context << eth::Instruction::CALL;
//Propagate error condition (if CALL pushes 0 on stack). //Propagate error condition (if CALL pushes 0 on stack).
if (!isSend) auto tag = m_context.appendConditionalJump();
{ m_context << eth::Instruction::STOP << tag; // STOP if CALL leaves 0.// }
m_context << eth::Instruction::ISZERO;
m_context.appendConditionalJumpTo(m_context.errorTag());
} else
{
auto tag = m_context.appendConditionalJump();
m_context << eth::Instruction::STOP << tag;
}
if (_functionType.valueSet()) if (_functionType.valueSet())
m_context << eth::Instruction::POP; m_context << eth::Instruction::POP;

6
libsolidity/ExpressionCompiler.h

@ -98,11 +98,7 @@ private:
void appendHighBitsCleanup(IntegerType const& _typeOnStack); void appendHighBitsCleanup(IntegerType const& _typeOnStack);
/// Appends code to call a function of the given type with the given arguments. /// Appends code to call a function of the given type with the given arguments.
void appendExternalFunctionCall( void appendExternalFunctionCall(FunctionType const& _functionType, std::vector<ASTPointer<Expression const>> const& _arguments);
FunctionType const& _functionType,
std::vector<ASTPointer<Expression const>> const& _arguments,
bool isSend = false
);
/// Appends code that evaluates the given arguments and moves the result to memory encoded as /// Appends code that evaluates the given arguments and moves the result to memory encoded as
/// specified by the ABI. The memory offset is expected to be on the stack and is updated by /// specified by the ABI. The memory offset is expected to be on the stack and is updated by
/// this call. If @a _padToWordBoundaries is set to false, all values are concatenated without /// this call. If @a _padToWordBoundaries is set to false, all values are concatenated without

32
test/libsolidity/SolidityEndToEndTest.cpp

@ -4080,7 +4080,6 @@ BOOST_AUTO_TEST_CASE(struct_delete_member)
} }
)"; )";
compileAndRun(sourceCode, 0, "test"); compileAndRun(sourceCode, 0, "test");
auto res = callContractFunction("deleteMember()");
BOOST_CHECK(callContractFunction("deleteMember()") == encodeArgs(0)); BOOST_CHECK(callContractFunction("deleteMember()") == encodeArgs(0));
} }
@ -4106,7 +4105,6 @@ BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping)
} }
)"; )";
compileAndRun(sourceCode, 0, "test"); compileAndRun(sourceCode, 0, "test");
auto res = callContractFunction("deleteIt()");
BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0));
} }
@ -4134,32 +4132,6 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_out_of_band_access)
BOOST_CHECK(callContractFunction("test()") == encodeArgs(false)); BOOST_CHECK(callContractFunction("test()") == encodeArgs(false));
} }
BOOST_AUTO_TEST_CASE(evm_exceptions_when_calling_non_existing_function)
{
char const* sourceCode = R"(
contract A {
uint public test = 0;
function badFunction() returns (uint)
{
this.call("123");
test = 1;
return 2;
}
function testIt() returns (bool)
{
this.badFunction();
test = 2;
return true;
}
}
)";
compileAndRun(sourceCode, 0, "A");
BOOST_CHECK(callContractFunction("test()") == encodeArgs(0));
BOOST_CHECK(callContractFunction("testIt()") == encodeArgs());
BOOST_CHECK(callContractFunction("test()") == encodeArgs(0));
}
BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail) BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
@ -4184,7 +4156,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_call_fail)
BOOST_CHECK(callContractFunction("test()") == encodeArgs(2)); BOOST_CHECK(callContractFunction("test()") == encodeArgs(2));
} }
BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band) BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
contract A { contract A {
@ -4199,7 +4171,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_band)
)"; )";
compileAndRun(sourceCode, 0, "A"); compileAndRun(sourceCode, 0, "A");
BOOST_CHECK(callContractFunction("test()") == encodeArgs(1)); //BOOST_CHECK(m_output.empty()); todo
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save