aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp33
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp24
-rw-r--r--test/libsolidity/SolidityParser.cpp15
-rw-r--r--test/libsolidity/SolidityScanner.cpp17
4 files changed, 64 insertions, 25 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index a4fab721..7ef34383 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -9233,6 +9233,39 @@ BOOST_AUTO_TEST_CASE(revert)
BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(42)));
}
+BOOST_AUTO_TEST_CASE(scientific_notation)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (uint) {
+ return 2e10 wei;
+ }
+ function g() returns (uint) {
+ return 200e-2 wei;
+ }
+ function h() returns (uint) {
+ return 2.5e1;
+ }
+ function i() returns (int) {
+ return -2e10;
+ }
+ function j() returns (int) {
+ return -200e-2;
+ }
+ function k() returns (int) {
+ return -2.5e1;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(20000000000)));
+ BOOST_CHECK(callContractFunction("g()") == encodeArgs(u256(2)));
+ BOOST_CHECK(callContractFunction("h()") == encodeArgs(u256(25)));
+ BOOST_CHECK(callContractFunction("i()") == encodeArgs(u256(-20000000000)));
+ BOOST_CHECK(callContractFunction("j()") == encodeArgs(u256(-2)));
+ BOOST_CHECK(callContractFunction("k()") == encodeArgs(u256(-25)));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 97a82f00..fa310434 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2790,18 +2790,6 @@ BOOST_AUTO_TEST_CASE(literal_strings)
CHECK_SUCCESS(text);
}
-BOOST_AUTO_TEST_CASE(invalid_integer_literal_exp)
-{
- char const* text = R"(
- contract Foo {
- function f() {
- var x = 1e2;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "");
-}
-
BOOST_AUTO_TEST_CASE(memory_structs_with_mappings)
{
char const* text = R"(
@@ -4951,18 +4939,6 @@ BOOST_AUTO_TEST_CASE(external_function_type_to_uint)
CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed");
}
-BOOST_AUTO_TEST_CASE(invalid_fixed_point_literal)
-{
- char const* text = R"(
- contract A {
- function a() {
- .8E0;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "");
-}
-
BOOST_AUTO_TEST_CASE(shift_constant_left_negative_rvalue)
{
char const* text = R"(
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index e5362e78..ffb4b6f2 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -1479,6 +1479,21 @@ BOOST_AUTO_TEST_CASE(function_type_state_variable)
BOOST_CHECK(successParse(text));
}
+BOOST_AUTO_TEST_CASE(scientific_notation)
+{
+ char const* text = R"(
+ contract test {
+ uint256 a = 2e10;
+ uint256 b = 2E10;
+ uint256 c = 200e-2;
+ uint256 d = 2E10 wei;
+ uint256 e = 2.5e10;
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp
index 3a5c6f24..020bce7f 100644
--- a/test/libsolidity/SolidityScanner.cpp
+++ b/test/libsolidity/SolidityScanner.cpp
@@ -115,9 +115,21 @@ BOOST_AUTO_TEST_CASE(octal_numbers)
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number);
}
+BOOST_AUTO_TEST_CASE(scientific_notation)
+{
+ Scanner scanner(CharStream("var x = 2e10;"));
+ BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Assign);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "2e10");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
+}
+
BOOST_AUTO_TEST_CASE(negative_numbers)
{
- Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9;"));
+ Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9 + 2e-2;"));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var);
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::Assign);
@@ -135,6 +147,9 @@ BOOST_AUTO_TEST_CASE(negative_numbers)
BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "8.9");
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
+ BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
+ BOOST_CHECK_EQUAL(scanner.currentLiteral(), "2e-2");
BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
}