mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Tests and fixes for ether subdenominations
This commit is contained in:
		
							parent
							
								
									19c92ee1d2
								
							
						
					
					
						commit
						5b8deb9866
					
				| @ -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); | 		auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e); | ||||||
| 		BOOST_FAIL(msg); | 		BOOST_FAIL(msg); | ||||||
| 	} | 	} | ||||||
| 	// BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))));
 |  | ||||||
| 
 | 
 | ||||||
| 	vector<Declaration const*> declarations; | 	vector<Declaration const*> declarations; | ||||||
| 	declarations.reserve(_globalDeclarations.size() + 1); | 	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_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"( | 	char const* sourceCode = R"( | ||||||
| 		contract c { | 		contract test { | ||||||
| 			function c () | 			function test () | ||||||
| 			{ | 			{ | ||||||
| 				 a = 1 wei; | 				 var x = 1 wei; | ||||||
| 		//		 b = 2 szabo;
 |  | ||||||
| 	//			 c = 3 finney;
 |  | ||||||
| //				 b = 4 ether;
 |  | ||||||
| 			} | 			} | ||||||
| 			uint256 a; |  | ||||||
| 			uint256 b; |  | ||||||
| 			uint256 c; |  | ||||||
| 			uint256 d; |  | ||||||
| 		})"; | 		})"; | ||||||
| 	bytes code = compileFirstExpression(sourceCode); | 	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()); | 	BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user