Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusaaguiar committed Feb 6, 2025
1 parent 33f72b5 commit a3e17ed
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 8 deletions.
10 changes: 10 additions & 0 deletions test/cmdlineTests/storage_base_location_defined_ancestor/in.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract A layout at 0x1234 {
}

contract B is A {
}

contract C layout at 0x1234 is B {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"language": "Solidity",
"sources": {
"fileA": {"urls": ["storage_base_location_defined_ancestor/in.sol"]}
},
"settings": {
"outputSelection": {
"fileA": { "A": ["*"] }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"errors": [
{
"component": "general",
"errorCode": "8894",
"formattedMessage": "TypeError: Storage base location can only be specified in the most derived contract.
--> fileA:6:1:
|
6 | contract B is A {
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Storage base location was already specified here.
--> fileA:3:12:
|
3 | contract A layout at 0x1234 {
| ^^^^^^^^^^^^^^^^

",
"message": "Storage base location can only be specified in the most derived contract.",
"secondarySourceLocations": [
{
"end": 85,
"file": "fileA",
"message": "Storage base location was already specified here.",
"start": 69
}
],
"severity": "error",
"sourceLocation": {
"end": 110,
"file": "fileA",
"start": 91
},
"type": "TypeError"
},
{
"component": "general",
"errorCode": "8894",
"formattedMessage": "TypeError: Storage base location can only be specified in the most derived contract.
--> fileA:9:1:
|
9 | contract C layout at 0x1234 is B {
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Storage base location was already specified here.
--> fileA:3:12:
|
3 | contract A layout at 0x1234 {
| ^^^^^^^^^^^^^^^^

",
"message": "Storage base location can only be specified in the most derived contract.",
"secondarySourceLocations": [
{
"end": 85,
"file": "fileA",
"message": "Storage base location was already specified here.",
"start": 69
}
],
"severity": "error",
"sourceLocation": {
"end": 148,
"file": "fileA",
"start": 112
},
"type": "TypeError"
}
],
"sources": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract contract C layout at 0x123 {
}
// ----
// TypeError 7587: (20-35): Storage layout cannot be specified for abstract contracts or libraries
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract A layout at 0x1234 {}

contract B is A {}

contract C is B layout at 0xABCD {}
// ----
// TypeError 8894: (32-50): Storage layout can only be specified in the most derived contract.
// TypeError 8894: (52-87): Storage layout can only be specified in the most derived contract.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
contract C layout at ~0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE {}
// ----
// TypeError 1763: (21-88): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is int_const -115...(71 digits omitted)...9935 Cannot implicitly convert signed literal to unsigned type.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
contract A layout at 3/2 {}
// ----
// TypeError 1763: (21-24): Storage layout cannot be specified by a fractional number.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract A layout at 0x1234 {}

contract B is A {}

contract C is B {}
// ----
// TypeError 8894: (32-50): Storage layout can only be specified in the most derived contract.
// TypeError 8894: (52-70): Storage layout can only be specified in the most derived contract.
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
contract C layout at 0xffff * (0x123 + 0xABC) { }
// ====
// stopAfter: parsing
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bytes32 constant b = "bytes";
contract A layout at b[1] {}
// ----
// TypeError 1763: (51-55): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is bytes1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
uint constant X = 42;
contract C layout at 0xffff * (50 - X) { }
// ====
// stopAfter: parsing
// ----
// TypeError 6396: (43-60): The storage layout can only be specified by number literals.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ function erc7201(bytes memory id) pure returns (uint256) {
);
}
contract C layout at erc7201("C") { }
// ====
// stopAfter: parsing
// ----
// TypeError 1139: (212-224): The storage layout must be specified by an expression that can be evaluated at compilation time.
// TypeError 6396: (212-224): The storage layout can only be specified by number literals.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
contract C layout at 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF {}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
contract C layout at 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + 1 {}
// ----
// TypeError 1763: (21-91): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is int_const 1157...(70 digits omitted)...9936 Literal is too large to fit in uint256.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
contract A layout at 0 - 1 {}
// ----
// TypeError 1763: (21-26): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is int_const -1 Cannot implicitly convert signed literal to unsigned type.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function f(uint x) returns (uint) { return x + 1; }
contract A layout at f(2) {}
// ----
// TypeError 1139: (73-77): The storage layout must be specified by an expression that can be evaluated at compilation time.
// TypeError 6396: (73-77): The storage layout can only be specified by number literals.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
contract A { }
contract B { }
contract Z { }
contract C is A, B layout at 0x1234 { }
contract D layout at 0xABCD is A, B { }
contract D layout at 0xABCD is Z { }
// ----
// TypeError 2031: (70-109): Conflicting storage layout specifications:Storage layout for base contract 'A' was also specified by another contract which derives from it.
// TypeError 2031: (70-109): Conflicting storage layout specifications:Storage layout for base contract 'B' was also specified by another contract which derives from it.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library L layout at 0x123 {
function f() public pure { }
}
// ----
// TypeError 7587: (10-25): Storage layout cannot be specified for abstract contracts or libraries
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract A {}
contract B is A layout at 64 {}
contract C is A layout at 42 {}
// ----
// TypeError 2031: (46-77): Conflicting storage layout specifications:Storage layout for base contract 'A' was also specified by another contract which derives from it.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
contract A layout at 0x1234 {}
contract B layout at 1024 {}
contract C layout at "C" {}
contract C layout at 0 {}
// ----

0 comments on commit a3e17ed

Please # to comment.