diff options
author | chriseth <chris@ethereum.org> | 2018-05-16 16:22:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 16:22:03 +0800 |
commit | 23adea88fdc7eafc5b67b759b4c2418bd6b93aa6 (patch) | |
tree | a648418931273de87ada16443d3c18b739c76d76 /test/libsolidity/syntaxTests/specialFunctions | |
parent | 54839fdffbc32f1f918790b1e09143a410bd1c80 (diff) | |
parent | 03f60410c9ad57c90a327ffb6e8b6b722ec9c995 (diff) | |
download | dexon-solidity-23adea88fdc7eafc5b67b759b4c2418bd6b93aa6.tar dexon-solidity-23adea88fdc7eafc5b67b759b4c2418bd6b93aa6.tar.gz dexon-solidity-23adea88fdc7eafc5b67b759b4c2418bd6b93aa6.tar.bz2 dexon-solidity-23adea88fdc7eafc5b67b759b4c2418bd6b93aa6.tar.lz dexon-solidity-23adea88fdc7eafc5b67b759b4c2418bd6b93aa6.tar.xz dexon-solidity-23adea88fdc7eafc5b67b759b4c2418bd6b93aa6.tar.zst dexon-solidity-23adea88fdc7eafc5b67b759b4c2418bd6b93aa6.zip |
Merge pull request #4138 from ethereum/warnVarArgs
Warn when hash functions are used with var arguments
Diffstat (limited to 'test/libsolidity/syntaxTests/specialFunctions')
5 files changed, 20 insertions, 6 deletions
diff --git a/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol b/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol new file mode 100644 index 00000000..3f8e3014 --- /dev/null +++ b/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol @@ -0,0 +1,12 @@ +contract C { + function f() pure public { + g(keccak256(uint(2))); + g(sha256(uint(2))); + g(ripemd160(uint(2))); + } + function g(bytes32) pure internal {} +} +// ---- +// Warning: (54-72): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. +// Warning: (85-100): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. +// Warning: (113-131): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol index c98d7a57..b94a4391 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol @@ -1,11 +1,11 @@ contract C { function f() public pure { - bytes32 h = keccak256(keccak256, f, this.f.gas, block.blockhash); + bytes32 h = keccak256(abi.encodePacked(keccak256, f, this.f.gas, block.blockhash)); h; } } // ---- -// TypeError: (74-83): This type cannot be encoded. -// TypeError: (85-86): This type cannot be encoded. -// TypeError: (88-98): This type cannot be encoded. -// TypeError: (100-115): This type cannot be encoded. +// TypeError: (91-100): This type cannot be encoded. +// TypeError: (102-103): This type cannot be encoded. +// TypeError: (105-115): This type cannot be encoded. +// TypeError: (117-132): 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 fa910260..05f5db0b 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol @@ -9,5 +9,6 @@ contract C { } } // ---- +// Warning: (132-144): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. // 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 index 1187ce4a..977a7d73 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs_abiv2.sol @@ -12,5 +12,6 @@ contract C { } // ---- // Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments. +// Warning: (167-179): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. // TypeError: (174-175): This type cannot be encoded. // TypeError: (177-178): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_without_encoding_problems.sol b/test/libsolidity/syntaxTests/specialFunctions/types_without_encoding_problems.sol index c8364548..d890e35f 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_without_encoding_problems.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_without_encoding_problems.sol @@ -2,7 +2,7 @@ contract C { uint[3] sarr; function f() view public { uint[3] memory arr; - bytes32 h = keccak256(this.f, arr, sarr); + bytes32 h = keccak256(abi.encodePacked(this.f, arr, sarr)); h; } } |