mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'ethereum/develop' into sol_optimizer
Conflicts: libevmcore/Instruction.cpp
This commit is contained in:
commit
3fbe72cc47
@ -57,7 +57,6 @@ public:
|
||||
eth::State m_statePost;
|
||||
eth::ExtVMFace m_environment;
|
||||
eth::Transaction m_transaction;
|
||||
bytes code;
|
||||
|
||||
private:
|
||||
json_spirit::mObject& m_TestObject;
|
||||
|
@ -134,10 +134,10 @@ void doMyTests(json_spirit::mValue& v)
|
||||
o["pre"] = mValue(fev.exportState());
|
||||
|
||||
fev.importExec(o["exec"].get_obj());
|
||||
if (!fev.code)
|
||||
if (fev.code.empty())
|
||||
{
|
||||
fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
|
||||
fev.code = &fev.thisTxCode;
|
||||
fev.code = fev.thisTxCode;
|
||||
}
|
||||
|
||||
vm.reset(fev.gas);
|
||||
|
@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers)
|
||||
byte(Instruction::JUMPDEST), // beginning of g
|
||||
byte(Instruction::PUSH1), 0x0,
|
||||
byte(Instruction::DUP1), // initialized e and h
|
||||
byte(Instruction::PUSH1), 0x29 + shift, // ret address
|
||||
byte(Instruction::PUSH1), byte(0x29 + shift), // ret address
|
||||
byte(Instruction::PUSH1), 0x1, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||
byte(Instruction::PUSH1), 0x2, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||
byte(Instruction::PUSH1), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||
|
@ -60,6 +60,16 @@ public:
|
||||
return callFunction(_index, toBigEndian(_argument1));
|
||||
}
|
||||
|
||||
bool testSolidityAgainstCpp(byte _index, std::function<u256(u256)> const& _cppfun, u256 const& _argument1)
|
||||
{
|
||||
return toBigEndian(_cppfun(_argument1)) == callFunction(_index, toBigEndian(_argument1));
|
||||
}
|
||||
|
||||
bool testSolidityAgainstCpp(byte _index, std::function<u256()> const& _cppfun)
|
||||
{
|
||||
return toBigEndian(_cppfun()) == callFunction(_index, bytes());
|
||||
}
|
||||
|
||||
private:
|
||||
void sendMessage(bytes const& _data, bool _isCreation)
|
||||
{
|
||||
@ -123,11 +133,19 @@ BOOST_AUTO_TEST_CASE(recursive_calls)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, u256(0)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callFunction(0, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callFunction(0, u256(2)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(callFunction(0, u256(3)) == toBigEndian(u256(6)));
|
||||
BOOST_CHECK(callFunction(0, u256(4)) == toBigEndian(u256(24)));
|
||||
std::function<u256(u256)> recursive_calls_cpp = [&recursive_calls_cpp](u256 const& n) -> u256
|
||||
{
|
||||
if (n <= 1)
|
||||
return 1;
|
||||
else
|
||||
return n * recursive_calls_cpp(n - 1);
|
||||
};
|
||||
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, recursive_calls_cpp, u256(0)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, recursive_calls_cpp, u256(1)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, recursive_calls_cpp, u256(2)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, recursive_calls_cpp, u256(3)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, recursive_calls_cpp, u256(4)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(while_loop)
|
||||
@ -140,11 +158,22 @@ BOOST_AUTO_TEST_CASE(while_loop)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, u256(0)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callFunction(0, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callFunction(0, u256(2)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(callFunction(0, u256(3)) == toBigEndian(u256(6)));
|
||||
BOOST_CHECK(callFunction(0, u256(4)) == toBigEndian(u256(24)));
|
||||
|
||||
auto while_loop_cpp = [](u256 const& n) -> u256
|
||||
{
|
||||
u256 nfac = 1;
|
||||
u256 i = 2;
|
||||
while (i <= n)
|
||||
nfac *= i++;
|
||||
|
||||
return nfac;
|
||||
};
|
||||
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, while_loop_cpp, u256(0)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, while_loop_cpp, u256(1)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, while_loop_cpp, u256(2)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, while_loop_cpp, u256(3)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, while_loop_cpp, u256(4)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(break_outside_loop)
|
||||
@ -182,18 +211,43 @@ BOOST_AUTO_TEST_CASE(nested_loops)
|
||||
"}\n";
|
||||
ExecutionFramework framework;
|
||||
framework.compileAndRun(sourceCode);
|
||||
BOOST_CHECK(framework.callFunction(0, u256(0)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(2)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(3)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(4)) == toBigEndian(u256(2)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(5)) == toBigEndian(u256(4)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(6)) == toBigEndian(u256(5)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(7)) == toBigEndian(u256(5)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(8)) == toBigEndian(u256(7)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(9)) == toBigEndian(u256(8)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(10)) == toBigEndian(u256(10)));
|
||||
BOOST_CHECK(framework.callFunction(0, u256(11)) == toBigEndian(u256(10)));
|
||||
|
||||
auto nested_loops_cpp = [](u256 n) -> u256
|
||||
{
|
||||
while (n > 1)
|
||||
{
|
||||
if (n == 10)
|
||||
break;
|
||||
while (n > 5)
|
||||
{
|
||||
if (n == 8)
|
||||
break;
|
||||
n--;
|
||||
if (n == 6)
|
||||
continue;
|
||||
return n;
|
||||
}
|
||||
n--;
|
||||
if (n == 3)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
};
|
||||
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(0)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(1)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(2)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(3)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(4)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(5)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(6)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(7)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(8)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(9)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(10)));
|
||||
BOOST_CHECK(framework.testSolidityAgainstCpp(0, nested_loops_cpp, u256(11)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(calling_other_functions)
|
||||
@ -214,11 +268,34 @@ BOOST_AUTO_TEST_CASE(calling_other_functions)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(2, u256(0)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(callFunction(2, u256(1)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callFunction(2, u256(2)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callFunction(2, u256(8)) == toBigEndian(u256(1)));
|
||||
BOOST_CHECK(callFunction(2, u256(127)) == toBigEndian(u256(1)));
|
||||
|
||||
auto evenStep_cpp = [](u256 const& n) -> u256
|
||||
{
|
||||
return n / 2;
|
||||
};
|
||||
|
||||
auto oddStep_cpp = [](u256 const& n) -> u256
|
||||
{
|
||||
return 3 * n + 1;
|
||||
};
|
||||
|
||||
auto collatz_cpp = [&evenStep_cpp, &oddStep_cpp] (u256 n) -> u256 {
|
||||
u256 y;
|
||||
while ((y = n) > 1)
|
||||
{
|
||||
if (n % 2 == 0)
|
||||
n = evenStep_cpp(n);
|
||||
else
|
||||
n = oddStep_cpp(n);
|
||||
}
|
||||
return y;
|
||||
};
|
||||
|
||||
BOOST_CHECK(testSolidityAgainstCpp(2, collatz_cpp, u256(0)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(2, collatz_cpp, u256(1)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(2, collatz_cpp, u256(2)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(2, collatz_cpp, u256(8)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(2, collatz_cpp, u256(127)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(many_local_variables)
|
||||
@ -270,8 +347,15 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, u256(0)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(callFunction(0, u256(1)) == toBigEndian(u256(8)));
|
||||
|
||||
auto short_circuiting_cpp = [](u256 n) -> u256
|
||||
{
|
||||
n == 0 || (n = 8) > 0;
|
||||
return n;
|
||||
};
|
||||
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, short_circuiting_cpp, u256(0)));
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, short_circuiting_cpp, u256(1)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(high_bits_cleaning)
|
||||
@ -284,7 +368,14 @@ BOOST_AUTO_TEST_CASE(high_bits_cleaning)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, bytes()) == toBigEndian(u256(9)));
|
||||
auto high_bits_cleaning_cpp = []() -> u256
|
||||
{
|
||||
uint32_t x = uint32_t(0xffffffff) + 10;
|
||||
if (x >= 0xffffffff)
|
||||
return 0;
|
||||
return x;
|
||||
};
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, high_bits_cleaning_cpp));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(sign_extension)
|
||||
@ -297,7 +388,14 @@ BOOST_AUTO_TEST_CASE(sign_extension)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, bytes()) == toBigEndian(u256(0xff)));
|
||||
auto sign_extension_cpp = []() -> u256
|
||||
{
|
||||
int64_t x = -int32_t(0xff);
|
||||
if (x >= 0xff)
|
||||
return 0;
|
||||
return u256(x) * -1;
|
||||
};
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, sign_extension_cpp));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(small_unsigned_types)
|
||||
@ -309,7 +407,12 @@ BOOST_AUTO_TEST_CASE(small_unsigned_types)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, bytes()) == toBigEndian(u256(0xfe0000)));
|
||||
auto small_unsigned_types_cpp = []() -> u256
|
||||
{
|
||||
uint32_t x = uint32_t(0xffffff) * 0xffffff;
|
||||
return x / 0x100;
|
||||
};
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, small_unsigned_types_cpp));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(small_signed_types)
|
||||
@ -320,7 +423,36 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, bytes()) == toBigEndian(u256(200)));
|
||||
auto small_signed_types_cpp = []() -> u256
|
||||
{
|
||||
return -int32_t(10) * -int64_t(20);
|
||||
};
|
||||
BOOST_CHECK(testSolidityAgainstCpp(0, small_signed_types_cpp));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(state_smoke_test)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" uint256 value1;\n"
|
||||
" uint256 value2;\n"
|
||||
" function get(uint8 which) returns (uint256 value) {\n"
|
||||
" if (which == 0) return value1;\n"
|
||||
" else return value2;\n"
|
||||
" }\n"
|
||||
" function set(uint8 which, uint256 value) {\n"
|
||||
" if (which == 0) value1 = value;\n"
|
||||
" else value2 = value;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(callFunction(0, bytes(1, 0x01)) == toBigEndian(u256(0)));
|
||||
BOOST_CHECK(callFunction(1, bytes(1, 0x00) + toBigEndian(u256(0x1234))) == bytes());
|
||||
BOOST_CHECK(callFunction(1, bytes(1, 0x01) + toBigEndian(u256(0x8765))) == bytes());
|
||||
BOOST_CHECK(callFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0x1234)));
|
||||
BOOST_CHECK(callFunction(0, bytes(1, 0x01)) == toBigEndian(u256(0x8765)));
|
||||
BOOST_CHECK(callFunction(1, bytes(1, 0x00) + toBigEndian(u256(0x3))) == bytes());
|
||||
BOOST_CHECK(callFunction(0, bytes(1, 0x00)) == toBigEndian(u256(0x3)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -154,10 +154,10 @@ BOOST_AUTO_TEST_CASE(comparison)
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation({byte(eth::Instruction::PUSH2), 0x10, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND),
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
||||
byte(eth::Instruction::PUSH2), 0x11, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::GT),
|
||||
byte(eth::Instruction::PUSH1), 0x1,
|
||||
byte(eth::Instruction::PUSH2), 0x10, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::LT),
|
||||
byte(eth::Instruction::EQ),
|
||||
byte(eth::Instruction::ISZERO)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(comparison)
|
||||
BOOST_AUTO_TEST_CASE(short_circuiting)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f() { var x = (10 + 8 >= 4 || 2 != 9) != true; }"
|
||||
" function f() { var x = true != (4 <= 8 + 10 || 9 != 2); }"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
|
||||
BOOST_AUTO_TEST_CASE(arithmetics)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f() { var x = (1 * (2 / (3 % (4 + (5 - (6 | (7 & (8 ^ 9)))))))); }"
|
||||
" function f() { var x = ((((((((9 ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
||||
@ -211,14 +211,11 @@ BOOST_AUTO_TEST_CASE(arithmetics)
|
||||
byte(eth::Instruction::XOR),
|
||||
byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::OR),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::SUB),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::MOD),
|
||||
byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::DIV),
|
||||
byte(eth::Instruction::MUL)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
@ -231,11 +228,11 @@ BOOST_AUTO_TEST_CASE(unary_operators)
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x1,
|
||||
byte(eth::Instruction::PUSH1), 0x0,
|
||||
byte(eth::Instruction::SUB),
|
||||
byte(eth::Instruction::NOT), byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::EQ),
|
||||
byte(eth::Instruction::ISZERO)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
@ -244,7 +241,7 @@ BOOST_AUTO_TEST_CASE(unary_operators)
|
||||
BOOST_AUTO_TEST_CASE(unary_inc_dec)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function f(uint a) { var x = ((a++ ^ ++a) ^ a--) ^ --a; }"
|
||||
" function f(uint a) { var x = --a ^ (a-- ^ (++a ^ a++)); }"
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
|
||||
|
||||
@ -299,16 +296,15 @@ BOOST_AUTO_TEST_CASE(assignment)
|
||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}});
|
||||
|
||||
// Stack: a, b
|
||||
bytes expectation({byte(eth::Instruction::DUP1),
|
||||
byte(eth::Instruction::DUP3),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b a+b
|
||||
byte(eth::Instruction::SWAP2),
|
||||
byte(eth::Instruction::POP),
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::DUP2),
|
||||
// Stack here: a+b b a+b
|
||||
byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::DUP4),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b 2 a+b
|
||||
byte(eth::Instruction::SWAP3),
|
||||
byte(eth::Instruction::POP),
|
||||
byte(eth::Instruction::DUP3),
|
||||
// Stack here: a+b b 2 a+b
|
||||
byte(eth::Instruction::MUL)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
@ -323,21 +319,20 @@ BOOST_AUTO_TEST_CASE(function_call)
|
||||
{{"test", "f", "a"}, {"test", "f", "b"}});
|
||||
|
||||
// Stack: a, b
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x0d,
|
||||
byte(eth::Instruction::DUP3),
|
||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x02, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::PUSH1), 0x12,
|
||||
byte(eth::Instruction::PUSH1), 0x01, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
byte(eth::Instruction::DUP5),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b <ret label> (a+1)
|
||||
byte(eth::Instruction::DUP3),
|
||||
byte(eth::Instruction::PUSH1), 0x1a,
|
||||
// Stack here: a b 2 <ret label> (a+1)
|
||||
byte(eth::Instruction::DUP4),
|
||||
byte(eth::Instruction::PUSH1), 0x19,
|
||||
byte(eth::Instruction::JUMP),
|
||||
byte(eth::Instruction::JUMPDEST),
|
||||
// Stack here: a b g(a+1, b)
|
||||
byte(eth::Instruction::PUSH1), 0x02, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND),
|
||||
// Stack here: a b 2 g(a+1, b)
|
||||
byte(eth::Instruction::MUL),
|
||||
// Stack here: a b g(a+1, b)*2
|
||||
byte(eth::Instruction::DUP3),
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::ADD),
|
||||
// Stack here: a b a+g(a+1, b)*2
|
||||
byte(eth::Instruction::SWAP2),
|
||||
@ -355,15 +350,15 @@ BOOST_AUTO_TEST_CASE(negative_literals_8bits)
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation(bytes({byte(eth::Instruction::PUSH1), 0x00,
|
||||
byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x81) +
|
||||
bytes({byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80) +
|
||||
bytes({byte(eth::Instruction::ADD)}));
|
||||
bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x81) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::PUSH1), 0x00,
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::ADD)}));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
|
||||
@ -376,11 +371,11 @@ BOOST_AUTO_TEST_CASE(negative_literals_16bits)
|
||||
"}\n";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x7f) +
|
||||
bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) +
|
||||
bytes({byte(eth::Instruction::PUSH1), 0x00,
|
||||
byte(eth::Instruction::SIGNEXTEND),
|
||||
byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x7f) +
|
||||
bytes({byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH1), 0x01,
|
||||
byte(eth::Instruction::SIGNEXTEND)}));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
|
14
state.cpp
14
state.cpp
@ -55,12 +55,6 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
|
||||
|
||||
ImportTest importer(o, _fillin);
|
||||
|
||||
if (_fillin)
|
||||
{
|
||||
importer.code = importer.m_statePre.code(importer.m_environment.myAddress);
|
||||
importer.m_environment.code = &importer.code;
|
||||
}
|
||||
|
||||
State theState = importer.m_statePre;
|
||||
bytes tx = importer.m_transaction.rlp();
|
||||
bytes output;
|
||||
@ -124,12 +118,4 @@ BOOST_AUTO_TEST_CASE(stSystemOperationsTest)
|
||||
dev::test::executeTests("stSystemOperationsTest", "/StateTests", dev::test::doStateTests);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(tmp)
|
||||
{
|
||||
int currentVerbosity = g_logVerbosity;
|
||||
g_logVerbosity = 12;
|
||||
dev::test::executeTests("tmp", "/StateTests", dev::test::doStateTests);
|
||||
g_logVerbosity = currentVerbosity;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -1,44 +0,0 @@
|
||||
{
|
||||
"ABAcalls0": {
|
||||
"env" : {
|
||||
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
|
||||
"currentNumber" : "0",
|
||||
"currentGasLimit" : "10000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "{ [[ (PC) ]] (CALL 1000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 24 0 0 0 0) }",
|
||||
"storage": {}
|
||||
},
|
||||
"945304eb96065b2a98b57a48a06ae28d285a71b5" : {
|
||||
"balance" : "23",
|
||||
"code" : " { [[ (PC) ]] (ADD 1 (CALL 500 0x095e7baea6a6c7c4c2dfeb977efac326af552d87 23 0 0 0 0)) } ",
|
||||
"nonce" : "0",
|
||||
"storage" : {
|
||||
}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "1000000000000000000",
|
||||
"nonce" : 0,
|
||||
"code" : "",
|
||||
"storage": {}
|
||||
}
|
||||
|
||||
},
|
||||
"transaction" : {
|
||||
"nonce" : "0",
|
||||
"gasPrice" : "1",
|
||||
"gasLimit" : "10000",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value" : "100000",
|
||||
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"data" : ""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
10
vm.cpp
10
vm.cpp
@ -29,7 +29,7 @@ using namespace dev::eth;
|
||||
using namespace dev::test;
|
||||
|
||||
FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix.
|
||||
ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytesConstRef(), _previousBlock, _currentBlock, _depth) {}
|
||||
ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, _depth) {}
|
||||
|
||||
h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&)
|
||||
{
|
||||
@ -195,11 +195,11 @@ void FakeExtVM::importExec(mObject& _o)
|
||||
gas = toInt(_o["gas"]);
|
||||
|
||||
thisTxCode.clear();
|
||||
code = &thisTxCode;
|
||||
code = thisTxCode;
|
||||
|
||||
thisTxCode = importCode(_o);
|
||||
if (_o["code"].type() != str_type && _o["code"].type() != array_type)
|
||||
code.reset();
|
||||
code.clear();
|
||||
|
||||
thisTxData.clear();
|
||||
thisTxData = importData(_o);
|
||||
@ -289,10 +289,10 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
||||
o["pre"] = mValue(fev.exportState());
|
||||
|
||||
fev.importExec(o["exec"].get_obj());
|
||||
if (!fev.code)
|
||||
if (fev.code.empty())
|
||||
{
|
||||
fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
|
||||
fev.code = &fev.thisTxCode;
|
||||
fev.code = fev.thisTxCode;
|
||||
}
|
||||
|
||||
bytes output;
|
||||
|
Loading…
Reference in New Issue
Block a user