From 19c92ee1d2d488179daec6bfdd5ed48764e2c19e Mon Sep 17 00:00:00 2001
From: Lefteris Karapetsas <lefteris@refu.co>
Date: Wed, 4 Feb 2015 22:02:35 +0100
Subject: Tests for ether subdenominations. Work in progress

---
 SolidityExpressionCompiler.cpp | 33 ++++++++++++++++++++++++++++++++-
 SolidityParser.cpp             | 19 +++++++++++++++++++
 SolidityScanner.cpp            |  9 +++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)

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<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);
+	}
+	// BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))));
 
 	vector<Declaration const*> 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"
diff --git a/SolidityParser.cpp b/SolidityParser.cpp
index 9ba38a4a..b6837866 100644
--- a/SolidityParser.cpp
+++ b/SolidityParser.cpp
@@ -660,6 +660,25 @@ BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers)
 	BOOST_CHECK_THROW(parseText(text), ParserError);
 }
 
+BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations)
+{
+	char const* text = 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;
+		})";
+	BOOST_CHECK_NO_THROW(parseTextExplainError(text));
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 }
diff --git a/SolidityScanner.cpp b/SolidityScanner.cpp
index 7dc9ef48..5bd897ab 100644
--- a/SolidityScanner.cpp
+++ b/SolidityScanner.cpp
@@ -255,6 +255,15 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence)
 	BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "documentation comment ");
 }
 
+BOOST_AUTO_TEST_CASE(ether_subdenominations)
+{
+	Scanner scanner(CharStream("wei szabo finney ether"));
+	BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::ETH_SUB_WEI);
+	BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_SZABO);
+	BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_FINNEY);
+	BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_ETHER);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 }
-- 
cgit v1.2.3


From 5b8deb986605e6b6adfc6cc3bce5d38455e113e3 Mon Sep 17 00:00:00 2001
From: Lefteris Karapetsas <lefteris@refu.co>
Date: Thu, 5 Feb 2015 13:48:02 +0100
Subject: Tests and fixes for ether subdenominations

---
 SolidityExpressionCompiler.cpp | 63 +++++++++++++++++++++++++++++++++---------
 1 file changed, 50 insertions(+), 13 deletions(-)

diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp
index 71f40bd2..3c3ea1ba 100644
--- a/SolidityExpressionCompiler.cpp
+++ b/SolidityExpressionCompiler.cpp
@@ -100,7 +100,6 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _
 		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<Scanner>(CharStream(_sourceCode))));
 
 	vector<Declaration const*> declarations;
 	declarations.reserve(_globalDeclarations.size() + 1);
@@ -186,25 +185,63 @@ 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)
+BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination)
 {
 	char const* sourceCode = R"(
-		contract c {
-			function c ()
+		contract test {
+			function test ()
 			{
-				 a = 1 wei;
-		//		 b = 2 szabo;
-	//			 c = 3 finney;
-//				 b = 4 ether;
+				 var x = 1 wei;
 			}
-			uint256 a;
-			uint256 b;
-			uint256 c;
-			uint256 d;
 		})";
 	bytes code = compileFirstExpression(sourceCode);
 
-	bytes expectation({byte(eth::Instruction::PUSH5), 0x38, 0xd4, 0xa5, 0x10, 0x00});
+	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());
 }
 
-- 
cgit v1.2.3


From fb55f4f24dc1fee6e35e828ba0454c328d14f7ca Mon Sep 17 00:00:00 2001
From: Lefteris Karapetsas <lefteris@refu.co>
Date: Thu, 5 Feb 2015 22:38:07 +0100
Subject: Minor Style fixes

---
 SolidityScanner.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/SolidityScanner.cpp b/SolidityScanner.cpp
index 5bd897ab..8088b4d4 100644
--- a/SolidityScanner.cpp
+++ b/SolidityScanner.cpp
@@ -258,10 +258,10 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence)
 BOOST_AUTO_TEST_CASE(ether_subdenominations)
 {
 	Scanner scanner(CharStream("wei szabo finney ether"));
-	BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::ETH_SUB_WEI);
-	BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_SZABO);
-	BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_FINNEY);
-	BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_ETHER);
+	BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::SubWei);
+	BOOST_CHECK_EQUAL(scanner.next(), Token::SubSzabo);
+	BOOST_CHECK_EQUAL(scanner.next(), Token::SubFinney);
+	BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
-- 
cgit v1.2.3


From bd41622341b7dd4acbe7dcbf56b77bbcd751bc2f Mon Sep 17 00:00:00 2001
From: Lu Guanqun <guanqun.lu@gmail.com>
Date: Fri, 6 Feb 2015 07:44:38 +0800
Subject: disallow declaration of void type

https://www.pivotaltracker.com/n/projects/1189488/stories/86318578
---
 SolidityNameAndTypeResolution.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
index ae6c374b..742d2ee2 100644
--- a/SolidityNameAndTypeResolution.cpp
+++ b/SolidityNameAndTypeResolution.cpp
@@ -904,6 +904,12 @@ BOOST_AUTO_TEST_CASE(invalid_parameter_names_in_named_args)
 	BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
 }
 
+BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type)
+{
+	char const* sourceCode = "contract c { function f() { var x = f(); } }";
+	BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 }
-- 
cgit v1.2.3