diff options
author | chriseth <chris@ethereum.org> | 2017-08-01 22:46:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-01 22:46:15 +0800 |
commit | f1ae38402e63c35d64cddcd8063836b57ac0adea (patch) | |
tree | 66d7912bb7af77063e5a419f69c29f68b351c461 | |
parent | 7e07eb6eea5195213398e0b6e0d502f03bfb4f19 (diff) | |
parent | 6ea4b7fa37ecef9c910bc9237f080095a60ece94 (diff) | |
download | dexon-solidity-f1ae38402e63c35d64cddcd8063836b57ac0adea.tar dexon-solidity-f1ae38402e63c35d64cddcd8063836b57ac0adea.tar.gz dexon-solidity-f1ae38402e63c35d64cddcd8063836b57ac0adea.tar.bz2 dexon-solidity-f1ae38402e63c35d64cddcd8063836b57ac0adea.tar.lz dexon-solidity-f1ae38402e63c35d64cddcd8063836b57ac0adea.tar.xz dexon-solidity-f1ae38402e63c35d64cddcd8063836b57ac0adea.tar.zst dexon-solidity-f1ae38402e63c35d64cddcd8063836b57ac0adea.zip |
Merge pull request #2674 from ethereum/builtin-tests
Add more tests for keccak256/sha256/ripemd160
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 81 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 50 |
2 files changed, 130 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index db7f59ee..2c9dfad9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1950,6 +1950,87 @@ BOOST_AUTO_TEST_CASE(ripemd) testContractAgainstCpp("a(bytes32)", f, u256(-1)); } +BOOST_AUTO_TEST_CASE(packed_keccak256) +{ + char const* sourceCode = R"( + contract test { + function a(bytes32 input) returns (bytes32 hash) { + var b = 65536; + uint c = 256; + return keccak256(8, input, b, input, c); + } + } + )"; + compileAndRun(sourceCode); + auto f = [&](u256 const& _x) -> u256 + { + return dev::keccak256( + toCompactBigEndian(unsigned(8)) + + toBigEndian(_x) + + toCompactBigEndian(unsigned(65536)) + + toBigEndian(_x) + + toBigEndian(u256(256)) + ); + }; + testContractAgainstCpp("a(bytes32)", f, u256(4)); + testContractAgainstCpp("a(bytes32)", f, u256(5)); + testContractAgainstCpp("a(bytes32)", f, u256(-1)); +} + +BOOST_AUTO_TEST_CASE(packed_sha256) +{ + char const* sourceCode = R"( + contract test { + function a(bytes32 input) returns (bytes32 hash) { + var b = 65536; + uint c = 256; + return sha256(8, input, b, input, c); + } + } + )"; + compileAndRun(sourceCode); + auto f = [&](u256 const& _x) -> bytes + { + if (_x == u256(4)) + return fromHex("804e0d7003cfd70fc925dc103174d9f898ebb142ecc2a286da1abd22ac2ce3ac"); + if (_x == u256(5)) + return fromHex("e94921945f9068726c529a290a954f412bcac53184bb41224208a31edbf63cf0"); + if (_x == u256(-1)) + return fromHex("f14def4d07cd185ddd8b10a81b2238326196a38867e6e6adbcc956dc913488c7"); + return fromHex(""); + }; + testContractAgainstCpp("a(bytes32)", f, u256(4)); + testContractAgainstCpp("a(bytes32)", f, u256(5)); + testContractAgainstCpp("a(bytes32)", f, u256(-1)); +} + +BOOST_AUTO_TEST_CASE(packed_ripemd160) +{ + char const* sourceCode = R"( + contract test { + function a(bytes32 input) returns (bytes32 hash) { + var b = 65536; + uint c = 256; + return ripemd160(8, input, b, input, c); + } + } + )"; + compileAndRun(sourceCode); + auto f = [&](u256 const& _x) -> bytes + { + if (_x == u256(4)) + return fromHex("f93175303eba2a7b372174fc9330237f5ad202fc000000000000000000000000"); + if (_x == u256(5)) + return fromHex("04f4fc112e2bfbe0d38f896a46629e08e2fcfad5000000000000000000000000"); + if (_x == u256(-1)) + return fromHex("c0a2e4b1f3ff766a9a0089e7a410391730872495000000000000000000000000"); + return fromHex(""); + }; + testContractAgainstCpp("a(bytes32)", f, u256(4)); + testContractAgainstCpp("a(bytes32)", f, u256(5)); + testContractAgainstCpp("a(bytes32)", f, u256(-1)); +} + BOOST_AUTO_TEST_CASE(ecrecover) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index cd922cc8..e2e9f08a 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6437,7 +6437,7 @@ BOOST_AUTO_TEST_CASE(using_this_in_constructor) CHECK_WARNING(text, "\"this\" used in constructor"); } -BOOST_AUTO_TEST_CASE(do_not_crash_on_not_lalue) +BOOST_AUTO_TEST_CASE(do_not_crash_on_not_lvalue) { // This checks for a bug that caused a crash because of continued analysis. char const* text = R"( @@ -6451,6 +6451,54 @@ BOOST_AUTO_TEST_CASE(do_not_crash_on_not_lalue) CHECK_ERROR_ALLOW_MULTI(text, TypeError, "is not callable"); } +BOOST_AUTO_TEST_CASE(builtin_reject_gas) +{ + char const* text = R"( + contract C { + function f() { + keccak256.gas(); + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup"); +} + +BOOST_AUTO_TEST_CASE(builtin_reject_value) +{ + char const* text = R"( + contract C { + function f() { + keccak256.value(); + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); + text = R"( + contract C { + function f() { + sha256.value(); + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); + text = R"( + contract C { + function f() { + ripemd160.value(); + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); + text = R"( + contract C { + function f() { + ecrecover.value(); + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); +} + BOOST_AUTO_TEST_SUITE_END() } |