Merge branch 'develop' of https://github.com/ethereum/cpp-ethereum into develop

This commit is contained in:
winsvega 2015-02-11 14:12:18 +03:00
commit a44feb813e
5 changed files with 85 additions and 3 deletions

View File

@ -56,6 +56,36 @@ BOOST_AUTO_TEST_CASE(empty_contract)
BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()).empty());
}
BOOST_AUTO_TEST_CASE(exp_operator)
{
char const* sourceCode = R"(
contract test {
function f(uint a) returns(uint d) { return 2 ** a; }
})";
compileAndRun(sourceCode);
testSolidityAgainstCppOnRange("f(uint256)", [](u256 const& a) -> u256 { return u256(1 << a.convert_to<int>()); }, 0, 16);
}
BOOST_AUTO_TEST_CASE(exp_operator_const)
{
char const* sourceCode = R"(
contract test {
function f() returns(uint d) { return 2 ** 3; }
})";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(8)));
}
BOOST_AUTO_TEST_CASE(exp_operator_const_signed)
{
char const* sourceCode = R"(
contract test {
function f() returns(int d) { return (-2) ** 3; }
})";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(-8)));
}
BOOST_AUTO_TEST_CASE(recursive_calls)
{
char const* sourceCode = "contract test {\n"
@ -2201,6 +2231,29 @@ BOOST_AUTO_TEST_CASE(sha3_multiple_arguments_with_string_literals)
bytes({0x66, 0x6f, 0x6f}))));
}
BOOST_AUTO_TEST_CASE(generic_call)
{
char const* sourceCode = R"**(
contract receiver {
uint public received;
function receive(uint256 x) { received = x; }
}
contract sender {
function doSend(address rec) returns (uint d)
{
string4 signature = string4(string32(sha3("receive(uint256)")));
rec.call.value(2)(signature, 23);
return receiver(rec).received();
}
}
)**";
compileAndRun(sourceCode, 0, "receiver");
u160 const c_receiverAddress = m_contractAddress;
compileAndRun(sourceCode, 50, "sender");
BOOST_REQUIRE(callContractFunction("doSend(address)", c_receiverAddress) == encodeArgs(23));
BOOST_CHECK_EQUAL(m_state.balance(m_contractAddress), 50 - 2);
}
BOOST_AUTO_TEST_SUITE_END()
}

View File

@ -974,6 +974,24 @@ BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units)
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_CASE(exp_operator_negative_exponent)
{
char const* sourceCode = R"(
contract test {
function f() returns(uint d) { return 2 ** -3; }
})";
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big)
{
char const* sourceCode = R"(
contract test {
function f() returns(uint d) { return 2 ** 10000000000; }
})";
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_SUITE_END()
}

View File

@ -387,6 +387,17 @@ BOOST_AUTO_TEST_CASE(complex_expression)
BOOST_CHECK_NO_THROW(parseText(text));
}
BOOST_AUTO_TEST_CASE(exp_expression)
{
char const* text = R"(
contract test {
function fun(uint256 a) {
uint256 x = 3 ** a;
}
})";
BOOST_CHECK_NO_THROW(parseText(text));
}
BOOST_AUTO_TEST_CASE(while_loop)
{
char const* text = "contract test {\n"

View File

@ -64,6 +64,9 @@ void connectClients(Client& c1, Client& c2)
namespace test
{
struct ValueTooLarge: virtual Exception {};
bigint const c_max256plus1 = bigint(1) << 256;
ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o)
{
importEnv(_o["env"].get_obj());

View File

@ -42,9 +42,6 @@ void connectClients(Client& c1, Client& c2);
namespace test
{
struct ValueTooLarge: virtual Exception {};
bigint const c_max256plus1 = bigint(1) << 256;
class ImportTest
{
public: