Skip to content

Commit

Permalink
e2e tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Oct 23, 2023
1 parent 5e881bd commit bd6c675
Show file tree
Hide file tree
Showing 29 changed files with 885 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Changelog and docs for `no-empty-blocks` rule to clarify its functionality

### Added
- `fixShow` option to show report. `fix` option skips showing report on screen
- `fix` option now shows the report on screen
- `save` option to store report on disk with the standard or the specified format
- Check for updates on Solhint version to keep users with the last versin available. There's an option to disable this check (`--disc`)
- Autofix for `explicit-types` rule [504](https://github.com/protofire/solhint/pull/504)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Options:
-q, --quiet report errors only - default: false
--ignore-path [file_name] file to use as your .solhintignore
--fix automatically fix problems. Skip report
--fixShow automatically fix problems. Show report
--noPrompt do not suggest to backup files when any `fix` option is selected
--init create configuration file for solhint
--disc do not check for solhint updates
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/best-practises/explicit-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This rule accepts an array of options:
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` or `--fixShow` option
- Solhint allows this rule to automatically fix the code with `--fix` option

## Examples
### 👍 Examples of **correct** code for this rule
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/naming/private-vars-leading-underscore.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: "private-vars-leading-underscore | Solhint"
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)

## Description
Non-external functions and state variables should start with a single underscore. Others, shouldn't.
Non-external functions and state variables should start with a single underscore. Others, shouldn't

## Options
This rule accepts an array of options:
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/security/avoid-sha3.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` or `--fixShow` option
- Solhint allows this rule to automatically fix the code with `--fix` option

## Examples
This rule does not have examples.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/security/avoid-throw.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` or `--fixShow` option
- Solhint allows this rule to automatically fix the code with `--fix` option

## Examples
This rule does not have examples.
Expand Down
5 changes: 5 additions & 0 deletions e2e/08-autofix/contracts/00-generic/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"explicit-types": ["error", "explicit"]
}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/contracts/00-generic/Foo1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/contracts/00-generic/Foo1AfterFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint256 public hola;
uint256 public hola2;
int256 public constant hola3 = 2;
ufixed128x18 hola4;
fixed128x18 internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/contracts/00-generic/Foo1BeforeFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
83 changes: 83 additions & 0 deletions e2e/08-autofix/contracts/Foo1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
pragma solidity 0.8.0;

library libraryName {
uint256 internal lzarasa1;
uint256 internal lzarasa2 = 2;
uint256 internal _lzarasa3;
uint256 private lzarasa4;
uint256 private lzarasa5 = 5;
uint256 private _lzarasa6;

uint256 public _lzarasa7;
uint256 public _lzarasa8 = 8;
uint256 public lzarasa9;

function fofo() public {}
function _fofo() public {}
function _fofo() internal {}
function fofo() internal {}
}

contract Foo1 {
uint256 internal zarasa1;
uint256 internal zarasa2 = 2;
uint256 internal _zarasa3;
uint256 private zarasa4;
uint256 private zarasa5 = 5;
uint256 private _zarasa6;

uint256 public _zarasa7;
uint256 public _zarasa8 = 8;
uint256 public zarasa9;

address payable internal constant zarasa10 = '0x0';
address public constant _zarasa11 = '0x0';
uint256 public immutable _zarasa12 = 2;
uint256 _zarasa13;
uint256 zarasa14;

mapping(address => uint256) internal zarMapping1;
mapping(address => uint256) public _zarMapping2;
mapping(address => uint256) internal _zarMapping3;
mapping(address => uint256) public zarMapping4;

function fooA(uint bar) internal payable onlyOwner returns (uint256 barA) {
uint256 zarasaFunc;
}

function fooB(uint bar) private onlyOwner returns (uint256 _barB) {
uint256 zarasaFunc;
}

function fooC(uint bar) private onlyOwner returns (uint256 _barC) {
uint256 zarasaFunc;
}

function fooD(uint bar) external onlyOwner {
uint256 zarasaFunc;
}

function fooE(uint bar) public onlyOwner {
uint256 zarasaFunc;
}

function fooF(uint bar) onlyOwner returns (uint256 _barF) {
uint256 zarasaFunc;
}

function fooG(uint bar) onlyOwner {
uint256 zarasaFunc;
}

function _fooH(uint bar) external onlyOwner {
uint256 zarasaFunc;
}

function _fooI(uint bar) public onlyOwner {
uint256 zarasaFunc;
}

function _fooJ(uint bar) onlyOwner returns (uint256 barJ) {
uint256 zarasaFunc;
}
}
5 changes: 5 additions & 0 deletions e2e/08-autofix/contracts/explicit-types/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"explicit-types": ["error", "explicit"]
}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/contracts/explicit-types/Foo1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/contracts/explicit-types/Foo1AfterFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint256 public hola;
uint256 public hola2;
int256 public constant hola3 = 2;
ufixed128x18 hola4;
fixed128x18 internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
22 changes: 22 additions & 0 deletions e2e/08-autofix/contracts/explicit-types/Foo1BeforeFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {ERC20Burnable} from '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol';

contract Foo1 is ERC20Burnable {
uint public hola;
uint public hola2;
int public constant hola3 = 2;
ufixed hola4;
fixed internal hola5;

constructor() ERC20('MyToken', 'MTK') {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}

function zarasa() {}
}
5 changes: 5 additions & 0 deletions e2e/08-autofix/contracts/no-console/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": "error"
}
}
37 changes: 37 additions & 0 deletions e2e/08-autofix/contracts/no-console/Foo1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pragma solidity 0.8.0;

import 'hardhat/console.sol';
import 'forge-std/console.sol';
import 'forge-std/console2.sol';
import 'forge-std/xxxxx.sol';

contract Foo1 {
Console[] public consoleTest;
Console[] public console;

struct Console {
uint256 one;
uint256 two;
}

function a() public {
console.log('test');
// comment
console.logString('test logString');
uint256 declaration;
console.logBytes12('test logBytes12');
}

function b() public {
console2.log('test console 2');
// comment
console.logString('test logString');
uint256 declaration;
console.logBytes12('test');
}

function c() external {
consoleTest.push(0, 0);
console.push = (1, 1);
}
}
37 changes: 37 additions & 0 deletions e2e/08-autofix/contracts/no-console/Foo1AfterFix.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pragma solidity 0.8.0;




import 'forge-std/xxxxx.sol';

contract Foo1 {
Console[] public consoleTest;
Console[] public console;

struct Console {
uint256 one;
uint256 two;
}

function a() public {

// comment

uint256 declaration;

}

function b() public {

// comment

uint256 declaration;

}

function c() external {
consoleTest.push(0, 0);
console.push = (1, 1);
}
}
Loading

0 comments on commit bd6c675

Please sign in to comment.