-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14103 from ethereum/extra-tests
A few extra tests for operators, denominations and virtual functions
- Loading branch information
Showing
9 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
test/libsolidity/semanticTests/literals/denominations_in_array_sizes.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
contract C { | ||
uint[2 wei] a; | ||
uint[2 gwei] b; | ||
uint[2 ether] c; | ||
uint[2 seconds] d; | ||
uint[2 minutes] e; | ||
uint[2 hours] f; | ||
uint[2 days] g; | ||
uint[2 weeks] h; | ||
|
||
function lengths() public returns (uint, uint, uint, uint, uint, uint, uint, uint) { | ||
return ( | ||
a.length, | ||
b.length, | ||
c.length, | ||
d.length, | ||
e.length, | ||
f.length, | ||
g.length, | ||
h.length | ||
); | ||
} | ||
} | ||
// ---- | ||
// lengths() -> 2, 2000000000, 2000000000000000000, 2, 120, 7200, 172800, 1209600 |
15 changes: 15 additions & 0 deletions
15
test/libsolidity/semanticTests/literals/fractional_denominations.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
contract C { | ||
uint public g = 1.5 gwei; | ||
uint public e = 1.5 ether; | ||
uint public m = 1.5 minutes; | ||
uint public h = 1.5 hours; | ||
uint public d = 1.5 days; | ||
uint public w = 1.5 weeks; | ||
} | ||
// ---- | ||
// g() -> 1500000000 | ||
// e() -> 1500000000000000000 | ||
// m() -> 90 | ||
// h() -> 5400 | ||
// d() -> 129600 | ||
// w() -> 907200 |
22 changes: 22 additions & 0 deletions
22
...manticTests/operators/userDefined/operator_parameter_and_return_cleanup_between_calls.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
type U8 is uint8; | ||
using {yoloAdd as +, yoloDiv as /} for U8 global; | ||
|
||
function yoloAdd(U8 x, U8 y) pure returns (U8 z) { | ||
assembly { | ||
z := add(x, y) // Wrong! No cleanup. | ||
} | ||
} | ||
|
||
function yoloDiv(U8 x, U8 y) pure returns (U8 z) { | ||
assembly { | ||
z := div(x, y) // Wrong! No cleanup. | ||
} | ||
} | ||
|
||
contract C { | ||
function divAddNoOverflow(U8 a, U8 b, U8 c) external pure returns (U8) { | ||
return a / (b + c); | ||
} | ||
} | ||
// ---- | ||
// divAddNoOverflow(uint8,uint8,uint8): 4, 0xff, 3 -> 0 |
23 changes: 23 additions & 0 deletions
23
...solidity/semanticTests/virtualFunctions/virtual_override_changing_mutability_internal.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
contract A { | ||
function f() internal virtual { | ||
mutableWithViewOverride(); | ||
mutableWithPureOverride(); | ||
viewWithPureOverride(); | ||
} | ||
|
||
function mutableWithViewOverride() internal virtual {} | ||
function mutableWithPureOverride() internal virtual {} | ||
function viewWithPureOverride() internal view virtual {} | ||
} | ||
|
||
contract C is A { | ||
function run() public { | ||
f(); | ||
} | ||
|
||
function mutableWithViewOverride() internal view override {} | ||
function mutableWithPureOverride() internal pure override {} | ||
function viewWithPureOverride() internal pure override {} | ||
} | ||
// ---- | ||
// run() -> |
23 changes: 23 additions & 0 deletions
23
...ibsolidity/semanticTests/virtualFunctions/virtual_override_changing_mutability_public.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
contract A { | ||
function f() internal virtual { | ||
mutableWithViewOverride(); | ||
mutableWithPureOverride(); | ||
viewWithPureOverride(); | ||
} | ||
|
||
function mutableWithViewOverride() public virtual {} | ||
function mutableWithPureOverride() public virtual {} | ||
function viewWithPureOverride() public view virtual {} | ||
} | ||
|
||
contract C is A { | ||
function run() public { | ||
f(); | ||
} | ||
|
||
function mutableWithViewOverride() public view override {} | ||
function mutableWithPureOverride() public pure override {} | ||
function viewWithPureOverride() public pure override {} | ||
} | ||
// ---- | ||
// run() -> |
12 changes: 12 additions & 0 deletions
12
test/libsolidity/syntaxTests/denominations/denominations_in_array_sizes.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
contract C { | ||
uint[42 wei] a; | ||
uint[42 gwei] b; | ||
uint[42 ether] c; | ||
uint[42 seconds] d; | ||
uint[42 minutes] e; | ||
uint[42 hours] f; | ||
uint[42 days] g; | ||
uint[42 weeks] h; | ||
} | ||
// ---- | ||
// Warning 7325: (58-72): Type uint256[42000000000000000000] covers a large part of storage and thus makes collisions likely. Either use mappings or dynamic arrays and allow their size to be increased only in small quantities per transaction. |
5 changes: 5 additions & 0 deletions
5
test/libsolidity/syntaxTests/denominations/invalid_denomination_address.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract C { | ||
address a = 0x11111122222333334444455555666667777788888 wei; | ||
} | ||
// ---- | ||
// TypeError 5145: (26-73): Hexadecimal numbers cannot be used with unit denominations. You can use an expression of the form "0x1234 * 1 day" instead. |
5 changes: 5 additions & 0 deletions
5
test/libsolidity/syntaxTests/denominations/invalid_denomination_on_bool.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract C { | ||
bool constant x = true ether; | ||
} | ||
// ---- | ||
// ParserError 2314: (37-42): Expected ';' but got 'ether' |
5 changes: 5 additions & 0 deletions
5
test/libsolidity/syntaxTests/denominations/invalid_denomination_on_string.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract C { | ||
string s = "abc" ether; | ||
} | ||
// ---- | ||
// ParserError 2314: (31-36): Expected ';' but got 'ether' |