aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-02-09 07:14:13 +0800
committerchriseth <c@ethdev.com>2015-02-09 07:14:13 +0800
commit5d7098eba7745ce4944b0b1d77d13a3a10929458 (patch)
treee9be945525099ba7d7ddc70e13c02305b925d6d9 /SolidityEndToEndTest.cpp
parent86729f9eeed4b2ea83949d29fa5d704de70c9d5e (diff)
parent895b5c13f0189106f71b670affab61b389e7991d (diff)
downloaddexon-solidity-5d7098eba7745ce4944b0b1d77d13a3a10929458.tar
dexon-solidity-5d7098eba7745ce4944b0b1d77d13a3a10929458.tar.gz
dexon-solidity-5d7098eba7745ce4944b0b1d77d13a3a10929458.tar.bz2
dexon-solidity-5d7098eba7745ce4944b0b1d77d13a3a10929458.tar.lz
dexon-solidity-5d7098eba7745ce4944b0b1d77d13a3a10929458.tar.xz
dexon-solidity-5d7098eba7745ce4944b0b1d77d13a3a10929458.tar.zst
dexon-solidity-5d7098eba7745ce4944b0b1d77d13a3a10929458.zip
Merge pull request #937 from LefterisJP/sol_MultiArgSHA3
Solidity multiple arg sha3
Diffstat (limited to 'SolidityEndToEndTest.cpp')
-rw-r--r--SolidityEndToEndTest.cpp65
1 files changed, 63 insertions, 2 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index 301cc06e..56ee631b 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -576,7 +576,7 @@ BOOST_AUTO_TEST_CASE(simple_mapping)
" }\n"
"}";
compileAndRun(sourceCode);
-
+
BOOST_CHECK(callContractFunction("get(uint8)", byte(0)) == encodeArgs(byte(0x00)));
BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0x00)));
BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00)));
@@ -933,7 +933,7 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("data()") == encodeArgs(8));
BOOST_CHECK(callContractFunction("name()") == encodeArgs("Celina"));
- BOOST_CHECK(callContractFunction("a_hash()") == encodeArgs(dev::sha3(toBigEndian(u256(123)))));
+ BOOST_CHECK(callContractFunction("a_hash()") == encodeArgs(dev::sha3(bytes({0x7b}))));
BOOST_CHECK(callContractFunction("an_address()") == encodeArgs(toBigEndian(u160(0x1337))));
BOOST_CHECK(callContractFunction("super_secret_data()") == bytes());
}
@@ -2113,6 +2113,67 @@ BOOST_AUTO_TEST_CASE(event_lots_of_data)
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,hash256,uint256,bool)")));
}
+BOOST_AUTO_TEST_CASE(sha3_multiple_arguments)
+{
+ char const* sourceCode = R"(
+ contract c {
+ function foo(uint a, uint b, uint c) returns (hash d)
+ {
+ d = sha3(a, b, c);
+ }
+ })";
+ compileAndRun(sourceCode);
+
+ BOOST_CHECK(callContractFunction("foo(uint256,uint256,uint256)", 10, 12, 13) == encodeArgs(
+ dev::sha3(
+ toBigEndian(u256(10)) +
+ toBigEndian(u256(12)) +
+ toBigEndian(u256(13)))));
+}
+
+BOOST_AUTO_TEST_CASE(sha3_multiple_arguments_with_numeric_literals)
+{
+ char const* sourceCode = R"(
+ contract c {
+ function foo(uint a, uint16 b) returns (hash d)
+ {
+ d = sha3(a, b, 145);
+ }
+ })";
+ compileAndRun(sourceCode);
+
+ BOOST_CHECK(callContractFunction("foo(uint256,uint16)", 10, 12) == encodeArgs(
+ dev::sha3(
+ toBigEndian(u256(10)) +
+ bytes({0x0, 0xc}) +
+ bytes({0x91}))));
+}
+
+BOOST_AUTO_TEST_CASE(sha3_multiple_arguments_with_string_literals)
+{
+ char const* sourceCode = R"(
+ contract c {
+ function foo() returns (hash d)
+ {
+ d = sha3("foo");
+ }
+ function bar(uint a, uint16 b) returns (hash d)
+ {
+ d = sha3(a, b, 145, "foo");
+ }
+ })";
+ compileAndRun(sourceCode);
+
+ BOOST_CHECK(callContractFunction("foo()") == encodeArgs(dev::sha3("foo")));
+
+ BOOST_CHECK(callContractFunction("bar(uint256,uint16)", 10, 12) == encodeArgs(
+ dev::sha3(
+ toBigEndian(u256(10)) +
+ bytes({0x0, 0xc}) +
+ bytes({0x91}) +
+ bytes({0x66, 0x6f, 0x6f}))));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}