From 44c0d7ca5e1d97027e4f1e24fb02fd805eda578d Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 21 Mar 2018 14:45:32 +0100 Subject: Tests. --- .../syntaxTests/tight_packing_literals.sol | 25 ++++++++++++++++++++++ .../syntaxTests/tight_packing_literals_fine.sol | 11 ++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/libsolidity/syntaxTests/tight_packing_literals.sol create mode 100644 test/libsolidity/syntaxTests/tight_packing_literals_fine.sol (limited to 'test/libsolidity/syntaxTests') 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)); + } +} -- cgit v1.2.3 From c4a6a63f362f478414ac886ed6e5e159038460aa Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 21 Mar 2018 18:38:06 +0100 Subject: Tests for view and pure. --- .../syntaxTests/viewPure/view_pure_abi_encode.sol | 8 +++++ .../viewPure/view_pure_abi_encode_arguments.sol | 36 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol create mode 100644 test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol (limited to 'test/libsolidity/syntaxTests') 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 -- cgit v1.2.3 From 7343c4028365d3fbc9fa46fca6078971a2bed426 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 21 Mar 2018 19:07:15 +0100 Subject: Check partial function parameters if rest is arbitrary. --- .../arbitrary_parameters_but_restricted_first_type.sol | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/libsolidity/syntaxTests/functionCalls/arbitrary_parameters_but_restricted_first_type.sol (limited to 'test/libsolidity/syntaxTests') 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. -- cgit v1.2.3 From 75b88286667690ffb4a5e079665ed8b70bcaeb87 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 5 Apr 2018 15:52:25 +0200 Subject: Allow struct encoding with new encoder. --- .../specialFunctions/abi_encode_structs.sol | 17 +++++++++++++++++ .../specialFunctions/abi_encode_structs_abiv2.sol | 18 ++++++++++++++++++ .../types_with_unspecified_encoding_structs.sol | 9 ++++----- .../types_with_unspecified_encoding_structs_abiv2.sol | 16 ++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs.sol create mode 100644 test/libsolidity/syntaxTests/specialFunctions/abi_encode_structs_abiv2.sol create mode 100644 test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol (limited to 'test/libsolidity/syntaxTests') 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. -- cgit v1.2.3