From 19c92ee1d2d488179daec6bfdd5ed48764e2c19e Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 4 Feb 2015 22:02:35 +0100 Subject: Tests for ether subdenominations. Work in progress --- SolidityExpressionCompiler.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'SolidityExpressionCompiler.cpp') diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp index a0cca3a3..71f40bd2 100644 --- a/SolidityExpressionCompiler.cpp +++ b/SolidityExpressionCompiler.cpp @@ -91,7 +91,16 @@ bytes compileFirstExpression(const string& _sourceCode, vector> _ { Parser parser; ASTPointer sourceUnit; - BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); + try + { + sourceUnit = parser.parse(make_shared(CharStream(_sourceCode))); + } + catch(boost::exception const& _e) + { + auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e); + BOOST_FAIL(msg); + } + // BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); vector declarations; declarations.reserve(_globalDeclarations.size() + 1); @@ -177,6 +186,28 @@ BOOST_AUTO_TEST_CASE(int_literal) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } +BOOST_AUTO_TEST_CASE(int_literals_with_ether_subdenominations) +{ + char const* sourceCode = R"( + contract c { + function c () + { + a = 1 wei; + // b = 2 szabo; + // c = 3 finney; +// b = 4 ether; + } + uint256 a; + uint256 b; + uint256 c; + uint256 d; + })"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::PUSH5), 0x38, 0xd4, 0xa5, 0x10, 0x00}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + BOOST_AUTO_TEST_CASE(comparison) { char const* sourceCode = "contract test {\n" -- cgit