aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorErik Kundt <bitshift@posteo.org>2018-07-27 03:45:24 +0800
committerchriseth <chris@ethereum.org>2018-09-04 00:35:57 +0800
commit75a92b0ffd0946c17a27a58e6e02abe96cd3fa00 (patch)
tree3a7c0b7e11942266eed23e7b2a0259fd5db1a56c /test
parent378f69160884ba23f6876d57a3eb6425bfa1d2cf (diff)
downloaddexon-solidity-75a92b0ffd0946c17a27a58e6e02abe96cd3fa00.tar
dexon-solidity-75a92b0ffd0946c17a27a58e6e02abe96cd3fa00.tar.gz
dexon-solidity-75a92b0ffd0946c17a27a58e6e02abe96cd3fa00.tar.bz2
dexon-solidity-75a92b0ffd0946c17a27a58e6e02abe96cd3fa00.tar.lz
dexon-solidity-75a92b0ffd0946c17a27a58e6e02abe96cd3fa00.tar.xz
dexon-solidity-75a92b0ffd0946c17a27a58e6e02abe96cd3fa00.tar.zst
dexon-solidity-75a92b0ffd0946c17a27a58e6e02abe96cd3fa00.zip
Warns if modifier uses msg.value in non-payable function.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_payable.sol4
-rw-r--r--test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_pure.sol6
-rw-r--r--test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_view.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol6
-rw-r--r--test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol6
5 files changed, 28 insertions, 0 deletions
diff --git a/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_payable.sol b/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_payable.sol
new file mode 100644
index 00000000..6e93626f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_payable.sol
@@ -0,0 +1,4 @@
+contract C {
+ modifier costs(uint _amount) { require(msg.value >= _amount); _; }
+ function f() costs(1 ether) public payable {}
+}
diff --git a/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_pure.sol b/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_pure.sol
new file mode 100644
index 00000000..398c127d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_pure.sol
@@ -0,0 +1,6 @@
+contract C {
+ modifier costs(uint _amount) { require(msg.value >= _amount); _; }
+ function f() costs(1 ether) public pure {}
+}
+// ----
+// TypeError: (101-115): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
diff --git a/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_view.sol b/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_view.sol
new file mode 100644
index 00000000..49a3139c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/memberLookup/msg_value_modifier_view.sol
@@ -0,0 +1,6 @@
+contract C {
+ modifier costs(uint _amount) { require(msg.value >= _amount); _; }
+ function f() costs(1 ether) public view {}
+}
+// ----
+// Warning: (101-115): This modifier uses "msg.value" and thus the function should be payable.
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol
new file mode 100644
index 00000000..160b20a7
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier.sol
@@ -0,0 +1,6 @@
+contract C {
+ modifier m(uint _amount, uint _avail) { require(_avail >= _amount); _; }
+ function f() m(1 ether, msg.value) public pure {}
+}
+// ----
+// TypeError: (118-127): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
diff --git a/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol
new file mode 100644
index 00000000..4cad4439
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPureChecker/msg_value_modifier_view.sol
@@ -0,0 +1,6 @@
+contract C {
+ modifier m(uint _amount, uint _avail) { require(_avail >= _amount); _; }
+ function f() m(1 ether, msg.value) public view {}
+}
+// ----
+// Warning: (118-127): "msg.value" used in non-payable function. Do you want to add the "payable" modifier to this function?