aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp62
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol2
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol2
-rw-r--r--test/libsolidity/syntaxTests/types/address/address_members_in_contract.sol (renamed from test/libsolidity/syntaxTests/types/address_members_in_contract.sol)0
-rw-r--r--test/libsolidity/syntaxTests/types/address/address_to_contract.sol (renamed from test/libsolidity/syntaxTests/types/address_to_contract.sol)0
-rw-r--r--test/libsolidity/syntaxTests/types/address/contract_to_address.sol (renamed from test/libsolidity/syntaxTests/types/contract_to_address.sol)0
-rw-r--r--test/libsolidity/syntaxTests/types/address/contract_to_address_implicitly.sol (renamed from test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol)0
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol2
8 files changed, 60 insertions, 8 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 6be9d95b..642c9929 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2215,7 +2215,7 @@ BOOST_AUTO_TEST_CASE(send_ether)
char const* sourceCode = R"(
contract test {
constructor() payable public {}
- function a(address addr, uint amount) public returns (uint ret) {
+ function a(address payable addr, uint amount) public returns (uint ret) {
addr.send(amount);
return address(this).balance;
}
@@ -2233,11 +2233,11 @@ BOOST_AUTO_TEST_CASE(transfer_ether)
char const* sourceCode = R"(
contract A {
constructor() public payable {}
- function a(address addr, uint amount) public returns (uint) {
+ function a(address payable addr, uint amount) public returns (uint) {
addr.transfer(amount);
return address(this).balance;
}
- function b(address addr, uint amount) public {
+ function b(address payable addr, uint amount) public {
addr.transfer(amount);
}
}
@@ -2406,7 +2406,7 @@ BOOST_AUTO_TEST_CASE(selfdestruct)
char const* sourceCode = R"(
contract test {
constructor() public payable {}
- function a(address receiver) public returns (uint ret) {
+ function a(address payable receiver) public returns (uint ret) {
selfdestruct(receiver);
return 10;
}
@@ -7151,7 +7151,7 @@ BOOST_AUTO_TEST_CASE(failing_send)
}
contract Main {
constructor() public payable {}
- function callHelper(address _a) public returns (bool r, uint bal) {
+ function callHelper(address payable _a) public returns (bool r, uint bal) {
r = !_a.send(5);
bal = address(this).balance;
}
@@ -8838,7 +8838,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library)
library lib {}
contract c {
constructor() public payable {}
- function f(address x) public returns (bool) {
+ function f(address payable x) public returns (bool) {
return x.send(1);
}
function () external payable {}
@@ -10095,6 +10095,54 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types_shortening)
ABI_CHECK(callContractFunction("f()"), encodeArgs("\xff\xff\xff\xff"));
}
+BOOST_AUTO_TEST_CASE(cleanup_address_types)
+{
+ // Checks that address types are properly cleaned before they are compared.
+ char const* sourceCode = R"(
+ contract C {
+ function f(address a) public returns (uint) {
+ if (a != 0x1234567890123456789012345678901234567890) return 1;
+ return 0;
+ }
+ function g(address payable a) public returns (uint) {
+ if (a != 0x1234567890123456789012345678901234567890) return 1;
+ return 0;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ // We input longer data on purpose.
+ ABI_CHECK(callContractFunction("f(address)", u256("0xFFFF1234567890123456789012345678901234567890")), encodeArgs(0));
+ ABI_CHECK(callContractFunction("g(address)", u256("0xFFFF1234567890123456789012345678901234567890")), encodeArgs(0));
+}
+
+BOOST_AUTO_TEST_CASE(cleanup_address_types_shortening)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() public pure returns (address r) {
+ bytes21 x = 0x1122334455667788990011223344556677889900ff;
+ bytes20 y;
+ assembly { y := x }
+ address z = address(y);
+ assembly { r := z }
+ require(z == 0x1122334455667788990011223344556677889900);
+ }
+ function g() public pure returns (address payable r) {
+ bytes21 x = 0x1122334455667788990011223344556677889900ff;
+ bytes20 y;
+ assembly { y := x }
+ address payable z = address(y);
+ assembly { r := z }
+ require(z == 0x1122334455667788990011223344556677889900);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(u256("0x1122334455667788990011223344556677889900")));
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(u256("0x1122334455667788990011223344556677889900")));
+}
+
BOOST_AUTO_TEST_CASE(skip_dynamic_types)
{
// The EVM cannot provide access to dynamically-sized return values, so we have to skip them.
@@ -12446,7 +12494,7 @@ BOOST_AUTO_TEST_CASE(interface_contract)
}
contract C {
- function f(address _interfaceAddress) public returns (bool) {
+ function f(address payable _interfaceAddress) public returns (bool) {
I i = I(_interfaceAddress);
return i.f();
}
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol
index b63d2a55..ad57224c 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol
@@ -1,6 +1,6 @@
contract C {
function f() public {
- address addr;
+ address payable addr;
uint balance = addr.balance;
(bool callSuc,) = addr.call("");
(bool delegatecallSuc,) = addr.delegatecall("");
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol
index 157ea36b..01b7b294 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol
@@ -6,6 +6,8 @@ contract C {
function transfer(uint amount) public {
address(this).transfer(amount); // to avoid pureness warning
}
+ function() payable external {
+ }
}
contract D {
function f() public {
diff --git a/test/libsolidity/syntaxTests/types/address_members_in_contract.sol b/test/libsolidity/syntaxTests/types/address/address_members_in_contract.sol
index eafc8268..eafc8268 100644
--- a/test/libsolidity/syntaxTests/types/address_members_in_contract.sol
+++ b/test/libsolidity/syntaxTests/types/address/address_members_in_contract.sol
diff --git a/test/libsolidity/syntaxTests/types/address_to_contract.sol b/test/libsolidity/syntaxTests/types/address/address_to_contract.sol
index 629a3df0..629a3df0 100644
--- a/test/libsolidity/syntaxTests/types/address_to_contract.sol
+++ b/test/libsolidity/syntaxTests/types/address/address_to_contract.sol
diff --git a/test/libsolidity/syntaxTests/types/contract_to_address.sol b/test/libsolidity/syntaxTests/types/address/contract_to_address.sol
index ec2f8184..ec2f8184 100644
--- a/test/libsolidity/syntaxTests/types/contract_to_address.sol
+++ b/test/libsolidity/syntaxTests/types/address/contract_to_address.sol
diff --git a/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol b/test/libsolidity/syntaxTests/types/address/contract_to_address_implicitly.sol
index 8be9daac..8be9daac 100644
--- a/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol
+++ b/test/libsolidity/syntaxTests/types/address/contract_to_address_implicitly.sol
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol
index f951feb4..5356f0b8 100644
--- a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol
+++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol
@@ -16,6 +16,8 @@ contract C {
(bool success,) = address(this).call("");
require(success);
}
+ function() payable external {
+ }
}
// ----
// TypeError: (52-77): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.