aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/libevmasm/Optimiser.cpp14
-rw-r--r--test/libsolidity/Assembly.cpp2
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp43
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp49
-rw-r--r--test/libsolidity/ViewPureChecker.cpp7
5 files changed, 111 insertions, 4 deletions
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp
index 9dc49581..0ab95b08 100644
--- a/test/libevmasm/Optimiser.cpp
+++ b/test/libevmasm/Optimiser.cpp
@@ -841,6 +841,20 @@ BOOST_AUTO_TEST_CASE(peephole_double_push)
);
}
+BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize)
+{
+ AssemblyItems items{
+ u256(4),
+ Instruction::CALLDATASIZE,
+ Instruction::LT,
+ Instruction::POP
+ };
+ PeepholeOptimiser peepOpt(items);
+ for (size_t i = 0; i < 3; i++)
+ BOOST_CHECK(peepOpt.optimise());
+ BOOST_CHECK(items.empty());
+}
+
BOOST_AUTO_TEST_CASE(jumpdest_removal)
{
AssemblyItems items{
diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp
index 56ac8cf5..358d3c72 100644
--- a/test/libsolidity/Assembly.cpp
+++ b/test/libsolidity/Assembly.cpp
@@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(location_test)
shared_ptr<string const> n = make_shared<string>("");
AssemblyItems items = compileContract(sourceCode);
vector<SourceLocation> locations =
- vector<SourceLocation>(18, SourceLocation(2, 75, n)) +
+ vector<SourceLocation>(24, SourceLocation(2, 75, n)) +
vector<SourceLocation>(32, SourceLocation(20, 72, n)) +
vector<SourceLocation>{SourceLocation(42, 51, n), SourceLocation(65, 67, n)} +
vector<SourceLocation>(2, SourceLocation(58, 67, n)) +
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index ac77a7e1..9a837113 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2899,6 +2899,25 @@ BOOST_AUTO_TEST_CASE(default_fallback_throws)
ABI_CHECK(callContractFunction("f()"), encodeArgs(0));
}
+BOOST_AUTO_TEST_CASE(short_data_calls_fallback)
+{
+ char const* sourceCode = R"(
+ contract A {
+ uint public x;
+ // Signature is d88e0b00
+ function fow() { x = 3; }
+ function () { x = 2; }
+ }
+ )";
+ compileAndRun(sourceCode);
+ // should call fallback
+ sendMessage(asBytes("\xd8\x8e\x0b"), false, 0);
+ ABI_CHECK(callContractFunction("x()"), encodeArgs(2));
+ // should call function
+ sendMessage(asBytes(string("\xd8\x8e\x0b") + string(1, 0)), false, 0);
+ ABI_CHECK(callContractFunction("x()"), encodeArgs(3));
+}
+
BOOST_AUTO_TEST_CASE(event)
{
char const* sourceCode = R"(
@@ -7309,6 +7328,30 @@ BOOST_AUTO_TEST_CASE(create_memory_array)
ABI_CHECK(callContractFunction("f()"), encodeArgs(string("A"), u256(8), u256(4), string("B")));
}
+BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size)
+{
+ // Check allocation size of byte array. Should be 32 plus length rounded up to next
+ // multiple of 32
+ char const* sourceCode = R"(
+ contract C {
+ function f() pure returns (uint d1, uint d2, uint d3) {
+ bytes memory b1 = new bytes(31);
+ bytes memory b2 = new bytes(32);
+ bytes memory b3 = new bytes(256);
+ bytes memory b4 = new bytes(31);
+ assembly {
+ d1 := sub(b2, b1)
+ d2 := sub(b3, b2)
+ d3 := sub(b4, b3)
+ }
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(0x40, 0x40, 0x20 + 256));
+}
+
+
BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes)
{
// Computes binomial coefficients the chinese way
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 2c720d03..9b0647bf 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -5537,7 +5537,7 @@ BOOST_AUTO_TEST_CASE(invalid_mobile_type)
}
}
)";
- CHECK_ERROR(text, TypeError, "Invalid mobile type.");
+ CHECK_ERROR(text, TypeError, "Invalid rational number.");
}
BOOST_AUTO_TEST_CASE(warns_msg_value_in_non_payable_public_function)
@@ -7096,6 +7096,53 @@ BOOST_AUTO_TEST_CASE(non_external_fallback)
CHECK_ERROR(text, TypeError, "Fallback function must be defined as \"external\".");
}
+BOOST_AUTO_TEST_CASE(invalid_literal_in_tuple)
+{
+ char const* text = R"(
+ contract C {
+ function f() pure public {
+ uint x;
+ (x, ) = (1E111);
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type");
+ text = R"(
+ contract C {
+ function f() pure public {
+ uint x;
+ (x, ) = (1, 1E111);
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Invalid rational number.");
+ text = R"(
+ contract C {
+ function f() pure public {
+ uint x;
+ (x, ) = (1E111, 1);
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Invalid rational number.");
+ text = R"(
+ contract C {
+ function f() pure public {
+ (2**270, 1);
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Invalid rational number.");
+ text = R"(
+ contract C {
+ function f() pure public {
+ ((2**270) / 2**100, 1);
+ }
+ }
+ )";
+ CHECK_SUCCESS(text);
+}
+
BOOST_AUTO_TEST_CASE(warn_about_sha3)
{
char const* text = R"(
diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp
index 80241519..6353ae8a 100644
--- a/test/libsolidity/ViewPureChecker.cpp
+++ b/test/libsolidity/ViewPureChecker.cpp
@@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(assembly)
assembly { x := 7 }
}
function g() view public {
- assembly { for {} 1 { pop(sload(0)) } { } }
+ assembly { for {} 1 { pop(sload(0)) } { } pop(gas) }
}
function h() view public {
assembly { function g() { pop(blockhash(20)) } }
@@ -357,6 +357,9 @@ BOOST_AUTO_TEST_CASE(assembly)
function j() public {
assembly { pop(call(0, 1, 2, 3, 4, 5, 6)) }
}
+ function k() public {
+ assembly { pop(call(gas, 1, 2, 3, 4, 5, 6)) }
+ }
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
@@ -367,7 +370,7 @@ BOOST_AUTO_TEST_CASE(assembly_staticcall)
string text = R"(
contract C {
function i() view public {
- assembly { pop(staticcall(0, 1, 2, 3, 4, 5)) }
+ assembly { pop(staticcall(gas, 1, 2, 3, 4, 5)) }
}
}
)";