mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
enable solidity test
This commit is contained in:
parent
858c41260d
commit
9816510065
@ -31,7 +31,7 @@ add_subdirectory(libsolidity)
|
|||||||
add_subdirectory(solc)
|
add_subdirectory(solc)
|
||||||
if (NOT EMSCRIPTEN)
|
if (NOT EMSCRIPTEN)
|
||||||
add_subdirectory(liblll)
|
add_subdirectory(liblll)
|
||||||
#add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
add_subdirectory(lllc)
|
add_subdirectory(lllc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -69,10 +69,10 @@ public:
|
|||||||
void appendProgramSize() { append(AssemblyItem(PushProgramSize)); }
|
void appendProgramSize() { append(AssemblyItem(PushProgramSize)); }
|
||||||
void appendLibraryAddress(std::string const& _identifier) { append(newPushLibraryAddress(_identifier)); }
|
void appendLibraryAddress(std::string const& _identifier) { append(newPushLibraryAddress(_identifier)); }
|
||||||
|
|
||||||
AssemblyItem appendJump() { auto ret = append(newPushTag()); append(Instruction::JUMP); return ret; }
|
AssemblyItem appendJump() { auto ret = append(newPushTag()); append(solidity::Instruction::JUMP); return ret; }
|
||||||
AssemblyItem appendJumpI() { auto ret = append(newPushTag()); append(Instruction::JUMPI); return ret; }
|
AssemblyItem appendJumpI() { auto ret = append(newPushTag()); append(solidity::Instruction::JUMPI); return ret; }
|
||||||
AssemblyItem appendJump(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(Instruction::JUMP); return ret; }
|
AssemblyItem appendJump(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(solidity::Instruction::JUMP); return ret; }
|
||||||
AssemblyItem appendJumpI(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(Instruction::JUMPI); return ret; }
|
AssemblyItem appendJumpI(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(solidity::Instruction::JUMPI); return ret; }
|
||||||
AssemblyItem errorTag() { return AssemblyItem(PushTag, 0); }
|
AssemblyItem errorTag() { return AssemblyItem(PushTag, 0); }
|
||||||
|
|
||||||
template <class T> Assembly& operator<<(T const& _d) { append(_d); return *this; }
|
template <class T> Assembly& operator<<(T const& _d) { append(_d); return *this; }
|
||||||
@ -86,7 +86,7 @@ public:
|
|||||||
void ignored() { m_baseDeposit = m_deposit; }
|
void ignored() { m_baseDeposit = m_deposit; }
|
||||||
void endIgnored() { m_deposit = m_baseDeposit; m_baseDeposit = 0; }
|
void endIgnored() { m_deposit = m_baseDeposit; m_baseDeposit = 0; }
|
||||||
|
|
||||||
void popTo(int _deposit) { while (m_deposit > _deposit) append(Instruction::POP); }
|
void popTo(int _deposit) { while (m_deposit > _deposit) append(solidity::Instruction::POP); }
|
||||||
|
|
||||||
void injectStart(AssemblyItem const& _i);
|
void injectStart(AssemblyItem const& _i);
|
||||||
std::string out() const;
|
std::string out() const;
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
|
|
||||||
AssemblyItem(u256 _push, SourceLocation const& _location = SourceLocation()):
|
AssemblyItem(u256 _push, SourceLocation const& _location = SourceLocation()):
|
||||||
AssemblyItem(Push, _push, _location) { }
|
AssemblyItem(Push, _push, _location) { }
|
||||||
AssemblyItem(Instruction _i, SourceLocation const& _location = SourceLocation()):
|
AssemblyItem(solidity::Instruction _i, SourceLocation const& _location = SourceLocation()):
|
||||||
AssemblyItem(Operation, byte(_i), _location) { }
|
AssemblyItem(Operation, byte(_i), _location) { }
|
||||||
AssemblyItem(AssemblyItemType _type, u256 _data = 0, SourceLocation const& _location = SourceLocation()):
|
AssemblyItem(AssemblyItemType _type, u256 _data = 0, SourceLocation const& _location = SourceLocation()):
|
||||||
m_type(_type),
|
m_type(_type),
|
||||||
|
@ -66,7 +66,7 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
|
|||||||
{
|
{
|
||||||
// increment source pointer to point to data
|
// increment source pointer to point to data
|
||||||
m_context << solidity::Instruction::SWAP1 << u256(0x20);
|
m_context << solidity::Instruction::SWAP1 << u256(0x20);
|
||||||
m_context << solidity::Instruction::ADD << solidity::Instruction::SWAP1;
|
m_context << solidity::Instruction::ADD << Instruction::SWAP1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack: target_ref source_ref source_length
|
// stack: target_ref source_ref source_length
|
||||||
|
@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(literal_true)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1});
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x1});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(literal_false)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x0});
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x0});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ BOOST_AUTO_TEST_CASE(int_literal)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH10), 0x12, 0x34, 0x56, 0x78, 0x90,
|
bytes expectation({byte(solidity::Instruction::PUSH10), 0x12, 0x34, 0x56, 0x78, 0x90,
|
||||||
0x12, 0x34, 0x56, 0x78, 0x90});
|
0x12, 0x34, 0x56, 0x78, 0x90});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination)
|
|||||||
})";
|
})";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1});
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x1});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination)
|
|||||||
})";
|
})";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00});
|
bytes expectation({byte(solidity::Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(int_with_finney_ether_subdenomination)
|
|||||||
})";
|
})";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH7), 0x3, 0x8d, 0x7e, 0xa4, 0xc6, 0x80, 0x00});
|
bytes expectation({byte(solidity::Instruction::PUSH7), 0x3, 0x8d, 0x7e, 0xa4, 0xc6, 0x80, 0x00});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination)
|
|||||||
})";
|
})";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH8), 0xd, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x00});
|
bytes expectation({byte(solidity::Instruction::PUSH8), 0xd, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x00});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,12 +268,12 @@ BOOST_AUTO_TEST_CASE(comparison)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x1,
|
||||||
byte(eth::Instruction::PUSH2), 0x11, 0xaa,
|
byte(solidity::Instruction::PUSH2), 0x11, 0xaa,
|
||||||
byte(eth::Instruction::PUSH2), 0x10, 0xaa,
|
byte(solidity::Instruction::PUSH2), 0x10, 0xaa,
|
||||||
byte(eth::Instruction::LT),
|
byte(solidity::Instruction::LT),
|
||||||
byte(eth::Instruction::EQ),
|
byte(solidity::Instruction::EQ),
|
||||||
byte(eth::Instruction::ISZERO)});
|
byte(solidity::Instruction::ISZERO)});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,22 +284,22 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x12, // 8 + 10
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x12, // 8 + 10
|
||||||
byte(eth::Instruction::PUSH1), 0x4,
|
byte(solidity::Instruction::PUSH1), 0x4,
|
||||||
byte(eth::Instruction::GT),
|
byte(solidity::Instruction::GT),
|
||||||
byte(eth::Instruction::ISZERO), // after this we have 4 <= 8 + 10
|
byte(solidity::Instruction::ISZERO), // after this we have 4 <= 8 + 10
|
||||||
byte(eth::Instruction::DUP1),
|
byte(solidity::Instruction::DUP1),
|
||||||
byte(eth::Instruction::PUSH1), 0x11,
|
byte(solidity::Instruction::PUSH1), 0x11,
|
||||||
byte(eth::Instruction::JUMPI), // short-circuit if it is true
|
byte(solidity::Instruction::JUMPI), // short-circuit if it is true
|
||||||
byte(eth::Instruction::POP),
|
byte(solidity::Instruction::POP),
|
||||||
byte(eth::Instruction::PUSH1), 0x2,
|
byte(solidity::Instruction::PUSH1), 0x2,
|
||||||
byte(eth::Instruction::PUSH1), 0x9,
|
byte(solidity::Instruction::PUSH1), 0x9,
|
||||||
byte(eth::Instruction::EQ),
|
byte(solidity::Instruction::EQ),
|
||||||
byte(eth::Instruction::ISZERO), // after this we have 9 != 2
|
byte(solidity::Instruction::ISZERO), // after this we have 9 != 2
|
||||||
byte(eth::Instruction::JUMPDEST),
|
byte(solidity::Instruction::JUMPDEST),
|
||||||
byte(eth::Instruction::PUSH1), 0x1,
|
byte(solidity::Instruction::PUSH1), 0x1,
|
||||||
byte(eth::Instruction::EQ),
|
byte(solidity::Instruction::EQ),
|
||||||
byte(eth::Instruction::ISZERO)});
|
byte(solidity::Instruction::ISZERO)});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,23 +309,23 @@ BOOST_AUTO_TEST_CASE(arithmetics)
|
|||||||
" function f(uint y) { var x = ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }"
|
" function f(uint y) { var x = ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }"
|
||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
|
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x1,
|
||||||
byte(eth::Instruction::PUSH1), 0x2,
|
byte(solidity::Instruction::PUSH1), 0x2,
|
||||||
byte(eth::Instruction::PUSH1), 0x3,
|
byte(solidity::Instruction::PUSH1), 0x3,
|
||||||
byte(eth::Instruction::PUSH1), 0x4,
|
byte(solidity::Instruction::PUSH1), 0x4,
|
||||||
byte(eth::Instruction::PUSH1), 0x5,
|
byte(solidity::Instruction::PUSH1), 0x5,
|
||||||
byte(eth::Instruction::PUSH1), 0x6,
|
byte(solidity::Instruction::PUSH1), 0x6,
|
||||||
byte(eth::Instruction::PUSH1), 0x7,
|
byte(solidity::Instruction::PUSH1), 0x7,
|
||||||
byte(eth::Instruction::PUSH1), 0x8,
|
byte(solidity::Instruction::PUSH1), 0x8,
|
||||||
byte(eth::Instruction::DUP10),
|
byte(solidity::Instruction::DUP10),
|
||||||
byte(eth::Instruction::XOR),
|
byte(solidity::Instruction::XOR),
|
||||||
byte(eth::Instruction::AND),
|
byte(solidity::Instruction::AND),
|
||||||
byte(eth::Instruction::OR),
|
byte(solidity::Instruction::OR),
|
||||||
byte(eth::Instruction::SUB),
|
byte(solidity::Instruction::SUB),
|
||||||
byte(eth::Instruction::ADD),
|
byte(solidity::Instruction::ADD),
|
||||||
byte(eth::Instruction::MOD),
|
byte(solidity::Instruction::MOD),
|
||||||
byte(eth::Instruction::DIV),
|
byte(solidity::Instruction::DIV),
|
||||||
byte(eth::Instruction::MUL)});
|
byte(solidity::Instruction::MUL)});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,13 +336,13 @@ BOOST_AUTO_TEST_CASE(unary_operators)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
|
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x2,
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x2,
|
||||||
byte(eth::Instruction::DUP3),
|
byte(solidity::Instruction::DUP3),
|
||||||
byte(eth::Instruction::PUSH1), 0x0,
|
byte(solidity::Instruction::PUSH1), 0x0,
|
||||||
byte(eth::Instruction::SUB),
|
byte(solidity::Instruction::SUB),
|
||||||
byte(eth::Instruction::NOT),
|
byte(solidity::Instruction::NOT),
|
||||||
byte(eth::Instruction::EQ),
|
byte(solidity::Instruction::EQ),
|
||||||
byte(eth::Instruction::ISZERO)});
|
byte(solidity::Instruction::ISZERO)});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,44 +354,44 @@ BOOST_AUTO_TEST_CASE(unary_inc_dec)
|
|||||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
|
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
|
||||||
|
|
||||||
// Stack: a, x
|
// Stack: a, x
|
||||||
bytes expectation({byte(eth::Instruction::DUP2),
|
bytes expectation({byte(solidity::Instruction::DUP2),
|
||||||
byte(eth::Instruction::DUP1),
|
byte(solidity::Instruction::DUP1),
|
||||||
byte(eth::Instruction::PUSH1), 0x1,
|
byte(solidity::Instruction::PUSH1), 0x1,
|
||||||
byte(eth::Instruction::ADD),
|
byte(solidity::Instruction::ADD),
|
||||||
// Stack here: a x a (a+1)
|
// Stack here: a x a (a+1)
|
||||||
byte(eth::Instruction::SWAP3),
|
byte(solidity::Instruction::SWAP3),
|
||||||
byte(eth::Instruction::POP), // first ++
|
byte(solidity::Instruction::POP), // first ++
|
||||||
// Stack here: (a+1) x a
|
// Stack here: (a+1) x a
|
||||||
byte(eth::Instruction::DUP3),
|
byte(solidity::Instruction::DUP3),
|
||||||
byte(eth::Instruction::PUSH1), 0x1,
|
byte(solidity::Instruction::PUSH1), 0x1,
|
||||||
byte(eth::Instruction::ADD),
|
byte(solidity::Instruction::ADD),
|
||||||
// Stack here: (a+1) x a (a+2)
|
// Stack here: (a+1) x a (a+2)
|
||||||
byte(eth::Instruction::SWAP3),
|
byte(solidity::Instruction::SWAP3),
|
||||||
byte(eth::Instruction::POP),
|
byte(solidity::Instruction::POP),
|
||||||
// Stack here: (a+2) x a
|
// Stack here: (a+2) x a
|
||||||
byte(eth::Instruction::DUP3), // second ++
|
byte(solidity::Instruction::DUP3), // second ++
|
||||||
byte(eth::Instruction::XOR),
|
byte(solidity::Instruction::XOR),
|
||||||
// Stack here: (a+2) x a^(a+2)
|
// Stack here: (a+2) x a^(a+2)
|
||||||
byte(eth::Instruction::DUP3),
|
byte(solidity::Instruction::DUP3),
|
||||||
byte(eth::Instruction::DUP1),
|
byte(solidity::Instruction::DUP1),
|
||||||
byte(eth::Instruction::PUSH1), 0x1,
|
byte(solidity::Instruction::PUSH1), 0x1,
|
||||||
byte(eth::Instruction::SWAP1),
|
byte(solidity::Instruction::SWAP1),
|
||||||
byte(eth::Instruction::SUB),
|
byte(solidity::Instruction::SUB),
|
||||||
// Stack here: (a+2) x a^(a+2) (a+2) (a+1)
|
// Stack here: (a+2) x a^(a+2) (a+2) (a+1)
|
||||||
byte(eth::Instruction::SWAP4),
|
byte(solidity::Instruction::SWAP4),
|
||||||
byte(eth::Instruction::POP), // first --
|
byte(solidity::Instruction::POP), // first --
|
||||||
byte(eth::Instruction::XOR),
|
byte(solidity::Instruction::XOR),
|
||||||
// Stack here: (a+1) x a^(a+2)^(a+2)
|
// Stack here: (a+1) x a^(a+2)^(a+2)
|
||||||
byte(eth::Instruction::DUP3),
|
byte(solidity::Instruction::DUP3),
|
||||||
byte(eth::Instruction::PUSH1), 0x1,
|
byte(solidity::Instruction::PUSH1), 0x1,
|
||||||
byte(eth::Instruction::SWAP1),
|
byte(solidity::Instruction::SWAP1),
|
||||||
byte(eth::Instruction::SUB),
|
byte(solidity::Instruction::SUB),
|
||||||
// Stack here: (a+1) x a^(a+2)^(a+2) a
|
// Stack here: (a+1) x a^(a+2)^(a+2) a
|
||||||
byte(eth::Instruction::SWAP3),
|
byte(solidity::Instruction::SWAP3),
|
||||||
byte(eth::Instruction::POP), // second ++
|
byte(solidity::Instruction::POP), // second ++
|
||||||
// Stack here: a x a^(a+2)^(a+2)
|
// Stack here: a x a^(a+2)^(a+2)
|
||||||
byte(eth::Instruction::DUP3), // will change
|
byte(solidity::Instruction::DUP3), // will change
|
||||||
byte(eth::Instruction::XOR)});
|
byte(solidity::Instruction::XOR)});
|
||||||
// Stack here: a x a^(a+2)^(a+2)^a
|
// Stack here: a x a^(a+2)^(a+2)^a
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
@ -404,16 +404,16 @@ BOOST_AUTO_TEST_CASE(assignment)
|
|||||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}});
|
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}});
|
||||||
|
|
||||||
// Stack: a, b
|
// Stack: a, b
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x2,
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x2,
|
||||||
byte(eth::Instruction::DUP2),
|
byte(solidity::Instruction::DUP2),
|
||||||
byte(eth::Instruction::DUP4),
|
byte(solidity::Instruction::DUP4),
|
||||||
byte(eth::Instruction::ADD),
|
byte(solidity::Instruction::ADD),
|
||||||
// Stack here: a b 2 a+b
|
// Stack here: a b 2 a+b
|
||||||
byte(eth::Instruction::SWAP3),
|
byte(solidity::Instruction::SWAP3),
|
||||||
byte(eth::Instruction::POP),
|
byte(solidity::Instruction::POP),
|
||||||
byte(eth::Instruction::DUP3),
|
byte(solidity::Instruction::DUP3),
|
||||||
// Stack here: a+b b 2 a+b
|
// Stack here: a+b b 2 a+b
|
||||||
byte(eth::Instruction::MUL)});
|
byte(solidity::Instruction::MUL)});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,26 +427,26 @@ BOOST_AUTO_TEST_CASE(function_call)
|
|||||||
{{"test", "f", "a"}, {"test", "f", "b"}});
|
{{"test", "f", "a"}, {"test", "f", "b"}});
|
||||||
|
|
||||||
// Stack: a, b
|
// Stack: a, b
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x02,
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x02,
|
||||||
byte(eth::Instruction::PUSH1), 0x0c,
|
byte(solidity::Instruction::PUSH1), 0x0c,
|
||||||
byte(eth::Instruction::PUSH1), 0x01,
|
byte(solidity::Instruction::PUSH1), 0x01,
|
||||||
byte(eth::Instruction::DUP5),
|
byte(solidity::Instruction::DUP5),
|
||||||
byte(eth::Instruction::ADD),
|
byte(solidity::Instruction::ADD),
|
||||||
// Stack here: a b 2 <ret label> (a+1)
|
// Stack here: a b 2 <ret label> (a+1)
|
||||||
byte(eth::Instruction::DUP4),
|
byte(solidity::Instruction::DUP4),
|
||||||
byte(eth::Instruction::PUSH1), 0x13,
|
byte(solidity::Instruction::PUSH1), 0x13,
|
||||||
byte(eth::Instruction::JUMP),
|
byte(solidity::Instruction::JUMP),
|
||||||
byte(eth::Instruction::JUMPDEST),
|
byte(solidity::Instruction::JUMPDEST),
|
||||||
// Stack here: a b 2 g(a+1, b)
|
// Stack here: a b 2 g(a+1, b)
|
||||||
byte(eth::Instruction::MUL),
|
byte(solidity::Instruction::MUL),
|
||||||
// Stack here: a b g(a+1, b)*2
|
// Stack here: a b g(a+1, b)*2
|
||||||
byte(eth::Instruction::DUP3),
|
byte(solidity::Instruction::DUP3),
|
||||||
byte(eth::Instruction::ADD),
|
byte(solidity::Instruction::ADD),
|
||||||
// Stack here: a b a+g(a+1, b)*2
|
// Stack here: a b a+g(a+1, b)*2
|
||||||
byte(eth::Instruction::SWAP2),
|
byte(solidity::Instruction::SWAP2),
|
||||||
byte(eth::Instruction::POP),
|
byte(solidity::Instruction::POP),
|
||||||
byte(eth::Instruction::DUP2),
|
byte(solidity::Instruction::DUP2),
|
||||||
byte(eth::Instruction::JUMPDEST)});
|
byte(solidity::Instruction::JUMPDEST)});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +457,7 @@ BOOST_AUTO_TEST_CASE(negative_literals_8bits)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80));
|
bytes expectation(bytes({byte(solidity::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80));
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ BOOST_AUTO_TEST_CASE(negative_literals_16bits)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(30, 0xff) + bytes{0xf5, 0x43});
|
bytes expectation(bytes({byte(solidity::Instruction::PUSH32)}) + bytes(30, 0xff) + bytes{0xf5, 0x43});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals)
|
|||||||
"}\n";
|
"}\n";
|
||||||
bytes code = compileFirstExpression(sourceCode);
|
bytes code = compileFirstExpression(sourceCode);
|
||||||
|
|
||||||
bytes expectation(bytes({byte(eth::Instruction::PUSH1), 0xbf}));
|
bytes expectation(bytes({byte(solidity::Instruction::PUSH1), 0xbf}));
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,8 +495,8 @@ BOOST_AUTO_TEST_CASE(blockhash)
|
|||||||
bytes code = compileFirstExpression(sourceCode, {}, {},
|
bytes code = compileFirstExpression(sourceCode, {}, {},
|
||||||
{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block))});
|
{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block))});
|
||||||
|
|
||||||
bytes expectation({byte(eth::Instruction::PUSH1), 0x03,
|
bytes expectation({byte(solidity::Instruction::PUSH1), 0x03,
|
||||||
byte(eth::Instruction::BLOCKHASH)});
|
byte(solidity::Instruction::BLOCKHASH)});
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +58,11 @@ public:
|
|||||||
m_optimize = true;
|
m_optimize = true;
|
||||||
bytes optimizedBytecode = compileAndRun(_sourceCode, _value, _contractName);
|
bytes optimizedBytecode = compileAndRun(_sourceCode, _value, _contractName);
|
||||||
size_t nonOptimizedSize = 0;
|
size_t nonOptimizedSize = 0;
|
||||||
eth::eachInstruction(nonOptimizedBytecode, [&](Instruction, u256 const&) {
|
solidity::eachInstruction(nonOptimizedBytecode, [&](Instruction, u256 const&) {
|
||||||
nonOptimizedSize++;
|
nonOptimizedSize++;
|
||||||
});
|
});
|
||||||
size_t optimizedSize = 0;
|
size_t optimizedSize = 0;
|
||||||
eth::eachInstruction(optimizedBytecode, [&](Instruction, u256 const&) {
|
solidity::eachInstruction(optimizedBytecode, [&](Instruction, u256 const&) {
|
||||||
optimizedSize++;
|
optimizedSize++;
|
||||||
});
|
});
|
||||||
BOOST_CHECK_MESSAGE(
|
BOOST_CHECK_MESSAGE(
|
||||||
@ -308,8 +308,8 @@ BOOST_AUTO_TEST_CASE(retain_information_in_branches)
|
|||||||
m_optimize = true;
|
m_optimize = true;
|
||||||
bytes optimizedBytecode = compileAndRun(sourceCode, 0, "c");
|
bytes optimizedBytecode = compileAndRun(sourceCode, 0, "c");
|
||||||
size_t numSHA3s = 0;
|
size_t numSHA3s = 0;
|
||||||
eth::eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
||||||
if (_instr == eth::Instruction::SHA3)
|
if (_instr == Instruction::SHA3)
|
||||||
numSHA3s++;
|
numSHA3s++;
|
||||||
});
|
});
|
||||||
BOOST_CHECK_EQUAL(1, numSHA3s);
|
BOOST_CHECK_EQUAL(1, numSHA3s);
|
||||||
@ -351,8 +351,8 @@ BOOST_AUTO_TEST_CASE(store_tags_as_unions)
|
|||||||
m_optimize = true;
|
m_optimize = true;
|
||||||
bytes optimizedBytecode = compileAndRun(sourceCode, 0, "test");
|
bytes optimizedBytecode = compileAndRun(sourceCode, 0, "test");
|
||||||
size_t numSHA3s = 0;
|
size_t numSHA3s = 0;
|
||||||
eth::eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
||||||
if (_instr == eth::Instruction::SHA3)
|
if (_instr == Instruction::SHA3)
|
||||||
numSHA3s++;
|
numSHA3s++;
|
||||||
});
|
});
|
||||||
// TEST DISABLED UNTIL 93693404 IS IMPLEMENTED
|
// TEST DISABLED UNTIL 93693404 IS IMPLEMENTED
|
||||||
@ -1071,16 +1071,16 @@ BOOST_AUTO_TEST_CASE(block_deduplicator)
|
|||||||
AssemblyItem(PushTag, 1),
|
AssemblyItem(PushTag, 1),
|
||||||
AssemblyItem(PushTag, 3),
|
AssemblyItem(PushTag, 3),
|
||||||
u256(6),
|
u256(6),
|
||||||
eth::Instruction::SWAP3,
|
Instruction::SWAP3,
|
||||||
eth::Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
AssemblyItem(Tag, 1),
|
AssemblyItem(Tag, 1),
|
||||||
u256(6),
|
u256(6),
|
||||||
eth::Instruction::SWAP3,
|
Instruction::SWAP3,
|
||||||
eth::Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
AssemblyItem(Tag, 2),
|
AssemblyItem(Tag, 2),
|
||||||
u256(6),
|
u256(6),
|
||||||
eth::Instruction::SWAP3,
|
Instruction::SWAP3,
|
||||||
eth::Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
AssemblyItem(Tag, 3)
|
AssemblyItem(Tag, 3)
|
||||||
};
|
};
|
||||||
BlockDeduplicator dedup(input);
|
BlockDeduplicator dedup(input);
|
||||||
@ -1097,23 +1097,23 @@ BOOST_AUTO_TEST_CASE(block_deduplicator_loops)
|
|||||||
{
|
{
|
||||||
AssemblyItems input{
|
AssemblyItems input{
|
||||||
u256(0),
|
u256(0),
|
||||||
eth::Instruction::SLOAD,
|
Instruction::SLOAD,
|
||||||
AssemblyItem(PushTag, 1),
|
AssemblyItem(PushTag, 1),
|
||||||
AssemblyItem(PushTag, 2),
|
AssemblyItem(PushTag, 2),
|
||||||
eth::Instruction::JUMPI,
|
Instruction::JUMPI,
|
||||||
eth::Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
AssemblyItem(Tag, 1),
|
AssemblyItem(Tag, 1),
|
||||||
u256(5),
|
u256(5),
|
||||||
u256(6),
|
u256(6),
|
||||||
eth::Instruction::SSTORE,
|
Instruction::SSTORE,
|
||||||
AssemblyItem(PushTag, 1),
|
AssemblyItem(PushTag, 1),
|
||||||
eth::Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
AssemblyItem(Tag, 2),
|
AssemblyItem(Tag, 2),
|
||||||
u256(5),
|
u256(5),
|
||||||
u256(6),
|
u256(6),
|
||||||
eth::Instruction::SSTORE,
|
Instruction::SSTORE,
|
||||||
AssemblyItem(PushTag, 2),
|
AssemblyItem(PushTag, 2),
|
||||||
eth::Instruction::JUMP,
|
Instruction::JUMP,
|
||||||
};
|
};
|
||||||
BlockDeduplicator dedup(input);
|
BlockDeduplicator dedup(input);
|
||||||
dedup.deduplicate();
|
dedup.deduplicate();
|
||||||
|
Loading…
Reference in New Issue
Block a user