Tests checking outputs produced in presence of errors

This commit is contained in:
Kamil Śliwak 2023-06-14 08:47:45 +02:00
parent 374a6fd50e
commit f50820fcae
20 changed files with 602 additions and 0 deletions

View File

@ -0,0 +1 @@
--allow-paths .

View File

@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;
contract C {
// This will trigger a fatal error at the analysis stage, of the kind that terminates analysis
// immediately without letting the current step finish.
constructor(uint[] storage) {}
}

View File

@ -0,0 +1,14 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_analysis_error_fatal/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}

View File

@ -0,0 +1,26 @@
{
"errors":
[
{
"component": "general",
"errorCode": "3644",
"formattedMessage": "TypeError: This parameter has a type that can only be used internally. You can make the contract abstract to avoid this problem.
--> C:7:17:
|
7 | constructor(uint[] storage) {}
| ^^^^^^^^^^^^^^
",
"message": "This parameter has a type that can only be used internally. You can make the contract abstract to avoid this problem.",
"severity": "error",
"sourceLocation":
{
"end": 258,
"file": "C",
"start": 244
},
"type": "TypeError"
}
],
"sources": {}
}

View File

@ -0,0 +1 @@
--allow-paths .

View File

@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;
// This will trigger a fatal error at the analysis stage, of the kind that lets the current
// analysis steps finish but terminates analysis after immediately after that step.
function f(uint immutable x) {}

View File

@ -0,0 +1,14 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_analysis_error_fatal_after_current_step/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}

View File

@ -0,0 +1,127 @@
{
"errors":
[
{
"component": "general",
"errorCode": "8297",
"formattedMessage": "DeclarationError: The \"immutable\" keyword can only be used for state variables.
--> C:6:12:
|
6 | function f(uint immutable x) {}
| ^^^^^^^^^^^^^^^^
",
"message": "The \"immutable\" keyword can only be used for state variables.",
"severity": "error",
"sourceLocation":
{
"end": 259,
"file": "C",
"start": 243
},
"type": "DeclarationError"
}
],
"sources":
{
"C":
{
"ast":
{
"absolutePath": "C",
"exportedSymbols":
{
"f":
[
7
]
},
"id": 8,
"license": "GPL-3.0",
"nodeType": "SourceUnit",
"nodes":
[
{
"id": 1,
"literals":
[
"solidity",
"*"
],
"nodeType": "PragmaDirective",
"src": "36:18:0"
},
{
"body":
{
"id": 6,
"nodeType": "Block",
"src": "261:2:0",
"statements": []
},
"id": 7,
"implemented": true,
"kind": "freeFunction",
"modifiers": [],
"name": "f",
"nameLocation": "241:1:0",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 4,
"nodeType": "ParameterList",
"parameters":
[
{
"constant": false,
"id": 3,
"mutability": "immutable",
"name": "x",
"nameLocation": "258:1:0",
"nodeType": "VariableDeclaration",
"scope": 7,
"src": "243:16:0",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName":
{
"id": 2,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "243:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
}
],
"src": "242:18:0"
},
"returnParameters":
{
"id": 5,
"nodeType": "ParameterList",
"parameters": [],
"src": "261:0:0"
},
"scope": 8,
"src": "232:31:0",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "internal"
}
],
"src": "36:228:0"
},
"id": 0
}
}
}

View File

@ -0,0 +1 @@
--allow-paths .

View File

@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;
contract C {
// This will trigger a non-fatal error at the analysis stage.
// With this kind of error we still run subsequent analysis stages.
uint x;
string y = x;
}

View File

@ -0,0 +1,14 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_analysis_error_non_fatal/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}

View File

@ -0,0 +1,26 @@
{
"errors":
[
{
"component": "general",
"errorCode": "7407",
"formattedMessage": "TypeError: Type uint256 is not implicitly convertible to expected type string storage ref.
--> C:8:16:
|
8 | string y = x;
| ^
",
"message": "Type uint256 is not implicitly convertible to expected type string storage ref.",
"severity": "error",
"sourceLocation":
{
"end": 235,
"file": "C",
"start": 234
},
"type": "TypeError"
}
],
"sources": {}
}

View File

@ -0,0 +1 @@
--allow-paths .

View File

@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;
contract C {
// This will trigger an error at the compilation stage.
// CodeGenerationError due to immutable initialization in constructor being optimized out.
uint immutable public x;
constructor() {
x = 0;
while (true) {}
}
}

View File

@ -0,0 +1,15 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_compilation_error/in.sol"]}
},
"settings": {
"optimizer": {"enabled": true},
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}

View File

