aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp108
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp16
2 files changed, 124 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 39f4b03e..a5b990ac 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -3557,6 +3557,45 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
ABI_CHECK(callContractFunction("f(uint256)", 9), encodeArgs(9));
}
+BOOST_AUTO_TEST_CASE(sha256_empty)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (bytes32) {
+ return sha256();
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()"), fromHex("0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
+}
+
+BOOST_AUTO_TEST_CASE(ripemd160_empty)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (bytes20) {
+ return ripemd160();
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()"), fromHex("0x9c1185a5c5e9fc54612808977ee8f548b2258d31000000000000000000000000"));
+}
+
+BOOST_AUTO_TEST_CASE(keccak256_empty)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (bytes32) {
+ return keccak256();
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
+}
+
BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments)
{
char const* sourceCode = R"(
@@ -11052,6 +11091,75 @@ BOOST_AUTO_TEST_CASE(snark)
BOOST_CHECK(callContractFunction("verifyTx()") == encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(abi_encode)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (bytes) {
+ return abi.encode(1, 2);
+ }
+ function g() returns (bytes) {
+ return abi.encodePacked(uint256(1), uint256(2));
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0x20), u256(0x40), u256(1), u256(2)));
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(0x20), u256(0x40), u256(1), u256(2)));
+}
+
+BOOST_AUTO_TEST_CASE(abi_encode_complex_call)
+{
+ char const* sourceCode = R"T(
+ contract C {
+ function f(uint8 a, string b, string c) {
+ require(a == 42);
+ require(bytes(b).length == 2);
+ require(bytes(b)[0] == 72); // 'H'
+ require(bytes(b)[1] == 101); // 'e'
+ require(keccak256(b) == keccak256(c));
+ }
+ function g(uint8 a, string b) returns (bool) {
+ bytes request = abi.encode(
+ bytes4(keccak256(abi.encodePacked("f(uint8,string)"))),
+ a,
+ b,
+ "He"
+ );
+ return this.call(request);
+ }
+ }
+ )T";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("g(uint8,string)", u256(42), u256(0x40), u256(2), string("He")), encodeArgs(u256(1)));
+}
+
+BOOST_AUTO_TEST_CASE(abi_encodewithselector_complex_call)
+{
+ char const* sourceCode = R"T(
+ contract C {
+ function f(uint8 a, string b, string c) {
+ require(a == 42);
+ require(bytes(b).length == 2);
+ require(bytes(b)[0] == 72); // 'H'
+ require(bytes(b)[1] == 101); // 'e'
+ require(keccak256(b) == keccak256(c));
+ }
+ function g(uint8 a, string b) returns (bool) {
+ bytes request = abi.encodeWithSignature(
+ "f(uint8,string)",
+ a,
+ b,
+ "He"
+ );
+ return this.call(request);
+ }
+ }
+ )T";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("g(uint8,string)", u256(42), u256(0x40), u256(2), string("He")), encodeArgs(u256(1)));
+}
+
BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 18a414e0..7678bf4a 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -7120,6 +7120,22 @@ BOOST_AUTO_TEST_CASE(tight_packing_literals)
}
)";
CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
+ text = R"(
+ contract C {
+ function f() pure public returns (bytes) {
+ return abi.encode(1);
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+ text = R"(
+ contract C {
+ function f() pure public returns (bytes) {
+ return abi.encodePacked(1);
+ }
+ }
+ )";
+ CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
}
BOOST_AUTO_TEST_CASE(non_external_fallback)