aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/syntaxTests
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-13 02:55:03 +0800
committerGitHub <noreply@github.com>2018-04-13 02:55:03 +0800
commit44416d1ac65b2cfae4bb15d39bc84b1a78211baa (patch)
tree7b8ee302e1c4f0604f29d2fe21a2d0393cc60d11 /test/libsolidity/syntaxTests
parent7453ff0f3a94ce4ddce55cdbb77146dd75a01e1c (diff)
parent75b88286667690ffb4a5e079665ed8b70bcaeb87 (diff)
downloaddexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar
dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar.gz
dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar.bz2
dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar.lz
dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar.xz
dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar.zst
dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.zip
Merge pull request #2980 from ethereum/abi-api
Add abi.encode and abi.encodePacked
Diffstat (limited to 'test/libsolidity/syntaxTests')
-rw-r--r--test/libsolidity/syntaxTests/functionCalls/arbitrary_parameters_but_restricted_first_type.sol13
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs.sol17
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs_abiv2.sol18
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol9
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol16
-rw-r--r--test/libsolidity/syntaxTests/tight_packing_literals.sol25
-rw-r--r--test/libsolidity/syntaxTests/tight_packing_literals_fine.sol11
-rw-r--r--test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol8
-rw-r--r--test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol36
9 files changed, 148 insertions, 5 deletions
diff --git a/test/libsolidity/syntaxTests/functionCalls/arbitrary_parameters_but_restricted_first_type.sol b/test/libsolidity/syntaxTests/functionCalls/arbitrary_parameters_but_restricted_first_type.sol
new file mode 100644
index 00000000..94da5881
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionCalls/arbitrary_parameters_but_restricted_first_type.sol
@@ -0,0 +1,13 @@
+contract C {
+ function f() pure public {
+ abi.encodeWithSelector();
+ abi.encodeWithSignature();
+ abi.encodeWithSelector(uint(2), 2);
+ abi.encodeWithSignature(uint(2), 2);
+ }
+}
+// ----
+// TypeError: (52-76): Need at least 1 arguments for function call, but provided only 0.
+// TypeError: (86-111): Need at least 1 arguments for function call, but provided only 0.
+// TypeError: (144-151): Invalid type for argument in function call. Invalid implicit conversion from uint256 to bytes4 requested.
+// TypeError: (189-196): Invalid type for argument in function call. Invalid implicit conversion from uint256 to string memory requested.
diff --git a/test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs.sol b/test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs.sol
new file mode 100644
index 00000000..d9eebee4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs.sol
@@ -0,0 +1,17 @@
+contract C {
+ struct S { uint x; }
+ S s;
+ struct T { uint y; }
+ T t;
+ function f() public view {
+ abi.encode(s, t);
+ }
+ function g() public view {
+ abi.encodePacked(s, t);
+ }
+}
+// ----
+// TypeError: (131-132): This type cannot be encoded.
+// TypeError: (134-135): This type cannot be encoded.
+// TypeError: (200-201): This type cannot be encoded.
+// TypeError: (203-204): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs_abiv2.sol b/test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs_abiv2.sol
new file mode 100644
index 00000000..d6cf60e4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs_abiv2.sol
@@ -0,0 +1,18 @@
+pragma experimental ABIEncoderV2;
+
+contract C {
+ struct S { uint x; }
+ S s;
+ struct T { uint y; }
+ T t;
+ function f() public view {
+ abi.encode(s, t);
+ }
+ function g() public view {
+ abi.encodePacked(s, t);
+ }
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
+// TypeError: (235-236): This type cannot be encoded.
+// TypeError: (238-239): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol
index cc354819..fa910260 100644
--- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol
+++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol
@@ -1,14 +1,13 @@
contract C {
struct S { uint x; }
S s;
- struct T { }
+ struct T { uint y; }
T t;
- function f() public pure {
+ function f() public view {
bytes32 a = sha256(s, t);
a;
}
}
// ----
-// Warning: (51-63): Defining empty structs is deprecated.
-// TypeError: (131-132): This type cannot be encoded.
-// TypeError: (134-135): This type cannot be encoded.
+// TypeError: (139-140): This type cannot be encoded.
+// TypeError: (142-143): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol
new file mode 100644
index 00000000..1187ce4a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol
@@ -0,0 +1,16 @@
+pragma experimental ABIEncoderV2;
+
+contract C {
+ struct S { uint x; }
+ S s;
+ struct T { uint y; }
+ T t;
+ function f() public view {
+ bytes32 a = sha256(s, t);
+ a;
+ }
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
+// TypeError: (174-175): This type cannot be encoded.
+// TypeError: (177-178): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/tight_packing_literals.sol b/test/libsolidity/syntaxTests/tight_packing_literals.sol
new file mode 100644
index 00000000..8258a8a6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/tight_packing_literals.sol
@@ -0,0 +1,25 @@
+contract C {
+ function f() pure public returns (bytes32) {
+ return keccak256(1);
+ }
+ function g() pure public returns (bytes32) {
+ return sha3(1);
+ }
+ function h() pure public returns (bytes32) {
+ return sha256(1);
+ }
+ function j() pure public returns (bytes32) {
+ return ripemd160(1);
+ }
+ function k() pure public returns (bytes) {
+ return abi.encodePacked(1);
+ }
+}
+
+// ----
+// Warning: (87-88): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
+// Warning: (161-168): "sha3" has been deprecated in favour of "keccak256"
+// Warning: (166-167): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
+// Warning: (247-248): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
+// Warning: (331-332): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
+// Warning: (420-421): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
diff --git a/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol b/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol
new file mode 100644
index 00000000..46407f71
--- /dev/null
+++ b/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol
@@ -0,0 +1,11 @@
+contract C {
+ function f() pure public returns (bytes32) {
+ return keccak256(uint8(1));
+ }
+ function g() pure public returns (bytes) {
+ return abi.encode(1);
+ }
+ function h() pure public returns (bytes) {
+ return abi.encodePacked(uint8(1));
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol
new file mode 100644
index 00000000..ca7db42e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() pure public returns (bytes r) {
+ r = abi.encode(1, 2);
+ r = abi.encodePacked(f());
+ r = abi.encodeWithSelector(0x12345678, 1);
+ r = abi.encodeWithSignature("f(uint256)", 4);
+ }
+}
diff --git a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol
new file mode 100644
index 00000000..547362c3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol
@@ -0,0 +1,36 @@
+contract C {
+ uint x;
+ function gView() public view returns (uint) { return x; }
+ function gNonPayable() public returns (uint) { x = 4; return 0; }
+
+ function f1() view public returns (bytes) {
+ return abi.encode(gView());
+ }
+ function f2() view public returns (bytes) {
+ return abi.encodePacked(gView());
+ }
+ function f3() view public returns (bytes) {
+ return abi.encodeWithSelector(0x12345678, gView());
+ }
+ function f4() view public returns (bytes) {
+ return abi.encodeWithSignature("f(uint256)", gView());
+ }
+ function g1() public returns (bytes) {
+ return abi.encode(gNonPayable());
+ }
+ function g2() public returns (bytes) {
+ return abi.encodePacked(gNonPayable());
+ }
+ function g3() public returns (bytes) {
+ return abi.encodeWithSelector(0x12345678, gNonPayable());
+ }
+ function g4() public returns (bytes) {
+ return abi.encodeWithSignature("f(uint256)", gNonPayable());
+ }
+ // This will generate the only warning.
+ function check() public returns (bytes) {
+ return abi.encode(2);
+ }
+}
+// ----
+// Warning: (1044-1121): Function state mutability can be restricted to pure