@ -0,0 +1,280 @@
{
"contracts":
{
"C":
{
"C":
{
"abi":
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "x",
"outputs":
[
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
],
"devdoc":
{
"kind": "dev",
"methods": {},
"version": 1
},
"evm":
{
"methodIdentifiers":
{
"x()": "0c55699c"
}
},
"metadata": "{\"compiler\":{\"version\":\"<VERSION REMOVED>\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"x\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"C\":\"C\"},\"evmVersion\":\"shanghai\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"C\":{\"keccak256\":\"0x67a13ebd685e4c6f792e71eb747dac57edb99e94d04d841ee6c979ae517934ce\",\"license\":\"GPL-3.0\",\"urls\":[\"bzz-raw://665b000da768823654f680d02686c1e59d682a0b3882e43a77fed9f80ce64ae8\",\"dweb:/ipfs/QmVnKvuidH6KiCdNQpoAQUtDbB8hXkafVLXWMNitUcxnqC\"]}},\"version\":1}",
"storageLayout":
{
"storage": [],
"types": null
},
"userdoc":
{
"kind": "user",
"methods": {},
"version": 1
}
}
}
},
"errors":
[
{
"component": "general",
"errorCode": "1284",
"formattedMessage": "CodeGenerationError: Some immutables were read from but never assigned, possibly because of optimization.
",
"message": "Some immutables were read from but never assigned, possibly because of optimization.",
"severity": "error",
"type": "CodeGenerationError"
}
],
"sources":
{
"C":
{
"ast":
{
"absolutePath": "C",
"exportedSymbols":
{
"C":
[
15
]
},
"id": 16,
"license": "GPL-3.0",
"nodeType": "SourceUnit",
"nodes":
[
{
"id": 1,
"literals":
[
"solidity",
"*"
],
"nodeType": "PragmaDirective",
"src": "36:18:0"
},
{
"abstract": false,
"baseContracts": [],
"canonicalName": "C",
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 15,
"linearizedBaseContracts":
[
15
],
"name": "C",
"nameLocation": "65:1:0",
"nodeType": "ContractDefinition",
"nodes":
[
{
"constant": false,
"functionSelector": "0c55699c",
"id": 3,
"mutability": "immutable",
"name": "x",
"nameLocation": "250:1:0",
"nodeType": "VariableDeclaration",
"scope": 15,
"src": "228:23:0",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName":
{
"id": 2,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "228:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "public"
},
{
"body":
{
"id": 13,
"nodeType": "Block",
"src": "272:46:0",
"statements":
[
{
"expression":
{
"id": 8,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide":
{
"id": 6,
"name": "x",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 3,
"src": "282:1:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"nodeType": "Assignment",
"operator": "=",
"rightHandSide":
{
"hexValue": "30",
"id": 7,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "286:1:0",
"typeDescriptions":
{
"typeIdentifier": "t_rational_0_by_1",
"typeString": "int_const 0"
},
"value": "0"
},
"src": "282:5:0",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"id": 9,
"nodeType": "ExpressionStatement",
"src": "282:5:0"
},
{
"body":
{
"id": 11,
"nodeType": "Block",
"src": "310:2:0",
"statements": []
},
"condition":
{
"hexValue": "74727565",
"id": 10,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "bool",
"lValueRequested": false,
"nodeType": "Literal",
"src": "304:4:0",
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
},
"value": "true"
},
"id": 12,
"nodeType": "WhileStatement",
"src": "297:15:0"
}
]
},
"id": 14,
"implemented": true,
"kind": "constructor",
"modifiers": [],
"name": "",
"nameLocation": "-1:-1:-1",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 4,
"nodeType": "ParameterList",
"parameters": [],
"src": "269:2:0"
},
"returnParameters":
{
"id": 5,
"nodeType": "ParameterList",
"parameters": [],
"src": "272:0:0"
},
"scope": 15,
"src": "258:60:0",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"scope": 16,
"src": "56:264:0",
"usedErrors": [],
"usedEvents": []
}
],
"src": "36:285:0"
},
"id": 0
}
}
}

View File

@ -0,0 +1 @@
--allow-paths .

View File

@ -0,0 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity *;
// This will trigger an error at the parsing stage
contract C {}}

View File

@ -0,0 +1,14 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_outputs_on_parsing_error/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {
"*": ["*"],
"": ["*"]
}
}
}
}

View File

@ -0,0 +1,26 @@
{
"errors":
[
{
"component": "general",
"errorCode": "7858",
"formattedMessage": "ParserError: Expected pragma, import directive or contract/interface/library/struct/enum/constant/function/error definition.
--> C:5:14:
|
5 | contract C {}}
| ^
",
"message": "Expected pragma, import directive or contract/interface/library/struct/enum/constant/function/error definition.",
"severity": "error",
"sourceLocation":
{
"end": 121,
"file": "C",
"start": 120
},
"type": "ParserError"
}
],
"sources": {}
}