diff options
author | chriseth <c@ethdev.com> | 2015-06-05 17:15:09 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-06-05 17:15:09 +0800 |
commit | 8ba801ec0e885ebca5babadef007f20bcdde1f0b (patch) | |
tree | ab3aef0cca030de38ff8edc1877f2d741c2e108f /libsolidity | |
parent | df293b9f188eb2a83399b75c0ebd6f65189bfeea (diff) | |
parent | 1f3e93785ea94c6897190399e29b1977198445ba (diff) | |
download | dexon-solidity-8ba801ec0e885ebca5babadef007f20bcdde1f0b.tar dexon-solidity-8ba801ec0e885ebca5babadef007f20bcdde1f0b.tar.gz dexon-solidity-8ba801ec0e885ebca5babadef007f20bcdde1f0b.tar.bz2 dexon-solidity-8ba801ec0e885ebca5babadef007f20bcdde1f0b.tar.lz dexon-solidity-8ba801ec0e885ebca5babadef007f20bcdde1f0b.tar.xz dexon-solidity-8ba801ec0e885ebca5babadef007f20bcdde1f0b.tar.zst dexon-solidity-8ba801ec0e885ebca5babadef007f20bcdde1f0b.zip |
Merge pull request #2074 from LianaHus/sol_PosIntegerLiteralsConversation
Solidity Positive integer literals conversion to signed if in value range.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/SolidityEndToEndTest.cpp | 15 | ||||
-rw-r--r-- | libsolidity/SolidityNameAndTypeResolution.cpp | 60 |
2 files changed, 75 insertions, 0 deletions
diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 9f6f27d7..1d0f1fc2 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4172,6 +4172,21 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty()); } +BOOST_AUTO_TEST_CASE(positive_integers_to_signed) +{ + char const* sourceCode = R"( + contract test { + int8 public x = 2; + int8 public y = 127; + int16 public q = 250; + } + )"; + compileAndRun(sourceCode, 0, "test"); + BOOST_CHECK(callContractFunction("x()") == encodeArgs(2)); + BOOST_CHECK(callContractFunction("y()") == encodeArgs(127)); + BOOST_CHECK(callContractFunction("q()") == encodeArgs(250)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 48404aaa..3691868c 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1816,6 +1816,66 @@ BOOST_AUTO_TEST_CASE(string_length) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(negative_integers_to_signed_out_of_bound) +{ + char const* sourceCode = R"( + contract test { + int8 public i = -129; + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(negative_integers_to_signed_min) +{ + char const* sourceCode = R"( + contract test { + int8 public i = -128; + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode)); +} + +BOOST_AUTO_TEST_CASE(positive_integers_to_signed_out_of_bound) +{ + char const* sourceCode = R"( + contract test { + int8 public j = 128; + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(positive_integers_to_signed_out_of_bound_max) +{ + char const* sourceCode = R"( + contract test { + int8 public j = 127; + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode)); +} + +BOOST_AUTO_TEST_CASE(negative_integers_to_unsigned) +{ + char const* sourceCode = R"( + contract test { + uint8 public x = -1; + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(positive_integers_to_unsigned_out_of_bound) +{ + char const* sourceCode = R"( + contract test { + uint8 public x = 700; + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } |