|
|
@ -91,7 +91,15 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _ |
|
|
|
{ |
|
|
|
Parser parser; |
|
|
|
ASTPointer<SourceUnit> sourceUnit; |
|
|
|
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); |
|
|
|
try |
|
|
|
{ |
|
|
|
sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))); |
|
|
|
} |
|
|
|
catch(boost::exception const& _e) |
|
|
|
{ |
|
|
|
auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e); |
|
|
|
BOOST_FAIL(msg); |
|
|
|
} |
|
|
|
|
|
|
|
vector<Declaration const*> declarations; |
|
|
|
declarations.reserve(_globalDeclarations.size() + 1); |
|
|
@ -177,6 +185,66 @@ BOOST_AUTO_TEST_CASE(int_literal) |
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination) |
|
|
|
{ |
|
|
|
char const* sourceCode = R"( |
|
|
|
contract test { |
|
|
|
function test () |
|
|
|
{ |
|
|
|
var x = 1 wei; |
|
|
|
} |
|
|
|
})"; |
|
|
|
bytes code = compileFirstExpression(sourceCode); |
|
|
|
|
|
|
|
bytes expectation({byte(eth::Instruction::PUSH1), 0x1}); |
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination) |
|
|
|
{ |
|
|
|
char const* sourceCode = R"( |
|
|
|
contract test { |
|
|
|
function test () |
|
|
|
{ |
|
|
|
var x = 1 szabo; |
|
|
|
} |
|
|
|
})"; |
|
|
|
bytes code = compileFirstExpression(sourceCode); |
|
|
|
|
|
|
|
bytes expectation({byte(eth::Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00}); |
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(int_with_finney_ether_subdenomination) |
|
|
|
{ |
|
|
|
char const* sourceCode = R"( |
|
|
|
contract test { |
|
|
|
function test () |
|
|
|
{ |
|
|
|
var x = 1 finney; |
|
|
|
} |
|
|
|
})"; |
|
|
|
bytes code = compileFirstExpression(sourceCode); |
|
|
|
|
|
|
|
bytes expectation({byte(eth::Instruction::PUSH7), 0x3, 0x8d, 0x7e, 0xa4, 0xc6, 0x80, 0x00}); |
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination) |
|
|
|
{ |
|
|
|
char const* sourceCode = R"( |
|
|
|
contract test { |
|
|
|
function test () |
|
|
|
{ |
|
|
|
var x = 1 ether; |
|
|
|
} |
|
|
|
})"; |
|
|
|
bytes code = compileFirstExpression(sourceCode); |
|
|
|
|
|
|
|
bytes expectation({byte(eth::Instruction::PUSH8), 0xd, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x00}); |
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(comparison) |
|
|
|
{ |
|
|
|
char const* sourceCode = "contract test {\n" |
|
|
|